Skip to content

Context overflow causes infinite loop - no circuit breaker #8596

@MuduiClaw

Description

@MuduiClaw

Problem

When context usage approaches 100%, the bot enters an infinite loop:

  1. User sends message → Context overflow error
  2. Bot tries to reply with error message → Context overflow again
  3. 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:

  1. No proactive compaction before context is full
  2. No circuit breaker to stop after N consecutive failures
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    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