Summary
After context compaction (auto or /compress), two defects appear in the new child session:
-
Assistant messages lost — replies the agent delivered between the last compaction boundary and the compaction event are absent from the child session DB. The user sees "compaction summary → their next message" with no agent replies in between.
-
User follow-ups merged into one turn — separate Telegram messages sent while the agent was busy are newline-joined into a single user message, destroying message boundaries visible to the user.
Root Cause
Issue 1: Stale offset after session split
compress_context() rotates to a child session and resets _last_flushed_db_idx = 0. However, _flush_messages_to_session_db computes start_idx = len(conversation_history) using the pre-compression history passed by the gateway/CLI caller. Since the old history is much longer than the compressed child transcript, messages[start_idx:] is empty and nothing gets written to the child session DB.
Issue 2: merge_pending_message_event with merge_text=True
The busy-mode interrupt path called merge_pending_message_event(..., merge_text=True) which joins consecutive text events with \n. The queue-mode path already used FIFO semantics (each message gets its own turn). The interrupt/steer-fallback paths did not.
Impact
- After compaction, the agent has no memory of its own recent replies
- Multiple user messages appear as one block — context and intent are lost
- Particularly visible in Telegram DMs where users send rapid sequential messages
Environment
- Platform: Telegram DM (no topic threads)
- Triggered by both auto-compaction and manual
/compress
- Current HEAD:
02f878e
Summary
After context compaction (auto or
/compress), two defects appear in the new child session:Assistant messages lost — replies the agent delivered between the last compaction boundary and the compaction event are absent from the child session DB. The user sees "compaction summary → their next message" with no agent replies in between.
User follow-ups merged into one turn — separate Telegram messages sent while the agent was busy are newline-joined into a single user message, destroying message boundaries visible to the user.
Root Cause
Issue 1: Stale offset after session split
compress_context()rotates to a child session and resets_last_flushed_db_idx = 0. However,_flush_messages_to_session_dbcomputesstart_idx = len(conversation_history)using the pre-compression history passed by the gateway/CLI caller. Since the old history is much longer than the compressed child transcript,messages[start_idx:]is empty and nothing gets written to the child session DB.Issue 2: merge_pending_message_event with merge_text=True
The busy-mode interrupt path called
merge_pending_message_event(..., merge_text=True)which joins consecutive text events with\n. The queue-mode path already used FIFO semantics (each message gets its own turn). The interrupt/steer-fallback paths did not.Impact
Environment
/compress02f878e