Skip to content

refactor(openai): decide strict per tool on declared routes; drop the URL strict helper - #206735

Merged
obviyus merged 24 commits into
mainfrom
fix/strict-per-tool
Nov 27, 2026
Merged

obviyus merged 24 commits into
mainfrom
fix/strict-per-tool

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

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.

- 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.
@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 gateway Gateway runtime agents Agent runtime and tooling size: XL labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. 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
…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.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

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

  • Before: Both tools receive strict: false.
  • After: lookup_order receives strict: true while issue_refund remains non-strict.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful direction and focused transport coverage, with blocking API, request-compatibility and argument-semantics defects.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 6 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A single incompatible tool disables provider-enforced schemas for healthy tools, and custom-endpoint tool calls can emit runaway arguments.
Reason: The core downgrade is independently reported and source-verifiable, and the collaborator-authored PR establishes direction for the broader strict-default repair.

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

Before merge

  • Preserve explicit non-strict tools on supported direct OpenRouter routes (P1) - For a public OpenRouter model without an explicit supportsStrictMode value, direct Completions now omits strict instead of sending false. That restores the exact request shape repaired in fix(openrouter): send strict:false so optional tool inputs stay optional #175267: OpenAI models behind OpenRouter fill unused optional browser selectors, causing validation failures. The changed integration expectation now accepts that omission. Preserve the verified endpoint's explicit non-strict behavior without enabling strict-by-default on unknown direct endpoints.
  • Give direct Responses requests a strict-refusal recovery path (P1) - The direct Responses serializer now enables strict on undeclared custom routes. However, runResponsesStreamLifecycle calls createResponsesStreamWithRecovery without buildToolsWithoutStrict or rejection learning, so an endpoint returning 400 for strict tools terminates the request instead of recovering. It also never reads a previously learned rejection. Either retain safe direct-route defaults or wire this entry point through the shared fallback owner.
  • Retain compatibility for the published strict-policy host hook (P1) - Removing resolveOpenAIStrictToolSetting and OpenAIStrictToolSettingOptions breaks the package-root API documented at https://docs.openclaw.ai/reference/openclaw-ai. Existing TypeScript embeddings configuring that port stop compiling, while JavaScript embeddings silently lose their override because serializers no longer consume it. The public-package reproduction in [Bug]: Requested strict tool mode is silently turned off for all tools when one schema has oneOf #197381 uses this hook. Preserve a deprecated compatibility path and document migration before removing the published contract.
  • Check all constraints before treating an optional schema as nullable (P2) - For an optional mode property with {type:["string","null"],enum:["auto","manual"]}, isNullSchemaLike returns true from the type list, so nullableStrictSchema leaves the enum unchanged. The enclosing object nevertheless makes mode required and the compatibility checker permits strict:true. Null cannot satisfy the enum, so omission is no longer representable and the model must invent a mode. Widen the whole constrained schema to include null or keep this tool non-strict.
  • Resolve referenced schemas when removing null placeholders (P2) - An optional offset defined by {$ref:"#/$defs/offset"}, where the definition is an integer with minimum:1, is inlined and made nullable by outbound normalization. When the model returns offset:null for omission, schemaAcceptsNull sees no local type and returns true, leaving the placeholder intact. Existing reference-aware coercion then converts it to 0 and validation fails. Resolve null acceptance against the original root schema before coercion so the strict projection's omission value is actually removed.
  • Complete the strict-policy cutover in existing consumer tests (P2) - Current-head CI still fails because schema-normalization-runtime-contract expects [false,false], openai-transport-stream.replay-and-tools expects an optional schema to remain non-strict, and ClawRouter expects the old strict:false wire schema. These failures directly follow the newly authorized policy, rather than proving that policy wrong. Update their independent expected schemas and preserve their consumer contracts; also reconcile rejection fixtures affected by the additional request instead of deleting their failure-path assertions.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.
  • Explain or restore the original intent of OpenRouter explicit non-strict serialization - e96ea4b: Explicit strict:false prevented OpenRouter-backed OpenAI models from inventing optional browser arguments on managed and direct paths.

Findings

  • [P1] Preserve explicit non-strict tools on supported direct OpenRouter routes — packages/ai/src/transports/openai-completions-params.ts:170-174
  • [P1] Give direct Responses requests a strict-refusal recovery path — packages/ai/src/providers/openai-responses-tools.ts:83-85
  • [P1] Retain compatibility for the published strict-policy host hook — packages/ai/src/host.ts:149-151

Provenance

  • OpenRouter explicit non-strict serialization changes intended behavior without addressing why it exists (e96ea4b: Explicit strict:false prevented OpenRouter-backed OpenAI models from inventing optional browser arguments on managed and direct paths.)

Tests

  • Missing end-to-end proof: Provide viewable shipped-CLI/model output, latest-stable upgrade evidence with settings intact, and base-fail/head-pass regression results.
Agent review details

How this fits together

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

Technical review

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

  • [P1] Preserve explicit non-strict tools on supported direct OpenRouter routes — packages/ai/src/transports/openai-completions-params.ts:170-174
    For a public OpenRouter model without an explicit supportsStrictMode value, direct Completions now omits strict instead of sending false. That restores the exact request shape repaired in fix(openrouter): send strict:false so optional tool inputs stay optional #175267: OpenAI models behind OpenRouter fill unused optional browser selectors, causing validation failures. The changed integration expectation now accepts that omission. Preserve the verified endpoint's explicit non-strict behavior without enabling strict-by-default on unknown direct endpoints.
    Confidence: 0.99
  • [P1] Give direct Responses requests a strict-refusal recovery path — packages/ai/src/providers/openai-responses-tools.ts:83-85
    The direct Responses serializer now enables strict on undeclared custom routes. However, runResponsesStreamLifecycle calls createResponsesStreamWithRecovery without buildToolsWithoutStrict or rejection learning, so an endpoint returning 400 for strict tools terminates the request instead of recovering. It also never reads a previously learned rejection. Either retain safe direct-route defaults or wire this entry point through the shared fallback owner.
    Confidence: 0.99
  • [P1] Retain compatibility for the published strict-policy host hook — packages/ai/src/host.ts:149-151
    Removing resolveOpenAIStrictToolSetting and OpenAIStrictToolSettingOptions breaks the package-root API documented at https://docs.openclaw.ai/reference/openclaw-ai. Existing TypeScript embeddings configuring that port stop compiling, while JavaScript embeddings silently lose their override because serializers no longer consume it. The public-package reproduction in [Bug]: Requested strict tool mode is silently turned off for all tools when one schema has oneOf #197381 uses this hook. Preserve a deprecated compatibility path and document migration before removing the published contract.
    Confidence: 0.98
  • [P2] Check all constraints before treating an optional schema as nullable — packages/ai/src/providers/tool-schema-normalization.ts:322-324
    For an optional mode property with {type:["string","null"],enum:["auto","manual"]}, isNullSchemaLike returns true from the type list, so nullableStrictSchema leaves the enum unchanged. The enclosing object nevertheless makes mode required and the compatibility checker permits strict:true. Null cannot satisfy the enum, so omission is no longer representable and the model must invent a mode. Widen the whole constrained schema to include null or keep this tool non-strict.
    Confidence: 0.99
  • [P2] Resolve referenced schemas when removing null placeholders — packages/llm-core/src/validation.ts:425-426
    An optional offset defined by {$ref:"#/$defs/offset"}, where the definition is an integer with minimum:1, is inlined and made nullable by outbound normalization. When the model returns offset:null for omission, schemaAcceptsNull sees no local type and returns true, leaving the placeholder intact. Existing reference-aware coercion then converts it to 0 and validation fails. Resolve null acceptance against the original root schema before coercion so the strict projection's omission value is actually removed.
    Confidence: 0.98
  • [P2] Complete the strict-policy cutover in existing consumer tests — packages/ai/src/providers/openai-tool-schema.ts:116-125
    Current-head CI still fails because schema-normalization-runtime-contract expects [false,false], openai-transport-stream.replay-and-tools expects an optional schema to remain non-strict, and ClawRouter expects the old strict:false wire schema. These failures directly follow the newly authorized policy, rather than proving that policy wrong. Update their independent expected schemas and preserve their consumer contracts; also reconcile rejection fixtures affected by the additional request instead of deleting their failure-path assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7d93619b4132.

Provenance checked

  • Request-wide strict fallback changes intended behavior with a stated reason (c508992: The projected-tool resolver retained strict handling after descriptor projection and computed compatibility across the emitted inventory.)
  • Native-versus-compatible strict defaults changes intended behavior with a stated reason (b4f12bb: This extraction carried the existing policy of strict native requests and non-strict compatible requests; it does not establish where that policy originally began.)
  • Embedding-host strict policy API changes intended behavior with a stated reason (062f88e: The reusable AI package injected application-owned policy through published host ports instead of bundling OpenClaw application behavior.)
  • Z.ai strict exclusion changes intended behavior with a stated reason (50d85dc: The shared compatibility-default extraction carried a Z.ai exclusion but recorded no provider rejection establishing its original necessity.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test packages/ai/src/providers/openai-tool-schema.test.ts packages/llm-core/src/validation.test.ts packages/ai/src/providers/openai-responses-tools.integration.test.ts packages/ai/src/transports/openai-strict-rejection.test.ts packages/ai/src/transports/openai-responses-replay-internal.test.ts test/plugins/openrouter-tool-schema.integration.test.ts --maxWorkers=1
  • pnpm test src/agents/schema-normalization-runtime-contract.test.ts src/agents/openai-transport-stream.replay-and-tools.test.ts extensions/clawrouter/index.test.ts extensions/openai/gpt-62-support.test.ts src/cron/isolated-agent.session-model-strictness.integration.test.ts src/agents/embedded-agent-runner.responses-cold-prefix.test.ts --maxWorkers=1
  • pnpm test src/agents/agent-tools.prefix-stability.test.ts --maxWorkers=1

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 548b556 adds src/agents/openai-tool-schema.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 548b55676fd0; files: src/agents/openai-tool-schema.ts)
  • Vincent Koc: Raw commit 50d85dc adds src/agents/openai-completions-compat.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 50d85dcd595a; files: src/agents/openai-completions-compat.ts)

PR surface

Source +168, Tests +306, Docs +1. Total +475 across 33 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 17 450 282 +168
Tests 13 396 90 +306
Docs 3 7 6 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 853 378 +475

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 merge-risk: 🚨 compatibility: The patch removes a published host-policy API and changes request defaults in ways that can break existing custom endpoints and OpenRouter tool calls.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • merge-risk: 🚨 compatibility: The patch removes a published host-policy API and changes request defaults in ways that can break existing custom endpoints and OpenRouter tool calls.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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, 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.
@openclaw-barnacle openclaw-barnacle Bot added the extensions: clawrouter Extension: clawrouter label Nov 27, 2026
- 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.
@obviyus obviyus changed the title fix(openai): strict tools per tool by default, learn routes that refuse them fix(openai): decide strict per tool on the schema as written; retry only strict-specific refusals Nov 27, 2026
…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).
@openclaw-barnacle openclaw-barnacle Bot removed the extensions: clawrouter Extension: clawrouter label Nov 27, 2026
…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.
@obviyus obviyus changed the title fix(openai): decide strict per tool on the schema as written; retry only strict-specific refusals refactor(openai): decide strict per tool on declared routes; drop the URL strict helper Nov 27, 2026
- 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.
@obviyus
obviyus merged commit 410fe6b into main Nov 27, 2026
134 checks passed
@obviyus
obviyus deleted the fix/strict-per-tool branch November 27, 2026 20:21
obviyus added a commit that referenced this pull request Nov 27, 2026
## 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]>
obviyus added a commit that referenced this pull request Nov 27, 2026
… 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]>
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
## 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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
… 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]>
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 gateway Gateway runtime impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant