fix: retry connection pool prewarm after failure - #2378
Merged
Conversation
🦋 Changeset detectedLatest commit: f3559c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
davidzhao
approved these changes
Aug 30, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port livekit/agents#6969 so a settled connection-pool prewarm no longer permanently suppresses later attempts. The target clears the matching prewarm controller when its asynchronous operation settles, allowing retry after failure while preserving in-flight deduplication and close-time cancellation.
Testing
pnpm test agents- 138 files passed, 2291 tests passed, 5 skippedpnpm build- 40/40 tasks passedpnpm lint- 40/40 tasks passed (existing warnings only)pnpm format:check- passedSource diff coverage
Authoritative source: livekit/agents#6969
livekit-agents/livekit/agents/utils/connection_pool.py: adapted toagents/src/connection_pool.ts. The TypeScript pool tracks anAbortControllerinstead of a weak task reference, so the controller is cleared when the corresponding prewarm promise settles. An identity check prevents an older operation from clearing a newer controller after close/restart.tests/test_connection_pool.py: adapted toagents/src/connection_pool.test.ts. The source retry-after-first-failure regression is ported with Vitest and asserts through the target public behavior because the TypeScript prewarm task is private and not returned.Ported from livekit/agents#6969
Original PR description
Summary
ConnectionPool.prewarm()records an in-flight task to suppress duplicate work. When that task completes or fails, the task reference was retained, so later prewarm calls permanently skipped the pool even though no prewarm operation was still running.This change clears the completed task reference before deciding whether to return, allowing a later call to retry after failure or perform a fresh prewarm after completion. The patch is limited to the connection-pool lifecycle and adds a regression for retry-after-failure behavior.
Testing
uv run pytest tests/test_connection_pool.py --unit- 7 passed.uv run ruff check livekit-agents/livekit/agents/utils/connection_pool.py tests/test_connection_pool.py- passed.uv run ruff format --check livekit-agents/livekit/agents/utils/connection_pool.py tests/test_connection_pool.py- passed.make checkformat and lint stages pass on the current head. The repository-wide type stage remains blocked by the existing missingboto3import in the experimental AWS realtime plugin, outside this patch.git diff --check origin/main...HEAD- passed.No external provider, LiveKit server, network credential, or integration account is required for this unit-level lifecycle regression.
The submitted commit is SSH-signed with the configured GitHub signing identity.
Compatibility
This is backward compatible. Successful prewarm behavior is unchanged; failed or completed prewarm tasks can now be retried instead of suppressing all future attempts.