Skip to content

Bug: Stop-button abort races with compaction completion, causing model confusion #89868

Description

@lykeion-dev

Bug: Stop-button abort races with compaction completion, causing model confusion

Description

When a user presses the stop button during an auto-compaction, the abort signal cancels the wait for compaction but the compaction LLM call continues in-flight and writes its result to the session transcript. This causes the model to receive only a compaction summary instead of the full context, leading to confused responses.

Note: The full transcript is preserved on disk — this is not data loss. The problem is model confusion, not user confusion.

Reproduction

  1. Have a session with enough context to trigger auto-compaction (~200K+ estimated tokens)
  2. Wait for auto-compaction to start (visible in logs as context overflow detected; attempting auto-compaction)
  3. Press the stop button during compaction
  4. Observe: compaction wait aborted + AbortError: This operation was aborted
  5. But compaction result still gets written to session
  6. Next message sees compacted session (e.g., 239 → 4 messages)

Evidence from logs

22:57:16 context overflow detected (attempt 1/3); attempting auto-compaction
22:57:17 [compaction-diag] start (compaction begins)
22:58:57 chat.abort → reply_operation_aborted
22:58:57 contextEngine.compact() threw during overflow recovery: AbortError: This operation was aborted
22:58:57 auto-compaction failed: AbortError
22:59:13 Auto-compaction failed. Preserving existing session mapping.
23:00:07 [compaction-diag] end outcome=compacted  ← compaction actually completed!
23:00:55 [context-diag] messages=4  ← model now sees only 4 messages

Root Cause

In selection-BMP-JCML.js:

  • unsubscribe() (line ~5817) calls session.abortCompaction() but this only signals the session manager
  • The LLM call for compaction summarization was already in-flight and completes independently
  • The compaction end handler (line ~4685) checks wasAborted and skips incrementCompactionCount(), but the session file has already been modified by the session manager's compaction handler
  • The main run's compaction-wait is aborted (line ~17277), but the compaction subprocess continues

Expected Behavior

When externalAbort=true and compaction was in-flight, the compaction result should be discarded (rolled back) rather than applied to the session. The session should remain in its pre-compaction state.

Impact

  • Model confusion: Model receives only compaction summary instead of full context → loses track of ongoing work, instructions, and state
  • Not data loss: The full transcript is preserved on disk. The Principal can read the original transcript. The problem is the model's confusion, not the Principal's.
  • Stop-button mismatch: User presses stop expecting cancellation, but compaction still happens
  • Degraded model context: Compaction summary generated from mid-turn state may be garbled

Environment

  • OpenClaw version: 2026.5.28
  • Model: xiaomi/mimo-v2.5-pro (but affects any model)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions