fix(cli): sync session_id after context compression to prevent orphaned sessions#3529
Open
dieutx wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(cli): sync session_id after context compression to prevent orphaned sessions#3529dieutx wants to merge 1 commit intoNousResearch:mainfrom
dieutx wants to merge 1 commit intoNousResearch:mainfrom
Conversation
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
After context compression fires (auto or
/compress), the CLI'ssession_iddesyncs from the agent's. The agent creates a child session in the DB, but the CLI never picks up the new ID. Subsequent/newor exit ends the wrong (already-ended parent) session, and the child session is orphaned forever.Reproduce
Tested on hermes v0.4.0 with GPT-5.4:
hermesand send 4+ messages to build conversation context/compress— compression creates a child session on the agent/new— CLI ends the old parent session, not the childResult:
The child session
20260328_213154_4944f2created during compression was never ended. It stays open in the DB indefinitely, invisible tohermes sessions pruneand accumulating stale entries over time.Root Cause
_compress_contextatrun_agent.py:4950ends the current session, creates a child session, and updatesself.session_idon the agent. But the CLI holds its ownself.session_idthat's never synced:_manual_compressatcli.py:4464— no sync after_compress_contextreturnsrun_conversationhandler atcli.py:5728— no sync for auto-compressionSo when
/newcallsend_session(self.session_id), it targets the parent session (already ended by compression), and the child session is never closed.Fix
Manual compress — sync after compression succeeds:
Auto compress — sync after
run_conversationreturns:Tests
4 new tests: manual compress syncs, failure preserves original, auto compress syncs, no-compression is no-op.