Repository navigation
fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items) - #47172
fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items)#47172tech-carrement wants to merge 10 commits into
Conversation
…tup completes With gemini_live_defer_setup, only audio frames were held until the backend acknowledged the setup. A response.create or conversation.item.create sent right after the synthetic session.created was forwarded between the setup and Gemini's setupComplete, answered with the text "Error: Session is not set up yet" and dropped, so the opening turn was lost. Only the session.update that triggers the setup may pass; every other client frame now waits.
Gemini Live's automaticActivityDetection accepts startOfSpeechSensitivity and endOfSpeechSensitivity, but nothing filled them: a client streaming the microphone continuously saw its sentences cut into fragments by an eager end-of-speech detection. OpenAI has no equivalent, so the client passes them under their Gemini names in snake_case; values outside the enums are dropped.
Gemini Live emits serverContent.interrupted when the user talks over the model; the bridge mapped it only to response.done, which loses the signal a realtime client acts on to flush its playback and cancel the response. The interrupted frame now also emits input_audio_buffer.speech_started, built with the shared speech_event helper, before the response.done.
…geCode Gemini Live picks the spoken language on its own and drifts mid-conversation (a French session answering in English after a few turns). The GA session field audio.output.language now reaches speechConfig.languageCode, next to the voice, on its own when no voice is sent, and even when an OpenAI stock voice name is dropped.
…ation items
Gemini Live has no response.create: it generates whenever a client turn
completes. The bridge therefore dropped response.create, so a client could
not replay a saved history and then ask for one answer: every replayed item
produced a spoken answer, and a bare response.create (no item) never gave the
model the floor.
- conversation.item.create honors turn_complete: false, which appends the turn
to the conversation without asking for a generation
- response.create emits a bare clientContent{turnComplete: true}, Google's
documented way to hand the floor to the model, unless the previous client
frame (an item that completed the turn, or a tool response) already asked for
a generation: standard OpenAI clients that send the item and then
response.create still get exactly one answer
OpenAI's response.done carries the items the response produced; the Gemini Live bridge always sent output: []. Clients that read the function calls or the message items off response.done (instead of collecting every response.output_item.done) saw an empty turn. The bridge now remembers the output_item.done events it emitted since the previous response.done, across frames, and lists them in the next response.done.
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
#39864 merged and reworks the Gemini Live setup in realtime_streaming.py, so fix 1 likely overlaps. Could you merge main and drop what it covers |
BerriAI#39864 holds client content until the first setup and sends it right after the setup; Gemini Live still drops what reaches it before setupComplete, so that content now waits with the other pending frames. The barge-in speech_started is emitted once per open response, ahead of the close events BerriAI#39864 added, and the manual-activity activityEnd counts as the generation request.
The speech config no longer rebinds its dropped-voice flag, the VAD sensitivity tables list their literals instead of get_args (Any), and the duplicated logging import from the merge is gone.
… covers Since BerriAI#39864 the Gemini Live setup goes out with the first content, and a client that sends session.update, an item and response.create back to back is answered 20 times out of 20 against Vertex eu (gemini-3.8-live) on main. The explicit response.create of the transcription-guardrail test now hands the floor to the model, per the response.create fix of this branch.
|
Thanks, merged main ( |
|
Follow-up on fix 1: audio setups win the race on main (the 20/20 above), but Live Avatar (video) setups don't: the first item gets |
…idge-fixes # Conflicts: # litellm/llms/gemini/realtime/transformation.py # tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py
TLDR
Five fixes to the Gemini Live bridge of
/v1/realtime, one commit each, each reviewable on its own. Main was merged in on 21 Nov 2026 (754c2225d7); the original fix 1 (holding client frames until the deferred setup completes) is dropped, because #39864 covers it, see its proof section below. They were opened as separate PRs; this account is capped at five open PRs on the repo, so they are consolidated here (the standalone PRs are closed and point to this one).buffer every client frame until the deferred Gemini setup completes(was fix(realtime): buffer every client frame until the deferred gemini setup completes #47131): dropped, fix(realtime)!: send the Gemini Live setup at the first content so session.update settings apply #39864 covers itb3ffabe019, was feat(gemini): map live start- and end-of-speech sensitivity #47139)automaticActivityDetectionacceptsstartOfSpeechSensitivityandendOfSpeechSensitivity, but nothing in the OpenAI-shapedturn_detectionmapping filled themturn_detection.start_of_speech_sensitivityandturn_detection.end_of_speech_sensitivity(the Gemini names in snake_case, since OpenAI has no equivalent) are forwarded toautomaticActivityDetectionStartOfSpeechSensitivityEnum/EndOfSpeechSensitivityEnumliterals are dropped rather than sent, because Gemini closes the socket on an unknown enum value0ad66deb1d, was feat(gemini/realtime): surface barge-in as input_audio_buffer.speech_started #31709)serverContent.interruptedwhen the user talks over the model; the bridge mapped it only toresponse.doneinput_audio_buffer.speech_startedto flush its playback and cancel the response; without it the model's already-buffered audio keeps playing after the interruptioninterruptedframe now also emitsinput_audio_buffer.speech_started(built with the sharedspeech_eventhelper, carrying the interrupted item id), once per open response and ahead of the events main now sends to close the interrupted item1ec6108d56, was never opened: no slot)audio.output.languagenever reached Gemini Live, sospeechConfig.languageCodewas never set and the model picked the spoken language on its own; on long French sessions it drifted to English after a few turnsaudio.output.languageis normalized likeaudio.output.voiceand forwarded tospeechConfig.languageCoded7238c6bf0, was feat(gemini): honor response.create and turn_complete on live conversation items #47167)response.create: it generates whenever a client turn completes, so the bridge droppedresponse.createentirelyconversation.item.createcompleted a turnconversation.item.createhonorsturn_complete: false, which appends the turn to the conversation without asking for a generationresponse.createemits a bareclientContent{turnComplete: true}, Google's documented way to hand the floor to the model, unless the previous client frame already asked for a generation (an item that completed the turn, or a tool response): standard OpenAI clients that send the item and thenresponse.createstill get exactly one answerd7d64a2f69, was fix(gemini): response.done lists the output items of the live turn #47168)response.donelists the items the response produced (output); the Gemini Live bridge always sentoutput: []response.done, instead of collecting everyresponse.output_item.done, saw an empty turnresponse.output_item.doneevents it emitted since the previousresponse.done, across frames, and lists their items in the nextresponse.doneresponse.doneafter a tool call (an existing special case) is untouched: items that follow it are carried to the next realresponse.doneUser Flow
2. map live start- and end-of-speech sensitivity
Before: a developer tunes
turn_detectiononws://localhost:4000/v1/realtime?model=gemini-livesession.updatewithsilence_duration_msandend_of_speech_sensitivity: END_SENSITIVITY_LOWsilenceDurationMs; the sensitivity is silently lostAfter: the same
session.updatestartOfSpeechSensitivity/endOfSpeechSensitivitynext tosilenceDurationMs3. surface live barge-in as input_audio_buffer.speech_started
Before: a user talks over the assistant on
ws://localhost:4000/v1/realtime?model=gemini-liveresponse.doneAfter: the same interruption
input_audio_buffer.speech_started, flushes its playback and cancels, then the events that close the interrupted item and a single cancelledresponse.done4. forward the output language to live speechConfig.languageCode
Before: a developer sets
audio.output.language: "fr-FR"insession.updateonws://localhost:4000/v1/realtime?model=gemini-livelanguageCode; with an OpenAI voice name it has nospeechConfigat allAfter: the same
session.updatespeechConfig.languageCode: "fr-FR", with or without a voice5. honor response.create and turn_complete on live conversation items
Before: a developer whose opening line lives in the system instruction connects to
ws://localhost:4000/v1/realtime?model=gemini-livesession.updatedthey sendresponse.createAfter: the same
response.createresponse.createstill gets one answer, not two6. response.done lists the output items of the live turn
Before: a developer runs a tool-calling turn on
ws://localhost:4000/v1/realtime?model=gemini-liveresponse.output_item.done, then the spoken answerresponse.doneevents carryoutput: []After: the same turn
response.donelists thefunction_callitem, the second lists themessageitemRelevant issues
Complements #39864 (setup sent with the first content frame) and #46702 (error when a session.update is dropped). Supersedes #47131, #47139, #31709, #47167 and #47168.
Pre-Submission checklist
tests/unitdirectory, Adding at least 1 test is a hard requirementmake test-unitProof of Fix
Every proof below is a live LiteLLM proxy run against
vertex_ai/gemini-3.8-liveineu, before at the merge base and after at the fix. Proofs 2, 4, 5 and 6 were taken in October before main was merged; 1 and 3 were re-measured after the merge.1. dropped: #39864 covers the deferred-setup race
Live LiteLLM proxy on main
754c2225d7(no change from this branch),vertex_ai/gemini-3.8-liveineu,gemini_live_defer_setup: true. Ten sessions per scenario, the question is "What is the capital of France?":session.update,conversation.item.createandresponse.createsent back to backThe branch after the merge gives the same 10/10 and 10/10, so the frame hold is gone from this PR.
2. map live start- and end-of-speech sensitivity
Run on the standalone branch at
c794d231c6; cherry-picked here asb3ffabe019with the same code.The
setup.realtimeInputConfigbuilt byVertexAIRealtimeConfig.transform_realtime_requestfrom the samesession.update(server_vad,silence_duration_ms: 700, both sensitivitiesLOW), run against each tree:Live LiteLLM proxy at the PR tip
c794d231c6,vertex_ai/gemini-3.8-liveineu, real calls, the samesession.updatethen one user text item:Gemini accepted the setup (no 1007) and answered. Unit test:
tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_maps_the_two_vad_sensitivities3. surface live barge-in as input_audio_buffer.speech_started
Run on the standalone branch at
a5de355a7d; cherry-picked here as0ad66deb1dwith the same code.Live LiteLLM proxy,
vertex_ai/gemini-3.8-liveineu, real calls. Client: the model is asked to count slowly from one to twenty; 1.5 s into its answer the client streams 6.3 s of real French speech (16 kHz PCM) over it.Before, merge base
46ae68021e:After, PR tip
a5de355a7d(a 4.7 s utterance this time):After the merge of main, same client on both sides: a long story is requested, 2.5 s into the spoken answer the client streams a 3.3 s spoken interruption (24 kHz PCM produced by Gemini TTS) under server VAD.
Before, main
754c2225d7:After, branch
70d1f63b67:Unit test:
tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_interrupted_emits_speech_started_before_response_done4. forward the output language to live speechConfig.languageCode
Run on the standalone branch at
f27f617aad; cherry-picked here as1ec6108d56with the same code.The
speechConfigbuilt byVertexAIRealtimeConfig.transform_realtime_requestfrom the samesession.update, run against each tree:Live LiteLLM proxy at the PR tip,
vertex_ai/gemini-3.8-liveineu, real calls,session.updatewithaudio.output.language: "fr-FR", voicePuck, then one user text item: Gemini accepted the setup (no 1007) and answeredUnit tests in
tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py:test_gemini_output_language_reaches_speech_config_language_code,test_gemini_output_language_is_kept_without_a_voice,test_gemini_output_language_is_kept_when_an_openai_voice_is_dropped5. honor response.create and turn_complete on live conversation items
Run on the standalone branch at
f7f6939876; cherry-picked here asd7238c6bf0with the same code.Live LiteLLM proxy,
vertex_ai/gemini-3.8-liveineu, real calls. Client: instruction "À ton tout premier tour, dis : « Bonjour, je suis DialogPro. Comment vous appelez-vous ? »", then a bareresponse.createoncesession.updatedarrives.Before, merge base
46ae68021e:After, PR tip
f7f6939876:Standard client (one user item, then
response.create) on the PR tip:response.created=1 response.done=1, no second generation. Unit tests intests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py:test_gemini_response_create_alone_hands_the_floor_to_the_model,test_gemini_response_create_after_a_completed_item_does_not_generate_twice,test_gemini_history_replay_with_turn_complete_false_generates_once,test_gemini_response_create_after_a_tool_response_does_not_generate_twice,test_gemini_response_create_works_again_once_the_turn_completed6. response.done lists the output items of the live turn
Run on the standalone branch at
63c03de617; cherry-picked here asd7d64a2f69with the same code.Live LiteLLM proxy,
vertex_ai/gemini-3.8-liveineu, real calls. Client: aset_usernametool, one user text item ("Je m'appelle Laurent, enregistre mon prénom s'il te plaît.") thenresponse.create; on the function call it answers withfunction_call_outputandresponse.create.Before, merge base
46ae68021e:After, PR tip
63c03de617:The function-call
response.donealready listed its item (built in the tool-call path); the spoken answer'sresponse.donenow lists itsmessageitem instead of[]. Unit test:tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_response_done_lists_the_output_items_of_the_turnType
🐛 Bug Fix (6) and 🆕 New Feature (2, 3, 4, 5)
Caveats
turn_detection; other providers ignore themcreate_response: falseon a model that rejects tuning next todisabled: true, the existing early return applies and the sensitivities are not sentlanguageCodesteers the spoken language, it does not override an instruction written in another language: with an English system prompt the model still answers in Englishresponse.createdoes on Gemini Live, from a no-op to a turn trigger; the guard against double generation covers the item-then-trigger and tool-response-then-trigger sequences, a client that sends two bareresponse.createin a row will trigger twice, as it would on OpenAIturn_completeonconversation.item.createis a Gemini-specific extension of the OpenAI eventFinal Attestation