Skip to content

fix(agents): runs end with "couldn't generate a response" when the model writes a tool call as text - #156342

Merged
obviyus merged 3 commits into
openclaw:mainfrom
namest504:fix/tooluse-stop-without-calls
Oct 1, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
namest504:fix/tooluse-stop-without-calls

Conversation

@namest504

@namest504 namest504 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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 exec against a local Anthropic Messages mock on current main d215e9279d66233f9c84f63e72cca70350746f59 and the candidate. The first response was a text block containing exec followed by a pseudo <invoke name="read"> call, with stop_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.

Case Current main Candidate
Malformed first turn, then normal answer 1 request; incomplete-turn warning; exit 1 2 requests; recovered answer; exit 0
Malformed turn persists Not repeated 2 requests; existing visible warning; exit 1
Normal structured read call 2 requests; 1 successful read; normal answer Same
Genuinely empty first answer 2 requests; normal answer Same
Bare NO_REPLY in required-answer agent exec 2 requests; existing warning Same

The 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, expected retry) and passes on the candidate. Focused recovery and terminal-resolution coverage passes: 3 files, 78 tests, 28.48 seconds wall with node 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.

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

clawsweeper Bot commented Sep 23, 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 23, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 5:46 AM ET / 09:46 UTC (Revision 3).

ClawSweeper review

What this changes

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with sufficient production-path evidence, meaningful regression coverage, and no actionable introduced defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured Docker CLI results exercise the production terminal resolver through the real Anthropic client with an injected malformed response: the candidate continues once and returns an answer, while persistent malformed output retains the warning. The continuation answer is scripted, so this establishes runner recovery rather than live-model compliance; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured Docker CLI results exercise the production terminal resolver through the real Anthropic client with an injected malformed response: the candidate continues once and returns an answer, while persistent malformed output retains the warning. The continuation answer is scripted, so this establishes runner recovery rather than live-model compliance; no stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The verified merge-base-to-head diff introduces only the malformed-turn recovery predicate, continuation instruction, retry diagnostic, and terminal regression tests.
Current-main gap: Current main still requires emptyResponse before selecting an empty-response continuation; classification excludes toolUse stops, including the reported text-bearing response.
Latest-release check: Reading this file at v2026.9.7 confirms that the latest release also lacks the tool-use-without-call recovery branch.
Findings None None.
Security None None.

How this fits together

OpenClaw’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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +102. Total +122 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 24 4 +20
Tests 1 102 0 +102
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 126 4 +122

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138929
Summary: This PR is the implementation candidate for the linked malformed-tool-call report.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a focused improvement to recovery from malformed model output with limited blast radius.
  • 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 (terminal): The captured Docker CLI results exercise the production terminal resolver through the real Anthropic client with an injected malformed response: the candidate continues once and returns an answer, while persistent malformed output retains the warning. The continuation answer is scripted, so this establishes runner recovery rather than live-model compliance; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Docker CLI results exercise the production terminal resolver through the real Anthropic client with an injected malformed response: the candidate continues once and returns an answer, while persistent malformed output retains the warning. The continuation answer is scripted, so this establishes runner recovery rather than live-model compliance; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The verified merge-base-to-head diff introduces only the malformed-turn recovery predicate, continuation instruction, retry diagnostic, and terminal regression tests. (src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts:194, a5d83e2cb949)
  • Current-main gap: Current main still requires emptyResponse before selecting an empty-response continuation; classification excludes toolUse stops, including the reported text-bearing response. (src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts, d47a0d4067ec)
  • Latest-release check: Reading this file at v2026.9.7 confirms that the latest release also lacks the tool-use-without-call recovery branch. (src/agents/embedded-agent-runner/run/incomplete-turn-recovery.ts, c074824a27c9)
  • Recovery safety and ownership: Recovery requires no structured call, tool metadata, or started lifecycle item. Existing failure, interruption, side-effect, delivery, and finalization guards remain authoritative; terminal resolution uses the existing one-retry budget. The run loop rechecks its admitted authority before each attempt, and pseudo-call text is never parsed or executed. (src/agents/embedded-agent-runner/run/terminal-resolution.ts:336, a5d83e2cb949)
  • Production-path proof: The captured PR body reports secretless Docker runs through openclaw agent exec and the real Anthropic Messages client against an injected malformed response. Main made one request and returned the warning with exit 1; the candidate made two requests and returned the scripted answer with exit 0. Persistent malformed output exhausted the retry and retained the warning. Structured read calls, genuinely empty answers, and required-answer NO_REPLY controls retained their behavior. This proves runner recovery, not live-model compliance.
  • Regression and re-review continuity: The terminal-owner regression covers retry, exhaustion, prior tool activity, and side effects. The body reports a failing main regression and 78 passing focused tests in 28.48 seconds. GitHub’s exact-head commit patch confirms that the latest commit only removes the exact prompt-string assertion; production behavior and the earlier runtime proof remain applicable. Previous completed reviews retained no findings or rank-up moves. (src/agents/embedded-agent-runner/run/terminal-resolution.tool-use-without-call.test.ts:55, a5d83e2cb949)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • sjf-oa: 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-23T09:38:16.789Z sha 3727f4c :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T03:43:01.472Z sha 86f093c :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Exact head a5d83e2cb94901fed701db31260d6bbccdf69e69 has a ready ClawSweeper review with no findings. CI is red for these unrelated failures:

  • checks-fast-baseline-ratchets: check-database-worker-ratchet.mts cannot spawn rg (ENOENT). Same failure elsewhere. The preceding line-cap and assertion-safety checks passed; this patch does not change runner executable installation.
  • checks-node-changed-compact-large-32-2: session-manager-branching.test.ts, “revalidates queued lifecycle changes before branching,” mismatched SessionTranscriptWriterClaimReboundError.
  • checks-node-changed-compact-large-32-4: run.compaction-runtime.test.ts, resolved-model-budget and independent-safety-timeout cases returned surface instead of retry; retained active maintenance rewrite rejected with “Agent database resources are closing.”
  • checks-node-changed-compact-large-31-7: session-manager-hydration-stream.test.ts, complete UTF-8 snapshot during row replacement, timed out in the worker task pool.

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 fb2487a903ab3b15fe72f599a7d0bb33c1ec0488. Both runs passed all 56 tests: branching 11, compaction 38, hydration 7. The affected fixtures call the session/database and compaction-recovery owners directly; they do not execute malformed-turn terminal resolution. The diff changes neither those lifecycle owners nor their fixtures. These replays establish matching head/revert behavior, not a fix for the CI flakes.

The aggregate openclaw/ci-gate is red from those jobs. Completed CI: 70 successful jobs, 23 selected skips, 4 failing jobs plus the aggregate gate, 0 cancelled CI jobs. One earlier PR-context check was superseded; its replacement passed. No selected test coverage was cancelled. No jobs were rerun and no branch refresh was performed.

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: every red on head a5d83e2cb94901fed701db31260d6bbccdf69e69 (run 36844244245, 0 cancelled CI jobs) is unrelated to this diff. Per-case attribution is in #156342 (comment). ClawSweeper's exact-head review is ready, with no findings.

Proof: a real agent exec in secretless Docker.

  • Recovery: on main, a text-only tool_use stop with a pseudo <invoke> call ends with the warning after 1 request. On this head it recovers after 2.
  • Bounds: a pseudo-call that keeps repeating still stops visibly at the bound.
  • Unchanged: normal structured tool calls, empty answers and the NO_REPLY contracts.
  • Regression test: fails on main and passes here.

@obviyus
obviyus merged commit a865288 into openclaw:main Oct 1, 2026
148 of 155 checks passed
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Landed as a865288. Thanks @namest504!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…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]>
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 P2 Normal backlog priority with limited blast radius. 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.

[Bug]: Model emits malformed pseudo tool-call text on first "read" tool use, causing "Agent couldn't generate a response"

2 participants