Skip to content

fix(agents): abort degenerate streamed tool arguments - #177659

Merged
steipete merged 1 commit into
mainfrom
steipete/degenerate-tool-args
Oct 19, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/degenerate-tool-args

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 exec call ("Verify edge cases and commit merge", a heredoc script) and then streams thousands of response.function_call_arguments.delta events 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 s without semantic progress) aborts the request exactly 360 s after it started. The transport log then reported abortReason=caller_abort, hiding which owner ended the request. The retry always produced a normal small exec call. 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

  • The Responses tool-call argument accumulator (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 typed DegenerateToolCallArgumentsError (degenerate_output). Partial arguments are never completed or executed; the existing transient same-model retry handles it. Covers the HTTP and WebSocket Responses paths.
  • Watchdog-triggered recovery carries OPENCLAW_SESSION_WATCHDOG, so the transport log shows abortReason=session_watchdog instead of caller_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.md documents the threshold.

Evidence

  • Live (isolated Gateway on this branch, real OpenAI key, 6 rounds × 3 parallel 8-child fleets): 3 runaways were cut with abortReason=degenerate_output and 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.
  • Regressions red on main (stream returned toolUse instead of degenerate_output; watchdog logged caller_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.

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.
@clawsweeper

clawsweeper Bot commented Oct 19, 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.

@steipete
steipete marked this pull request as ready for review October 19, 2026 19:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T19:45:09.845621Z c9c13c9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 19, 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Abort 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.

  • Before: The deltas keep the idle timer alive until the session watchdog interrupts the stalled request.
  • After: The accumulator rejects the unfinished call with degenerate_output, closes the request, and permits bounded transient recovery.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and exact-head gates support correctness; independently inspectable behavior evidence remains limited to the committed test composition.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports successful recovery in a real isolated Gateway soak, while the inspectable committed regressions use mocked OpenAI transport and real stream/recovery owners.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An embedded agent can spend minutes generating whitespace inside an unfinished tool call before watchdog recovery begins.
Reason: The reported production incidents justify a small bounded guard, and maintainer authorship supplies direction for the threshold without another product decision.

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
Reviewed head: c9c13c9d20249cd6dcc6e4577fb41fc59b45f32a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported live Gateway soak has no attached request/abort/retry trace for independent inspection.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b0525e1 adds packages/ai/src/transports/openai-responses-stream-internal.ts:70 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b0525e1a70b6; files: packages/ai/src/transports/openai-responses-stream-internal.ts)
  • Vyctor H. Brzezowski: Raw commit ddd12ca adds packages/ai/src/transports/openai-responses-stream-internal.ts:64 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ddd12ca27bea; files: packages/ai/src/transports/openai-responses-stream-internal.ts)
  • von8794: Raw commit 4a87ca5 adds src/agents/embedded-agent-runner/run/attempt-execution-phase.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 4a87ca504381; files: src/agents/embedded-agent-runner/run/attempt-execution-phase.ts)

PR surface

Source +50, Tests +110, Docs +2. Total +162 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 52 2 +50
Tests 2 110 0 +110
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 164 2 +162

Labels

Label changes:

  • add P2: Intermittent runaway provider output delays embedded agent work for several minutes; the repair has a focused runtime boundary.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Intermittent runaway provider output delays embedded agent work for several minutes; the repair has a focused runtime boundary.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach a redacted abort-and-retry trace from the reported live Gateway soak.

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.

Reviewed October 19, 2026, 3:54 PM ET / 19:54 UTC.

@steipete
steipete merged commit b5d7e07 into main Oct 19, 2026
225 of 227 checks passed
@steipete
steipete deleted the steipete/degenerate-tool-args branch October 19, 2026 19:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
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.
tideclaw-bot added a commit that referenced this pull request Nov 6, 2026
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]>
tideclaw-bot added a commit that referenced this pull request Nov 6, 2026
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)
obviyus added a commit that referenced this pull request Nov 27, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…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)
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant