Skip to content

fix(gateway): preserve transcript on /compress and hygiene compression (salvage #3516)#3556

Merged
teknium1 merged 2 commits intomainfrom
hermes/hermes-5e6ebebb
Mar 28, 2026
Merged

fix(gateway): preserve transcript on /compress and hygiene compression (salvage #3516)#3556
teknium1 merged 2 commits intomainfrom
hermes/hermes-5e6ebebb

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

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 /compress and hygiene pre-compression called rewrite_transcript() on the old session_id — overwriting the preserved transcript with compressed messages. Full conversation history became unsearchable via session_search.

The fix

After _compress_context runs, 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

  • Original PR fixed only the /compress handler
  • This PR also fixes the hygiene pre-compression path (line ~2207) which had the identical bug
  • Fixed cosmetic spacing (new_tokens=new_tokens =)
  • Updated FakeCompressAgent test mock to include session_id attribute and simulate the session_id change

Tests

  • 1603 gateway tests pass (19 hygiene tests pass)
  • Updated FakeCompressAgent mock to simulate real _compress_context behavior
MacroAnarchy and others added 2 commits March 28, 2026 11:34
…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>
@teknium1 teknium1 merged commit 3939298 into main Mar 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants