Repository navigation
fix(agents): abort degenerate streamed tool arguments - #177659
Conversation
Stop Responses tool calls after 32 KiB of trailing whitespace without limiting total argument size. Preserve a typed degenerate_output code for existing same-model transient recovery and fixed-label transport diagnostics. Partial arguments never reach tool completion. Tag watchdog-triggered model recovery with OPENCLAW_SESSION_WATCHDOG so transport errors retain session_watchdog attribution. Add stream/retry and watchdog regressions, including a legitimate 200 KiB argument control, and document the threshold.
|
🦞👀 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 changesAbort Responses tool arguments after 32,768 consecutive trailing whitespace characters, retry through existing recovery, and identify watchdog aborts in diagnostics. Example: An exec argument streams 32 consecutive deltas containing 1,024 whitespace characters each.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a concrete agent stall using the existing stream and retry owners; no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe shared Responses processor converts provider events into assistant text and completed tool calls; transport errors feed the embedded runner's existing recovery policy. flowchart TD
A[Responses HTTP or WebSocket] --> B[Shared stream processor]
B --> C[Argument whitespace counter]
C --> D[Completed tool calls]
C --> E[Typed stream error]
E --> F[Transport cancellation and diagnostics]
F --> G[Existing bounded retry owner]
Technical reviewBest possible solution: Use the shared accumulator's bounded whitespace guard and existing recovery policy while preserving terminal tool validation and content-free diagnostics. Do we have a high-confidence way to reproduce the issue? Current-main source refreshes request activity for argument deltas without limiting whitespace churn, matching the reported stall; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch is a small complete repair: one per-call counter rejects the reported runaway at the shared producer, while existing transport cancellation, terminal validation, and bounded recovery retain their responsibilities. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8b1ac41c3145. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +50, Tests +110, Docs +2. Total +162 across 9 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 19, 2026, 3:54 PM ET / 19:54 UTC. |
|
Merged via squash.
|
Stop Responses tool calls after 32 KiB of trailing whitespace without limiting total argument size. Preserve a typed degenerate_output code for existing same-model transient recovery and fixed-label transport diagnostics. Partial arguments never reach tool completion. Tag watchdog-triggered model recovery with OPENCLAW_SESSION_WATCHDOG so transport errors retain session_watchdog attribution. Add stream/retry and watchdog regressions, including a legitimate 200 KiB argument control, and document the threshold.
Stop Responses tool calls after 32 KiB of trailing whitespace without limiting total argument size. Preserve a typed degenerate_output code for existing same-model transient recovery and fixed-label transport diagnostics. Partial arguments never reach tool completion. Tag watchdog-triggered model recovery with OPENCLAW_SESSION_WATCHDOG so transport errors retain session_watchdog attribution. Add stream/retry and watchdog regressions, including a legitimate 200 KiB argument control, and document the threshold. Backport: preserve B payload diagnostics and existing terminal-error suite; add fixed abort-reason classification through B local request signal, and adapt churn/large-argument/recovery regressions to B fixtures. No newer diagnostic-label dependency or test-suite replacement. (cherry picked from commit b5d7e07) Co-authored-by: RomneyDa <[email protected]>
Remove the unused avatar-cache test assert import, brace the unchanged async event collection loop, and apply the canonical settings selector wrapping. No assertions, transport behavior, CSS selectors, or declarations change. Follow-ups to 7105904 (#185112), 5ddd59a (#177659), and a84f8f4 (#178175). Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Mitchell Etzel <[email protected]> Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 06ed73025cd0704a6f1d2778bbab23e682fa0efa)
…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
In sub-agent fleets on the embedded OpenClaw runtime with OpenAI Responses and Code Mode, about 1% of Responses requests degenerate into a runaway tool call. The model starts a normal Code Mode
execcall ("Verify edge cases and commit merge", a heredoc script) and then streams thousands ofresponse.function_call_arguments.deltaevents of pure whitespace (" \n \n \n ..."or" \r\r\n ..."), observed up to 26,317 deltas / 5.3 MB. No text or tool completion is produced, so the LLM idle timer stays satisfied and the session watchdog (abortMs = max(5 min, 3 × 120 s) = 360 swithout semantic progress) aborts the request exactly 360 s after it started. The transport log then reportedabortReason=caller_abort, hiding which owner ended the request. The retry always produced a normal smallexeccall. Each incident cost a child ~6 minutes plus megabytes of generated output; three concurrent fleets hit it within the same minute.User Impact
OpenAI Responses tool calls that degenerate into endless whitespace are now aborted and retried within seconds instead of stalling a run for six minutes; watchdog aborts are labeled as such in transport logs. No configuration or migration is required.
Why This Change Was Made
packages/ai/src/transports/openai-responses-stream-internal.ts) tracks the trailing run of consecutive whitespace per call (bounded counter, no extra buffering) and aborts the attempt at 32,768 whitespace characters with a typedDegenerateToolCallArgumentsError(degenerate_output). Partial arguments are never completed or executed; the existing transient same-model retry handles it. Covers the HTTP and WebSocket Responses paths.OPENCLAW_SESSION_WATCHDOG, so the transport log showsabortReason=session_watchdoginstead ofcaller_abort(fixed labels only, per fix(ai): attribute Responses aborts without logging provider text #176915/fix(logging): omit content from AI transport diagnostics #174217).docs/concepts/retry.mddocuments the threshold.Evidence
abortReason=degenerate_outputand retried successfully; zero 360 s watchdog aborts; all 18 fleets passed 35/35. The same soak on main had runaway-hit rounds of 441-481 s versus a 322 s worst round here.toolUseinstead ofdegenerate_output; watchdog loggedcaller_abort), green now; a legitimate 200 KiB argument control is not aborted. 248 focused tests pass across Responses terminal errors, stream parity/recovery, debug logging, attempt execution phase, session watchdog, failover retry and classification. Targeted lint/type checks, formatting, and isolated review are clean.Release note context
Fix: OpenAI Responses tool calls that degenerate into endless whitespace are now aborted and retried within seconds instead of stalling a run for six minutes; watchdog aborts are labeled as such in transport logs.