fix(elevenlabs): stop routing TTS audio to an interrupted stream - #6936
Open
longcw wants to merge 1 commit into
Open
fix(elevenlabs): stop routing TTS audio to an interrupted stream#6936longcw wants to merge 1 commit into
longcw wants to merge 1 commit into
Conversation
The recv loop routes messages through a context map owned by the shared websocket connection. An interrupted run ended its audio segment but left the context registered, so the audio the server flushes after close_context() was pushed into an emitter with no open segment, killing AudioEmitter._main_task with "start_segment() must be called before pushing audio data". Unregister the stream before ending the segment. The context id stays in _active_contexts so close_context() still releases it server-side.
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.
Problem
The ElevenLabs plugin sends many TTS streams over one websocket, and its recv loop routes each message through a context map owned by the connection.
An interrupted run ends its audio segment, but it leaves the context in that map.
The server still sends the audio that it generated before the close, so those late bytes reach an emitter with no open segment, and
AudioEmitter._main_taskstops withRuntimeError: start_segment() must be called before pushing audio data.Fixes #6929.
Fix
_Connection.unregister_stream()drops the routing entry for a stream, andSynthesizeStream._runcalls it before it ends the segment.The context id stays in
_active_contexts, soclose_context()still asks the server to release the context (#5844).A message for a context that is no longer registered is now normal, so the recv loop logs it at debug level.
A final message still frees the context id, and the drain of an old connection continues to work.