ITADN

Gemini 3.1 (gemini-3.1-flash-live-preview): sessions die after ~10 min — plugin re-seeds chat ctx via send_client_content on reconnect → infinite 1007 storm

#5985Openacrdlph 创建于 2026-06-05
A
acrdlphcommented
## Summary Any realtime session using `gemini-3.1-flash-live-preview` that lasts past the Gemini Live ~10-minute connection lifetime enters an infinite reconnect loop of `google.genai.errors.APIError: 1007 ... Request contains an invalid argument` and the session dies (~9 minutes in practice). ## Versions - `livekit-agents` 1.5.1 - `livekit-plugins-google` 1.5.1 - `google-genai` 1.67.0 ## Root cause On every (re)connect, `RealtimeSession._main_task` re-seeds the accumulated chat context via `session.send_client_content(...)` (`livekit/plugins/google/realtime/realtime_api.py`, ~L791–825). Gemini 3.1 rejects `send_client_content` after the first model turn with a `1007` error (already noted in the [Gemini 3.1 compatibility docs](https://docs.livekit.io/agents/models/realtime/plugins/gemini/#gemini-3-1-compatibility)). When the server sends `GoAway` at the connection-lifetime boundary, the plugin reconnects and re-seeds → `1007` → retry → reconnect → re-seed → infinite storm. Crucially, session resumption is already enabled unconditionally — `_build_connect_config` always sends `session_resumption=SessionResumptionConfig(handle=self._session_resumption_handle)` — so on reconnect the server **already** restores conversation context server-side. The `send_client_content` re-seed on reconnect is therefore redundant *and* fatal for 3.1. ## Reproduction 1. Start an `AgentSession` with `llm=google.realtime.RealtimeModel(model="gemini-3.1-flash-live-preview", ...)`. 2. Keep the session active for >10 minutes (past one `GoAway`). 3. Observe the repeating `1007 ... Request contains an invalid argument` immediately after each `connecting to Gemini Realtime API...`, until the session is torn down. ``` google.genai.errors.APIError: 1007 None. Request contains an invalid argument. ... File ".../livekit/plugins/google/realtime/realtime_api.py", line 953, in _recv_task async for response in session.receive(): File ".../google/genai/live.py", line 545, in _receive errors.APIError.raise_error(code, reason, None) ``` ## Suggested fix Skip the chat-context re-seed when a resumption handle already exists (i.e. only seed on the initial connect), and rely on session resumption to restore context on reconnect: ```python # in _main_task, where the initial chat ctx is sent: if turns_dict and self._session_resumption_handle is None: turns = [types.Content.model_validate(turn) for turn in turns_dict] await session.send_client_content(turns=turns, turn_complete=False) # else: a resumption handle exists -> reconnect; the server restores context # server-side, so re-seeding here is redundant and triggers the 3.1 1007. ``` We're running this gate in production with `gemini-3.1-flash-live-preview` and it resolves the crash, with conversation memory preserved across the reconnect (verified by asking the model to recall a fact stated before the ~10-min boundary). Happy to open a PR if useful. ## Docs gap The "Gemini 3.1 compatibility" page frames the limitations as mid-session feature restrictions (`update_instructions()` / `generate_reply()` ignored). It doesn't state the larger impact: **sessions longer than ~10 minutes are currently impossible without patching the plugin.** Worth calling out the long-session/reconnect failure and the ~10-minute connection-lifetime boundary explicitly. (Filed separately via the docs feedback channel as well.)
0 条评论