Skip to content

Auto-compaction during ongoing turn silently abandons task execution without resumption #59618

Description

@mpz4life

Bug Description

When automatic context compaction triggers during an ongoing conversation turn (while tools are executing), the task execution is silently abandoned without resuming. Unlike overflow recovery (where willRetry=true ensures the prompt is retried after compaction), regular auto-compaction lacks a mechanism to continue the interrupted task.

Image

Root Cause

The willRetry mechanism in handleAutoCompactionEnd() only applies to overflow recovery scenarios. When regular auto-compaction triggers mid-turn:

  1. The compaction summary does NOT preserve execution state (pending tool results, accumulated search data, current task goal)
  2. After compaction completes, there is NO continuation mechanism to resume the task
  3. The agent essentially "forgets" what it was doing

Reproduction Example

From session log analysis:

  1. User asks: "Which Robot Framework version supports [Return]?"
  2. Agent executes multiple web searches and fetches
  3. Last tool returns successfully with data
  4. Compaction triggers (57,658 tokens) - BEFORE assistant generates response
  5. Task is abandoned - agent never synthesizes the answer
  6. Conversation ends without completion

Expected Behavior

After automatic compaction during a turn, the agent should resume execution and complete the current task, similar to how willRetry=true works for overflow recovery.

Actual Behavior

The task is silently abandoned. The agent stops processing after compaction, leaving the turn incomplete.

Related Code

File: agents/pi-embedded-subscribe.handlers.compaction.ts:69-76

if (willRetry) {
    ctx.noteCompactionRetry();
    ctx.resetForCompactionRetry();  // Only for overflow recovery!
} else {
    ctx.maybeResolveCompactionWait();  // Regular compaction - no continuation!
}

Issue: Regular auto-compaction (not triggered by overflow) goes to the else branch, which only resolves the wait but does not continue execution.

Suggested Fix

@jalehman

Option 1: Delay compaction until turn completes

  • Check if current turn is complete before allowing compaction
  • If incomplete, wait for turn completion (with timeout)

Option 2: Include execution state in summary

  • Add executionState field to compaction summary containing:
    • Current task goal
    • Pending tool results
    • Next execution step
  • Resume from this state after compaction

Option 3: Universal post-compaction resume

  • Always resume execution after compaction, not just for overflow
  • Add checkIncompleteTurn() and call continueExecution()

Environment

  • OpenClaw version: latest
  • Context threshold: ~58K tokens

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions