Skip to content

fix(agents): retry silent malformed tool rejections - #142176

Merged
obviyus merged 4 commits into
openclaw:mainfrom
lraesly:fix/retry-pre-dispatch-tool-call-rejection
Sep 9, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
lraesly:fix/retry-pre-dispatch-tool-call-rejection

Conversation

@lraesly

@lraesly lraesly commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 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.

…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
@clawsweeper

clawsweeper Bot commented Sep 8, 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 agents Agent runtime and tooling size: S labels Sep 8, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 10:58 PM ET / September 9, 2026, 02:58 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: b0e728bda06a925a9fa79f57855a8d0f6352c116

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful production-path evidence and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Reported isolated Gateway runs exercise the changed retry owner through public chat RPCs and the real HTTP transport against injected malformed SSE: main fails after one request, while the candidate recovers after two. Request-count, fallback, and safety-fence observations support this internal reliability change; official-provider live behavior is not claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported isolated Gateway runs exercise the changed retry owner through public chat RPCs and the real HTTP transport against injected malformed SSE: main fails after one request, while the candidate recovers after two. Request-count, fallback, and safety-fence observations support this internal reliability change; official-provider live behavior is not claimed.
Evidence reviewed 8 items Current main still has the reported gate: Current main returns false for empty errored content with positive output usage, without the proposed malformed-tool exception.
Latest release retains the same limitation: The v2026.9.3 source also rejects this empty positive-output case; the proposed recovery is not present in the supplied latest release.
Narrow retry exception preserves vetoes: Recognition occurs after visible-output, terminal-state, replay-safety, and terminal-assistant checks. Only empty content gains the exact-code or exact-message exception.
Findings None None.
Security None None.

How this fits together

Provider 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +21, Tests +556. Total +577 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 22 1 +21
Tests 3 556 0 +556
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 578 1 +577

Review metrics

Metric Value Why it matters
Production versus test growth Production +21 net lines; tests +556 lines Production growth is limited to rejection recognition; test growth covers exact matching, safety vetoes, bounded fallback, and Gateway-to-transport recovery.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #135111
Summary: This PR is a candidate recovery fix for the linked malformed-tool report; parser repair remains complementary.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best 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.

Labels

Label justifications:

  • P1: The linked reports describe active agent turns failing without retry or configured fallback after malformed provider output.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Reported isolated Gateway runs exercise the changed retry owner through public chat RPCs and the real HTTP transport against injected malformed SSE: main fails after one request, while the candidate recovers after two. Request-count, fallback, and safety-fence observations support this internal reliability change; official-provider live behavior is not claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported isolated Gateway runs exercise the changed retry owner through public chat RPCs and the real HTTP transport against injected malformed SSE: main fails after one request, while the candidate recovers after two. Request-count, fallback, and safety-fence observations support this internal reliability change; official-provider live behavior is not claimed.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-08T13:21:13.324Z sha aed516d :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-08T14:44:52.221Z sha 444b884 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T16:58:30.538Z sha 848a0ec :: needs maintainer review before merge. :: none

…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
@lraesly

lraesly commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 444b884 and updated the PR body with after-fix runtime proof: a new test/pr142176-real-runtime-proof.e2e.test.ts boots a real gateway against a loopback Anthropic-format provider whose first streaming reply is a truncated tool call and whose second is plain text. On this branch agent.wait returns status: ok after two POST /v1/messages; with upstream/main sources the same test gets status: error ("Agent run failed") after one request. Also fixed the two CI items from the first run (typed usage fixture for tsgo; no casts in the gate helper for the assertion ratchet). The remaining red shard was a Telegram sticker image-model test this PR does not touch.

@clawsweeper clawsweeper Bot added 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 8, 2026
…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
@lraesly

lraesly commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 848a0ec (test only): pins that once the three resubmits are spent and a fallback chain is configured, the rejection routes through the existing exhaustedUnclassifiedSilentError path to fallback_model instead of surfacing. PR body also gains a bound/replay check from the gateway harness with an always-rejecting provider: 4 requests per turn, then the same error as today, and the next turn's request carries nothing from the rejected turn (no tool block, no error text).

@obviyus obviyus self-assigned this Sep 9, 2026
@obviyus obviyus changed the title fix(agents): run dies without retry when a transport rejects malformed tool-call arguments fix(agents): retry silent malformed tool rejections Sep 9, 2026
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-unrelated-red
pr: 142176
head: b0e728b
run: 34304870127 attempt: 1
failed: checks-node-changed-extensions-bundle-13 job=102319504622 conclusion=failure
check: openclaw/ci-gate

@obviyus
obviyus merged commit 6ac9827 into openclaw:main Sep 9, 2026
211 of 213 checks passed
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Bug: positive output usage prevented an otherwise safe retry after malformed tool arguments were rejected.
  • Fix: exact rejection signals use the existing bounded retry after all output, effect and terminal guards.
Before After
One failed request; rejected call never executes Recovery in two requests; a later valid tool executes once
No recovery from repeated rejected calls Four-request limit, then existing failure or configured fallback

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 /new reset test timed out at 120 seconds; 3,695 other tests in that shard passed. This command returns its reset acknowledgement before model execution, so the changed provider retry branch is not reached. The test and reset/session/dispatch owners are unchanged in the exact tested merge.

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
## 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]>
@lraesly

lraesly commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

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.

lraesly added a commit to lraesly/openclaw that referenced this pull request Sep 14, 2026
…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
obviyus pushed a commit that referenced this pull request Oct 4, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

[Bug]: Intermittent "Provider completed tool call with malformed JSON arguments" on v2026.8.1 (claude-sonnet-5), not tied to specific file/tool

2 participants