fix(openai): prevent early channel close causing lost transcripts#1176
fix(openai): prevent early channel close causing lost transcripts#1176TanmayChaurasia24 wants to merge 2 commits intolivekit:mainfrom
Conversation
|
|
@TanmayChaurasia24 I tried on my end but couldn't reproduce the scenario you mentioned. Could you make a short demo on that? Or if there's any logs that would be super helpful! |
|
@toubatbrian, thanks for taking a look! As I mentioned in the PR description, I don't currently have an active OpenAI API key to record a live demo of the gpt-realtime-1.5 model. Specifically, response.output_item.done is firing before the final response.output_audio_transcript.delta chunks are emitted. In the current code, handleResponseOutputItemDone closes the channels immediately, causing those trailing chunks to be dropped. If you have a test environment, you can verify this by logging the arrival order of those two events. My fix ensures the channels stay open until the final handleResponseDone sweep. |
Summary
This PR fixes a critical bug where
gpt-realtime-1.5mostly loses transcript events and stops speaking prematurely instead of continuing autonomously.Why this happens
In the new
gpt-realtime-1.5model, OpenAI changed the event streaming lifecycle. The model now often fires theresponse.output_item.doneevent before it finishes asynchronously sending allresponse.output_audio_transcript.deltachunks.Because handleResponseOutputItemDone was aggressively closing
itemGeneration.textChannelandaudioChannel, any transcript chunks that arrived even a millisecond later were bouncing off a closed channel and getting completely lost.Changes
textChannel.close()andaudioChannel.close()from handleResponseOutputItemDone.Note: As this is my first contribution, I don't currently have an active OpenAI API key to run a live connection test to
gpt-realtime-1.5locally. However, this perfectly mirrors the reported issue logic. Could a maintainer run a quick live agent test to verify?Fixes #1133