run_live does not retry 1008 "session is already connected to an existing client" when resuming with a session handle
維護者通常 3 天內回覆
評估
這個 Issue 還沒有評估資料。
描述
Describe the bug
When a Live connection drops and ADK reconnects using the session resumption
handle (Vertex AI, SessionResumptionConfig(transparent=True)), the server
sometimes rejects the new connection with close code 1008:
google.genai.errors.APIError: 1008 None. BidiGenerateContent session is already connected to an existing client
ADK reconnects immediately, before Vertex has released the previous socket.
_live_llm_flow.run_live_flow treats only 1000, 1006, 1011 as recoverable, so
the 1008 is re-raised and the whole run_live stream fails. In a phone-call
agent, that ends the call.
The condition is transient: the server releases the old session within about a
second. Other Gemini Live clients report the same error and fix it with backoff
plus a retry. adk-go has a matching change for 1008 in isResumable
(google/adk-go#1993).
To reproduce
- Vertex AI backend (
GOOGLE_GENAI_USE_VERTEXAI=1), a native-audio Live model,
RunConfig(session_resumption=types.SessionResumptionConfig(transparent=True), context_window_compression=...). - Run
runner.run_live(...)long enough for the connection to drop or rotate
(GoAway / network drop) while a resumption handle is held. - Intermittently, ADK's reconnect attempt fails at
llm.connect()with 1008 and
run_liveraises instead of retrying.
Traceback (trimmed)
File ".../google/adk/live/_live_llm_flow.py", line 595, in run_live_flow
async with llm.connect(llm_request) as llm_connection:
File ".../google/adk/models/google_llm.py", line 665, in connect
async with self._live_api_client.aio.live.connect(
File ".../google/genai/live.py", line 1198, in connect
raw_response = await ws.recv(decode=False)
websockets.exceptions.ConnectionClosedError: received 1008 (policy violation)
BidiGenerateContent session is already connected to an existing client
...
google.genai.errors.APIError: 1008 None. BidiGenerateContent session is already
connected to an existing client
The error is raised inside live.connect() while it waits for the setup
response, so this is the reconnect attempt. A first connection has no handle
and cannot collide.
Where
src/google/adk/live/_live_llm_flow.py (2.14.1; same logic on main):
except errors.APIError as e:
...
# Error code 1000, 1006 and 1011 indicates a recoverable connection drop.
if e.code in [1000, 1006, 1011]:
if invocation_context.live_session_resumption_handle and (not client_closed):
...
continue
There is also no delay between reconnect attempts (while True → continue).
Expected behavior
When a resumption handle is held, a 1008 "already connected" on reconnect is
retried with a short backoff (e.g. 0.5 s, 1 s, 2 s), within
DEFAULT_MAX_RECONNECT_ATTEMPTS, instead of failing the stream.
Suggested fix
- Add 1008 to the recoverable codes only for the reconnect path (a handle is
set), ideally matched on the "already connected" reason so other policy
violations still fail fast. - Add exponential backoff before each reconnect attempt (
asyncio.sleep), for all
recoverable codes. Reconnecting instantly is what loses the race. - Make sure the previous connection is fully closed before opening the new one.
Related (smaller)
- A connect-time
TimeoutError("timed out during opening handshake")orOSError
on a reconnect with a handle also escapes as "An unexpected error occurred in
live flow". With a handle held, it could get the same bounded retry. mainalready keeps the last non-empty resumption handle when an update arrives
with an emptynew_handle. In 2.14.x, an empty update overwrites the handle, so
a drop during generation or a tool call cannot be resumed. Could that fix ship in
the next release?
Environment
- google-adk 2.14.0 (live flow identical in 2.14.1)
- google-genai 2.34.0
- websockets 15.0.1
- Python 3.11, Linux (Docker), uvloop
- Backend: Vertex AI Live API,
transparent=Truesession resumption
Workaround
We catch APIError 1008, and connect-time TimeoutError/OSError raised from
the websocket, around runner.run_live ourselves. We then open a fresh
run_live on the same ADK session after a short delay, which reseeds the
history. That works, but it loses server-side resumption and duplicates logic
ADK already has.
- 主要語言
- Python
- 星號
- 22.3k
- 分支
- 4.4k
- 平均合併
- 1 天 2 小時
- 30 天內合併 PR
- 6
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
google/adk-python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
google/adk-python#8360 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
google/adk-python#8359 ·
維護者通常 3 天內回覆
-
Can pin to litellm version be changed?可能已有人在做 @llalitkumarrr 於 10 天前認領。 未關閉models
難度 1/5 1 小時以內 新手友好度 65/100
google/adk-python#8129 · 2 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
OpenAPI tools ignore operation- and path-level server overrides可能已有人在做 @sanketpatil06 於 14 天前認領。 未關閉tools
難度 2/5 1-3 小時 新手友好度 75/100
google/adk-python#8064 · 4 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
Two docstrings in openapi_tool document parameters the signatures do not accept可能已有人在做 @surajksharma07 於 17 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 88/100
google/adk-python#8024 · 1 則留言 · 已指派 1 人 ·
維護者通常 3 天內回覆
查看 google/adk-python 的全部 Issue
相似的 Issue
-
🧫10장-투향
難度 2/5 1-3 小時 新手友好度 65/100
hyunjimoon/golden-cage-book#188 ·
-
agent/scanner bug stage/010-actionable
難度 1/5 1 小時以內 新手友好度 88/100
torch-spyre/spyre-inference#1812 ·
維護者通常 1 天內回覆
-
Bug: fenced drafts inside <think> tags break parsing or are returned instead of the answer可能已有人在做 @aad1tyaaaaa 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
google/langextract#639 ·
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Update autodoc routing docs for relative in-repo lock uses可能已有人在做 @github-actions 今天認領。 未關閉
難度 1/5 1-3 小時 新手友好度 87/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆