Skip to content

loop: graduated guardrails — identical-call and consecutive-mistake detectors (closes #344)#352

Merged
erain merged 1 commit into
mainfrom
issue/344-loop-guardrails
Jun 9, 2026
Merged

loop: graduated guardrails — identical-call and consecutive-mistake detectors (closes #344)#352
erain merged 1 commit into
mainfrom
issue/344-loop-guardrails

Conversation

@erain

@erain erain commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Closes #344. Roadmap P2.8.

Two graduated detectors (RunRequest.Guardrails, on by default, Disabled opt-out — same shape as RetryPolicy):

Detector Streak At 3 At 5/6
Identical call (name + canonicalized args hash, single-call rounds) resets on any arg change inject corrective user message ErrRepeatedToolCalls (typed) at 5
All-error tool rounds resets on any success inject corrective user message ErrTooManyMistakes (typed) at 6

Tests: nudge-then-halt for both detectors (call counts, event actions, typed errors), reset-on-different-args, reset-on-success, disabled passthrough, nudge message shape. One existing test (default-max-turns) now disables guardrails since its scripted 50 identical calls are exactly what the detector halts. Full suite + vet green.

🤖 Generated with Claude Code

…etectors (closes #344)

Two detectors watch every tool round, on by default with opt-out via
RunRequest.Guardrails (zero value = defaults, mirroring RetryPolicy):

- Identical-call: a single-call round whose name+canonicalized-args
  hash matches the previous round's extends a streak. At 3 the loop
  injects a corrective user message ("it will keep producing the same
  result — change arguments or approach"); at 5 the run ends with the
  typed ErrRepeatedToolCalls. Any change of arguments resets.
- Consecutive mistakes: rounds where every tool result IsError. At 3 a
  corrective message ("re-read the error messages before acting");
  at 6 the run ends with ErrTooManyMistakes. Any success resets.

Injected messages are marked glue/guardrail in metadata;
EventGuardrail reports kind/count/action so UIs and the goal loop can
surface them. Graduated nudge-then-halt policy per Gemini CLI, with
Cline's thresholds (docs/coding-harness-roadmap.md P2.8).

The "no tool used" reprompt from the roadmap is deliberately omitted:
glue turns legitimately end without tool calls, and the narrated-stall
case is covered by AutoContinue (#343).

TestRunMaxTurnsDefaultIs32 now disables guardrails — it scripts 50
identical calls to test the turn budget, which the repeat detector
would correctly halt first.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

glue-review

No concerns — LGTM.

New guardrails for repeated tool calls and consecutive mistakes are well-implemented with appropriate graduated nudges and halt limits, backed by a comprehensive test suite.


🤖 Posted by glue-review.

@erain erain merged commit cc3f98c into main Jun 9, 2026
5 checks passed
@erain erain deleted the issue/344-loop-guardrails branch June 9, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loop: mistake and loop guardrails — consecutive-mistake counter, identical-call detector, no-tool reprompt

1 participant