Repository navigation
fix: stop a long Claude CLI turn from redoing its tool work on the fallback model - #200801
Conversation
A claude-cli turn whose stream exceeds the output limit is refused as a format FailoverError. Model fallback then sent the same user message to the next model, which repeated tool calls the refused turn had already completed (openclaw#200744). The refused output now carries the run's tool summary and accepted session spawns, and the CLI runner applies the existing empty-response rule to it: a turn that completed tool effects records a model fallback stop. Overflows without tool calls keep falling back as before.
|
🦞👀 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. What this changesPrevents model fallback after refused CLI output when the turn already called tools or accepted session spawns. Example: Claude CLI executes a command that appends one line to a file, then streams 10 MiB of reply text.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current replay bug through the existing fallback-stop mechanism; no actionable defects were found, and current-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe CLI executor collects stream and tool facts, the CLI runner settles the attempt, and the shared model-fallback loop consumes its terminal-stop marker. flowchart TD
User[Agent request] --> CLI[Claude CLI execution]
CLI --> Facts[Stream parser and tool tracking]
Facts --> Refusal[Output refusal with tool facts]
Refusal --> Runner[CLI runner settlement]
Runner --> Stop[Stop after tool effects]
Runner --> Fallback[Fallback when no tool ran]
Technical reviewBest possible solution: Use finalized execution facts to apply the existing fallback stop while retaining native-session continuity and fallback for refusals before tools run. Do we have a high-confidence way to reproduce the issue? The supplied Gateway traces reproduce duplicate execution on the base, whose refusal path remains present on current main; this review inspected source and supplied results without executing target code. Is this the best way to solve the issue? The patch restores the existing no-replay invariant at the refused-output boundary without changing failure classification, parser budgets, or session-binding policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2d52a33ef7ac. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +27, Tests +29, Docs +1. Total +57 across 5 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. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 (3 earlier review cycles)Reviewed November 17, 2026, 6:57 PM ET / 23:57 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Gateway proof for #200744 (real Claude Code 2.1.322 as claude-cli, built dist, local fixtures; workdir paths shortened) |
|
Maintainer override: the only red on head c180c81 is |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Thanks @fede-kamel for the fix and @jzmudzinski for the report. This is merged in fea4a9d: when a Claude CLI turn goes over its output limit after a tool already ran, the turn now stops with the limit error instead of falling back to another model and running the tool work again. |
…llback model (openclaw#200801) Root cause: `src/agents/cli-runner.ts:410` (main 5a5cb32) handles a refused CLI stream (`CLI JSONL output exceeded …`) by keeping the first-turn session and rethrowing, but never applies the existing rule that a turn which already ran tools must not be replayed on another model (`cli-runner.ts:466-472`, from openclaw#162567). The executor also rethrew the refusal without the run's tool facts, so model fallback sent the same user message to the fallback model, which ran the completed tools again. Fixes openclaw#200744 ## What Problem This Solves A long Claude CLI turn can edit files and run commands, then produce more output than OpenClaw will parse. OpenClaw refuses that output and, when a fallback model is configured, hands the same request to the fallback model. That model starts from scratch and repeats the work on top of half-applied changes, while queued messages wait behind it. Thanks @jzmudzinski for the detailed report (a 54-minute turn replayed this way). ## User Impact User impact: when a `claude-cli` turn that already ran a tool hits the stream output limit, the run stops with the limit error instead of replaying the request on another model, so finished tool actions are not repeated. A turn that hits the limit before running any tool still falls back as before. ## Why This Change Was Made OpenClaw already refuses to fall back after tool effects when a CLI turn ends with an empty answer. The output-limit refusal never reached that check, because the refused output did not carry the run's tool summary. The executor now attaches the tool summary and accepted session spawns to the refused output, and the runner applies the same stop to both failures. The refused first turn's native session is still kept for the next message (openclaw#192838 unchanged). The issue also suggests a new failover reason for output budgets. This keeps the existing reason and uses the existing fallback stop, so failover reasons and their consumers stay unchanged. Fix by @fede-kamel (d2169a3), kept as is; on top: a merge of current `main` and a shorter regression test. ## Evidence Real Gateway, real Claude Code 2.1.322 as the `claude-cli` backend, built `dist/`, isolated state. Claude Code talks to a local Anthropic Messages fixture; the fallback `stub/stub` is a local OpenAI-compatible fixture that starts the request from scratch. The turn runs `exec` once (appends a line to a marker file) through the Gateway's MCP, then streams 10 MiB of reply text. | Build | Result | `exec` runs | | --- | --- | --- | | `main` 5a5cb32, run 1 and 2 | output refused, fallback `stub/stub` runs `exec` again and answers | **2**, **2** | | this PR, run 1 and 2 | output refused, run fails with `CLI JSONL output exceeded 8388608 characters`, fallback never called | **1**, **1** | | this PR, no tool before the overflow | output refused, fallback to `stub/stub` as before | 0 from Claude Code | Regression test: `execute.output-limit.test.ts` › "stops model fallback when a turn that already ran a tool exceeds the output limit" fails on `main` (`expected false to be true`) and passes here; the existing first-turn refusal test now also checks that a refusal without tools records no stop. Gateway and fixture logs: openclaw#200801 (comment) Merge danger: two-way door. Reverting restores the old fallback behavior; nothing is written or migrated. Blast radius: `claude-cli` turns that hit the output limit after running a tool now end with the error instead of falling back. Co-authored-by: Ayaan Zaidi <[email protected]>
…llback model (#200801) Root cause: `src/agents/cli-runner.ts:410` (main 91614b5) handles a refused CLI stream (`CLI JSONL output exceeded …`) by keeping the first-turn session and rethrowing, but never applies the existing rule that a turn which already ran tools must not be replayed on another model (`cli-runner.ts:466-472`, from #162567). The executor also rethrew the refusal without the run's tool facts, so model fallback sent the same user message to the fallback model, which ran the completed tools again. Fixes #200744 ## What Problem This Solves A long Claude CLI turn can edit files and run commands, then produce more output than OpenClaw will parse. OpenClaw refuses that output and, when a fallback model is configured, hands the same request to the fallback model. That model starts from scratch and repeats the work on top of half-applied changes, while queued messages wait behind it. Thanks @jzmudzinski for the detailed report (a 54-minute turn replayed this way). ## User Impact User impact: when a `claude-cli` turn that already ran a tool hits the stream output limit, the run stops with the limit error instead of replaying the request on another model, so finished tool actions are not repeated. A turn that hits the limit before running any tool still falls back as before. ## Why This Change Was Made OpenClaw already refuses to fall back after tool effects when a CLI turn ends with an empty answer. The output-limit refusal never reached that check, because the refused output did not carry the run's tool summary. The executor now attaches the tool summary and accepted session spawns to the refused output, and the runner applies the same stop to both failures. The refused first turn's native session is still kept for the next message (#192838 unchanged). The issue also suggests a new failover reason for output budgets. This keeps the existing reason and uses the existing fallback stop, so failover reasons and their consumers stay unchanged. Fix by @fede-kamel (d2169a3), kept as is; on top: a merge of current `main` and a shorter regression test. ## Evidence Real Gateway, real Claude Code 2.1.322 as the `claude-cli` backend, built `dist/`, isolated state. Claude Code talks to a local Anthropic Messages fixture; the fallback `stub/stub` is a local OpenAI-compatible fixture that starts the request from scratch. The turn runs `exec` once (appends a line to a marker file) through the Gateway's MCP, then streams 10 MiB of reply text. | Build | Result | `exec` runs | | --- | --- | --- | | `main` 91614b5, run 1 and 2 | output refused, fallback `stub/stub` runs `exec` again and answers | **2**, **2** | | this PR, run 1 and 2 | output refused, run fails with `CLI JSONL output exceeded 8388608 characters`, fallback never called | **1**, **1** | | this PR, no tool before the overflow | output refused, fallback to `stub/stub` as before | 0 from Claude Code | Regression test: `execute.output-limit.test.ts` › "stops model fallback when a turn that already ran a tool exceeds the output limit" fails on `main` (`expected false to be true`) and passes here; the existing first-turn refusal test now also checks that a refusal without tools records no stop. Gateway and fixture logs: #200801 (comment) Merge danger: two-way door. Reverting restores the old fallback behavior; nothing is written or migrated. Blast radius: `claude-cli` turns that hit the output limit after running a tool now end with the error instead of falling back. Release adaptation: the unchanged shared fallback-stop policy lives in the existing CLI exit-error owner instead of the already-full orchestrator, keeping the 700-line limit intact without exemptions. Both refusal and empty-answer callers use that single policy. Added a 29-line regression allocation. Backported to release/2026.11.6 from baseline 309067b under Dallin's explicit intake authorization. Companion audit through 9e917f0: later same-path commit 2b7950c (#193550) adds a model-request hook and is not a prerequisite; no later #200801 mention. Existing refusal/session continuity, finalized tool tracking, accepted-spawn evidence, and fallback-stop consumer are present. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit fea4a9d) Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…llback model (#200801) Root cause: `src/agents/cli-runner.ts:410` (main 91614b5) handles a refused CLI stream (`CLI JSONL output exceeded …`) by keeping the first-turn session and rethrowing, but never applies the existing rule that a turn which already ran tools must not be replayed on another model (`cli-runner.ts:466-472`, from #162567). The executor also rethrew the refusal without the run's tool facts, so model fallback sent the same user message to the fallback model, which ran the completed tools again. Fixes #200744 ## What Problem This Solves A long Claude CLI turn can edit files and run commands, then produce more output than OpenClaw will parse. OpenClaw refuses that output and, when a fallback model is configured, hands the same request to the fallback model. That model starts from scratch and repeats the work on top of half-applied changes, while queued messages wait behind it. Thanks @jzmudzinski for the detailed report (a 54-minute turn replayed this way). ## User Impact User impact: when a `claude-cli` turn that already ran a tool hits the stream output limit, the run stops with the limit error instead of replaying the request on another model, so finished tool actions are not repeated. A turn that hits the limit before running any tool still falls back as before. ## Why This Change Was Made OpenClaw already refuses to fall back after tool effects when a CLI turn ends with an empty answer. The output-limit refusal never reached that check, because the refused output did not carry the run's tool summary. The executor now attaches the tool summary and accepted session spawns to the refused output, and the runner applies the same stop to both failures. The refused first turn's native session is still kept for the next message (#192838 unchanged). The issue also suggests a new failover reason for output budgets. This keeps the existing reason and uses the existing fallback stop, so failover reasons and their consumers stay unchanged. Fix by @fede-kamel (d2169a3), kept as is; on top: a merge of current `main` and a shorter regression test. ## Evidence Real Gateway, real Claude Code 2.1.322 as the `claude-cli` backend, built `dist/`, isolated state. Claude Code talks to a local Anthropic Messages fixture; the fallback `stub/stub` is a local OpenAI-compatible fixture that starts the request from scratch. The turn runs `exec` once (appends a line to a marker file) through the Gateway's MCP, then streams 10 MiB of reply text. | Build | Result | `exec` runs | | --- | --- | --- | | `main` 91614b5, run 1 and 2 | output refused, fallback `stub/stub` runs `exec` again and answers | **2**, **2** | | this PR, run 1 and 2 | output refused, run fails with `CLI JSONL output exceeded 8388608 characters`, fallback never called | **1**, **1** | | this PR, no tool before the overflow | output refused, fallback to `stub/stub` as before | 0 from Claude Code | Regression test: `execute.output-limit.test.ts` › "stops model fallback when a turn that already ran a tool exceeds the output limit" fails on `main` (`expected false to be true`) and passes here; the existing first-turn refusal test now also checks that a refusal without tools records no stop. Gateway and fixture logs: #200801 (comment) Merge danger: two-way door. Reverting restores the old fallback behavior; nothing is written or migrated. Blast radius: `claude-cli` turns that hit the output limit after running a tool now end with the error instead of falling back. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit fea4a9d) Co-authored-by: RomneyDa <[email protected]> Release adaptation: none; source change applies to the pinned beta baseline. Follow-up disposition: dependency #192838 is included immediately before this commit to retain refused-stream ownership. (cherry picked from commit 4ffdd547f489a727eb7ed66ca08a197a899f2eb1)
…llback model (#200801) Baseline adaptation: Use accepted tool and spawn evidence already tracked by the .33 CLI runner; classify only the parser output-limit refusal. (cherry picked from commit fea4a9d) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 65bdcf1fa44c53cc77c9041d14983fa32631004a)
Root cause:
src/agents/cli-runner.ts:410(main 91614b5) handles a refused CLI stream (CLI JSONL output exceeded …) by keeping the first-turn session and rethrowing, but never applies the existing rule that a turn which already ran tools must not be replayed on another model (cli-runner.ts:466-472, from #162567). The executor also rethrew the refusal without the run's tool facts, so model fallback sent the same user message to the fallback model, which ran the completed tools again.Fixes #200744
What Problem This Solves
A long Claude CLI turn can edit files and run commands, then produce more output than OpenClaw will parse. OpenClaw refuses that output and, when a fallback model is configured, hands the same request to the fallback model. That model starts from scratch and repeats the work on top of half-applied changes, while queued messages wait behind it. Thanks @jzmudzinski for the detailed report (a 54-minute turn replayed this way).
User Impact
User impact: when a
claude-cliturn that already ran a tool hits the stream output limit, the run stops with the limit error instead of replaying the request on another model, so finished tool actions are not repeated. A turn that hits the limit before running any tool still falls back as before.Why This Change Was Made
OpenClaw already refuses to fall back after tool effects when a CLI turn ends with an empty answer. The output-limit refusal never reached that check, because the refused output did not carry the run's tool summary. The executor now attaches the tool summary and accepted session spawns to the refused output, and the runner applies the same stop to both failures. The refused first turn's native session is still kept for the next message (#192838 unchanged).
The issue also suggests a new failover reason for output budgets. This keeps the existing reason and uses the existing fallback stop, so failover reasons and their consumers stay unchanged.
Fix by @fede-kamel (d2169a3), kept as is; on top: a merge of current
mainand a shorter regression test.Evidence
Real Gateway, real Claude Code 2.1.322 as the
claude-clibackend, builtdist/, isolated state. Claude Code talks to a local Anthropic Messages fixture; the fallbackstub/stubis a local OpenAI-compatible fixture that starts the request from scratch. The turn runsexeconce (appends a line to a marker file) through the Gateway's MCP, then streams 10 MiB of reply text.execrunsmain91614b5, run 1 and 2stub/stubrunsexecagain and answersCLI JSONL output exceeded 8388608 characters, fallback never calledstub/stubas beforeRegression test:
execute.output-limit.test.ts› "stops model fallback when a turn that already ran a tool exceeds the output limit" fails onmain(expected false to be true) and passes here; the existing first-turn refusal test now also checks that a refusal without tools records no stop.Gateway and fixture logs: #200801 (comment)
Merge danger: two-way door. Reverting restores the old fallback behavior; nothing is written or migrated. Blast radius:
claude-cliturns that hit the output limit after running a tool now end with the error instead of falling back.