Skip to content

fix(google): finalize realtime generation when turn_complete is missing#4979

Open
3DRX wants to merge 1 commit intolivekit:mainfrom
3DRX:fix/google_realtime_turn_complete
Open

fix(google): finalize realtime generation when turn_complete is missing#4979
3DRX wants to merge 1 commit intolivekit:mainfrom
3DRX:fix/google_realtime_turn_complete

Conversation

@3DRX
Copy link

@3DRX 3DRX commented Mar 2, 2026

Problem

Some Gemini Live responses emit generation_complete but never emit turn_complete.
When that happens, RealtimeSession does not call _mark_current_generation_done(), so:

  • generation channels can stay open longer than expected,
  • downstream audio pipelines may not flush promptly,
  • integrations that rely on end-of-segment signaling can truncate final playback.

What this changes

  • Add TURN_COMPLETE_FALLBACK_SECONDS = 1.0.
  • When generation_complete=True and turn_complete=False, schedule a fallback task that finalizes the active generation for that response_id.
  • Cancel that fallback task on:
    • normal turn_complete completion,
    • generation replacement (_start_new_generation),
    • session shutdown (aclose),
    • explicit generation finalization (_mark_current_generation_done).

What this doesn't change

  • Normal behavior is unchanged when turn_complete arrives.
  • The fallback only applies to the non-standard/missing-event case.
  • Response ID checks prevent finalizing a newer generation by mistake.

Tests

Added tests/test_plugin_google_realtime.py with coverage for:

  • scheduling fallback on generation_complete without turn_complete,
  • immediate finalization on turn_complete,
  • fallback finalization path closing generation channels.

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

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

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 4 additional findings.

Open in Devin Review

@3DRX 3DRX force-pushed the fix/google_realtime_turn_complete branch from 73b533f to 8c4e41e Compare March 4, 2026 06:11
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.

2 participants