Repository navigation
fix(agents): runs end with "couldn't generate a response" when the model writes a tool call as text - #156342
Conversation
A model can write a tool call as text and still stop for tool use. The turn then has no structured call, nothing runs, and the run surfaced the incomplete-turn warning instead of recovering. Treat that shape like an empty response when no tool ran in the attempt, and continue once with an instruction to make the call through the tool interface.
|
🦞👀 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 October 1, 2026, 5:46 AM ET / 09:46 UTC (Revision 3). ClawSweeper reviewWhat this changesThe agent runner retries once when a model stops for tool use without a structured call, records the stop reason in retry logs, and adds recovery regression coverage. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release still lack recovery for the reported malformed turn. The bounded continuation has sufficient production-path proof, and no introduced correctness blocker was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s embedded agent runner receives model responses and tool results, then decides whether to continue or return a reply. This change repairs that terminal decision before an incomplete-turn warning reaches the user. flowchart LR
A[User request] --> B[Model response]
B --> C[Agent runner]
C --> D{Missing structured tool call?}
D -->|Safe and budget available| E[One continuation]
E --> B
D -->|Otherwise| F[Reply or visible warning]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +20, Tests +102. Total +122 across 3 files. View PR surface stats
Review metricsNone. 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-turn recovery in the existing terminal owner, with one continuation, preserved transcript content, and unchanged tool-execution and side-effect boundaries. Do we have a high-confidence way to reproduce the issue? Yes. Injecting an Anthropic tool-use stop containing pseudo-call text but no structured tool block exercises the source-proven main failure; the supplied before/after CLI results corroborate it. This read-only review did not execute product code. Is this the best way to solve the issue? Yes. Extending the existing guarded continuation is a narrow repair that avoids interpreting model prose as executable tool input. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d47a0d4067ec. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Exact head
For the three test jobs, ran their exact failing files in secretless Docker on the head and then on the same tree with both production files restored to merge base The aggregate |
|
Maintainer override: every red on head
Proof: a real agent exec in secretless Docker.
|
|
Landed as a865288. Thanks @namest504! |
…del writes a tool call as text (openclaw#156342) * fix(agents): retry a tool-use stop that carries no tool call A model can write a tool call as text and still stop for tool use. The turn then has no structured call, nothing runs, and the run surfaced the incomplete-turn warning instead of recovering. Treat that shape like an empty response when no tool ran in the attempt, and continue once with an instruction to make the call through the tool interface. * test(agents): assert recovery behavior without pinning prompt wording --------- Co-authored-by: Ayaan Zaidi <[email protected]>
…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.
Closes #138929
What Problem This Solves
Fixes: a run ends with “Agent couldn't generate a response” when the model writes a tool call as text and stops for tool use without a structured call.
User Impact
User impact: that malformed turn gets one automatic continuation instead of immediately failing. If the malformed output persists, the existing visible warning remains. No text is parsed or executed as a tool call.
Why This Change Was Made
Reuse the existing empty-response retry budget for a tool-use stop without a structured call, only when no tool ran. Existing interruption, side-effect, delivery, and lifecycle guards remain in charge. Genuine empty answers and authored silence retain their existing contracts.
Original fix and initial reproduction: @namest504; the contributor commits are retained.
Maintainer intent: checked Sarah's #149642 and Pash's
a2bbcbf4068; their intentional-silence and completed-side-effect guards are unchanged, covered by the controls and terminal tests below. No compact Slack rendering code changes.Evidence
Ran isolated
openclaw --profile <profile> agent execagainst a local Anthropic Messages mock on current maind215e9279d66233f9c84f63e72cca70350746f59and the candidate. The first response was a text block containingexecfollowed by a pseudo<invoke name="read">call, withstop_reason: "tool_use"and no structured tool block. Explicit isolated home, state, config, and profile paths were resolved and checked before execution. All product execution was inside secretless Docker.NO_REPLYin required-answeragent execThe CLI control requires an answer; it does not represent reply-optional channel silence. Existing terminal-owner tests for optional
NO_REPLY, internal notifications, and side-effecting intentional silence also pass unchanged. The mock scripts its continuation, so this proves runner behavior, not live-model compliance.The retained regression fails on current main at the retry decision (actual
complete, expectedretry) and passes on the candidate. Focused recovery and terminal-resolution coverage passes: 3 files, 78 tests, 28.48 seconds wall withnode scripts/run-vitest.mjs. The new regression cases take 28 ms, 11 ms, and 6 ms. Coverage includes retry exhaustion and refusal after tool activity or side effects. Removed the exact prompt-wording assertion while retaining behavioral coverage.A first test attempt overlapped the initial CLI build and failed before executing tests because artifacts changed during compilation. After the build completed, the scoped run passed. No project-wide validation was run locally.