Fix Gemini Live session resumption hanging after reconnect
After a reconnect, _ready_for_realtime_input was never set back to True because _create_initial_response (which sets the flag) is only called on initial connection. This caused all audio/video/text to be silently dropped after reconnecting, making the bot appear to hang. Set the flag in _handle_session_ready when we detect a reconnect, either via session_resumption_handle (server restores state) or via existing context (rare case where connection drops before first resumption handle).
This commit is contained in:
1
changelog/4242.fixed.md
Normal file
1
changelog/4242.fixed.md
Normal file
@@ -0,0 +1 @@
|
||||
- Fixed Gemini Live bot hanging after a session resumption reconnect. Audio, video, and text input were silently dropped after reconnecting because the internal `_ready_for_realtime_input` flag was not being reset.
|
||||
@@ -1355,14 +1355,28 @@ class GeminiLiveLLMService(LLMService):
|
||||
async def _handle_session_ready(self, session: AsyncSession):
|
||||
"""Handle the session being ready."""
|
||||
self._session = session
|
||||
# If we were just waititng for the session to be ready to run the LLM,
|
||||
# do that now.
|
||||
if self._run_llm_when_session_ready:
|
||||
# Initial connection: context arrived before session was ready.
|
||||
self._run_llm_when_session_ready = False
|
||||
await self._create_initial_response()
|
||||
elif self._context:
|
||||
# Reconnect case: context already exists, no need for _create_initial_response
|
||||
elif self._session_resumption_handle:
|
||||
# Reconnect with session resumption: the server will restore
|
||||
# session state, so we can accept realtime input right away.
|
||||
self._ready_for_realtime_input = True
|
||||
elif self._context:
|
||||
# Reconnect without session resumption (e.g. error occurred
|
||||
# before server sent a resumption handle).
|
||||
# TODO: ideally we'd re-send conversation history here via
|
||||
# _create_initial_response(), but that currently doesn't handle
|
||||
# the reconnect case properly. This should be very rare — the
|
||||
# connection would have to drop before we've received our first
|
||||
# session_resumption_handle from the server.
|
||||
self._ready_for_realtime_input = True
|
||||
else:
|
||||
# Initial connection: session is ready before context has
|
||||
# arrived. Nothing to do — _handle_context will call
|
||||
# _create_initial_response when the context arrives.
|
||||
pass
|
||||
|
||||
async def _handle_msg_model_turn(self, msg: LiveServerMessage):
|
||||
"""Handle the model turn message."""
|
||||
|
||||
Reference in New Issue
Block a user