You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In long-running sessions, assistant responses are generated by the model (response_len > 0, finish_reason=stop) but never persisted to state.db. User messages are persisted (by the gateway), but assistant responses silently disappear. The model doesn't see its own previous responses and repeats the same answer indefinitely.
Root Cause
In _flush_messages_to_session_db (run_agent.py:~1562):
conversation_history is loaded from state.db by the gateway and contains all stored messages (e.g., 347).
messages starts as a copy of conversation_history, then repair_message_sequence removes stray tool results and merges consecutive user messages. After repair, messages is shorter (e.g., 303).
The bug: start_idx = len(conversation_history) = 347, but len(messages) = 306 (after repair + new assistant + tool). messages[347:] is an empty slice. Nothing is flushed.
This happens every turn — assistant responses are never persisted, the model never sees its own answers, and it repeats the same content indefinitely.
Reproduction
Start a long session where consecutive user messages accumulate (background process notifications, system notes, user multi-messages)
Let the agent run several turns
Check state.db: user messages will be present, but assistant responses after a certain point will be missing
The model will start repeating itself because it doesn't see its previous responses
9 subsequent turns (03:35–04:48) all completed with response_len > 0
Assistant count remained at 161 — none were persisted
Violations grew 43→51 (consecutive user messages from background notifications)
Fix
Remove conversation_history from the flush cursor calculation. Use _last_flushed_db_idx as the sole cursor:
# Before (buggy):start_idx=len(conversation_history) ifconversation_historyelse0flush_from=max(start_idx, self._last_flushed_db_idx)
# After (fixed):flush_from=self._last_flushed_db_idx
_last_flushed_db_idx is always ≤ len(messages) because it's set to len(messages) after each flush. It correctly tracks what's been persisted regardless of repair-induced length changes.
Additional context
Not related to LCM compression. Consecutive user messages that trigger the repair come from background process notifications, system notes, and user multi-messages — not from LCM.
Debug logging added:FLUSH SKIP / FLUSH log lines in _flush_messages_to_session_db to diagnose future persistence issues.
Severity: Critical. In affected sessions, the agent becomes unusable — repeats walls of text, ignores new user requests, because it has no memory of its own responses.
Description
In long-running sessions, assistant responses are generated by the model (
response_len > 0,finish_reason=stop) but never persisted tostate.db. User messages are persisted (by the gateway), but assistant responses silently disappear. The model doesn't see its own previous responses and repeats the same answer indefinitely.Root Cause
In
_flush_messages_to_session_db(run_agent.py:~1562):conversation_historyis loaded fromstate.dbby the gateway and contains all stored messages (e.g., 347).messagesstarts as a copy ofconversation_history, thenrepair_message_sequenceremoves stray tool results and merges consecutive user messages. After repair,messagesis shorter (e.g., 303).The bug:
start_idx = len(conversation_history) = 347, butlen(messages) = 306(after repair + new assistant + tool).messages[347:]is an empty slice. Nothing is flushed.This happens every turn — assistant responses are never persisted, the model never sees its own answers, and it repeats the same content indefinitely.
Reproduction
state.db: user messages will be present, but assistant responses after a certain point will be missingEvidence
Session
20260612_050850_378fa296:response_len > 0Fix
Remove
conversation_historyfrom the flush cursor calculation. Use_last_flushed_db_idxas the sole cursor:_last_flushed_db_idxis always ≤len(messages)because it's set tolen(messages)after each flush. It correctly tracks what's been persisted regardless of repair-induced length changes.Additional context
FLUSH SKIP/FLUSHlog lines in_flush_messages_to_session_dbto diagnose future persistence issues.