fix(gateway): preserve transcript on /compress and hygiene compression (salvage #3516)#3556
Merged
fix(gateway): preserve transcript on /compress and hygiene compression (salvage #3516)#3556
Conversation
…iting The /compress command calls _compress_context() which correctly ends the old session (preserving its full transcript in SQLite) and creates a new session_id for the continuation. However, it then immediately called rewrite_transcript() on the OLD session_id, overwriting the preserved transcript with the compressed version — destroying searchable history. Auto-compression (triggered by context pressure) does not have this bug because the gateway already handles the session_id swap via the agent.session_id != session_id check after _run_agent_sync. Fix: after _compress_context creates the new session, write the compressed messages into the NEW session_id and update the session store pointer. The old session's full transcript stays intact and searchable via session_search. Before: /compress destroys original messages, session_search can't find details from compressed portions. After: /compress behaves like /new for history — full transcript preserved, compressed context for the live session.
Apply session_id swap after _compress_context in both /compress handler and hygiene pre-compression. _compress_context creates a new session (ending the old one), but both paths were calling rewrite_transcript on the OLD session_id — overwriting the preserved transcript and destroying searchable history. Now follows the same pattern as the auto-compression handler (lines 5415-5423): detect the new session_id, update the session store entry, and write compressed messages to the new session. Also fix FakeCompressAgent test mock to include session_id attribute and simulate the session_id change that real _compress_context performs. Co-authored-by: MacroAnarchy <MacroAnarchy@users.noreply.github.com>
3 tasks
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.
Summary
Salvage of #3516 by @MacroAnarchy with an additional fix for the hygiene pre-compression path.
The bug
_compress_context()creates a new session (ends the old one, preserving its transcript in SQLite, and creates a new session_id). But both/compressand hygiene pre-compression calledrewrite_transcript()on the old session_id — overwriting the preserved transcript with compressed messages. Full conversation history became unsearchable viasession_search.The fix
After
_compress_contextruns, detect the new session_id, update the session store entry, and write compressed messages to the new session. Follows the same pattern already used by auto-compression (lines 5415-5423 in the agent result handler).What changed vs original PR
/compresshandlernew_tokens=→new_tokens =)FakeCompressAgenttest mock to includesession_idattribute and simulate the session_id changeTests
FakeCompressAgentmock to simulate real_compress_contextbehavior