fix: re-seed Gemini Live context on reconnect without session resumption

This commit is contained in:
denxxs
2026-04-18 01:14:05 +05:30
parent c5c18335fd
commit 928ade993b
2 changed files with 18 additions and 6 deletions

3
changelog/9999.fixed.md Normal file
View File

@@ -0,0 +1,3 @@
Fixed Gemini Live losing conversation history on WebSocket reconnect. When the session
reconnects (e.g. on system instruction change), conversation history is now re-seeded
into the new session before it is marked ready for input.

View File

@@ -1363,12 +1363,21 @@ class GeminiLiveLLMService(LLMService):
self._ready_for_realtime_input = True self._ready_for_realtime_input = True
elif self._context: elif self._context:
# Reconnect without session resumption (e.g. error occurred # Reconnect without session resumption (e.g. error occurred
# before server sent a resumption handle). # before server sent a resumption handle): re-seed conversation
# TODO: ideally we'd re-send conversation history here via # history so the new session retains full context before
# _create_initial_response(), but that currently doesn't handle # accepting input.
# the reconnect case properly. This should be very rare — the try:
# connection would have to drop before we've received our first adapter = self.get_llm_adapter()
# session_resumption_handle from the server. messages = adapter.get_llm_invocation_params(self._context).get("messages", [])
if messages:
logger.info(
f"Re-seeding {len(messages)} conversation turns after reconnect"
)
await self._session.send_client_content(
turns=messages, turn_complete=False
)
except Exception as e:
logger.error(f"Failed to re-seed conversation on reconnect: {e}")
self._ready_for_realtime_input = True self._ready_for_realtime_input = True
else: else:
# Initial connection: session is ready before context has # Initial connection: session is ready before context has