Skip to content

fix(agent): clear compressor state on session start to prevent cross-session task leakage (#14603)#15368

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/compressor-session-start-reset
Open

fix(agent): clear compressor state on session start to prevent cross-session task leakage (#14603)#15368
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/compressor-session-start-reset

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

ContextCompressor._previous_summary persists across session boundaries when the same cached AIAgent instance is reused in the gateway or cron. When a new session starts without an explicit /reset, on_session_start() is called but on_session_reset() is not. Since on_session_start() is a no-op on the base ContextEngine, _previous_summary from the old session leaks into the next session's iterative summary update, causing old task context (e.g. "## Active Task: Deploy the web server") to bleed into the new session's compression summary.

This PR overrides on_session_start() on ContextCompressor to clear _previous_summary and _ineffective_compression_count, ensuring a fresh compressor state when a new session begins while preserving the more thorough cleanup in on_session_reset() for explicit /new or /reset.

Related Issue

Fixes #14603

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/context_compressor.py: Override on_session_start() to clear _previous_summary and _ineffective_compression_count.
  • tests/agent/test_compressor_session_isolation.py: 3 targeted tests:
    1. on_session_start clears _previous_summary.
    2. on_session_reset still works as before.
    3. Summary state does not leak between sessions.

How to Test

  1. Run the targeted suite:
    pytest tests/agent/test_compressor_session_isolation.py -v
    Tested on macOS (Python 3.14).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

N/A — see commit description and PR diff.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 24, 2026
@Tranquil-Flow Tranquil-Flow force-pushed the fix/compressor-session-start-reset branch from c3a1e43 to cc98c9c Compare May 25, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Context compaction SUMMARY_PREFIX causes cross-session task leakage

2 participants