Repository navigation
Description
Part of #3705. Found by the #3710 Phase A check of the protocol against real Google (results).
Context
Done (drainAndStop) sends audioStreamEnd. It then waits until a final arrives with finished: true or turnComplete: true, or until GEMINI_DRAIN_MS (3 s) passes (receive, packages/ui-react/src/voice/asr-gemini.ts:244; the timer is at packages/ui-react/src/voice/asr-gemini.ts:153). The plan describes the same wait (docs/plans/selectable-dictation.md §6, "Done (drainAndStop)").
Measured against models/gemini-3.5-transcribe-live on 2026-11-09 (kit main fb999b8ba):
- Google never sent
finishedorturnComplete, in any of 14 sessions that opened, during an 8 s watch afteraudioStreamEnd. It never closed the socket either. - Each final arrives as a burst:
inputTranscription, thenserverContent.generationComplete: true, thenspeechState: NON_SPEECH. It comes on a pause, or +253 ms afteraudioStreamEndwhen speech was still pending. - With no speech pending (silence, or a final already delivered before Done), nothing at all follows
audioStreamEnd.
So every Done waits the full 3 s, about 2.7 s longer than it needs to. No words are lost.
Scope
- After
audioStreamEndhas been sent, end the drain ongenerationCompleteas well as the existingfinished/turnComplete. - When no speech is pending at
audioStreamEnd, end the drain after a short quiet grace period instead of the full cap. No speech pending means nospeechState: SPEECHsince the lastNON_SPEECH, and no interim since the last final. - Any
SPEECHor interim during that grace period switches to waiting forgenerationComplete. - Keep
GEMINI_DRAIN_MSas the upper bound. - Update the plan's Done description and its "still unproven" list with the measured behavior.
Out of scope
Language hints (separate issue). Changing the 3 s cap. Session resumption. Deepgram or browser drains. Any vendor-key test.
Acceptance criteria
- A drain with an interim pending resolves on the first
generationCompletereceived afteraudioStreamEnd, with the final committed. A unit test proves it and fails on the tree before the change. - A
generationCompletereceived beforeaudioStreamEndis sent does not end the drain: the tail can still be flushing. A test proves it. - A drain with nothing pending resolves within the grace period, and speech or an interim arriving inside the grace period extends it to
generationComplete. Tests prove both. - The cap still resolves at
GEMINI_DRAIN_MSwhen Google stays silent, and the teardown assertions are unchanged. - A mutation receipt for each new guard is recorded in the PR.
- Plan §2 and §6 state the measured end-of-stream behavior.
Verification
bun run test packages/ui-react/tests/asr-gemini.test.ts, plus the existing browser dictation suites. A real-device timing check is part of #3710 Phase B.
Contract impact
None. Internal client behavior; no API, schema or --json shape.
Activity
schlessera commentedon Nov 9, 2026
Claimed (token
claim-1794216672-25469). Branchfix/3768-gemini-drain-language, which fixes #3768 and #3769 in one PR. Collisions: none on these paths, only closure-level overlap with older draft PRs.