fix(compression): guard against cross-session stale _previous_summary contamination#38832
Closed
basilalshukaili wants to merge 1 commit into
Closed
Conversation
… contamination When a cron or background session compacts, it sets _previous_summary for iterative updates. If that session ends without /new or /reset (which calls on_session_reset()), the stale summary survives on the ContextCompressor instance. A subsequent live messaging session's compaction then injects it as 'PREVIOUS SUMMARY:' into the summarizer prompt — contaminating the live session with unrelated content from the prior session. Add an else guard in compress(): when no handoff summary is found in the current messages but _previous_summary is non-empty, discard it so _generate_summary() starts fresh instead of iteratively updating a stale cross-session summary. Fixes NousResearch#38788
Contributor
|
Merged via #41717 (commit 8513a6a) — your point-of-use guard in |
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.
What
When a cron or background session compacts, the ContextCompressor sets
_previous_summaryfor iterative summary updates. If that session ends without/newor/reset(which callon_session_reset()), the stale summary survives on the shared instance. A subsequent live messaging session's compaction then injects it asPREVIOUS SUMMARY:into the summarizer prompt — contaminating the live session with unrelated content.Root Cause
In
compress(), when no handoff summary is found in the current messages (via_find_latest_context_summary), but_previous_summaryis non-empty from a prior session, the code silently carries the stale value forward._generate_summary()then enters its iterative-update branch (line 1343), injecting the stale cron summary into the summarizer prompt.Fix
Added an
elifguard incompress()(after the handoff-search block, line 1911): when no handoff summary is found in the current messages but_previous_summaryis non-empty, discard it. This ensures_generate_summary()starts fresh when the summary state belongs to a different session.The guard does NOT fire when a handoff summary IS found in the current messages — iterative updates within the same session are preserved.
Tests
Three new tests in
tests/agent/test_context_compressor_cross_session_guard.py:_previous_summaryset from a simulated prior session, no handoff in current messages → cleared to None_previous_summarypreserved (guard doesn't fire)_previous_summaryalready None → guard is no-opAll 33 tests pass (26 existing + 7 in this change set).
Related
Fixes #38788