fix(compression): prevent compressed history injection on session split#27519
Open
Tranquil-Flow wants to merge 2 commits into
Open
fix(compression): prevent compressed history injection on session split#27519Tranquil-Flow wants to merge 2 commits into
Tranquil-Flow wants to merge 2 commits into
Conversation
e4e8129 to
5acd009
Compare
5acd009 to
f8a2551
Compare
Contributor
|
Thanks for chasing this compression/session-split bug. I traced the current main persistence path and found one blocking correctness issue in the proposed fix. Problems
Suggested changes
Automated hermes-sweeper review. |
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.
What does this PR do?
Prevents compressed history that was already written into a newly split session from being appended again as live conversation history.
The bug had two related paths:
compress_context()created a new session and reset_last_flushed_db_idxto0. Later_flush_messages_to_session_db()appended the entire compressed history to the new session as if it were new live output.session hygieneand/compress) wrote compressed messages withrewrite_transcript(), but the next agent instance still started with a flush cursor of0, causing the compressed transcript to be appended a second time.Since transcript replay prefers the source with more messages, the duplicate SQLite transcript could win and make compressed summaries / referenced old turns appear as valid live history.
Related Issue
Fixes #20293
Type of Change
Changes Made
agent/conversation_compression.py— setagent._last_flushed_db_idx = len(compressed)after a compression session split.SessionEntry._prewritten_msg_count— add field with serialization/deserialization so gateway compression paths can persist how many messages were already written viarewrite_transcript().gateway/run.py:session_entry._prewritten_msg_count = len(_compressed)/compressrecordssession_entry._prewritten_msg_count = len(compressed)_run_agent()accepts_prewritten_msg_countand advances the agent flush cursor before the turn runsHow to Test
python3 -m pytest -o 'addopts=' tests/compression/test_context_compaction_flush.py -q→ 11 passedChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs