Skip to content

fix(google): close realtime output streams on generation_complete#6431

Merged
longcw merged 1 commit into
mainfrom
longc/gemini-audio-segment-end
Jul 17, 2026
Merged

fix(google): close realtime output streams on generation_complete#6431
longcw merged 1 commit into
mainfrom
longc/gemini-audio-segment-end

Conversation

@longcw

@longcw longcw commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Gemini's realtime API delays turn_complete until it estimates client-side playback has finished, so ending the response on turn_complete made AudioSegmentEnd (and the finalized transcript) arrive several seconds after the last audio chunk. This closes the audio and text streams on generation_complete instead, matching the OpenAI realtime behavior. Full finalization (input transcription, metrics) still waits for turn_complete, and any audio/text received after generation_complete is dropped with a warning.

Fixes #6421 and #5821 (comment)

Gemini delays turn_complete until it estimates client-side playback has finished, so ending the response on turn_complete made AudioSegmentEnd and the finalized transcript arrive seconds after the last audio chunk. Close the audio and text streams on generation_complete instead, matching OpenAI. Finalization still waits for turn_complete; late audio/text is dropped with a warning.

Fixes #6421
@longcw
longcw requested a review from a team as a code owner July 15, 2026 07:42

@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 potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@3DRX

3DRX commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

I tested this, it's working great now.

@longcw
longcw merged commit af38b94 into main Jul 17, 2026
26 checks passed
@longcw
longcw deleted the longc/gemini-audio-segment-end branch July 17, 2026 05:44
ronanmcnulty pushed a commit to GreyhoundRecyclingIreland/agents that referenced this pull request Jul 23, 2026
Routine + handled on our deployment: post-completion re-emissions are dropped
by design (livekit#6431/livekit#6481) and the worker's capture wrap folds the text into the
stored transcript before this handler runs. The WARNING paged Rollbar on
essentially every Gemini call (cai items livekit#1543/livekit#1544, livekit#1606/livekit#1607).
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.

google.realtime.RealtimeModel sends AudioSegmentEnd too late

3 participants