fix(compression): flush messages before session rotation to prevent data loss#47204
Closed
x7peeps wants to merge 1 commit into
Closed
fix(compression): flush messages before session rotation to prevent data loss#47204x7peeps wants to merge 1 commit into
x7peeps wants to merge 1 commit into
Conversation
…ata loss compress_context() and cli.new_session() both call end_session() without first flushing in-memory messages to the session DB. When auto-compression triggers mid-turn (context exceeds threshold), messages generated during the current turn that haven't yet been persisted are permanently lost — the old session ends with a gap and the new session has no reference to them. Fix: call _flush_messages_to_session_db() before end_session() in both sites so all un-persisted messages are written to the existing session_id before it rotates. Closes NousResearch#47202
Collaborator
|
Related: this is the flush-before-rotation fix for the mid-turn compression data-loss bug (#47202, #46567). Competing/complementary open PRs target the same root cause via different mechanisms and file-sets:
This PR (#47204) is the only one that also covers the |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
compress_context()inconversation_compression.pyandnew_session()incli.pycallend_session()without first flushing in-memory messages to the session DB. When auto-compression triggers mid-turn (context exceeds threshold), messages generated during the current turn that haven't yet been persisted are permanently lost:message_countfrom its last clean turnsession_search,/resume, and offline backup all show a gapThis is especially painful for long tool-heavy turns (vision analysis, code execution, multi-step workflows) where 50+ messages can be generated in a single turn.
Fix
Add
_flush_messages_to_session_db(messages)beforeend_session()in both sites:agent/conversation_compression.py:compress_context()— flush beforeend_sessionwhen auto-compression rotates the sessioncli.py:new_session()— flush beforeend_sessionwhen the/newcommand rotates the sessionBoth fixes use the existing
_flush_messages_to_session_db()method which is already idempotent (tracks_last_flushed_db_idx) and has proper error handling.Closes #47202