fix(live): resolve Protocol 1007 collisions during active audio sessions#5097
Open
jordac wants to merge 2 commits intogoogle:mainfrom
Open
fix(live): resolve Protocol 1007 collisions during active audio sessions#5097jordac wants to merge 2 commits intogoogle:mainfrom
jordac wants to merge 2 commits intogoogle:mainfrom
Conversation
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
I noticed while experimenting with the 3.1 live api + ADK that the websockets were disconnecting and I couldn't maintain a connection to the adk after trying on 2.0.2a and 1.27 and some debugging identified where the issue was occurring. I had no problems when using the gemini genai api directly so it must be ADK? So I dug into the issue and patched it to get my use-case going (yay). While i was drafting this PR I saw the recent contribution to the main branch, (commit
80828936closing#5018) successfully fixing the path for text-routing strictness for the3.1API endpoint. My findings where that whenever bidirectional audio is enabled by the live content config (needed for newer models), attempting to transport text was causing the 1007 error. So sending text before the audio instantly triggered 1007 collisions.Solution:
To resolve this websocket connectivity issue, this PR adds on to the changes in
80828936:_audio_activeboolean initialized directly fromlive_config.response_modalitiesso that GeminiLlmConnection more defensively routes media blobs during what it considers audio only sessions.send_realtime_input()during any active audio scenario, preventing session corruption (those 1007's).isinstance(..., str)evaluations to eliminate generic truthiness exceptions.Testing Plan
Unit Tests:
Please include a summary of passed
pytestresults.Executed full local
pytestsuite ensuring 100% downstream passing output organically (75 passed).test_gemini_llm_connection.pyto evaluate dynamic routing paths for explicit audio logic execution natively.media=routing fallback conditional pathway.Manual End-to-End (E2E) Tests:
Verified via custom hardware/PyAudio ingestion script tracking active Live API routing manually against the
gemini-3.1-flash-live-previewengine.send_realtime_inputmitigating the session closures entirely.I've run successful e2e testing confirming payloads/messages successfully in an isolated test for iterating on the fix and also as part of a seperate project the instantiates the ADK for a usecase.
Checklist
Additional context
This PR builds directly on top of the recent upstream merges (specifically commit
80828936closing#5018) that introducedsend_realtime_input()routing for Gemini 3.1 Flash Live, ensuring complete multiplexing compatibility uniformly across the ADK surface.cc @wuliang229 — Thanks for getting this fix out, this is gonna to enable some cool use-cases. I was about to share my changes in a PR for the 1007 collision errors but saw you had just pushed a fix, so I incorporated your changes generalizing them slightly, into my branch, my changes do some extra type checking and leverage the LiveContentConfig.response_modalities as a deterministic logic gate. Doing that shifts the responsbility more towards whoever is invoking it upstream, if there is a different approach planned, I can go ahead and close this PR. Thanks for reading.