Skip to content

fix(agents): continue after rejected malformed tool calls - #158568

Closed
MagMueller wants to merge 1 commit into
openclaw:mainfrom
MagMueller:agent/malformed-tool-continuation-pr-20260926
Closed

MagMueller wants to merge 1 commit into
openclaw:mainfrom
MagMueller:agent/malformed-tool-continuation-pr-20260926

Conversation

@MagMueller

@MagMueller MagMueller commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A provider can reject a malformed tool call before dispatch after earlier tools have already completed. OpenClaw currently terminates that run even though the transcript has settled results and can be continued safely.

Change

  • continue the existing transcript after a provider rejects a malformed tool call before dispatch
  • cap recovery at two attempts and reuse the existing continuation path
  • fail closed when tool results are missing, work is active, approval is pending, the harness owns recovery, or the run yielded/cancelled/timed out

This is deliberately separate from #126255: it is a generic embedded-runner fix, not Browser Harness integration code. It changes three files.

Safety

The original user request and already-completed tools are never replayed. Recovery is allowed only after all prior tool calls are settled; otherwise the existing terminal failure remains unchanged.

Evidence

  • attempt-recovery.test.ts: 94/94 passing in 7.90s; the new malformed-call continuation case completed in 3ms
  • oxlint: 0 warnings, 0 errors
  • git diff --check: passing
  • exact combined OpenClaw + recovery benchmark: 81/106; recovery activated in 21 tasks, 18 reached clean final envelopes, and 16 passed the judge
  • exact two-task follow-up: 2/2 passed, although neither rerun reproduced the malformed provider response, so this confirms the failure is stochastic rather than independently proving this recovery path

Redacted real-path recovery trace

One retained exact-run task used target 4a1081fbeda9182f8c99710bafe7706715e0237f (the benchmarked revision of this patch), real Anthropic Claude Opus 5, and the normal embedded OpenClaw runner. Its terminal log records the provider rejection, the guarded continuation on the same run/session, and a normal stop:

[model-fetch] provider=anthropic model=claude-opus-5 status=200
[agent/embedded] embedded run agent end: runId=[redacted] isError=true ... rawError=Provider completed tool call with malformed JSON arguments
[agent/embedded] malformed tool call rejected after settled tools; continuing transcript attempt=1/2 runId=[same redacted id] sessionId=[redacted]
[agent/embedded] tool-search: cataloged 39 tools behind compact prompt surface
[agents/agent-command] run [redacted] ended with stopReason=stop

The preserved result envelope is status=completed with a 7,443-character final answer, and the independent semantic judge awarded 1.0. This is the real provider/transcript path; the prompt, task identifier, run identifier, and task output are omitted because the benchmark is private. The settled-tool gate and continuation budget are the same paths covered by the focused test.

Current head f116adaa665fa5e5eafdd2bdb31790cc6e642a47 is rebased on deb168691b2a10fde299ec0f911c8a5cbd9d0dda. Hosted general lint passes. The only current hosted CI failure is check-lint-core-2, which reports that unchanged base file src/gateway/server-kernel.test.ts is over its line cap; that file is 1,033 lines on the exact base and is not in this PR diff.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 26, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 3, 2026, 11:06 PM ET / October 4, 2026, 03:06 UTC (Revision 3).

ClawSweeper review

What this changes

The embedded agent runner resumes the existing transcript up to twice after a malformed tool call is rejected, provided earlier tools have fully settled.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This remains a useful, proven fix that current main does not implement. No introduced correctness defect was found, but the pinned head has confirmed merge conflicts.

Priority: P1
Reviewed head: f116adaa665fa5e5eafdd2bdb31790cc6e642a47

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful real-path proof and no identified patch defect; merge conflicts remain an integration blocker.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The captured redacted trace exercises the changed embedded recovery owner with a real provider: malformed rejection is followed by guarded continuation on the same run/session and a completed answer. Focused tests supplement the trace; stored formats and migration contracts are unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The captured redacted trace exercises the changed embedded recovery owner with a real provider: malformed rejection is followed by guarded continuation on the same run/session and a completed answer. Focused tests supplement the trace; stored formats and migration contracts are unchanged.
Evidence reviewed 8 items Pinned introduced change: The verified base-to-head delta adds malformed-call classification, a two-continuation budget, guarded transcript continuation, and focused regression cases. The original head records the supplied base as its parent.
Settlement and continuation ownership: Settlement requires matching recorded results, positive started work, equal completed and started counts, and zero active items. The new path also excludes asynchronous work, approvals, intentional termination, interruption, yielding, client tool calls, and transport-owning harnesses. The existing continuation owner suppresses another user-message persistence and instructs the model to preserve completed work.
Owned transport rejection contract: The repository's AI transport validates complete object-shaped arguments before making calls executable and emits the exact malformed-arguments code consumed by this patch. This is an OpenClaw-owned transport contract; no introduced behavior depends on the sibling Codex implementation.
Findings None None.
Security None None.

How this fits together

The embedded agent runner coordinates model responses, tool execution, and conversation history. Its recovery layer decides whether a failed response can continue safely or must end the run.

flowchart TD
  A[Model response] --> B[Tool argument validation]
  B --> C[Malformed call rejected]
  C --> D[Recovery safety checks]
  E[Recorded tool results and lifecycle] --> D
  D --> F[Continue existing transcript]
  D --> G[End failed run]
  F --> A
Loading

Before merge

  • Complete next step (P2) - Resolve the conflicts with current main, preserve its newer recovery changes, and validate and review the resulting head.
Agent review details

Security

None.

PR surface

Source +43, Tests +41. Total +84 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 43 0 +43
Tests 1 41 0 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 84 0 +84

Review metrics

None.

Technical review

Best possible solution:

Keep malformed-call recovery in the existing runner owner, preserving settled results, cancellation, approval boundaries, and the bounded continuation budget.

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

Yes, source establishes the settled-tool malformed-response path, and the supplied real-run trace observes it. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes, the patch extends the existing recovery and transcript owners without replaying the original request or adding configuration; the conflict-resolved version still needs assessment against current main.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Real-provider malformed tool responses can terminate otherwise recoverable agent work after tools have completed.
  • 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. Sufficient (logs): The captured redacted trace exercises the changed embedded recovery owner with a real provider: malformed rejection is followed by guarded continuation on the same run/session and a completed answer. Focused tests supplement the trace; stored formats and migration contracts are unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured redacted trace exercises the changed embedded recovery owner with a real provider: malformed rejection is followed by guarded continuation on the same run/session and a completed answer. Focused tests supplement the trace; stored formats and migration contracts are unchanged.

Evidence

What I checked:

  • Pinned introduced change: The verified base-to-head delta adds malformed-call classification, a two-continuation budget, guarded transcript continuation, and focused regression cases. The original head records the supplied base as its parent. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:367, f116adaa665f)
  • Settlement and continuation ownership: Settlement requires matching recorded results, positive started work, equal completed and started counts, and zero active items. The new path also excludes asynchronous work, approvals, intentional termination, interruption, yielding, client tool calls, and transport-owning harnesses. The existing continuation owner suppresses another user-message persistence and instructs the model to preserve completed work. (src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts:239, f116adaa665f)
  • Owned transport rejection contract: The repository's AI transport validates complete object-shaped arguments before making calls executable and emits the exact malformed-arguments code consumed by this patch. This is an OpenClaw-owned transport contract; no introduced behavior depends on the sibling Codex implementation. (packages/ai/src/transports/transport-stream-shared.ts:139, f116adaa665f)
  • Still necessary on current main: Current main retains output-limit, transient, overflow, and harness recovery but lacks the introduced malformed-call continuation. Existing replay-safe empty-error handling does not cover the settled side-effectful scenario this PR repairs. (src/agents/embedded-agent-runner/run/attempt-recovery.ts, cc740dfaf528)
  • Latest release check: The latest supplied release, v2026.9.8, has the existing continuation paths but no dedicated malformed-call recovery branch or budget. No merged fixing PR establishing supersession was supplied or verified. (src/agents/embedded-agent-runner/run/attempt-recovery.ts, fc23bc864e45)
  • Captured real behavior proof and review continuity: The supplied complete PR body, captured under sourceRevision 2a920221fa9c996f7b5b00a9d63a5edfc9dfa5c89673412f724e0e423a28f03a, preserves a redacted real-provider trace from benchmark revision 4a1081f: malformed rejection, guarded continuation on the same run/session, normal stop, and a completed result envelope. The prior completed review assessed the same pinned head with sufficient proof and no findings. The separate two-task rerun did not reproduce the rejection and is supplemental only. (f116adaa665f)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Victor Jaepyo Jo: 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 (2 earlier review cycles)
  • reviewed 2026-09-26T02:17:47.931Z sha bd3163d7a651f0dbcaf9755186683f53648df9b8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-26T02:45:37.574Z sha f116ada :: needs maintainer review before merge. :: none

@MagMueller
MagMueller force-pushed the agent/malformed-tool-continuation-pr-20260926 branch from bd3163d to f116ada Compare September 26, 2026 02:23
@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026

@ericcaiwx-star ericcaiwx-star left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced on qq-ci-158568 at head f116adaa665fa5e5eafdd2bdb31790cc6e642a47.

Lane: qq-ci-158568 (v24.19.0)
Command: python3 /Users/ericstudio/repos/oc-pr-management/.tmp/qq-upstream-review-20261004/ci-proof.py --pr 158568
Result: exit 0, passed 3 Vitest shards in 117.53s

Independent secretless Ubuntu 24.04 fork CI used Node 24.19.0, pnpm 12.4.2, the built native CLI, a deterministic loopback Chat Completions stream, and a real exec effect ledger. Workflow, artifacts, and raw logs; pinned harness.

Parent deb168691b2a10fde299ec0f911c8a5cbd9d0dda failed the continuation assertions and the CLI recovery scenario. At this head, the selected tests passed. The recovery scenario completed on the third model request with the original user turn present once, the existing tool result retained, and the preparation command executed once. Persistent malformed output failed after six model requests, with the preparation command still executed once. A settled foreground tool timeout also continued with the prior failure retained and explicitly reported by the synthetic response.

These are deterministic stream and native-runner observations. They do not establish live provider compliance, actual channel delivery, or executor-enforced exactly-once semantics.

Additional evidence: Adds publicly inspectable exact-parent/head Chat Completions CLI regression evidence with real tool-effect and transcript counts, including persistent rejection and a settled foreground tool timeout; the supplied real-provider trace uses an older combined benchmark revision.

Sibling surface checked: src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts:297; src/agents/embedded-agent-runner/run/terminal-resolution.ts:246; src/agents/embedded-agent-runner/run/message-tool-terminal.ts:94.

Not covered: live DeepSeek, real QQ delivery, Browser Harness/Codex/native-provider routes, and concurrency races; message/spawn producer probes use synthetic receipts and a mocked recovery seam.

@steipete

Copy link
Copy Markdown
Contributor

Thanks @MagMueller for this fix and the careful fail-closed conditions. The same behavior is now on main via #164274 (c5fcae2): when a provider rejects or truncates a malformed tool call after earlier tools in the turn have completed, the incomplete-turn recovery grants one bounded continuation so the model can re-issue the call, completed tools are never repeated, persistently malformed calls still end with the existing error, and turns without prior tools are unchanged.

We re-verified the shared continuation scenario on current main with a local Gemma 4 Gateway run while working on the related #168500 (auth misclassification of 401/403-character arguments, also now fixed), so I'm closing this as superseded. If you have a case where a settled tool batch still ends the turn on a current build, please open an issue with the provider stream and we'll look again.

@steipete steipete closed this Oct 10, 2026
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: S 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.

3 participants