Repository navigation
fix(agents): retry silent malformed tool rejections - #142176
Conversation
…ng the run
A transport that rejects a completed tool-call set ("Provider completed
tool call with malformed JSON arguments" and its sibling messages) throws
before any tool runs and drops the rejected calls from the message. On
direct Claude streams the whole content is discarded, leaving empty content
with positive output usage, which the silent-error retry gate reads as
provider progress and refuses to resubmit. The run then dies with no retry
even though a plain resubmit almost always succeeds.
Recognize the rejection (stable code malformed_tool_call_arguments, or the
exact terminal messages the transports raise today) and let positive output
usage stop blocking the existing bounded empty-error retry for that case.
Visible text, side effects, replay-unsafe metadata, terminal codes, and the
MAX_EMPTY_ERROR_RETRIES budget all still apply.
Related: openclaw#135111
Related: openclaw#141323
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 10:58 PM ET / September 9, 2026, 02:58 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR lets the existing bounded agent retry recover from silent malformed-tool rejections while preserving output, side-effect, and terminal-error safeguards. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix: current main still blocks recovery for empty malformed-tool errors with positive output usage. The production-path evidence supports the change, and no blocking defect was found. Priority: P1 Review scores
Verification
How this fits togetherProvider transports validate tool arguments before exposing executable calls. The embedded agent runner examines failed attempts and decides whether to retry, use a configured fallback, or return an error. flowchart TD
A[Provider response] --> B[Strict tool argument validation]
B --> C[Silent rejection]
C --> D[Output and replay safety checks]
D --> E[Bounded retry]
E --> A
E --> F[Configured fallback or final error]
B --> G[Valid answer or tool call]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +21, Tests +556. Total +577 across 6 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep malformed arguments non-executable while allowing the existing bounded recovery path to retry only attempts proven silent and replay-safe. Do we have a high-confidence way to reproduce the issue? Yes: current source establishes that a discarded malformed tool call can retain positive output usage and fail the silent-error retry gate. The contributor reports a matching before/after Gateway reproduction; this review did not execute it. Is this the best way to solve the issue? Yes: extending the existing retry predicate preserves strict parsing, replay vetoes, and the established retry/fallback budget without adding a competing recovery path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ee2d54f0dc89. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
…y and transport Add a real-runtime proof e2e: a loopback Anthropic-format provider answers the first streaming request with a sealed tool_use block whose argument buffer is truncated, and the second with a plain text reply. The gateway's embedded runner must reject the first turn, resubmit through the real transport, and finish with the recovered text and no leaked argument bytes. Also address CI on the first revision: use the typed usage fixture in the new assistant-failure cases (tsgo), and read the assistant's typed errorCode/errorMessage directly instead of casting (assertion-safety ratchet). Related: openclaw#135111
|
Pushed 444b884 and updated the PR body with after-fix runtime proof: a new |
…tries are spent Once the bounded resubmits for a pre-dispatch tool-call rejection are exhausted and a fallback chain is configured, the run must move to the fallback model through the existing exhausted-silent-error path instead of surfacing the rejection. Related: openclaw#135111
|
Pushed 848a0ec (test only): pins that once the three resubmits are spent and a fallback chain is configured, the rejection routes through the existing |
|
landpr-approve-unrelated-red |
|
Thanks @lraesly! Landed in 6ac9827. Proof: 316 focused tests and 24 independently exercised Gateway scenarios passed, including strict rejection, counted tool effects, replay, pending approval and cancellation.
CI exception: run 34304870127, attempt 1 completed with one failed child, checks-node-changed-extensions-bundle-13 / job 102319504622, and the resulting aggregate gate failure. The first bare Discord The main-parent run passed but did not select Discord tests; it is not claimed as a matching reproduction. No matching red main run or exact stalled await was established. The unchanged test came from #140637, commit 93562ca; that is test provenance, not blame for the timeout. Used the guarded standing approval for this causally separate failure. No timeout, assertion, source or CI rerun was changed to hide it. |
## What Problem This Solves A provider can consume output tokens before rejecting a malformed tool call. When that rejection leaves no visible answer or executable action, positive token usage prevented OpenClaw's existing silent-error retry. The user received a failed turn after one request even when a second attempt could succeed. ## Why This Change Was Made Let the existing retry owner recognize the stable malformed-tool error code and five exact transport-owned rejection messages after its visibility, terminal-state and replay-safety checks. Message matching preserves case, whitespace and punctuation exactly. Parsing stays strict, and the existing budget remains three retries after the initial request. ## User Impact Transient malformed tool output can recover through the same model or the existing configured fallback. Visible output, admitted actions, possible effects, active work, approvals and terminal failures retain their retry vetoes. A valid tool call from a later attempt still follows normal policy. Fixes openclaw#135111. ## Evidence - Real isolated built Gateway through public `chat.send`, `agent.wait` and `chat.history`, with local Messages/Responses streams and counted tool actions. - Main: one failed request and zero rejected-call executions. Candidate: recovery in two requests; a later valid tool executes once across three requests; repeated rejection stops at four requests; configured fallback succeeds on request five. - Independent public scenarios cover same-session replay, visibility, accepted work, real background activity, pending approval and owner cancellation, refusal, timeout, abort, authentication/context errors, and unrelated Responses errors. Additional real channel delivery and an potentially mutating action that made no domain change preserve the retry fence. - 316 focused tests pass, including the exact-match regressions, retry/fallback owner, asynchronous settlement and permanent WebSocket-close producer. Formatting, lint, size/assertion guards and the native commit hook pass. Native early asynchronous provider eligibility and typed terminal-code precedence are covered at their unchanged component boundaries. The local provider fixtures do not claim an official-provider live result. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Thank you @obviyus, both for landing it and for the write-up: the independent 24-scenario gateway run and the before/after table are a better summary of the change than my PR body was. Appreciate the care on the unrelated red shard too. |
…fter completed tool calls A tool call the transport rejects before dispatch (malformed JSON arguments) still ends the turn when earlier exec/edit/write calls in the same attempt committed side effects, because the openclaw#142176 recovery resubmits the original prompt and the replay-safety gate correctly refuses that. The transcript is valid through the last settled tool result, so continue it instead: route the rejection through sessionPromptState.continueFromCurrentTranscript, bounded to three continuations per run and gated on a fully settled tool batch. Fresh-turn rejections keep the resubmit path; truncated arguments still fail closed. Related: openclaw#147040
…fter earlier tools ran (#164274) A turn ended with an error when the provider streamed a malformed or incomplete tool call after another tool in the same turn had already run. The incomplete-turn recovery now grants one bounded continuation, so the model can re-issue the call, but only when earlier tools completed. Completed tools are never repeated, persistently malformed calls still end with the existing error, and turns with no prior tool are unchanged. The only new model-facing text is the 390-byte continuation message. Proof: on a real Gateway with a scripted stub, base failed after 2 requests, and this change recovered after 4 with the first side-effecting tool run exactly once. The persistent-malformed control ends after 6 requests with the existing error, and the no-prior-tool control matches main at 4 requests. A live gpt-5-mini smoke call passed. Related: #142176 #156342 #157469.
…fter earlier tools ran (openclaw#164274) A turn ended with an error when the provider streamed a malformed or incomplete tool call after another tool in the same turn had already run. The incomplete-turn recovery now grants one bounded continuation, so the model can re-issue the call, but only when earlier tools completed. Completed tools are never repeated, persistently malformed calls still end with the existing error, and turns with no prior tool are unchanged. The only new model-facing text is the 390-byte continuation message. Proof: on a real Gateway with a scripted stub, base failed after 2 requests, and this change recovered after 4 with the first side-effecting tool run exactly once. The persistent-malformed control ends after 6 requests with the existing error, and the no-prior-tool control matches main at 4 requests. A live gpt-5-mini smoke call passed. Related: openclaw#142176 openclaw#156342 openclaw#157469.
What Problem This Solves
A provider can consume output tokens before rejecting a malformed tool call. When that rejection leaves no visible answer or executable action, positive token usage prevented OpenClaw's existing silent-error retry. The user received a failed turn after one request even when a second attempt could succeed.
Why This Change Was Made
Let the existing retry owner recognize the stable malformed-tool error code and five exact transport-owned rejection messages after its visibility, terminal-state and replay-safety checks. Message matching preserves case, whitespace and punctuation exactly. Parsing stays strict, and the existing budget remains three retries after the initial request.
User Impact
Transient malformed tool output can recover through the same model or the existing configured fallback. Visible output, admitted actions, possible effects, active work, approvals and terminal failures retain their retry vetoes. A valid tool call from a later attempt still follows normal policy.
Fixes #135111.
Evidence
chat.send,agent.waitandchat.history, with local Messages/Responses streams and counted tool actions.Native early asynchronous provider eligibility and typed terminal-code precedence are covered at their unchanged component boundaries. The local provider fixtures do not claim an official-provider live result.