Skip to content

fix(compressor): reset cooldown and model-fallback flag on session reset (#16067) - #16152

Closed
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:fix/compressor-session-reset-state-leak-16067
Closed

fix(compressor): reset cooldown and model-fallback flag on session reset (#16067)#16152
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:fix/compressor-session-reset-state-leak-16067

Conversation

@briandevans

Copy link
Copy Markdown
Contributor

Summary

  • Add self._summary_failure_cooldown_until = 0.0 to on_session_reset()
  • Add self._summary_model_fallen_back = False to on_session_reset()

The bug

ContextCompressor.on_session_reset() (called on /new and /reset) was missing two attribute resets:

1. _summary_failure_cooldown_until — when compression summary fails (no aux provider, rate limit, transient error), the compressor sets a cooldown of up to 10 minutes before retrying. This attribute was initialized to 0.0 in __init__ but was never zeroed in on_session_reset(). Result: a compression failure in session A causes summarization to be silently skipped at the start of session B, with the log line "Skipping context summary during cooldown" as the only indication.

2. _summary_model_fallen_back — set to True when the primary summary model fails and a fallback is selected. Also missing from on_session_reset(). Result: session B always skips the primary model and goes straight to the fallback, even though the failure was in a different session entirely.

Both attributes are set to their clean values in __init__ but the reset path was incomplete.

Test plan

  • Before: direct Python test confirms both attributes persist across on_session_reset() call — _summary_failure_cooldown_until remains ~600s and _summary_model_fallen_back remains True
  • After: TestCompressorSessionReset::test_reset_clears_summary_failure_cooldown and test_reset_clears_summary_model_fallen_back both pass
  • All 3 TestCompressorSessionReset tests pass
  • Adjacent tests/agent/test_context_engine.py suite unchanged

Related

🤖 Generated with Claude Code

…set (NousResearch#16067)

ContextCompressor.on_session_reset() was missing two attribute resets:

1. _summary_failure_cooldown_until — when compression summary fails (no aux
   provider, rate limit, transient error) the compressor enters a cooldown of
   up to 10 minutes before retrying. /new or /reset should clear this fully
   so the next session starts fresh. Without the reset, a failure in session A
   causes summarization to be silently skipped at the start of session B.

2. _summary_model_fallen_back — tracks whether the compressor has already
   tried and failed the primary summary model and switched to a fallback.
   Persisting this flag across sessions means session B always skips the
   primary model even though the failure was in session A.

Both attributes are initialized to their clean values in __init__ but were
omitted from on_session_reset, which is the /new and /reset path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 26, 2026 17:14
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15549 — same root cause (incomplete on_session_reset), and #15549 is a superset that also resets summary_model.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes cross-session leakage in the agent’s ContextCompressor by ensuring additional per-session summarization state is cleared when the user starts a new session (/new) or resets (/reset).

Changes:

  • Reset _summary_failure_cooldown_until to 0.0 in ContextCompressor.on_session_reset().
  • Reset _summary_model_fallen_back to False in ContextCompressor.on_session_reset().
  • Add unit tests asserting both values are cleared by on_session_reset().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
agent/context_compressor.py Clears summarization cooldown and fallback flag during session reset to prevent state leaking across sessions.
tests/agent/test_context_engine.py Adds regression tests for session reset clearing cooldown and fallback flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +300 to +301
self._summary_failure_cooldown_until = 0.0
self._summary_model_fallen_back = False
self._last_compression_savings_pct = 100.0
self._ineffective_compression_count = 0
self._summary_failure_cooldown_until = 0.0
self._summary_model_fallen_back = False
"""_summary_model_fallen_back must be False after reset.

If the summary model fell back in session A, the fallback flag must not
persist into session B — the primary model should be tried first again.
@briandevans

Copy link
Copy Markdown
Contributor Author

CI baseline classification

The test job failure is a pre-existing baseline on origin/main, unrelated to this PR:

File Error Status
tests/gateway/test_discord_channel_controls.py AttributeError: 'types.SimpleNamespace' object has no attribute 'guild' Pre-existing (tracked in #15820)
tools/browser_tool.py ValueError: I/O operation on closed file Pre-existing cleanup noise

These failures reproduce on origin/main without my changes. All other checks pass ✅ (check, nix/macos, nix/ubuntu, e2e, supply-chain, attribution).

@briandevans

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #15549, which is a more complete fix for the same root cause (incomplete on_session_reset()) — it also restores summary_model from a preserved _summary_model_original value. My patch is a strict subset. Recommend merging #15549 first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

3 participants