Repository navigation
fix(agents): stop whitespace tool-call runaways for every provider - #206754
Conversation
- Move the 4 KiB trailing-whitespace rule from the Responses transport to the agent-core toolcall_delta consumer, so Chat Completions and every other provider stop a runaway tool call instead of streaming to the output cap. - Delete the Responses-only counter, error class and client abort. - Give degenerate_output its own reply text instead of the service-error copy.
|
🦞👀 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. |
- withServer expects a void handler; run the whitespace stream as a tracked promise and await it before the assertions (no-misused-promises).
|
Maintainer override:
The failing test ( |
|
Codex review: passed. What this changesMoves the 4 KiB tool-argument whitespace guard into the shared agent stream consumer and adds specific failure guidance. Example: A Chat Completions tool call streams 60,013 argument characters dominated by whitespace.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a source-confirmed cross-provider gap through the existing stream owner, and no introduced correctness or security defect was found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherProvider transports emit assistant events into agent-core, which publishes conversation fragments and admits completed tool calls; failed responses pass through the existing retry and failure-copy owners. flowchart TD
A[Provider stream] --> B[Transport adapter]
B --> C[Agent stream consumer]
C --> D[Whitespace guard]
D --> E[Abort and bounded recovery]
C --> F[Completed tool admission]
E --> G[Answer or failure guidance]
Technical reviewBest possible solution: Keep one whitespace policy in the shared stream consumer while preserving bounded recovery and rejection of unfinished tool calls. Do we have a high-confidence way to reproduce the issue? Source confirms that main guards Responses only; the author reports a failing base regression and before/after CLI replays, which this read-only review did not rerun. Is this the best way to solve the issue? The shared consumer is the appropriate existing owner: the patch transfers the established threshold, removes the former counter, and preserves the existing retry classification. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 450dae2b752b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +5, Tests +48, Docs 0. Total +53 across 10 files. Added test files: 1. 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. LabelsLabel 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 Reviewed November 27, 2026, 10:23 AM ET / 15:23 UTC. |
… URL strict helper (#206735) ## Problem Signal: none from users. The audit counts 0 strict-schema rejections in 517 real non-200 responses (team logs). The motivating failure is the board's whitespace runaway on gpt-6.1-sol (OpenClaw 2026.10.6), which #206754 now bounds at about 23 s; its fix at the tool owner (`read`) is a follow-up PR. On OpenAI-protocol routes, `strict` was all-or-nothing per request: one tool whose schema was not strict-compatible downgraded every tool to `strict: false`, so on native OpenAI a strict-compatible tool rarely got grammar-constrained arguments. The decision lived in a separate URL/provider-name helper (`src/agents/openai-strict-tool-setting.ts`) reached through a host hook, beside the compat owner's own `supportsStrictMode` default (with a Z.ai special case). Population: Gateway and one-shot users on routes that declare strict support (native OpenAI, Azure OpenAI, OpenRouter, or `compat.supportsStrictMode: true` in a catalog or config), managed transport: Completions `packages/ai/src/transports/openai-completions-params.ts:168-190`, Responses `openai-responses-params-internal.ts:200` and `providers/openai-responses-tools.ts:52-71`. ## Fix - **One owner for "declared".** `resolveOpenAICompletionsCompat` (`openai-completions-compat.ts`) resolves `supportsStrictMode` for the OpenAI and Azure OpenAI endpoints, OpenRouter, and the openai provider's default route; any other route declares it in its catalog or config. The Z.ai case and the separate URL/provider helper and host hook are deleted. - **Strict per tool, on the schema as written.** On a declared route, a tool whose schema is strict-compatible before strict normalization (object root, every key required, closed objects) is sent `strict: true`; every other tool is sent `strict: false` with its schema unchanged. No schema is rewritten to qualify. - **Undeclared routes are unchanged:** no strict field, same tool bytes. - The strict detector accepts string type lists (`["string", "null"]`), applies object rules to nullable objects and to typeless branches with `properties`, and flags untyped value schemas (`{}`); unions still keep a tool non-strict. - Deleted: `src/agents/openai-strict-tool-setting.ts`, the host `resolveOpenAIStrictToolSetting` hook, and the all-or-nothing downgrade diagnostics. Not benchmark-shaped: nothing changes on undeclared custom endpoints (the benchmark meter routes), and this PR does not fix the Sol runaway on its own (`read` has optional keys, so it stays non-strict here). ## Evidence - Net-negative vs the merge base (+249/−357). - Undeclared custom endpoint, real `agent --local` against a recording endpoint, merge-base build vs this head: the request's tool array is byte-identical (23,844 B, same sha1; 0 tools carry `strict`). - Tests: undeclared custom endpoint sends no strict field (Completions and Responses); declared route sends strict only for a strict-as-written tool; optional-key and open-root tools stay `strict: false` and unchanged; one permissive tool no longer downgrades the rest; detector on nullable objects. - Strict-related suites and `agent-tools.prefix-stability` pass; provider/transport parity snapshot unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
…206754) ## What Problem This Solves A model that stops closing a tool call and streams whitespace runs to the provider's output cap (128k tokens on some models, about 32 min at the measured rate). OpenClaw stopped this only for OpenAI Responses: the 4 KiB rule from #177659 and #179233 lived inside the Responses transport. Every other provider, including Chat Completions endpoints, had no limit. Each chunk that carried tool-call text counted as model progress, so no watchdog fired either. When Responses did stop a runaway and the retries ran out, the user saw "The AI service is having trouble". The model's output caused the failure, not the service. ## Solution - The agent-core stream consumer (`packages/agent-core/src/agent-stream-response.ts`) now owns the rule. It already stops repetitive text and thinking. Every provider's `toolcall_delta` passes through it. At 4 KiB of consecutive trailing whitespace in one tool call's arguments, it aborts the request and ends the response with `degenerate_output`. The bounded transient retry is unchanged. - Removed from the Responses transport: `countToolCallTrailingWhitespace`, `DegenerateToolCallArgumentsError`, the per-call counter and the client abort. - `degenerate_output` now has its own reply text: "The model's reply turned into a long run of blank characters, so OpenClaw stopped it. Send your message again, or choose another model." - No output cap or timeout changed. No model or provider detection. Credit: the 4 KiB rule and its rationale are @steipete's (#177659, #179233). This PR moves it to the shared owner. ## Evidence | Check | Tier | Base (`844bfbfe`) | Head | |---|---|---|---| | Chat Completions whitespace runaway through the real transport and agent loop (`agent-loop.degenerate-output.test.ts`) | vitest-source | **fails**: the whole 60,000-char runaway streams, the turn does not end with `degenerate_output` | passes: aborted after 4 KiB, no tool runs, 1 request | | 200 KiB tool argument with 4,095-char whitespace runs (same file) | vitest-source | passes | passes | | Touched suites: Responses terminal-error, item-conflict integration, agent-loop async-tools and streaming, stream parity, debug labels, failure copy | vitest-source | | pass | | `pnpm check:changed` (lint, typecheck core and tests, dead exports, boundaries) | static | | pass | | `ocx build --dts` | full | | pass | End-to-end replays (full build, `openclaw agent --local`, isolated scratch HOME/state/config, loopback fake provider replaying a captured runaway response at its captured pace: 20,009 events over 301 s; no credentials): | Case | Base (`844bfbfe`) | Head | |---|---|---| | Chat Completions, every request runs away | **no abort**: each request streamed all 60,013 chars for ~330 s and ended only because the capture ran out; 2 requests, 682 s, "LLM request timed out." (a live provider runs each attempt to the output cap) | each request aborted at ~23 s (1,406 frames); 5 requests (1 + 4 retries); 149 s; the new reply text | | Responses, every request runs away | ~23 s per request, 5 requests, 154 s, "The AI service is having trouble." | ~23 s per request, 5 requests, 153 s, the new reply text | | Responses, runaway then a normal answer | 47 s, the answer | 43 s, the answer | ## Accepted edge cases - A real tool argument with a 4 KiB run of literal whitespace is stopped. This is the existing accepted risk; JSON escapes newlines, so real indentation stays far below it. It now applies to every provider. - Providers that send only a final snapshot and no argument deltas are not covered (unchanged). Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit dd39023)
…206754) ## What Problem This Solves A model that stops closing a tool call and streams whitespace runs to the provider's output cap (128k tokens on some models, about 32 min at the measured rate). OpenClaw stopped this only for OpenAI Responses: the 4 KiB rule from #177659 and #179233 lived inside the Responses transport. Every other provider, including Chat Completions endpoints, had no limit. Each chunk that carried tool-call text counted as model progress, so no watchdog fired either. When Responses did stop a runaway and the retries ran out, the user saw "The AI service is having trouble". The model's output caused the failure, not the service. ## Solution - The agent-core stream consumer (`packages/agent-core/src/agent-stream-response.ts`) now owns the rule. It already stops repetitive text and thinking. Every provider's `toolcall_delta` passes through it. At 4 KiB of consecutive trailing whitespace in one tool call's arguments, it aborts the request and ends the response with `degenerate_output`. The bounded transient retry is unchanged. - Removed from the Responses transport: `countToolCallTrailingWhitespace`, `DegenerateToolCallArgumentsError`, the per-call counter and the client abort. - `degenerate_output` now has its own reply text: "The model's reply turned into a long run of blank characters, so OpenClaw stopped it. Send your message again, or choose another model." - No output cap or timeout changed. No model or provider detection. Credit: the 4 KiB rule and its rationale are @steipete's (#177659, #179233). This PR moves it to the shared owner. ## Evidence | Check | Tier | Base (`844bfbfe`) | Head | |---|---|---|---| | Chat Completions whitespace runaway through the real transport and agent loop (`agent-loop.degenerate-output.test.ts`) | vitest-source | **fails**: the whole 60,000-char runaway streams, the turn does not end with `degenerate_output` | passes: aborted after 4 KiB, no tool runs, 1 request | | 200 KiB tool argument with 4,095-char whitespace runs (same file) | vitest-source | passes | passes | | Touched suites: Responses terminal-error, item-conflict integration, agent-loop async-tools and streaming, stream parity, debug labels, failure copy | vitest-source | | pass | | `pnpm check:changed` (lint, typecheck core and tests, dead exports, boundaries) | static | | pass | | `ocx build --dts` | full | | pass | End-to-end replays (full build, `openclaw agent --local`, isolated scratch HOME/state/config, loopback fake provider replaying a captured runaway response at its captured pace: 20,009 events over 301 s; no credentials): | Case | Base (`844bfbfe`) | Head | |---|---|---| | Chat Completions, every request runs away | **no abort**: each request streamed all 60,013 chars for ~330 s and ended only because the capture ran out; 2 requests, 682 s, "LLM request timed out." (a live provider runs each attempt to the output cap) | each request aborted at ~23 s (1,406 frames); 5 requests (1 + 4 retries); 149 s; the new reply text | | Responses, every request runs away | ~23 s per request, 5 requests, 154 s, "The AI service is having trouble." | ~23 s per request, 5 requests, 153 s, the new reply text | | Responses, runaway then a normal answer | 47 s, the answer | 43 s, the answer | ## Accepted edge cases - A real tool argument with a 4 KiB run of literal whitespace is stopped. This is the existing accepted risk; JSON escapes newlines, so real indentation stays far below it. It now applies to every provider. - Providers that send only a final snapshot and no argument deltas are not covered (unchanged). Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit dd39023) Co-authored-by: RomneyDa <[email protected]>
…penclaw#206754) ## What Problem This Solves A model that stops closing a tool call and streams whitespace runs to the provider's output cap (128k tokens on some models, about 32 min at the measured rate). OpenClaw stopped this only for OpenAI Responses: the 4 KiB rule from openclaw#177659 and openclaw#179233 lived inside the Responses transport. Every other provider, including Chat Completions endpoints, had no limit. Each chunk that carried tool-call text counted as model progress, so no watchdog fired either. When Responses did stop a runaway and the retries ran out, the user saw "The AI service is having trouble". The model's output caused the failure, not the service. ## Solution - The agent-core stream consumer (`packages/agent-core/src/agent-stream-response.ts`) now owns the rule. It already stops repetitive text and thinking. Every provider's `toolcall_delta` passes through it. At 4 KiB of consecutive trailing whitespace in one tool call's arguments, it aborts the request and ends the response with `degenerate_output`. The bounded transient retry is unchanged. - Removed from the Responses transport: `countToolCallTrailingWhitespace`, `DegenerateToolCallArgumentsError`, the per-call counter and the client abort. - `degenerate_output` now has its own reply text: "The model's reply turned into a long run of blank characters, so OpenClaw stopped it. Send your message again, or choose another model." - No output cap or timeout changed. No model or provider detection. Credit: the 4 KiB rule and its rationale are @steipete's (openclaw#177659, openclaw#179233). This PR moves it to the shared owner. ## Evidence | Check | Tier | Base (`4ab4f103`) | Head | |---|---|---|---| | Chat Completions whitespace runaway through the real transport and agent loop (`agent-loop.degenerate-output.test.ts`) | vitest-source | **fails**: the whole 60,000-char runaway streams, the turn does not end with `degenerate_output` | passes: aborted after 4 KiB, no tool runs, 1 request | | 200 KiB tool argument with 4,095-char whitespace runs (same file) | vitest-source | passes | passes | | Touched suites: Responses terminal-error, item-conflict integration, agent-loop async-tools and streaming, stream parity, debug labels, failure copy | vitest-source | | pass | | `pnpm check:changed` (lint, typecheck core and tests, dead exports, boundaries) | static | | pass | | `ocx build --dts` | full | | pass | End-to-end replays (full build, `openclaw agent --local`, isolated scratch HOME/state/config, loopback fake provider replaying a captured runaway response at its captured pace: 20,009 events over 301 s; no credentials): | Case | Base (`4ab4f103`) | Head | |---|---|---| | Chat Completions, every request runs away | **no abort**: each request streamed all 60,013 chars for ~330 s and ended only because the capture ran out; 2 requests, 682 s, "LLM request timed out." (a live provider runs each attempt to the output cap) | each request aborted at ~23 s (1,406 frames); 5 requests (1 + 4 retries); 149 s; the new reply text | | Responses, every request runs away | ~23 s per request, 5 requests, 154 s, "The AI service is having trouble." | ~23 s per request, 5 requests, 153 s, the new reply text | | Responses, runaway then a normal answer | 47 s, the answer | 43 s, the answer | ## Accepted edge cases - A real tool argument with a 4 KiB run of literal whitespace is stopped. This is the existing accepted risk; JSON escapes newlines, so real indentation stays far below it. It now applies to every provider. - Providers that send only a final snapshot and no argument deltas are not covered (unchanged). Co-authored-by: Ayaan Zaidi <[email protected]>
… URL strict helper (openclaw#206735) ## Problem Signal: none from users. The audit counts 0 strict-schema rejections in 517 real non-200 responses (team logs). The motivating failure is the board's whitespace runaway on gpt-6.1-sol (OpenClaw 2026.10.6), which openclaw#206754 now bounds at about 23 s; its fix at the tool owner (`read`) is a follow-up PR. On OpenAI-protocol routes, `strict` was all-or-nothing per request: one tool whose schema was not strict-compatible downgraded every tool to `strict: false`, so on native OpenAI a strict-compatible tool rarely got grammar-constrained arguments. The decision lived in a separate URL/provider-name helper (`src/agents/openai-strict-tool-setting.ts`) reached through a host hook, beside the compat owner's own `supportsStrictMode` default (with a Z.ai special case). Population: Gateway and one-shot users on routes that declare strict support (native OpenAI, Azure OpenAI, OpenRouter, or `compat.supportsStrictMode: true` in a catalog or config), managed transport: Completions `packages/ai/src/transports/openai-completions-params.ts:168-190`, Responses `openai-responses-params-internal.ts:200` and `providers/openai-responses-tools.ts:52-71`. ## Fix - **One owner for "declared".** `resolveOpenAICompletionsCompat` (`openai-completions-compat.ts`) resolves `supportsStrictMode` for the OpenAI and Azure OpenAI endpoints, OpenRouter, and the openai provider's default route; any other route declares it in its catalog or config. The Z.ai case and the separate URL/provider helper and host hook are deleted. - **Strict per tool, on the schema as written.** On a declared route, a tool whose schema is strict-compatible before strict normalization (object root, every key required, closed objects) is sent `strict: true`; every other tool is sent `strict: false` with its schema unchanged. No schema is rewritten to qualify. - **Undeclared routes are unchanged:** no strict field, same tool bytes. - The strict detector accepts string type lists (`["string", "null"]`), applies object rules to nullable objects and to typeless branches with `properties`, and flags untyped value schemas (`{}`); unions still keep a tool non-strict. - Deleted: `src/agents/openai-strict-tool-setting.ts`, the host `resolveOpenAIStrictToolSetting` hook, and the all-or-nothing downgrade diagnostics. Not benchmark-shaped: nothing changes on undeclared custom endpoints (the benchmark meter routes), and this PR does not fix the Sol runaway on its own (`read` has optional keys, so it stays non-strict here). ## Evidence - Net-negative vs the merge base (+249/−357). - Undeclared custom endpoint, real `agent --local` against a recording endpoint, merge-base build vs this head: the request's tool array is byte-identical (23,844 B, same sha1; 0 tools carry `strict`). - Tests: undeclared custom endpoint sends no strict field (Completions and Responses); declared route sends strict only for a strict-as-written tool; optional-key and open-root tools stay `strict: false` and unchanged; one permissive tool no longer downgrades the rest; detector on nullable objects. - Strict-related suites and `agent-tools.prefix-stability` pass; provider/transport parity snapshot unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
A model that stops closing a tool call and streams whitespace runs to the provider's output cap (128k tokens on some models, about 32 min at the measured rate). OpenClaw stopped this only for OpenAI Responses: the 4 KiB rule from #177659 and #179233 lived inside the Responses transport. Every other provider, including Chat Completions endpoints, had no limit. Each chunk that carried tool-call text counted as model progress, so no watchdog fired either.
When Responses did stop a runaway and the retries ran out, the user saw "The AI service is having trouble". The model's output caused the failure, not the service.
Solution
packages/agent-core/src/agent-stream-response.ts) now owns the rule. It already stops repetitive text and thinking. Every provider'stoolcall_deltapasses through it. At 4 KiB of consecutive trailing whitespace in one tool call's arguments, it aborts the request and ends the response withdegenerate_output. The bounded transient retry is unchanged.countToolCallTrailingWhitespace,DegenerateToolCallArgumentsError, the per-call counter and the client abort.degenerate_outputnow has its own reply text: "The model's reply turned into a long run of blank characters, so OpenClaw stopped it. Send your message again, or choose another model."Credit: the 4 KiB rule and its rationale are @steipete's (#177659, #179233). This PR moves it to the shared owner.
Evidence
844bfbfe)agent-loop.degenerate-output.test.ts)degenerate_outputpnpm check:changed(lint, typecheck core and tests, dead exports, boundaries)ocx build --dtsEnd-to-end replays (full build,
openclaw agent --local, isolated scratch HOME/state/config, loopback fake provider replaying a captured runaway response at its captured pace: 20,009 events over 301 s; no credentials):844bfbfe)Accepted edge cases