fix: preserve messages after compaction split, keep busy follow-ups as separate turns#43067
Conversation
|
Verification comment — reviewed the diff (3 files, +113/-74 lines). The compression-split message-loss fix is well-designed:
One observation: the Overall: clean fix for a real data-loss bug. LGTM. ✅ |
…lush cursor Three-layer fix for post-compaction message persistence loss: 1. After compress_context() rotates to a child session, mark the next flush to ignore the stale conversation_history offset. The flush method consumes this flag once, writing the full compressed child transcript from index 0. 2. Clamp the cached SessionDB flush cursor when it exceeds actual DB row count (stale gateway AIAgent instances retaining a longer pre-compaction index). Compares against canonical DB rows before clamping to preserve duplicate-write protection. 3. Gateway-side fallback: after each agent turn, verify the assistant response was actually persisted to SessionDB. If the DB tail does not contain the current turn, mirror it directly (skip_db=False), preventing silent assistant message loss. Also routes busy-mode text follow-ups through FIFO queue instead of newline-merging, preserving separate user turns. Closes NousResearch#43066
ffaf12e to
e0bf7d3
Compare
|
Verification review — compaction persistence, no issues found. The |
Summary
Fixes #43066 — assistant messages lost after context compaction, and user follow-ups merged into single turns.
Root Cause
Three related persistence failures:
Stale offset after compression split — compress_context() rotates to a child session but _flush_messages_to_session_db still computes start_idx from the pre-compression history length, making messages[start_idx:] empty.
Stale flush cursor on cached gateway agents — A long-lived gateway AIAgent retains _last_flushed_db_idx from a longer transcript. After compaction shortens the DB, the cursor exceeds actual row count and subsequent flushes skip all new messages.
No gateway-side verification — When agent_persisted=True, the gateway skips its own DB writes. If the agent flush silently fails, assistant messages are delivered but never persisted.
Fix
Tests
All 183 targeted tests pass.