fix: handle APIError code 1000 in _receive_from_model for google-genai >= 1.62.0#4911
fix: handle APIError code 1000 in _receive_from_model for google-genai >= 1.62.0#4911TonyLee-AI wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @TonyLee-AI, thank you for creating this PR! It looks like you haven't signed the Contributor License Agreement (CLA) yet. Please visit https://cla.developers.google.com/ to sign the agreement. Also, for bug fixes like this one, our contribution guidelines require an associated GitHub issue. If one doesn't exist, could you please create one and link it to this PR? This information will help reviewers to review your PR more efficiently. Thanks! |
…i >= 1.62.0 google-genai >= 1.62.0 changed live.py to catch ConnectionClosedOK inside _receive() and re-raise it as APIError(code=1000). Because APIError is not a subclass of ConnectionClosedOK, it bypassed the existing `except ConnectionClosedOK: pass` handler in _receive_from_model and propagated to run_live()'s generic `except Exception` handler, which logged it as an unexpected error even though WebSocket close code 1000 (RFC 6455 Normal Closure) indicates a clean session end. Fix: catch APIError in _receive_from_model and treat code 1000 the same as ConnectionClosedOK — silently discard it. Any other APIError code is re-raised as before.
b731b2e to
1af6892
Compare
Problem
google-genai >= 1.62.0changedlive.pyto catchConnectionClosedOKinside_receive()and re-raise it asAPIError(code=1000).Because
APIErroris not a subclass ofConnectionClosedOK, it bypassed the existing handler in_receive_from_model:It then propagated to
run_live()'s genericexcept Exceptionhandler, which logged it as an unexpected error — even though WebSocket close code 1000 (RFC 6455 Normal Closure) indicates a clean, intentional session end.With
google-genai == 1.61.0(which did not perform this conversion), the behaviour was silent and correct.Fix
Catch
APIErrorin_receive_from_modeland treat code1000the same asConnectionClosedOK— silently discard it. Any otherAPIErrorcode is re-raised unchanged.Logs
Before (
google-genai==1.68.0, unpatched) — triggered on every normal session close (e.g. call transfer):After (
google-genai==1.68.0, patched) — no error log on normal session close. The session ends silently as intended.Testing plan
tests/unittests/flows/llm_flows/test_base_llm_flow_connection_close.pywith 3 unit tests:test_receive_from_model_connection_closed_ok_is_silent— existing behaviour unchangedtest_receive_from_model_api_error_1000_is_silent— new:APIError(1000)is swallowedtest_receive_from_model_api_error_non_1000_is_raised— non-1000 codes still propagategoogle-genai==1.68.0+google-adk==1.27.2that normal session close (call transfer, hang-up) no longer producesERROR: An unexpected error occurred in live flow: 1000 None.