Problem
When context usage approaches 100%, the bot enters an infinite loop:
- User sends message → Context overflow error
- Bot tries to reply with error message → Context overflow again
- Repeat indefinitely
Evidence
Bot repeatedly outputs:
Context overflow: prompt too large for the model. Try again with less input or a larger-context model.
Even when trying to tell the user about the overflow, the reply itself triggers another overflow.
Root Cause
agent-runner-execution.js has didResetAfterCompactionFailure flag, but:
- No proactive compaction before context is full
- No circuit breaker to stop after N consecutive failures
- The error message delivery itself requires context
Proposed Fix
P0: Circuit Breaker (immediate)
const MAX_OVERFLOW_RETRIES = 2;
let overflowCount = 0;
// After catching overflow error:
if (++overflowCount > MAX_OVERFLOW_RETRIES) {
// Return static text WITHOUT calling LLM
return { text: '⚠️ Context overflow. Use /new to start fresh.', isStatic: true };
}
P1: Proactive Compaction
Trigger compaction when context reaches 75%, not 100%.
P2: Spawn Subagent on Overflow
Auto-spawn a clean subagent to continue the task.
Environment
- OpenClaw 2026.2.1
- Model: claude-opus-4-5 (200k context)
Problem
When context usage approaches 100%, the bot enters an infinite loop:
Evidence
Bot repeatedly outputs:
Even when trying to tell the user about the overflow, the reply itself triggers another overflow.
Root Cause
agent-runner-execution.jshasdidResetAfterCompactionFailureflag, but:Proposed Fix
P0: Circuit Breaker (immediate)
P1: Proactive Compaction
Trigger compaction when context reaches 75%, not 100%.
P2: Spawn Subagent on Overflow
Auto-spawn a clean subagent to continue the task.
Environment