openclaw - 💡(How to fix) Fix Auto-compaction during ongoing turn silently abandons task execution without resumption [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#59618Fetched 2026-04-08 02:42:28
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
mentioned ×2subscribed ×2

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

Code Example

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

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.

<img width="480" height="610" alt="Image" src="https://github.com/user-attachments/assets/2c05f970-6299-4f11-bba0-78d73436e173" />

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

extent analysis

TL;DR

Implement a mechanism to resume task execution after regular auto-compaction, similar to the willRetry mechanism used for overflow recovery.

Guidance

  • Review the handleAutoCompactionEnd() function to understand how the willRetry mechanism works for overflow recovery and consider applying a similar approach for regular auto-compaction.
  • Investigate the suggested fix options, such as delaying compaction until the turn completes, including execution state in the compaction summary, or implementing a universal post-compaction resume mechanism.
  • Analyze the agents/pi-embedded-subscribe.handlers.compaction.ts file, specifically lines 69-76, to determine the best approach for resuming execution after regular auto-compaction.
  • Consider adding a checkIncompleteTurn() function to determine if a turn is incomplete before allowing compaction, and a continueExecution() function to resume execution after compaction.

Example

if (willRetry || isTurnIncomplete()) {
    ctx.noteCompactionRetry();
    ctx.resetForCompactionRetry();
} else {
    ctx.maybeResolveCompactionWait();
    // Add a call to continueExecution() if the turn is incomplete
    if (isTurnIncomplete()) {
        continueExecution();
    }
}

Notes

The best approach will depend on the specific requirements of the application and the trade-offs between delaying compaction, storing execution state, and resuming execution. Further analysis and testing will be necessary to determine the most effective solution.

Recommendation

Apply workaround: Implement a universal post-compaction resume mechanism, as it seems to be the most straightforward solution that can be applied to all cases, including regular auto-compaction. This approach ensures that execution is always resumed after compaction, regardless of the trigger.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING