Fix #39704: Guard session transcript rewrite on successful rotation - #41000
Closed
iamlukethedev wants to merge 1 commit into
Closed
iamlukethedev wants to merge 1 commit into
iamlukethedev wants to merge 1 commit into
Conversation
…l rotation Fixes NousResearch#39704: Session Hygiene compression overwrites original messages when _session_db is None, permanently deleting hundreds of messages. PROBLEM: - Gateway Session Hygiene compression via _compress_context() checks if session rotation succeeded by comparing old and new session IDs (line 9319) - When _session_db is None, compress_context() skips rotation entirely, leaving the session ID unchanged - However, rewrite_transcript() was called UNCONDITIONALLY (line 9327), even when rotation failed - This resulted in the original session's messages (200+ messages) being deleted and replaced with ~7 compressed messages — irreversible data loss ROOT CAUSE: - The comment at line 9314 said 'Write compressed messages into the NEW session so the old transcript stays intact' but the code didn't follow this intent - rewrite_transcript() was unconditional while session rotation was conditional SOLUTION: - Move rewrite_transcript() INSIDE the if-block that confirms successful rotation - Only rewrite the transcript when _hyg_new_sid != session_entry.session_id (session was actually rotated) - When rotation fails, keep compressed messages in memory only (for current API call) but do NOT persist to database - Add warning log when rotation fails due to unavailable _session_db TESTS: - 4 new tests verify: * rewrite_transcript only called after successful rotation * rewrite_transcript called when session ID changes * session rotation skipped when _session_db is None * original messages preserved when rotation fails - All 152 compression-related tests pass - No regressions in agent context compression
This was referenced Jun 12, 2026
Collaborator
|
Automated hermes-sweeper review: this PR's fix is now implemented on current Evidence:
Thanks for the report and patch — the current mainline fix also accounts for the in-place compaction success path while preserving the same data-loss guard. |
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.
Fixes #39704: Session Hygiene compression overwrites original messages when _session_db is None, permanently deleting 200+ messages.
Problem
Root Cause
Solution
Tests