Skip to content

feat(agents): escalate unbroken identical tool-call runs (consecutive-repeat detector)#112447

Open
interkelstar wants to merge 1 commit into
openclaw:mainfrom
interkelstar:feat/consecutive-repeat-loop-guard
Open

feat(agents): escalate unbroken identical tool-call runs (consecutive-repeat detector)#112447
interkelstar wants to merge 1 commit into
openclaw:mainfrom
interkelstar:feat/consecutive-repeat-loop-guard

Conversation

@interkelstar

Copy link
Copy Markdown

What Problem This Solves

#78865 asks for a platform-level circuit breaker: "If the same tool is called with similar arguments N times… block the next call", because "AGENTS.md is a suggestion… the enforcement has to happen at the platform level, not the prompt level."

Today the generic detector's critical tier requires identical results (noProgressStreak resets whenever the result hash changes). A model stuck re-issuing the same call whose output differs every time — timestamps, fresh page dumps, rate-limited errors with new request ids — only ever produces a log-side warning the model never sees, and runs until the token budget burns out.

Production incident that motivated this (OpenClaw 2026.7.1, mimo-v2.5): a model re-issued the identical exec date +%S call 62 times in an unbroken run — every result differed (seconds changed), so nothing escalated past the log warning; the turn ended only by output-token exhaustion (stopReason=length, ~34K output tokens). A second incident the same week ran a browser-workflow marathon of 141 rounds for the same reason.

Why This Change Was Made

Adds a consecutive_repeat detector: an unbroken run of byte-identical (tool, args) calls — nothing else interleaved — escalates to a critical veto at criticalThreshold, regardless of result hashes. The veto reason reaches the model as the tool result, which both breaks the streak and tells the model how to proceed.

Scope guards:

Deliberate behavior change: two exec tests that pinned changing-output runs at warning level now expect the consecutive critical instead. Their original concern — the global no-progress breaker must not fire on changing results — still holds and is still asserted (via the detector kind). If you'd prefer a separate, higher threshold for this tier instead of reusing criticalThreshold, happy to adjust.

User Impact

Runaway identical-call loops stop after criticalThreshold consecutive calls with an actionable, model-visible message, instead of silently burning the run budget. No config surface changes (the detector rides the existing internal defaults; disabled together with tools.loopDetection.enabled=false).

Evidence

  • pnpm test -- src/agents/tool-loop-detection.test.ts — 56/56 pass (3 new tests: unbroken-run block with varying results; interrupted run does not escalate; below-threshold stays at warning).
  • pnpm run tsgo:prod — clean.
  • Same design validated in production on our deployment (implemented as a plugin hook while this PR is open): a 15×-identical-exec request executed 11 calls, refused the rest with the guard message, and the model recovered and summarized cleanly — the veto text is sufficient for models to break out.
  • Cross-model replays of the incident contexts (mimo, deepseek-v4-flash, kimi-k2.6/k3, minimax-m2.5, gpt-5.6, gemini-3.5-flash) show mid-tier models continue such loops 2/2–3/3 once loop history is in context — platform-level enforcement is the only reliable layer, exactly as Tool call circuit breaker needed — LLMs will blindly retry forever without one #78865 argues.

Closes #78865

…-repeat detector)

The generic loop detector's critical tier requires identical results
(noProgressStreak): a model stuck re-issuing the same call whose output
differs every time (timestamps, fresh page dumps, rate-limited errors
with new request ids) only ever produces a log-side warning the model
never sees, and runs until the token budget burns out.

Add a consecutive-repeat detector: an unbroken run of byte-identical
(tool, args) calls — nothing else interleaved — escalates to a critical
veto at criticalThreshold regardless of result hashes. The veto reason
reaches the model as the tool result, which both breaks the streak and
tells the model how to proceed. Known polling tools and messaging sends
are exempt (polling legitimately repeats; sends have their own
volatility-strip escalation that understands result-side progress,
openclaw#89090).

Deliberate behavior change: two exec tests that pinned changing-output
runs at warning level now expect the consecutive critical instead; their
original concern (the global no-progress breaker must not fire on
changing results) still holds and is asserted via the detector kind.

Closes openclaw#78865

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WN55iikjZy6hKzFuzL6Gey
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Jul 22, 2026
@clawsweeper

clawsweeper Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: feat(agents): escalate unbroken identical tool-call runs (consecutive-repeat detector) This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool call circuit breaker needed — LLMs will blindly retry forever without one

1 participant