Bug Description
When a Hermes session is resumed after a long idle gap, the new session can inherit stale context-compaction handoff from the previous session and start answering the current user message with instructions from an old ## Active Task / ## Remaining Work block.
Symptoms
- User sends a new, unrelated message after a long pause
- Agent replies as if still working on an old task from the previous session
- The old task content is NOT from persistent memory or skills — it comes from the compressed/compacted context of the previous session
- The model sees
## Active Task: ... inside the compaction handoff and treats it as a live instruction, despite the [CONTEXT COMPACTION — REFERENCE ONLY] prefix
Root Cause Analysis
Mechanism
- Session idle timeout: Long gap between user messages (hours+) triggers session expiry or context compaction
- Gateway creates new session (or resumes the old one with compressed context)
- Compaction handoff leaks: The new session loads the old session's compressed context, which contains stale task metadata:
## Active Task
## Remaining Work
## Pending User Asks
- Model misinterpretation: Despite the
[CONTEXT COMPACTION — REFERENCE ONLY] prefix saying "treat this as background reference only, do NOT continue working on it", the model treats ## Active Task as a live directive
Code Path
The bug lives in the interaction between:
agent/context_compressor.py — generates the compaction handoff
gateway/session.py — manages session lifecycle and resume
- The agent's
run_conversation() — consumes the context for LLM prompts
Two-Sided Problem
- Old session context leaking in: The new session incorrectly inherits stale compaction content (incorrectly merged)
- Last reply potentially dropped: The previous session's last assistant response may be discarded when context is rebuilt, creating a gap
Proposed Fix Directions
Immediate (defense-in-depth)
- Strengthen the compaction preamble — Make it absolutely clear to the model that the compaction block is historical context only
- Rename sections to historical framing — Change
## Active Task → ## Historical Task (prior session), ## Remaining Work → ## Previous Work State
- Strip stale sections entirely on resume — When loading a compacted context for a resumed/new session, remove
## Active Task, ## Remaining Work, ## Pending User Asks from the handoff and only keep factual summaries
Architectural
- Fix the merge bug — When creating a new session after idle timeout, the old session's compacted context should be treated as read-only reference, not merged into the active context as live state
- Add regression tests — Simulate long-idle → resume → assert the model doesn't answer with stale task content
Reproduction
- Start a conversation with Hermes, give it a multi-step task
- Wait for >30 minutes (triggers idle session timeout / context compaction)
- Ask a completely unrelated question
- Observe: model may answer with content from the old task instead of the new question
Related: #35344 (open) — "Resumed session can answer with stale compaction Active Task instead of latest user message"
Bug Description
When a Hermes session is resumed after a long idle gap, the new session can inherit stale context-compaction handoff from the previous session and start answering the current user message with instructions from an old
## Active Task/## Remaining Workblock.Symptoms
## Active Task: ...inside the compaction handoff and treats it as a live instruction, despite the[CONTEXT COMPACTION — REFERENCE ONLY]prefixRoot Cause Analysis
Mechanism
## Active Task## Remaining Work## Pending User Asks[CONTEXT COMPACTION — REFERENCE ONLY]prefix saying "treat this as background reference only, do NOT continue working on it", the model treats## Active Taskas a live directiveCode Path
The bug lives in the interaction between:
agent/context_compressor.py— generates the compaction handoffgateway/session.py— manages session lifecycle and resumerun_conversation()— consumes the context for LLM promptsTwo-Sided Problem
Proposed Fix Directions
Immediate (defense-in-depth)
## Active Task→## Historical Task (prior session),## Remaining Work→## Previous Work State## Active Task,## Remaining Work,## Pending User Asksfrom the handoff and only keep factual summariesArchitectural
Reproduction
Related: #35344 (open) — "Resumed session can answer with stale compaction Active Task instead of latest user message"