Skip to content

fix: close temporary speech stream adapters - #2449

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
lyricist-lone-spooking
Open

rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
lyricist-lone-spooking

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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 skipped
  • pnpm --filter @livekit/agents build: passed
  • pnpm --filter @livekit/agents typecheck: passed
  • pnpm --filter @livekit/agents lint: run, but blocked by pre-existing repository-wide Prettier errors in unrelated code; changed-file lint reported no new errors
  • cue-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 run
Source diff coverage
  • Ported: 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 in agents/src/stt/stream_adapter.ts, which now detaches provider metrics/error listeners without closing the configured provider.
  • Ported: 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.
  • Adapted: 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.
  • Adapted: tests/test_agent_stt_node.py -> agents/src/voice/agent.test.ts. Uses Vitest and ReadableStream.cancel() to exercise the equivalent JS node lifecycle and verifies listener count returns to baseline without closing the provider.
  • Adapted: 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.
  • Ported: tests/test_stt_fallback.py -> agents/src/stt/fallback_adapter.test.ts. Verifies fallback-owned adapters are closed while the configured STT remains open.
  • Ported: 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.
  • Not applicable: none.

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

please investigate AGT-3451

yes, let's close that temp wrapper and create a draft PR

we don't have to do this for stt fallback adapter?

@rosetta-livekit-bot
rosetta-livekit-bot Bot requested a review from a team as a code owner September 8, 2026 09:55
@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b42bb43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 38 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants