Repository navigation
fix(ai): abort degenerate tool-call whitespace after 4 KiB - #179233
Conversation
Live runaway argument streams emit ~100 whitespace chars/s, so the 32 KiB limit aborted only ~325 s in, just before the 360 s session watchdog. Tool-call arguments are JSON with escaped newlines, so real whitespace runs stay far below 4 KiB; the existing 200 KiB mixed-whitespace acceptance test still passes.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesLower the Responses tool-call whitespace abort threshold from 32 KiB to 4 KiB and update the existing regression test and documentation. Example: An unfinished Responses tool call emits whitespace at approximately 100 characters per second.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR makes a focused correction to a documented agent stall, and no concrete introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe shared Responses stream processor converts provider events into assistant output and completed tool calls; excessive argument whitespace raises a typed transport error consumed by existing cancellation and retry owners. flowchart TD
A[Responses HTTP or WebSocket] --> B[Shared stream processor]
B --> C[Per-call whitespace counter]
C --> D[Validated completed tool calls]
C --> E[Typed degenerate output error]
E --> F[Request cancellation]
F --> G[Existing bounded retry]
Technical reviewBest possible solution: Use the existing per-call guard with the lower threshold while preserving terminal validation, request cancellation, and bounded retry. Do we have a high-confidence way to reproduce the issue? Main's 32,768-character counter permits roughly 328 seconds of whitespace at the reported rate, matching the observed stall; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete correction: adjust the existing shared counter, retain its meaningful regression and large-argument control, and align the documentation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 84593afb7355. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests 0, Docs 0. Total +1 across 3 files. Added test files: 0. View PR surface stats
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 October 21, 2026, 3:49 AM ET / 07:49 UTC. |
|
ClawSweeper reports no code findings on |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…179233) Live runaway argument streams emit ~100 whitespace chars/s, so the 32 KiB limit aborted only ~325 s in, just before the 360 s session watchdog. Tool-call arguments are JSON with escaped newlines, so real whitespace runs stay far below 4 KiB; the existing 200 KiB mixed-whitespace acceptance test still passes.
…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]>
…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]>
What Problem This Solves
The degenerate tool-call guard from #177659 aborts a Responses tool-call argument stream after 32 KiB of consecutive whitespace. Live, a sub-agent's runaway argument stream emitted about 100 whitespace characters per second. Its last real progress was at 06:13:16 and the guard fired at 06:18:41, so the run stalled for 325 s and was saved only about 35 s before the 360 s session watchdog.
User Impact
Runaway Responses tool-call whitespace now aborts in about 40 s and goes through the existing bounded retry, while large arguments with ordinary indentation remain unaffected.
Why This Change Was Made
The limit is now 4 KiB. Tool-call arguments are JSON text, where newlines inside strings are escaped, so real whitespace runs (indentation and spacing) stay far below 4 KiB. The same runaway now aborts in about 40 s and goes through the same bounded retry.
docs/concepts/retry.mdis updated.Evidence
openai-responses-client.terminal-error.test.ts: the churn case now aborts after 4 deltas of 1 KiB (red on base, where it expected 32), and the file passes 17/17 (run on the Crabbox host). The existing "accepts 200 KiB of arguments with whitespace runs interrupted by code" case, which uses 1,023-space runs, still passes, so real large arguments are unaffected. oxfmt, oxlint and the line-cap ratchet are clean.Local test note
The local host is overloaded and Vitest runs stall without verdicts; the coordinator already ran the focused tests on a Crabbox host (results above). PR CI provides the broad proof.
CI attribution
CI run 39562698588, head
f3f9f24693074338ff4a2ece9987d91865d08c39, reports a failure incheck-test-types-core-2:test/scripts/ci-changed-node-test-plan.test.ts:813and:891passCompactNodeTestShardwhereChangedNodeTestShardrequiresconfigs(TS2345). This PR does not touch the test or planner.The exact same two errors reproduce on main commit
4fa2da58c1273b0aa3cc00d4cbde0ce33a71b85awithnode scripts/run-tsgo.mjs --noEmit -p test/tsconfig/tsconfig.test.root.tooling.json. The failing test blob is identical (a13438acd4cdb59db81477a3435959475399141e) on that main commit and the CI merge baselinec5d7bc0741f4e942e81efcd2714b01fa32bdd5fd. This is an inherited main failure; the scoped landing instruction authorizes the native inherited-failure exception after the remaining gates finish.