You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This hardens context-compaction handoffs so resumed or idle-reset conversations do not see live-sounding persisted headings like ## Active Task and continue stale work from an old session. Persisted summaries now use explicitly historical section names in the transcript, while resume-time rehydration converts them back to the canonical internal headings the iterative compressor expects.
🐛 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: rewrite persisted handoff headings from canonical active names to explicit historical names before prefixing the compaction summary, and canonicalize those headings again when a resumed session rehydrates the summary for iterative updates.
tests/agent/test_resume_stale_active_task.py: add resume-path regressions proving historicalized handoffs are restored to canonical internal headings while old prefixes still normalize correctly.
tests/agent/test_context_compressor_summary_continuity.py: add coverage that the transcript-facing handoff is historicalized without mutating the compressor's internal _previous_summary state.
How to Test
Run pytest tests/agent/test_resume_stale_active_task.py tests/agent/test_context_compressor_summary_continuity.py -q and confirm the new stale-handoff regressions pass.
Create or load a conversation with a compaction handoff, then verify the persisted handoff text now uses ## Historical Task (prior session), ## Previous In-Flight Work, ## Previous Pending User Asks, and ## Previous Work State instead of the live-sounding headings.
Re-run compaction on that resumed transcript and verify iterative summary state still restores to canonical internal headings, so the compressor updates the prior summary instead of treating the historical headings as a brand-new user instruction.
The required broad local command /opt/homebrew/bin/timeout -k 30 480 sh -c 'pytest tests/ -q -x --timeout=60 "$@"' sh stopped early on an unrelated shared-venv import error: ModuleNotFoundError: No module named 'fastapi' while collecting tests/hermes_cli/test_dashboard_auth_401_reauth.py.
The mechanical compressor-covering subset completed and our changed-module tests passed, but several unrelated pre-existing tests failed under the sandbox when they instantiated AIAgent and tried to open /Users/kon5i/.hermes/logs/agent.log (PermissionError: [Errno 1] Operation not permitted).
Positive verification: Reviewed the diff — expanding on_session_end() to clear all per-session compressor state (matching on_session_reset()'s surface) is correct defense-in-depth. The original #38788 fix only cleared _previous_summary, but stale _ineffective_compression_count, _summary_failure_cooldown_until, _last_compress_aborted, and _context_probed could all leak across session boundaries on compressor reuse. The test file covers each variable individually. LGTM.
For maintainer context: #42813 (by @JerryLiu369, opened ~3.5h before this PR) is already open on the same issue #42812 and overlaps this change directly — both edit agent/context_compressor.py and tests/agent/test_resume_stale_active_task.py. #42813 is Refs: #42812 (relates), this PR is Fixes #42812. They appear to be competing/overlapping approaches to the same compaction-historicalization fix; flagging so they can be consolidated / one picked rather than landing both.
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
comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointP1High — major feature broken, no workaroundtype/bugSomething isn't working
3 participants
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 does this PR do?
This hardens context-compaction handoffs so resumed or idle-reset conversations do not see live-sounding persisted headings like
## Active Taskand continue stale work from an old session. Persisted summaries now use explicitly historical section names in the transcript, while resume-time rehydration converts them back to the canonical internal headings the iterative compressor expects.Related Issue
Fixes #42812
Type of Change
Changes Made
agent/context_compressor.py: rewrite persisted handoff headings from canonical active names to explicit historical names before prefixing the compaction summary, and canonicalize those headings again when a resumed session rehydrates the summary for iterative updates.tests/agent/test_resume_stale_active_task.py: add resume-path regressions proving historicalized handoffs are restored to canonical internal headings while old prefixes still normalize correctly.tests/agent/test_context_compressor_summary_continuity.py: add coverage that the transcript-facing handoff is historicalized without mutating the compressor's internal_previous_summarystate.How to Test
pytest tests/agent/test_resume_stale_active_task.py tests/agent/test_context_compressor_summary_continuity.py -qand confirm the new stale-handoff regressions pass.## Historical Task (prior session),## Previous In-Flight Work,## Previous Pending User Asks, and## Previous Work Stateinstead of the live-sounding headings.pytest tests/agent/test_compress_focus.py tests/agent/test_compression_concurrent_fork.py tests/agent/test_compression_logging_session_context.py tests/agent/test_compressor_historical_media.py tests/agent/test_compressor_image_tokens.py tests/agent/test_context_compressor.py tests/agent/test_context_compressor_cross_session_guard.py tests/agent/test_context_compressor_summary_continuity.py tests/agent/test_context_compressor_temporal_anchoring.py tests/agent/test_context_engine.py tests/agent/test_context_engine_host_contract.py tests/agent/test_last_total_tokens.py tests/agent/test_memory_provider.py tests/agent/test_resume_stale_active_task.py tests/agent/test_summary_prefix_semantics.py tests/agent/test_turn_context.py tests/gateway/test_compress_command.py tests/gateway/test_compress_focus.py tests/gateway/test_compress_plugin_engine.py tests/gateway/test_compression_concurrent_sessions.py tests/gateway/test_session_hygiene.py tests/gateway/test_usage_command.py -q.What platforms tested on
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
pytest tests/agent/test_resume_stale_active_task.py tests/agent/test_context_compressor_summary_continuity.py -q/opt/homebrew/bin/timeout -k 30 480 sh -c 'pytest tests/ -q -x --timeout=60 "$@"' shstopped early on an unrelated shared-venv import error:ModuleNotFoundError: No module named 'fastapi'while collectingtests/hermes_cli/test_dashboard_auth_401_reauth.py.AIAgentand tried to open/Users/kon5i/.hermes/logs/agent.log(PermissionError: [Errno 1] Operation not permitted).