Skip to content

Stale compaction Active Task hijacks resumed sessions after idle timeout #42812

@JerryLiu369

Description

@JerryLiu369

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

  1. Session idle timeout: Long gap between user messages (hours+) triggers session expiry or context compaction
  2. Gateway creates new session (or resumes the old one with compressed context)
  3. 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
  4. 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

  1. Old session context leaking in: The new session incorrectly inherits stale compaction content (incorrectly merged)
  2. 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)

  1. Strengthen the compaction preamble — Make it absolutely clear to the model that the compaction block is historical context only
  2. Rename sections to historical framing — Change ## Active Task## Historical Task (prior session), ## Remaining Work## Previous Work State
  3. 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

  1. 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
  2. Add regression tests — Simulate long-idle → resume → assert the model doesn't answer with stale task content

Reproduction

  1. Start a conversation with Hermes, give it a multi-step task
  2. Wait for >30 minutes (triggers idle session timeout / context compaction)
  3. Ask a completely unrelated question
  4. 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/agentCore agent loop, run_agent.py, prompt buildercomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions