-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
Add loop detection for repeated identical tool calls #16583
Copy link
Copy link
Closed
Labels
staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Problem
When a session accumulates large context (126K+ tokens), the model can enter a degenerate loop where it makes the same tool call repeatedly without processing the result. In my case, it issued process.poll on the same sub-agent 5+ times in a row, became completely unresponsive to new user messages, and required a gateway restart to recover.
Root Cause
- Context degradation at high token counts causes the model to repeat actions mechanically
- No circuit breaker exists in OpenClaw to detect and interrupt repeated identical tool calls
Proposed Fix
Detect when a session makes N identical (or near-identical) tool calls in a row (e.g. 3-5), then either:
- Force a context compaction to reduce token count and restore model reasoning quality
- Inject a system message like: "You appear to be in a loop making the same tool call repeatedly. Stop and reassess what you're doing."
- Or both: inject the message first, and if it happens again, force compaction
This would catch this class of bug regardless of context length or which tool is being looped.
Impact
Session becomes completely unresponsive. User messages queue up but are never answered. Only fix is a manual gateway restart.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Give feedbackNo fields configured for issues without a type.