Expand description
Loop detection — catches runaway repeated tool calls. Loop detection for the inference loop.
Modeled after Gemini CLI’s approach: simple consecutive-identical-call detection + feedback injection instead of hard stops. No windowed fingerprinting, no name saturation heuristics, no tool-only suppression.
§Design philosophy
Claude Code and Codex have zero loop detection — they trust the model. Gemini CLI has the only thoughtful approach: detect consecutive identical tool calls (same name + args), then inject a “take a step back” feedback message to nudge the model out of the loop. Hard-stop only on the 2nd detection (model ignored the feedback).
§What we DON’T do (and why)
- No windowed fingerprint tracking — nobody else does this.
- No tool-name saturation — editing 12 files in a refactoring is normal.
- No tool-only response suppression — efficient models work silently.
- No per-turn tool call cap — frontier models emit 30+ parallel calls.
- No deduplication — if a model emits 66 identical calls, the user should see that and switch models, not have us silently paper over it.
§What we DO
- Consecutive identical calls — same
(tool, args)calledCONSECUTIVE_REPEAT_THRESHOLDtimes in a row → inject feedback. - Hard iteration cap — absolute ceiling on loop iterations. User can extend interactively.
Structs§
- Loop
Detector - Tracks consecutive identical tool calls.
Enums§
- Loop
Action - What to do when a loop is detected.
- Loop
Continuation - Options for continuing after hitting the hard cap.
Constants§
- MAX_
ITERATIONS_ DEFAULT - Default hard cap for the main inference loop.
- MAX_
SUB_ AGENT_ ITERATIONS - Hard cap for sub-agent loops.