Skip to content

fix(elevenlabs): enforce TTS WebSocket context limit - #2314

Open
swayamg20 wants to merge 1 commit into
livekit:mainfrom
swayamg20:fix/1985-elevenlabs-context-cap
Open

fix(elevenlabs): enforce TTS WebSocket context limit#2314
swayamg20 wants to merge 1 commit into
livekit:mainfrom
swayamg20:fix/1985-elevenlabs-context-cap

Conversation

@swayamg20

Copy link
Copy Markdown

Description

Fixes #1985.

Rapid interruptions could enqueue a replacement ElevenLabs TTS context before the provider finalized an interrupted one. Because ElevenLabs allows up to five concurrent contexts, a sixth context could trigger max_active_conversations and reset the shared socket.

Changes Made

  • Track active and closing contexts and defer new-context admission until ElevenLabs finalizes a previous context.
  • Prioritize cancellation cleanup, remove queued content for interrupted streams, and prevent text from being sent after close_context.
  • Preserve per-context ordering and graceful flush-before-close behavior.
  • Add regression coverage for rapid interruptions at the five-context limit, cancellation before startup, and graceful stream closure.
  • Add a patch changeset for @livekit/agents-plugin-elevenlabs.

Pre-Review Checklist

  • Build passes: Build, lint, typecheck, formatting, throws, and scoped API checks pass locally on Node 24.
  • AI-generated code reviewed: Removed unnecessary comments and reviewed the changes for correctness and code quality.
  • Changes explained: Changes and their purpose are documented above.
  • Scope appropriate: The three changed files are limited to the ElevenLabs fix, tests, and changeset.
  • Video demo: Not applicable; this is WebSocket lifecycle logic covered by deterministic local-server tests.

Testing

  • Automated tests added and updated.
  • pnpm test plugins/elevenlabs/src/tts.test.ts --silent — 10 passed, 1 credential-gated test skipped on Node 24.
  • pnpm build
  • pnpm lint
  • pnpm typecheck
  • pnpm throws:check
  • pnpm format:check
  • pnpm --filter @livekit/agents-plugin-elevenlabs api:check
  • restaurant_agent.ts and realtime_agent.ts are not applicable to this internal provider scheduling fix.

Additional Notes

The full monorepo suite was also exercised: 186 test files passed. The remaining failures were unrelated environment-dependent credential, network, and LFS cases plus an existing FishAudio test; the focused ElevenLabs suite passes.

@swayamg20
swayamg20 requested a review from a team as a code owner August 21, 2026 14:19
@changeset-bot

changeset-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dc921fd

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

This PR includes changesets to release 39 packages
Name Type
@livekit/agents-plugin-elevenlabs Patch
@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-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra 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-plugin-trugen Patch
@livekit/agents-plugin-xai Patch
@livekit/agents-plugins-test 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.

Open in 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.

elevenlabs plugin: rapid supersedes exhaust the 5-context WebSocket cap (max_active_conversations) + teardown instability

1 participant