Skip to content

fix(agents): stop whitespace tool-call runaways for every provider - #206754

Merged
obviyus merged 2 commits into
mainfrom
core/turn-termination
Nov 27, 2026
Merged

obviyus merged 2 commits into
mainfrom
core/turn-termination

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

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

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

clawsweeper Bot commented Nov 27, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:crash-loop Crash, hang, restart loop, or process-level availability failure. 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 Nov 27, 2026
- withServer expects a void handler; run the whitespace stream as a tracked
  promise and await it before the assertions (no-misused-promises).
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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 Nov 27, 2026
@obviyus

obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: checks-ui-e2e (1/3) and openclaw/ci-gate on head eadd688.

ci-triage 206754:

# PR #206754 head eadd688d1f41; main run 46007024811
checks-ui-e2e (1/3)	ui/src/e2e/chat-flow.model-picker-refresh.e2e.test.ts	MAIN-ALSO

The failing test (chat-flow.model-picker-refresh.e2e.test.ts:240, "keeps historical work with its author when switching routed models") also fails on main run 46007024811 (head 122584a, job checks-ui-e2e 7/10). This PR changes no ui/ file. All other checks pass, and the local ClawSweeper review of this head is clean.

@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

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

  • Before: The supplied CLI replay consumed the entire capture and eventually timed out.
  • After: The supplied replay aborted each attempt after approximately 4 KiB of whitespace and displayed the specific model-output guidance after bounded retries.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with production-entry-point replay evidence and distinct regression coverage; no definite patch defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied built-CLI replay results exercise the shared consumer through real transport clients against an injected loopback fault, including early abort, bounded retry exhaustion, specific failure copy, and successful recovery; no stored format changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Non-Responses providers can keep generating blank tool arguments until an output cap or deadline, leaving users waiting without useful progress.
Reason: The maintainer-authored direction extends an established safeguard through the existing owner without adding configuration or changing retry budgets.

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: eadd688d1f418edd9f267c8ec43ff82508fe317a

Before merge

None.

Findings

None.

Agent review details

How this fits together

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

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +5, Tests +48, Docs 0. Total +53 across 10 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 51 46 +5
Tests 3 127 79 +48
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 179 126 +53

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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:

  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 November 27, 2026, 10:23 AM ET / 15:23 UTC.

@obviyus
obviyus merged commit dd39023 into main Nov 27, 2026
131 of 134 checks passed
@obviyus
obviyus deleted the core/turn-termination branch November 27, 2026 15:25
obviyus added a commit that referenced this pull request Nov 27, 2026
… 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]>
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
… 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]>
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 impact:crash-loop Crash, hang, restart loop, or process-level availability failure. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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