Repository navigation
fix(agents): continue a malformed tool call after a consumed tool failure - #170846
akushonkamen wants to merge 4 commits into
Conversation
… tool failure When the provider streams a tool call with malformed arguments after an earlier tool in the same turn failed, the bounded rejected-call continuation was still skipped and the turn ended with 'Agent run failed'. shouldSkipNonVisibleTurnRetry vetoed on attempt.lastToolError regardless of the rejectedBeforeDispatch tolerance, and recordSuccess clears lastToolError only when the same tool name succeeds, so an exec preflight refusal followed by a malformed second call dropped the turn even though the failed result was already in the transcript and the rejected call never ran. resolveEmptyResponseRetryInstruction now proves provenance through resolveSettledToolBatchEvidence: when the rejected call never dispatched and the retained error is a failed result the model already saw in a proven-settled batch (its name matches the batch's failed results, or a fully settled successful batch proves the error is stale from an earlier tool), the lastToolError veto alone is relaxed. Every other skip guard stays fail-closed: unfinished work, async activity, unattributed errors and replay-unsafe attempts still block, and the continuation stays bounded to one. Fixes openclaw#170522.
|
🦞👀 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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Codex review: ready, awaiting a maintainer decision. What this changesAllows one malformed-call continuation after an earlier failed tool result has already reached the model, regardless of whether that tool started. Example: An edit tool returns an error, then the model sends truncated JSON for a write call.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete Merge readiness⏳ Ready, awaiting maintainer decision Keep this PR open: it repairs a demonstrated recovery gap with no concrete patch defect found, but broadens an intentionally restricted policy and still lacks a successful exact-head CI gate. Priority: P2 Decision needed
Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded agent runner consumes provider responses, transcript ordering, and tool lifecycle facts to choose between bounded continuation and terminal completion. flowchart TD
A[Chat or scheduled turn] --> B[Provider response]
B --> C[Tool execution and results]
C --> D[Transcript and lifecycle facts]
B --> E[Recovery eligibility]
D --> E
E --> F[One continuation or terminal result]
Technical reviewBest possible solution: Accept the transcript-based exception in the existing recovery owner while preserving failure records, lifecycle guards, and the single-continuation budget. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically blocks executed failures, and the supplied base-versus-head Gateway traces demonstrate that exact sequence; this read-only review ran no target code. Is this the best way to solve the issue? The smallest complete fix removes the execution-start distinction and receipt restriction from the existing consumed-failure check, retaining transcript attribution and bounded continuation without adding another owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9d6f4a94adf5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -13, Tests +11, Docs +1. Total -1 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 18, 2026, 7:26 AM ET / 12:26 UTC (Revision 2). |
|
Production proof for this gap, filed as #199537. On 2026.10.10, an MCP tool ran and returned |
# Conflicts: # src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts
- A retained tool error no longer vetoes the single rejected-call continuation once its failed result precedes the rejected response in the current turn, whether or not the failed tool had started. - Reconciles openclaw#170846 with the transcript check now on main; the settled-batch exemption it added is superseded. - Folds the executed-failure cases into the existing rejected-call table and drops the duplicate block.
# Conflicts: # src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts
|
Gateway proof for this head (d00cf7a) against main 93ec0fe (which already includes #201117): isolated Gateway from source, local Anthropic Messages fixture. An edit tool call runs and returns an error, then the next call has truncated JSON arguments (rejected before dispatch, malformed_tool_call_arguments). Provider request log, this head: |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
This pull request has been automatically marked as stale after 7 days without qualifying human activity. |
Root cause: src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts:465 treats a retained tool error as consumed only when
executionStarted === false(and :484 also requires a not_started receipt on every failure), so a tool that ran and returned an error keeps vetoing the single continuation for a later tool call rejected before dispatch, although the model already read that failure.Fixes #199537
Thanks @jaxonparrott for the production report and source trace, and @akushonkamen for the original fix.
What Problem This Solves
A tool runs and returns an error, the model reads it and makes its next tool call, and that call streams malformed JSON arguments. The call is rejected before it runs, and the turn ends with "couldn't finish this reply" instead of getting the one continuation every other rejected call gets. In the reported cron run this threw away 13.5 minutes and 4.7M tokens.
User Impact
The turn continues once and the model can re-issue its call or answer. Completed tools are not repeated. Failures the model has not seen (no result yet, a result after the rejected response, a prior turn, or a different tool), unfinished or asynchronous work, and the one-continuation budget still block, as before.
Why This Change Was Made
The continuation replays nothing: the rejected call never ran, and the earlier failure already sits in the transcript before the rejected response. Whether that failed tool had started does not change what the continuation does, so the started/not-started split only blocked recovery. The retained error now counts as consumed when its failed result is the latest failure in the current turn, precedes the rejected response, and names the retained tool.
This keeps @akushonkamen's commits and reconciles them with the transcript check main gained in #170615: the settled-batch exemption from the original commit is superseded by that check, and the executed-failure cases join the existing rejected-call test table.
docs/concepts/agent-loop.mddescribes the new boundary. No new model-facing text. Production lines: +5/-14.Evidence
Isolated Gateway from source (
ocx src) on main vs this branch, local Anthropic Messages fixture: aneditcall that runs and returns an error, then awritecall with truncated JSON arguments.editis not repeated.status=error; with both fixes the run endsstatus=okafter one continuation.continues after consumed tool failures (started | unknown | earlier started)fail on main and pass here; the negative table (missing, unconsumed, prior-turn, different tool, active, async) still passes.Proof log: #170846 (comment)
Merge danger: two-way door; a revert restores the started-failure veto. No config, schema or state change. Blast radius: turns whose last model response was a tool call rejected before dispatch after an earlier tool error in the same turn.