Skip to content

fix(agent): clamp flush cursor after repair_message_sequence compacts messages (#44837)#44870

Closed
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44837
Closed

fix(agent): clamp flush cursor after repair_message_sequence compacts messages (#44837)#44870
kyssta-exe wants to merge 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44837

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

Fixes #44837. repair_message_sequence() merges consecutive user messages in-place, shrinking the messages list. The DB-write cursor (_last_flushed_db_idx) was not clamped after compaction, so the turn-end flush would skip persisting the assistant/tool chain. This fix clamps the cursor after repair and adds a safety guard in _flush_messages_to_session_db.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good defensive fix. Clamps _last_flushed_db_idx after repair_message_sequence() compacts the message list, preventing the turn-end flush from skipping assistant/tool chain that now sits at indices below the stale cursor (#44837). Well-commented. No issues found.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists labels Jun 12, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #44838 (earlier open) — same fix for #44837: clamp the SessionDB flush cursor (_last_flushed_db_idx) after repair_message_sequence compacts the message list, plus a flush guard.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #45260 — your commit was cherry-picked onto current main with your authorship preserved in git log (5d0408d). We added a follow-up on top that rewinds the cursor exactly when repair compacts messages below the flush cursor (a case the min() clamp alone misses). Thanks for the clean diagnosis and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session DB turn-end flush drops assistant after repair_message_sequence compacts list (orphan user → \n\n merge)

4 participants