fix: close temporary speech stream adapters - #2449
Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
rosetta-livekit-bot[bot] wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: b42bb43 The changes in this PR will be included in the next version bump. This PR includes changesets to release 38 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 |
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.
Ports livekit/agents#7154 so owner-created speech stream adapters release provider listeners when their pipeline or fallback lifecycle ends. Configured STT/TTS providers remain reusable.
The target lacked listener-detaching cleanup on the STT stream adapter, so that infrastructure is included here. Cleanup also covers setup failures, unavailable fallback providers, blocked synthesis, cancellation, and normal completion.
Validation
pnpm test agents: 151 files passed, 2498 tests passed, 5 skippedpnpm --filter @livekit/agents build: passedpnpm --filter @livekit/agents typecheck: passedpnpm --filter @livekit/agents lint: run, but blocked by pre-existing repository-wide Prettier errors in unrelated code; changed-file lint reported no new errorscue-cli: attempted with a built non-streaming TTS agent, but worker registration was rejected by the configured LiveKit server with HTTP 401, so framework-event validation could not runSource diff coverage
livekit-agents/livekit/agents/stt/fallback_adapter.py->agents/src/stt/fallback_adapter.ts. Tracks and closes only automatically created STT stream adapters. The target prerequisite missing from Python was added inagents/src/stt/stream_adapter.ts, which now detaches provider metrics/error listeners without closing the configured provider.livekit-agents/livekit/agents/tts/fallback_adapter.py->agents/src/tts/fallback_adapter.ts. Closes each temporary non-streaming TTS wrapper after success, fallback, failure, or cancellation; unavailable providers are skipped before wrapper creation.livekit-agents/livekit/agents/voice/agent.py->agents/src/voice/agent.ts. Uses Web Streams cleanup hooks and awaits adapter closure before signaling completion. The target already had TTS adapter cleanup, which was hardened for deterministic completion and setup failures; STT cleanup was added.tests/test_agent_stt_node.py->agents/src/voice/agent.test.ts. Uses Vitest andReadableStream.cancel()to exercise the equivalent JS node lifecycle and verifies listener count returns to baseline without closing the provider.tests/test_agent_tts_node.py->agents/src/voice/agent.test.ts. Ports success, synthesis failure, and cancellation coverage using target Web Stream fakes and listener-count assertions.tests/test_stt_fallback.py->agents/src/stt/fallback_adapter.test.ts. Verifies fallback-owned adapters are closed while the configured STT remains open.tests/test_tts_fallback.py->agents/src/tts/fallback_adapter.test.ts. Ports repeated success, failure/fallback, recovery lifecycle, and blocked cancellation listener cleanup coverage.Ported from livekit/agents#7154
Original PR description
Automatic stream adaptation retained wrappers through their providers' metrics listener sets. Close owner-created wrappers when their turn, activity, or fallback lifecycle ends. Listener counts now return to baseline after success, failure, recovery, cancellation, and fallback shutdown. Configured providers remain reusable.
Addresses AGT-3451
Initial prompt and agent context
Model: GPT-5.6