Skip to content

fix(agents): allow bounded recovery after repeated identical tool errors - #186853

Merged
fuller-stack-dev merged 4 commits into
mainfrom
openclaw/tool-error-recovery-publish-20261028
Oct 28, 2026
Merged

fuller-stack-dev merged 4 commits into
mainfrom
openclaw/tool-error-recovery-publish-20261028

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Why

The tool loop guard ended a run on the third identical tool failure (same tool, arguments and error), before the model could see the failure and change plan. Its stop message also blamed the model's tool calling.

What changed

  • The third identical failure quarantines that action and uses the existing shared critical-loop allowance: one per accepted user input, shared with configured rolling detectors and by all tool batches in one provider response until the model sees the feedback. While the run continues, each newly quarantined action gets a neutral recovery note; the next critical loop ends the run.
  • Quarantine matches the final arguments after hooks and blocks the tool implementation before it starts; hooks and argument preparation may still run. Only newly committed user input clears it; successes and context-only updates do not.
  • On a guard stop the model stops at once. Started calls settle without being cancelled or replayed, and may still fail. Persisted and turn_end results keep source order; a batch suppressed at the stop skips only admission and lifecycle hooks.
  • Stop copy, diagnostics and receipts name the tool and a bounded error class. Docs are updated.
  • Recovery logic moves into a private agent-core helper; plugin SDK and runtime entry points are unchanged.

Scope

Native embedded tool-loop recovery and per-input accounting of the shared critical-loop allowance. Approvals, permissions, configuration, providers and deployment are unchanged, and nothing retries automatically.

Tradeoffs

  • No automatic retry: the model must see a failure to choose a different action.
  • Test volume grows but stays within main's unchanged test-line ceiling (6,303,410 of 6,310,000 lines). One stale mock-export baseline entry is removed; no new waiver.

Blast Radius

Runs that hit a critical tool loop: repeated identical failures get one bounded recovery attempt instead of an immediate stop, and a further critical loop for the same input still ends the run.

Verification

On this branch merged with current main (the only conflict was the test-line baseline, resolved to main's value):

  • 216 tests in 11 files pass: 156 focused tests, including regressions that drive a real Agent through the production bridge and tool wrapper and failed before the fix, plus 60 payload-error and approval-policy integration tests. The five edited test files (49 cases) are unchanged by the merge and were audited in full.
  • Lint, format, line-cap, mock-export and test-line checks pass.
  • The QA runtime build of this head passes, and the before-tool-call E2E suite passes against it (74 tests, none skipped).
  • A live run of that build on an isolated Gateway with a real agent and model hit three identical directory-read errors. The recovery note reached the model's next request, and the model switched to a successful file read and answered usefully. Saved history stayed in order and was identical after reloading in a fresh Gateway. The calls were serial; parallel batches and terminal stops are covered by the deterministic tests.
Selected fields from the live run's asserted execution receipt
{
  "realNativeReadSourceStarts": [3, 1],
  "orderedToolResults": ["error", "error", "error", "success"],
  "orderedActivityStatus": ["failed", "failed", "failed", "completed"],
  "nextModelContextContainsRecovery": true,
  "agentWaitStatus": "ok",
  "usefulAnswerVerified": true,
  "persistedMessages": 10,
  "persistedActivityItems": 8,
  "freshGatewayReloadEqual": true,
  "sessionDoneInactive": true
}
  • All seven selected hosted typecheck jobs pass on this head, as do the security review, CodeQL, OpenGrep and changed-boundary checks. Locally, the core and agents type graphs report one WebSocket headers error (TS2353) that the integrated main base reproduces exactly; this change adds no diagnostics.
  • Reviews of the pre-merge change found nothing actionable (one optional typing nit), and the automated P0–P2 review was clean.

Exact-head CI passed; the requested fresh-head review is pending.

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL labels Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets agents change plans after three identical tool failures while blocking unchanged retries and terminating another critical loop.

Example: An agent fails three times while reading a directory, then chooses a file read.

  • Before: The third identical failure ends the turn before the model can choose the file.
  • After: The model receives recovery feedback and can read the file; another identical directory read is blocked.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, coherent recovery behavior supported by a serial live execution receipt and meaningful boundary coverage; no actionable findings remain.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied live Gateway receipt exercises embedded repeated-error recovery with a real agent and model, showing three failed reads followed by a successful changed read, useful completion, ordered history, and equal history after reload; deterministic production-path tests cover parallel and terminal settlement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Preference · Worth it: Yes · Fix scope: Complete
User problem: A capable model loses the task when the third identical tool failure stops the turn before it can choose another approach.
Reason: Immediate termination was intentional behavior; this maintainer-authored PR supplies the owner decision for bounded replanning while preserving unchanged-action blocking.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it provides useful bounded recovery, no actionable defect was found, and the previous merge conflict is resolved.

Priority: P2
Reviewed head: f3e218beca5cca02abe2cbbb08f976d17a3d0964

Before merge

None.

Findings

None.

Agent review details

How this fits together

The embedded agent loop receives model tool calls, applies tool policies and execution admission, and publishes ordered results to the model and session history.

flowchart TD
  A[Model tool calls] --> B[Batch admission]
  B --> C[Argument preparation and policies]
  C --> D[Final launch and quarantine check]
  D --> E[Tool implementation]
  E --> F[Ordered outcome observation]
  F --> G[Recovery feedback or terminal result]
  G --> A
Loading

Technical review

Best possible solution:

Retain recovery in the existing agent-loop owner with final-argument quarantine, one shared allowance per accepted input, and ordered settlement of started work.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows immediate termination after three identical failures; this read-only review ran no target code or tests.

Is this the best way to solve the issue?

The patch coherently extends the existing recovery policy and launch boundary, with no unnecessary competing owner or unsupported restriction identified.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fb6ec25c2c97.

Provenance checked

  • Always-on repeated-error guard and terminal copy changes intended behavior with a stated reason (d860aa6: Bound identical failures even with rolling detection disabled, preserve full error identity, and reset the streak on committed user input.)
  • Critical-loop recovery allowance changes intended behavior with a stated reason (1f10ef8: Let the model recover once while terminating another critical loop through the agent-loop owner.)
  • Implementation-start and input lifecycle keeps the original intent (f83b7ad: Consolidate tool launch and accepted-input decisions at their existing lifecycle owners.)
  • Ordered answer and error payloads keeps the original intent (6349e43: Preserve completed answers for each steered input through shared answer boundaries.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d860aa6 adds src/agents/tool-loop-detection.ts:417 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d860aa62909e; files: src/agents/tool-loop-detection.ts)
  • Paul Bohm: Raw commit f83b7ad adds packages/agent-core/src/agent-loop-tool-execution.ts:114 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: f83b7ade15f3; files: packages/agent-core/src/agent-loop-tool-execution.ts)

PR surface

Source +289, Tests +961, Docs +19, Other -1. Total +1268 across 24 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 16 438 149 +289
Tests 5 1073 112 +961
Docs 2 46 27 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 24 1557 289 +1268

Review metrics

Metric Value Why it matters
Production versus test diff lines Production +438/-149; tests +1073/-112 Production growth implements quarantine, recovery accounting, and ordered draining; tests protect distinct execution, input, ordering, and diagnostic boundaries.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This improves recovery for embedded runs encountering repeated identical tool failures with a limited affected surface.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-28T15:38:01.166Z sha 8648698 :: needs changes before merge. :: none

Reviewed October 28, 2026, 12:19 PM ET / 16:19 UTC (Revision 2).

OpenClaw-Publication: 7f14d82c-9c2f-4ded-92bd-25248db94fad
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Oct 28, 2026
@fuller-stack-dev
fuller-stack-dev merged commit 21fdc27 into main Oct 28, 2026
166 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the openclaw/tool-error-recovery-publish-20261028 branch October 28, 2026 16:22
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant