Skip to content

fix: scheduled runs stop on a malformed tool call - #201117

Merged
obviyus merged 3 commits into
openclaw:mainfrom
ericcurtin:fix/cron-malformed-tool-call-continuation
Nov 18, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
ericcurtin:fix/cron-malformed-tool-call-continuation

Conversation

@ericcurtin

@ericcurtin ericcurtin commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: src/agents/embedded-agent-runner/run/terminal-resolution.ts:231 treats the "optional" reply expectation as unconditional reply-recovery suppression, so a scheduled run (cron sets "optional" at src/cron/isolated-agent/run-prompt-executor.ts:449) never reaches the existing single continuation for a tool call rejected before dispatch.

Fixes #201104

Thanks @jaxonparrott for the report and the source trace, and @ericcurtin for the fix.

What Problem This Solves

A scheduled run ends with "OpenClaw couldn't finish this reply" when the provider sends one malformed tool call. Chat turns and subagents get one continuation for the same failure and finish.

User Impact

Scheduled runs, heartbeats and hooks (every "optional" reply turn) get the same single continuation as chat turns when a tool call is rejected before it ran. Optional turns that author silence stay silent; delivered replies, ordinary empty optional turns and the one-continuation budget are unchanged.

Why This Change Was Made

"Optional reply" means the model may author silence. A call the transport rejected before dispatch is a provider error, not authored silence. The rejected-before-dispatch check moves into one helper in the recovery owner (isRejectedBeforeDispatch), and the optional-reply gate exempts only that fact. No new model-facing text: the existing continuation instruction is reused.

terminal-resolution.ts stays within its 700-line cap: a single-use local in resolveSettledTurnFinalizationRequest is inlined (no behavior change). Production +28/-16 (mostly the moved check), tests +13/-1.

Evidence

Isolated Gateway from source (ocx src) on main 1fc5296 vs this branch, with a local Anthropic Messages fixture: a side-effecting write call, then a write call with truncated JSON arguments (rejected with malformed_tool_call_arguments).

  • Cron run (cron.add isolated agentTurn, cron.run force): main ends status=error "couldn't finish this reply" with no continuation request; this branch sends one continuation and the run ends status=ok with the model's answer. The completed write is not repeated.
  • Cron run where the model keeps sending malformed calls: one continuation ("retrying 1/1"), then the run fails as before.
  • Chat control: one continuation and recovery on both main and this branch, unchanged.
  • An executed tool that returned an error before the malformed call ([Bug]: Malformed tool call is not continued when the previous tool ran and returned an error (executionStarted: true) #199537) still ends without a continuation on both; that is a separate guard and not changed here.
  • Regression continues a rejected call once in a scheduled run: fails on main, passes here. terminal-resolution, incomplete-turn-recovery and cron message-tool-policy suites pass; oxfmt and oxlint clean.

Proof log: #201117 (comment)

Merge danger: two-way door; a revert restores the old suppression. No config, schema or state change. Blast radius: optional-reply turns (cron, heartbeat, hooks) whose last model response was a tool call rejected before dispatch.

@clawsweeper

clawsweeper Bot commented Nov 18, 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 Nov 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allows optional-reply runs to use the existing bounded continuation after an eligible malformed tool call is rejected before dispatch.

Example: An isolated cron run completes a write, then receives a write call with truncated JSON arguments.

  • Before: The run ends with “OpenClaw couldn't finish this reply” without requesting a continuation.
  • After: One continuation produces “RECOVERED SCEN_OK”, the run finishes successfully, and the completed write runs only once.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, source-verified repair with shipped Gateway proof, a distinct regression, and no actionable findings; CI completion remains outstanding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied isolated Gateway and real Anthropic transport trace exercises cron recovery after a completed write and malformed arguments, records one continuation and successful completion without repeating the write, and verifies persistent failure and chat controls; the final production edit does not alter that path.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scheduled tasks stop after a malformed provider tool call instead of receiving the bounded correction already available to chat turns.
Reason: The change restores documented recovery for a demonstrated scheduled-workflow failure, preserves intentional silence, and has direct collaborator implementation and verification.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current scheduled-run failure with a focused change and sufficient Gateway proof; no actionable defects were found, and exact-head CI remains in progress.

Priority: P1
Reviewed head: 8a1160745e94285c41beb48c125dd13bb2ed0162

Before merge

None.

Findings

None.

Agent review details

How this fits together

The embedded runner combines provider responses, tool lifecycle evidence, delivery state, and reply expectations to choose continuation or a terminal result for chat and scheduled callers.

flowchart TD
  A[Scheduled agent turn] --> B[Embedded runner]
  B --> C[Provider response]
  C --> D[Terminal resolution]
  E[Tool and delivery evidence] --> D
  D --> F[Bounded continuation]
  F --> B
  D --> G[Completed run result]
Loading

Technical review

Best possible solution:

Keep rejection eligibility in the existing recovery owner and allow optional turns through its bounded continuation without weakening silence, delivery, or tool-settlement guards.

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

The supplied isolated Gateway comparison reproduces failure on baseline 1fc5296 and recovery on 6897df4 through cron.run; current-main source retains the same failing gate, and no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete repair: one shared rejection predicate serves the existing recovery selector and optional-policy gate, with one focused scheduled-turn regression and no new state or configuration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Optional-reply recovery suppression changes intended behavior with a stated reason (bd5f760: Optional empty finals should settle quietly without recovery or manufactured answers.)
  • Rejected-before-dispatch continuation eligibility keeps the original intent (c5fcae2: Continue once after a rejected malformed call following settled tools, without replaying completed effects.)
  • Visible progress and consumed refusal handling keeps the original intent (889968f: Progress text must not veto correction of a call that never ran; delivered finals and uncertain tool failures retain their exclusions.)
  • Settled-turn finalization keeps the original intent (ca3c749: Recover summaries after transient post-tool failures while retaining terminal-error and delivery exclusions.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +12, Tests +12. Total +24 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 28 16 +12
Tests 1 13 1 +12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 41 17 +24

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The latest official release interrupts real unattended cron workflows after a recoverable malformed provider call, and the supplied Gateway comparison confirms the failure.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

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

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-18T09:56:45.577Z sha 6950884 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-18T11:27:24.116Z sha 6897df4 :: needs maintainer review before merge. :: none

Reviewed November 18, 2026, 6:56 AM ET / 11:56 UTC (Revision 3).

@ericcurtin

Copy link
Copy Markdown
Contributor Author

@vincentkoc @obviyus PTAL when you get a chance, and could one of you approve the workflow runs? Thank you!

- isRejectedBeforeDispatch reads the attempt's own assistant; callers keep the delivered-reply veto.
- The optional-reply gate reads it in one line; terminal-resolution.ts is one line over the 700-line cap.
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Gateway proof for this head (6897df4) against main 1fc5296: isolated Gateway from source, local Anthropic Messages fixture.

BASE 1fc5296 (runs/base)
  cron SCEN_OK:      cron run status=error error="⚠️ OpenClaw couldn't finish this reply." ; provider requests: first:write, after-tool:malformed ; no continuation request
  cron SCEN_PERSIST: status=error ; no continuation request
  chat SCEN_OK (control):      continuation 1/1 -> assistant(stop) "RECOVERED SCEN_OK" ; write ran once
  chat SCEN_PERSIST (control): "empty response detected ... retrying 1/1" once, then 3 empty-error-retry resubmits of that attempt, then "Your request couldn't be completed."

CANDIDATE 6897df4 (runs/cand)
  cron SCEN_OK:      cron run status=ok summary="RECOVERED SCEN_OK" ; provider: first:write, after-tool:malformed, continuation:final-answer (continuations_in_history=1) ; write ran once (not repeated)
  cron SCEN_PERSIST: "empty response detected ... retrying 1/1" once, then the same 3 empty-error-retry resubmits as the chat control, then status=error "couldn't finish" (continuation budget holds at one)
  chat SCEN_OK (control):      unchanged from base: continuation 1/1 -> "RECOVERED SCEN_OK"
  chat SCEN_PERSIST (control): unchanged from base
  chat SCEN_ERR (executed edit tool returned isError, then malformed call): fails on base and candidate ("Your request couldn't be completed.", no continuation request). That is #199537, a separate veto; not claimed fixed here.

Gateway log counts: base "empty response detected" = 2 (chat SCEN_OK, chat SCEN_PERSIST only); candidate = 4 (both cron runs + both chat runs), each run once.

Provider request log, candidate cron run (one continuation, the completed write is not repeated):

=== cron-SCEN_OK
  cron run: status=ok error=null summary="RECOVERED SCEN_OK"
  provider: 2026-11-18T11:09:51.754Z lane=cron SCEN_OK first:write continuations_in_history=0 shape=[u:txt u:txt]
  provider: 2026-11-18T11:09:51.879Z lane=cron SCEN_OK after-tool(is_error=false):malformed continuations_in_history=0 shape=[u:txt u:txt a:tool_use u:result]
  provider: 2026-11-18T11:09:52.974Z lane=cron SCEN_OK continuation:final-answer continuations_in_history=1 shape=[u:txt u:txt a:tool_use u:result u:CONT u:txt]

Fixture and harness: an Anthropic SSE server that returns a write tool call, then a write call with truncated JSON arguments, then (after the host continuation) a final answer or another malformed call.

@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 18, 2026
- Drops the file-scoped max-lines exception.
- Inlines the single-use terminalAssistant local in resolveSettledTurnFinalizationRequest; no behavior change.
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Head is now 8a11607: the .oxlintrc.json max-lines exception is gone; terminal-resolution.ts stays within 700 lines by inlining a single-use local (no behavior change). The Gateway proof above (6897df4) covers the same gate and helper.

@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Nov 18, 2026
@obviyus
obviyus merged commit 93ec0fe into openclaw:main Nov 18, 2026
121 of 124 checks passed
@obviyus

obviyus commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks @ericcurtin for the fix and @jaxonparrott for the report. This is merged in 93ec0fe: scheduled (cron) runs now get the same one-time continuation after a malformed tool call that chat turns already get, so the run can recover instead of ending with an error. A model that keeps producing malformed calls still fails after that single continuation.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
Root cause: src/agents/embedded-agent-runner/run/terminal-resolution.ts:231 treats the "optional" reply expectation as unconditional reply-recovery suppression, so a scheduled run (cron sets "optional" at src/cron/isolated-agent/run-prompt-executor.ts:449) never reaches the existing single continuation for a tool call rejected before dispatch.

Fixes openclaw#201104

Thanks @jaxonparrott for the report and the source trace, and @ericcurtin for the fix.

## What Problem This Solves

A scheduled run ends with "OpenClaw couldn't finish this reply" when the provider sends one malformed tool call. Chat turns and subagents get one continuation for the same failure and finish.

## User Impact

Scheduled runs, heartbeats and hooks (every "optional" reply turn) get the same single continuation as chat turns when a tool call is rejected before it ran. Optional turns that author silence stay silent; delivered replies, ordinary empty optional turns and the one-continuation budget are unchanged.

## Why This Change Was Made

"Optional reply" means the model may author silence. A call the transport rejected before dispatch is a provider error, not authored silence. The rejected-before-dispatch check moves into one helper in the recovery owner (`isRejectedBeforeDispatch`), and the optional-reply gate exempts only that fact. No new model-facing text: the existing continuation instruction is reused.

`terminal-resolution.ts` stays within its 700-line cap: a single-use local in `resolveSettledTurnFinalizationRequest` is inlined (no behavior change). Production +28/-16 (mostly the moved check), tests +13/-1.

## Evidence

Isolated Gateway from source (`ocx src`) on main 2076d8a vs this branch, with a local Anthropic Messages fixture: a side-effecting `write` call, then a `write` call with truncated JSON arguments (rejected with `malformed_tool_call_arguments`).

- Cron run (cron.add isolated agentTurn, cron.run force): main ends `status=error` "couldn't finish this reply" with no continuation request; this branch sends one continuation and the run ends `status=ok` with the model's answer. The completed `write` is not repeated.
- Cron run where the model keeps sending malformed calls: one continuation ("retrying 1/1"), then the run fails as before.
- Chat control: one continuation and recovery on both main and this branch, unchanged.
- An executed tool that returned an error before the malformed call (openclaw#199537) still ends without a continuation on both; that is a separate guard and not changed here.
- Regression `continues a rejected call once in a scheduled run`: fails on main, passes here. terminal-resolution, incomplete-turn-recovery and cron message-tool-policy suites pass; oxfmt and oxlint clean.

Proof log: openclaw#201117 (comment)

Merge danger: two-way door; a revert restores the old suppression. No config, schema or state change. Blast radius: optional-reply turns (cron, heartbeat, hooks) whose last model response was a tool call rejected before dispatch.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Root cause: src/agents/embedded-agent-runner/run/terminal-resolution.ts:231 treats the "optional" reply expectation as unconditional reply-recovery suppression, so a scheduled run (cron sets "optional" at src/cron/isolated-agent/run-prompt-executor.ts:449) never reaches the existing single continuation for a tool call rejected before dispatch.

Fixes #201104

Thanks @jaxonparrott for the report and the source trace, and @ericcurtin for the fix.

## What Problem This Solves

A scheduled run ends with "OpenClaw couldn't finish this reply" when the provider sends one malformed tool call. Chat turns and subagents get one continuation for the same failure and finish.

## User Impact

Scheduled runs, heartbeats and hooks (every "optional" reply turn) get the same single continuation as chat turns when a tool call is rejected before it ran. Optional turns that author silence stay silent; delivered replies, ordinary empty optional turns and the one-continuation budget are unchanged.

## Why This Change Was Made

"Optional reply" means the model may author silence. A call the transport rejected before dispatch is a provider error, not authored silence. The rejected-before-dispatch check moves into one helper in the recovery owner (`isRejectedBeforeDispatch`), and the optional-reply gate exempts only that fact. No new model-facing text: the existing continuation instruction is reused.

`terminal-resolution.ts` stays within its 700-line cap: a single-use local in `resolveSettledTurnFinalizationRequest` is inlined (no behavior change). Production +28/-16 (mostly the moved check), tests +13/-1.

## Evidence

Isolated Gateway from source (`ocx src`) on main 1fc5296 vs this branch, with a local Anthropic Messages fixture: a side-effecting `write` call, then a `write` call with truncated JSON arguments (rejected with `malformed_tool_call_arguments`).

- Cron run (cron.add isolated agentTurn, cron.run force): main ends `status=error` "couldn't finish this reply" with no continuation request; this branch sends one continuation and the run ends `status=ok` with the model's answer. The completed `write` is not repeated.
- Cron run where the model keeps sending malformed calls: one continuation ("retrying 1/1"), then the run fails as before.
- Chat control: one continuation and recovery on both main and this branch, unchanged.
- An executed tool that returned an error before the malformed call (#199537) still ends without a continuation on both; that is a separate guard and not changed here.
- Regression `continues a rejected call once in a scheduled run`: fails on main, passes here. terminal-resolution, incomplete-turn-recovery and cron message-tool-policy suites pass; oxfmt and oxlint clean.

Proof log: #201117 (comment)

Merge danger: two-way door; a revert restores the old suppression. No config, schema or state change. Blast radius: optional-reply turns (cron, heartbeat, hooks) whose last model response was a tool call rejected before dispatch.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 93ec0fe)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
Root cause: src/agents/embedded-agent-runner/run/terminal-resolution.ts:231 treats the "optional" reply expectation as unconditional reply-recovery suppression, so a scheduled run (cron sets "optional" at src/cron/isolated-agent/run-prompt-executor.ts:449) never reaches the existing single continuation for a tool call rejected before dispatch.

Fixes openclaw#201104

Thanks @jaxonparrott for the report and the source trace, and @ericcurtin for the fix.

## What Problem This Solves

A scheduled run ends with "OpenClaw couldn't finish this reply" when the provider sends one malformed tool call. Chat turns and subagents get one continuation for the same failure and finish.

## User Impact

Scheduled runs, heartbeats and hooks (every "optional" reply turn) get the same single continuation as chat turns when a tool call is rejected before it ran. Optional turns that author silence stay silent; delivered replies, ordinary empty optional turns and the one-continuation budget are unchanged.

## Why This Change Was Made

"Optional reply" means the model may author silence. A call the transport rejected before dispatch is a provider error, not authored silence. The rejected-before-dispatch check moves into one helper in the recovery owner (`isRejectedBeforeDispatch`), and the optional-reply gate exempts only that fact. No new model-facing text: the existing continuation instruction is reused.

`terminal-resolution.ts` stays within its 700-line cap: a single-use local in `resolveSettledTurnFinalizationRequest` is inlined (no behavior change). Production +28/-16 (mostly the moved check), tests +13/-1.

## Evidence

Isolated Gateway from source (`ocx src`) on main 1fc5296 vs this branch, with a local Anthropic Messages fixture: a side-effecting `write` call, then a `write` call with truncated JSON arguments (rejected with `malformed_tool_call_arguments`).

- Cron run (cron.add isolated agentTurn, cron.run force): main ends `status=error` "couldn't finish this reply" with no continuation request; this branch sends one continuation and the run ends `status=ok` with the model's answer. The completed `write` is not repeated.
- Cron run where the model keeps sending malformed calls: one continuation ("retrying 1/1"), then the run fails as before.
- Chat control: one continuation and recovery on both main and this branch, unchanged.
- An executed tool that returned an error before the malformed call (openclaw#199537) still ends without a continuation on both; that is a separate guard and not changed here.
- Regression `continues a rejected call once in a scheduled run`: fails on main, passes here. terminal-resolution, incomplete-turn-recovery and cron message-tool-policy suites pass; oxfmt and oxlint clean.

Proof log: openclaw#201117 (comment)

Merge danger: two-way door; a revert restores the old suppression. No config, schema or state change. Blast radius: optional-reply turns (cron, heartbeat, hooks) whose last model response was a tool call rejected before dispatch.

Co-authored-by: Ayaan Zaidi <[email protected]>

Release adaptation: Source rejected-before-dispatch optional scheduled reply recovery retained.

(cherry picked from commit 93ec0fe)

Co-authored-by: RomneyDa <[email protected]>
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: 🦞 diamond lobster Very strong PR readiness with only minor 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]: Scheduled (cron) runs never get the malformed-tool-call continuation: terminalReplyExpectation "optional" suppresses reply recovery (v2026.11.5)

2 participants