fix(agent): clear _previous_summary on session end to prevent cross-contamination (#38788)#39725
Closed
dusterbloom wants to merge 1 commit into
Closed
Conversation
…ontamination (NousResearch#38788) ContextCompressor.on_session_end() is inherited as a no-op from ContextEngine. When a cron or background session compresses and rotates, _previous_summary survives session end. The memory manager exposes it to the next live session via on_session_switch, causing cron compaction summaries to leak into unrelated conversations. Fix: override on_session_end() in ContextCompressor to clear _previous_summary. This is a 3-line change that closes the only path by which per-session compaction state crosses session boundaries. Verified with: - Quint formal spec: bug found in 13ms across 3 states; fix passes 100K+ traces with zero violations - 2 unit tests: summary cleared + other state preserved - Full compressor test suite: 93 passed, 0 regressions Closes NousResearch#38788
This was referenced Jun 8, 2026
Contributor
|
Merged via #41717 (commit cca3b77) — your |
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
Fixes #38788 — Context compaction cross-contamination where cron session summaries leak into unrelated live conversations.
Root Cause
ContextCompressor.on_session_end()is inherited as a no-op fromContextEngine. When a cron or background session compresses and rotates,_previous_summarysurvives session end. The memory manager'son_session_switchpath exposes it to the next live session, causing compaction summaries to leak across session boundaries.The comment at
run_agent.py:2773-2777already acknowledges this class of bug ("engines that accumulate per-session state... leak that state"), but the fix only calledon_session_end— it didn't makeon_session_endactually clear the state.Fix
Override
on_session_end()inContextCompressorto clear_previous_summary = None. This is a 3-line change.Verification
Quint Formal Spec
specs/session_isolation.qnt— Quint finds the violation in 13ms (3 states)specs/session_isolation_fixed.qnt— Quint passes 100K+ traces with zero violationsUnit Tests
test_on_session_end_clears_previous_summary: summary is None after session endtest_on_session_end_preserves_other_state: global state (token tracking, compression count) is preservedSpec Design (Socratic Flow)
The formal spec was developed through an interactive Socratic specification process:
See
specs/session_isolation.qntandspecs/session_isolation_fixed.qntfor the formal models.