Repository navigation
refactor(openai): decide strict per tool on declared routes; drop the URL strict helper - #206735
Conversation
- Not ready: the 400/422 retry-without-strict guard is not built; two openai-completions-params tests are still red. See STATUS-owed W3 item 3.
- A 400/422 before any output on an undeclared route whose request carried strict tools is retried once with strict tools off; only an accepted retry records the route (core plugin state, 30-day TTL) and warns with compat.supportsStrictMode. - Later requests on a learned route send non-strict tools from the start. - normalizeModelCompat no longer fills in supportsStrictMode, so a present value means the route declared it; declared routes never retry.
- custom-providers compat table, OpenRouter note and changelog.
…usals - The argument boundary also visits array items and union branches, and decides null acceptance from union branches before the missing-type default. - The process cache re-reads a learned refusal hourly, so the record's TTL applies to long-lived Gateways.
- Open nested objects and optional keys inside union branches are not projected; their tools go non-strict. - Optional untyped enums and consts get a null member, so omission stays representable. - The argument boundary no longer walks union branches, so one branch cannot drop a null another requires.
- Remove the core Z.ai strict gate: a route that refuses strict tools is learned by the one retry, not by provider name. - Completions keeps the learned or declared tool model in its own binding.
- The strict retry swaps only the tools, so compaction and continuation recovery keep their input and metadata.
|
🦞👀 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. |
…t requests declared-only - An optional anyOf with a sibling type or enum is wrapped whole, so null stays representable. - Direct (no-retry) Completions requests send the strict field only where the route declares support. - Tests: projection diagnostics read from the projection; OpenRouter and parity fixtures follow the strict default.
|
Codex review: blocked before merge. What this changesThis PR enables strict schemas per tool and retries undeclared routes without strict tools when they reject a request. Example: A request contains a strict-compatible lookup_order tool and an issue_refund tool using oneOf.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 8 items remain Keep open: this PR addresses a current strict-tool limitation, but introduces compatibility and optional-argument regressions that need repair. Reviewed head: Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe AI package converts tool descriptors into OpenAI protocol requests, handles provider responses and retries, and validates returned arguments before tool execution. flowchart TD
A[Model and tool descriptors] --> B[Schema projection]
B --> C[Completions or Responses transport]
C --> D[Provider endpoint]
D --> E[Refusal recovery]
E --> C
E --> F[Plugin state store]
D --> G[Argument validation]
Technical reviewBest possible solution: Keep per-tool strictness while preserving supported public contracts, making nullable projection reversible, and completing recovery across affected entry points. Do we have a high-confidence way to reproduce the issue? Current main deterministically applies one compatibility result to every tool, matching the independent published-package reproduction in #197381; no target code was executed during this review. Is this the best way to solve the issue? Per-tool strictness addresses the demonstrated limitation, but the implementation must preserve existing entry-point contracts and reliably reverse nullable placeholders before it is complete. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7d93619b4132. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +168, Tests +306, Docs +1. Total +475 across 33 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 27, 2026, 9:54 AM ET / 14:54 UTC. |
- One schemaAcceptsNull in normalization-core validates null against the schema node (with root definitions), shared by the strict projection and the argument boundary; nullable widening only adds null where it is missing. - Replace the strict-refusal helper's casts with record checks; shrink its assertion baseline.
- The argument boundary resolves $defs references through the existing root-ref owner before walking, matching what the strict projection inlined. - Runtime contract test follows per-tool strict (one permissive tool no longer downgrades the rest).
… never retry native 400s - An object with key-count or dependency keywords (maxProperties, dependentRequired, if/then, ...) keeps its optional keys optional, so its tool goes non-strict. - Native OpenAI endpoints serve strict tools; their 400s are sent once and never learned as strict refusals. - Clawrouter (declares strict support) now sends its optional input as a required nullable key.
- Native OpenAI is no longer exempt: any undeclared route gets the one strict-off retry and the learned record; only a declared compat.supportsStrictMode skips it. - Tests follow: Responses retry+record on the loopback route; gpt-6.2 and cron billing fixtures count the one retry.
- The retry and the learned record need the provider error to name strict or the tool schema (OpenAI: invalid_function_parameters, tools[n].parameters, 'Invalid schema for function'). - Quota, billing, auth, rate and context-length errors never retry, also as 400; a generic 400 is sent once and learns nothing. - gpt-6.2 and cron billing fixtures are back to one request.
… the message - An account code or type vetoes; invalid_function_parameters or a tools[n] param confirms; the message decides only without either, so a tool name cannot veto OpenAI's strict refusal.
…1 from 5610339 review) Not pushed. Regression test in openai-tool-schema.test.ts. Full-suite proof pending.
…optional-key projection - PR A scope (Ayaan 23:48): a tool is strict only when its schema is strict-compatible as written; optional keys are never rewritten and the argument-boundary null drop is removed. - Fixtures follow: optional-key tools send strict: false unchanged; fully required tools go strict; the Z.ai fixture row pinned the removed gate.
…ring reader - Direct Completions requests send strict: false wherever resolved compat supports the field (#175267: OpenRouter treats an omitted field as strict). - The strict-rejection classifier reads error fields with normalization-core readStringValue (coercion-helpers guard).
Co-authored-by: Ayaan Zaidi <[email protected]>
…written (D3) - Delete the strict-refusal retry, its classifier and the learned-route store; undeclared routes send tools exactly as before. - The compat owner declares strict support for OpenAI, Azure OpenAI, OpenRouter and the openai default route; others declare it in catalog or config. No Z.ai case. - Per tool: strict only when the schema is strict-compatible before strict normalization (object root, all keys required, closed objects); otherwise strict: false, schema unchanged. - Detector: anyOf and string type lists allowed; object rules for nullable objects and typeless branches with properties.
- anyOf stays a strict violation (a branch can lack the type strict mode needs); string type lists such as ["integer", "null"] remain accepted. - Shrink the assertion baseline for openai-responses-params-internal.ts.
- The detector flags a value schema with no type, $ref, enum or const (e.g. {} from MCP inputs); its tool stays non-strict.
## Problem `checks-fast-baseline-ratchets` fails on every PR merged with current main: `provider-branching` asks to shrink 3 allowlist entries. The allowlist from #206878 was taken at `ea77ca3d`. PRs merged later removed provider branches (#206735 deleted `openai-strict-tool-setting.ts`, and others touched `attempt-stream.ts` and `openai-tool-schema.ts`). The shrink-only ratchet fails when a file's count drops below its entry. ## Solution `--prune` on current main `8a8e0177`: - `src/agents/openai-strict-tool-setting.ts` 3 → removed (file deleted) - `src/agents/embedded-agent-runner/run/attempt-stream.ts` 2 → 1 - `packages/ai/src/providers/openai-tool-schema.ts` 1 → removed - `packages/ai/src/transports/openai-completions-compat.ts` 61 → 63: #206735 moved the strict-mode default from the deleted helper into the compat owner before the ratchet existed. This records main as it is; no branch is added here. Net: 840 → 837 branches, 218 → 216 files. ## Impact Contributors only. PRs are no longer red on `provider-branching` for branches that main already removed. There is no runtime change. ## Evidence - Before: `check-provider-branching-ratchet.mts --base origin/main` on main `8a8e0177` lists the 3 shrink entries (the same list as the CI failure on #206948). - After: `Provider branching ratchet OK: 216 files, 837 grandfathered branches.` - Local review on this head: patch is correct, 0 findings. Co-authored-by: Ayaan Zaidi <[email protected]>
… the field (#206991) ## Problem Since #206735, OpenAI-protocol routes that accept the `strict` tool field send `strict: true` for each tool whose schema is strict-compatible as written. Measured on native OpenAI Responses, strict tools make requests slower and gave no measurable benefit. Measurement: a mid-tool-loop request built by `main` (17 default tools, about 14.1k input tokens). Both arms closed the root of the two tools that pass the strict check (`apply_patch`, `write`). ON = `strict: true` on those two, OFF = `strict: false`; nothing else differs. Two warm-ups per arm, then 30 interleaved pairs per model. The cache was warm in both arms (about 14.1k of 14.1k input tokens cached on gpt-6.2-sol, 13.95k of 14.1k on gpt-5.4-mini; no request had 0 cached tokens). | Model | Arm | n | Total p50 / p90 | First token p50 / p90 | Invalid / malformed args | |---|---|---|---|---|---| | gpt-6.2-sol | strict ON | 30 | 3,247 / 4,052 ms | 2,557 / 3,379 ms | 0 / 0 | | gpt-6.2-sol | strict OFF | 30 | 2,273 / 3,363 ms | 1,209 / 2,654 ms | 0 / 0 | | gpt-5.4-mini | strict ON | 30 | 3,129 / 4,364 ms | 2,002 / 2,699 ms | 0 / 0 | | gpt-5.4-mini | strict OFF | 30 | 3,135 / 4,639 ms | 1,950 / 2,422 ms | 0 / 0 | - Paired ON − OFF median, gpt-6.2-sol: total **+427 ms (95% CI +73 to +1,284)**, first token **+510 ms (95% CI +39 to +1,544)**. - gpt-5.4-mini: no difference (total +145 ms, 95% CI −345 to +806; first token +68 ms, 95% CI −144 to +353). - Benefit: **0 invalid or malformed tool arguments in 120 of 120 runs**, in both arms. - On sol, all 30 calls went to the non-strict `edit` tool and the request was still slower, so the cost comes with the request, not with calling a strict tool. ## Solution `compat.supportsStrictMode` keeps its documented meaning: the route accepts the `strict` tool field. A route that accepts it now sends `strict: false` on every tool; other routes still omit the field. Explicit `false` is required: a live request today showed that OpenAI Responses treats an omitted `strict` as `true` (and filled an optional argument). Deleted, now unreachable: per-tool strict eligibility (`resolveOpenAIToolStrictFlag`), strict schema normalization (`normalizeStrictOpenAIJsonSchema` and the `strict` profile in tool-schema normalization), `isStrictOpenAIJsonSchemaCompatible`, the strict schema prewarm, and the strict arms of three perf scripts. Kept: `findOpenAIStrictSchemaViolations`, a public plugin SDK export. **Turning strict on:** there is no config switch. A provider plugin can still set `strict` in its own payload hook. A config switch would need a new compat field, and strict has no measured benefit on any current request; the decision record was amended to this. Before #206735 (which is in no release tag), `supportsStrictMode: true` on a custom route already meant "send `false`", so no shipped config changes meaning. ## Impact - Native OpenAI, Azure OpenAI, OpenRouter, and routes that declare the field (ClawRouter `openai/*` Responses, Baseten, `compat.supportsStrictMode: true`): every tool goes `strict: false`. Default and code-mode requests already had no strict tool on `main` (0 of 17 default tools qualify as written), so their bytes do not change. A closed, all-required plugin or MCP tool loses `strict: true`; its tool bytes change once, so expect one prompt-cache miss per affected session. - Undeclared custom endpoints: unchanged (field omitted). ## Evidence - Touched and consumer tests pass (provider and transport serialization on declared and undeclared routes, runtime schema contract, prefix stability, schema reuse and truncation). Co-authored-by: Ayaan Zaidi <[email protected]>
… URL strict helper (openclaw#206735) ## Problem Signal: none from users. The audit counts 0 strict-schema rejections in 517 real non-200 responses (team logs). The motivating failure is the board's whitespace runaway on gpt-6.1-sol (OpenClaw 2026.10.6), which openclaw#206754 now bounds at about 23 s; its fix at the tool owner (`read`) is a follow-up PR. On OpenAI-protocol routes, `strict` was all-or-nothing per request: one tool whose schema was not strict-compatible downgraded every tool to `strict: false`, so on native OpenAI a strict-compatible tool rarely got grammar-constrained arguments. The decision lived in a separate URL/provider-name helper (`src/agents/openai-strict-tool-setting.ts`) reached through a host hook, beside the compat owner's own `supportsStrictMode` default (with a Z.ai special case). Population: Gateway and one-shot users on routes that declare strict support (native OpenAI, Azure OpenAI, OpenRouter, or `compat.supportsStrictMode: true` in a catalog or config), managed transport: Completions `packages/ai/src/transports/openai-completions-params.ts:168-190`, Responses `openai-responses-params-internal.ts:200` and `providers/openai-responses-tools.ts:52-71`. ## Fix - **One owner for "declared".** `resolveOpenAICompletionsCompat` (`openai-completions-compat.ts`) resolves `supportsStrictMode` for the OpenAI and Azure OpenAI endpoints, OpenRouter, and the openai provider's default route; any other route declares it in its catalog or config. The Z.ai case and the separate URL/provider helper and host hook are deleted. - **Strict per tool, on the schema as written.** On a declared route, a tool whose schema is strict-compatible before strict normalization (object root, every key required, closed objects) is sent `strict: true`; every other tool is sent `strict: false` with its schema unchanged. No schema is rewritten to qualify. - **Undeclared routes are unchanged:** no strict field, same tool bytes. - The strict detector accepts string type lists (`["string", "null"]`), applies object rules to nullable objects and to typeless branches with `properties`, and flags untyped value schemas (`{}`); unions still keep a tool non-strict. - Deleted: `src/agents/openai-strict-tool-setting.ts`, the host `resolveOpenAIStrictToolSetting` hook, and the all-or-nothing downgrade diagnostics. Not benchmark-shaped: nothing changes on undeclared custom endpoints (the benchmark meter routes), and this PR does not fix the Sol runaway on its own (`read` has optional keys, so it stays non-strict here). ## Evidence - Net-negative vs the merge base (+249/−357). - Undeclared custom endpoint, real `agent --local` against a recording endpoint, merge-base build vs this head: the request's tool array is byte-identical (23,844 B, same sha1; 0 tools carry `strict`). - Tests: undeclared custom endpoint sends no strict field (Completions and Responses); declared route sends strict only for a strict-as-written tool; optional-key and open-root tools stay `strict: false` and unchanged; one permissive tool no longer downgrades the rest; detector on nullable objects. - Strict-related suites and `agent-tools.prefix-stability` pass; provider/transport parity snapshot unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
## Problem `checks-fast-baseline-ratchets` fails on every PR merged with current main: `provider-branching` asks to shrink 3 allowlist entries. The allowlist from openclaw#206878 was taken at `ea4af5f4`. PRs merged later removed provider branches (openclaw#206735 deleted `openai-strict-tool-setting.ts`, and others touched `attempt-stream.ts` and `openai-tool-schema.ts`). The shrink-only ratchet fails when a file's count drops below its entry. ## Solution `--prune` on current main `b5101725`: - `src/agents/openai-strict-tool-setting.ts` 3 → removed (file deleted) - `src/agents/embedded-agent-runner/run/attempt-stream.ts` 2 → 1 - `packages/ai/src/providers/openai-tool-schema.ts` 1 → removed - `packages/ai/src/transports/openai-completions-compat.ts` 61 → 63: openclaw#206735 moved the strict-mode default from the deleted helper into the compat owner before the ratchet existed. This records main as it is; no branch is added here. Net: 840 → 837 branches, 218 → 216 files. ## Impact Contributors only. PRs are no longer red on `provider-branching` for branches that main already removed. There is no runtime change. ## Evidence - Before: `check-provider-branching-ratchet.mts --base origin/main` on main `b5101725` lists the 3 shrink entries (the same list as the CI failure on openclaw#206948). - After: `Provider branching ratchet OK: 216 files, 837 grandfathered branches.` - Local review on this head: patch is correct, 0 findings. Co-authored-by: Ayaan Zaidi <[email protected]>
… the field (openclaw#206991) ## Problem Since openclaw#206735, OpenAI-protocol routes that accept the `strict` tool field send `strict: true` for each tool whose schema is strict-compatible as written. Measured on native OpenAI Responses, strict tools make requests slower and gave no measurable benefit. Measurement: a mid-tool-loop request built by `main` (17 default tools, about 14.1k input tokens). Both arms closed the root of the two tools that pass the strict check (`apply_patch`, `write`). ON = `strict: true` on those two, OFF = `strict: false`; nothing else differs. Two warm-ups per arm, then 30 interleaved pairs per model. The cache was warm in both arms (about 14.1k of 14.1k input tokens cached on gpt-6.2-sol, 13.95k of 14.1k on gpt-5.4-mini; no request had 0 cached tokens). | Model | Arm | n | Total p50 / p90 | First token p50 / p90 | Invalid / malformed args | |---|---|---|---|---|---| | gpt-6.2-sol | strict ON | 30 | 3,247 / 4,052 ms | 2,557 / 3,379 ms | 0 / 0 | | gpt-6.2-sol | strict OFF | 30 | 2,273 / 3,363 ms | 1,209 / 2,654 ms | 0 / 0 | | gpt-5.4-mini | strict ON | 30 | 3,129 / 4,364 ms | 2,002 / 2,699 ms | 0 / 0 | | gpt-5.4-mini | strict OFF | 30 | 3,135 / 4,639 ms | 1,950 / 2,422 ms | 0 / 0 | - Paired ON − OFF median, gpt-6.2-sol: total **+427 ms (95% CI +73 to +1,284)**, first token **+510 ms (95% CI +39 to +1,544)**. - gpt-5.4-mini: no difference (total +145 ms, 95% CI −345 to +806; first token +68 ms, 95% CI −144 to +353). - Benefit: **0 invalid or malformed tool arguments in 120 of 120 runs**, in both arms. - On sol, all 30 calls went to the non-strict `edit` tool and the request was still slower, so the cost comes with the request, not with calling a strict tool. ## Solution `compat.supportsStrictMode` keeps its documented meaning: the route accepts the `strict` tool field. A route that accepts it now sends `strict: false` on every tool; other routes still omit the field. Explicit `false` is required: a live request today showed that OpenAI Responses treats an omitted `strict` as `true` (and filled an optional argument). Deleted, now unreachable: per-tool strict eligibility (`resolveOpenAIToolStrictFlag`), strict schema normalization (`normalizeStrictOpenAIJsonSchema` and the `strict` profile in tool-schema normalization), `isStrictOpenAIJsonSchemaCompatible`, the strict schema prewarm, and the strict arms of three perf scripts. Kept: `findOpenAIStrictSchemaViolations`, a public plugin SDK export. **Turning strict on:** there is no config switch. A provider plugin can still set `strict` in its own payload hook. A config switch would need a new compat field, and strict has no measured benefit on any current request; the decision record was amended to this. Before openclaw#206735 (which is in no release tag), `supportsStrictMode: true` on a custom route already meant "send `false`", so no shipped config changes meaning. ## Impact - Native OpenAI, Azure OpenAI, OpenRouter, and routes that declare the field (ClawRouter `openai/*` Responses, Baseten, `compat.supportsStrictMode: true`): every tool goes `strict: false`. Default and code-mode requests already had no strict tool on `main` (0 of 17 default tools qualify as written), so their bytes do not change. A closed, all-required plugin or MCP tool loses `strict: true`; its tool bytes change once, so expect one prompt-cache miss per affected session. - Undeclared custom endpoints: unchanged (field omitted). ## Evidence - Touched and consumer tests pass (provider and transport serialization on declared and undeclared routes, runtime schema contract, prefix stability, schema reuse and truncation). Co-authored-by: Ayaan Zaidi <[email protected]>
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,
strictwas all-or-nothing per request: one tool whose schema was not strict-compatible downgraded every tool tostrict: 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 ownsupportsStrictModedefault (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: truein a catalog or config), managed transport: Completionspackages/ai/src/transports/openai-completions-params.ts:168-190, Responsesopenai-responses-params-internal.ts:200andproviders/openai-responses-tools.ts:52-71.Fix
resolveOpenAICompletionsCompat(openai-completions-compat.ts) resolvessupportsStrictModefor 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: true; every other tool is sentstrict: falsewith its schema unchanged. No schema is rewritten to qualify.["string", "null"]), applies object rules to nullable objects and to typeless branches withproperties, and flags untyped value schemas ({}); unions still keep a tool non-strict.src/agents/openai-strict-tool-setting.ts, the hostresolveOpenAIStrictToolSettinghook, 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 (
readhas optional keys, so it stays non-strict here).Evidence
agent --localagainst a recording endpoint, merge-base build vs this head: the request's tool array is byte-identical (23,844 B, same sha1; 0 tools carrystrict).strict: falseand unchanged; one permissive tool no longer downgrades the rest; detector on nullable objects.agent-tools.prefix-stabilitypass; provider/transport parity snapshot unchanged.