fix(google): fail generate_reply when the server ends the turn without a reply - #6713
Open
biztex wants to merge 2 commits into
Open
fix(google): fail generate_reply when the server ends the turn without a reply#6713biztex wants to merge 2 commits into
biztex wants to merge 2 commits into
Conversation
…t a reply a turn the server rejects outright - a malformed function call, a rejected response - never creates a generation, and the pending generate_reply future is only ever resolved by generation_created. The caller sat through the full 5s timeout for an outcome the server had already reported in a fraction of a second, which lands as dead air on top of a failure. The turn ending with no generation now fails that future straight away, carrying the reason the server gave.
…ng generation _current_generation is never cleared, so keying the failure off the "no generation" branch made it unreachable from the second reply of a call onwards - the reported case, an abort mid-conversation, was untouched. It now settles on turn_complete itself: the pending future is cleared as soon as a generation is created for it, so one still parked there means the server ended the turn without producing anything. A tool-rejection drain also ends with turn_complete but its reply is still coming, so that path is excluded.
biztex
force-pushed
the
fix/gemini-aborted-turn
branch
from
August 5, 2026 16:36
29be1e9 to
20234c2
Compare
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.
Fixes #6708.
Problem
generate_reply()parks a future that onlygeneration_createdever resolves, backed by a 5s timeout. When the server ends a turn without generating anything —turn_complete_reason=MALFORMED_FUNCTION_CALL, or a rejected response — no generation is created, so_handle_server_contenttakes itsif not current_gen:early return and nothing settles the future.The caller then waits out the full five seconds for an outcome the server reported in ~250ms. @luce98 measured it: 12 aborts, 12 timeouts, 1:1, with the failure arriving instantly each time. That's five seconds of dead air stacked on top of a failure.
turn_complete_reasonis never read anywhere in the plugin today.Fix
When a turn completes with no generation in flight, the pending
generate_replyfuture is failed immediately, carrying the reason the server gave:The caller gets a
RealtimeErroras soon as the abort lands rather than at the timeout, and the reason is in the message and the log rather than being dropped.Deliberately narrow: only
turn_completesettles it, and only when there is no current generation. A turn that produced a generation is untouched, and a stray frame mid-request can't fail a live call.Verification
tests/test_plugin_google_realtime.py:turn_completecarryingMALFORMED_FUNCTION_CALLfails the pending future at once, with the reason in the error — fails onmain, where the future is still pendingturn_completewith no reason still fails the caller rather than stranding itturn_completeleaves a live request aloneruff format --check,ruff checkandmypy -p livekit.plugins.googlepass locally.