Repository navigation
fix(zod): reject non-object Zod v3 strict schema roots - #2358
Conversation
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Reviewed exact head e1f2b1d97c6da364550aba75c8c6c76658c235ba. The documented strict helpers are correct, but two Low internal strict-mode consistency gaps remain:
-
Validate the effective returned root after name wrapping.
validateStrictRootSchema(main)accepts an object, after which the default namednameStrategy: 'ref'path returns a root$ref, which strict Structured Outputs forbids. Public helpers useduplicate-ref, so this is limited to the package-importable_vendorconverter and its internalopenaiStrictModeoption. Validate the final structural root or reject this strict name strategy; add direct strict named-object coverage. -
Reject nullable OpenAPI roots in the strict predicate. The new type-only check accepts the OpenAPI3 nullable parser's
{ type: 'object', nullable: true }, even though the root admitsnull. Public strict helpers do not select OpenAPI3, so this has the same narrow direct-converter scope. Make the predicate semantic enough to rejectnullable: trueand add a direct strict OpenAPI nullable-object regression.
No supported-helper/API issue was found; the focused matrix and strict thermo are clean, and exact CI is fully green.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2d73fe2ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Re-reviewed the full merge-base diff at exact head d2d73fe. No findings. The strict-root guard now validates both the parsed and final wrapped schema, rejects OpenAPI nullable object roots, preserves supported strict-helper and non-strict behavior, and has focused parity coverage. Strict thermo and exact CI are clean.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Found one Medium reference-semantics bug and one Medium strict-thermo/architecture blocker in the exact-head diff. The earlier named-ref and nullable-root issues remain fixed; exact CI is green.
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Found one Medium strict-root serialization correctness issue in the exact-head diff. The prior reference-materialization problems are fixed and strict thermo passes; the sole live ecosystem failure is an unrelated external service-auth 500.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e73208685
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jbeckwith-oai
left a comment
There was a problem hiding this comment.
The boxed-BigInt gap is fixed on exact 2e732086851e88730d9cee70a879695bfde6f905, but this needs one structural correction before another carrier-specific patch.
[Medium, strict thermo] Define one ordinary JSON-schema record boundary. zodToJsonSchema.ts has grown 128→211 lines and the focused test to 449 lines by approximating JSON serialization piecemeal: prototype walking, arrays, toJSON, and four primitive unboxers. Two remaining holes show the catalog is still open-ended:
- [Low] A callable root such as
Object.assign(() => {}, { type: "object" })passes both checks, butJSON.stringifyreturnsundefined. - [Low] An extensible Proxy whose
getPrototypeOftrap returns itself serializes as a valid object, but the prototype walk never terminates.
Please stop adding isolated coercion cases and establish one explicit accepted carrier invariant—preferably a plain/ordinary JSON-schema record at the strict typed converter/helper boundary—then reject exotic carriers uniformly. This should remove the unboxer matrix and arbitrary prototype traversal while preserving the focused public-helper/reference regressions. If the callable fix is made locally during that reframing, reject typeof schema === "function"; if any prototype walk remains, detect repeats.
All exact-head CI is green and no file crosses 1k, but the repeated special-case growth is the blocker under the repository architecture guidance.
Anchors:
openai-node/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts
Lines 8 to 84 in 2e73208
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62b93b2a4a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jbeckwith-oai
left a comment
There was a problem hiding this comment.
The latest Proxy keyword reads help, but exact 8a545a1b9ed6f5f3a5331a90b57e0c6bc16b2cde still needs the same Medium boundary redesign rather than more serialization cases.
zodToJsonSchema.ts has grown 128→212 lines and the focused suite to 512 lines around a prototype walker, cycle state, array/function cases, four primitive-brand probes, descriptors/accessors, toJSON, omitted values, and Proxy reads. This remains an open-ended approximation of ECMAScript serialization rather than one typed root invariant. Concrete holes remain: boxed nullable: Object(true) passes but serializes as true; a Proxy can synthesize callable toJSON from get while descriptors show none; and a fresh Proxy at every getPrototypeOf hop never repeats in the WeakSet.
Please define one supported canonical/owned JSON-schema record boundary at the strict converter/helper edge, snapshot/own the root once, validate and return that same stable record, reject unsupported carriers uniformly, and delete the prototype/unboxer catalog. Preserve the canonical parseDef(..., forceResolution) path and focused public-helper/registered/lazy/recursive/naming/non-strict regressions. The three examples above are evidence for this single structural fix, not requests for three more local patches.
No file crosses 1k and no suppression/mock issue was found. All changed focused tests pass; the sole Node 22 failure is the unrelated generated Skills Versions APIConnectionError (Node 24/26 and every other applicable check pass).
Anchor:
openai-node/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts
Lines 8 to 85 in 8a545a1
jbeckwith-oai
left a comment
There was a problem hiding this comment.
Re-reviewed exact head ef52f13308394db93d8f64fd6af40e9a5705f494 and approved. The prior architecture blocker is resolved: strict conversion now owns one stable plain-record snapshot, validates and returns that same record, and removes the open-ended prototype/unboxer/serialization catalog. Canonical forced parsing, registered/lazy/recursive roots, frozen definitions, naming, public helpers, and non-strict behavior remain sound. Strict thermo is clean at 194 production lines plus a focused 331-line suite, with no suppressions or problematic mocks. The sole Node 22 generated Skills/Versions connection failure is the unrelated mock-server early-404 flake; changed tests, Node 24/26, build, lint, ecosystem, performance, detect-breaking, and CodeQL are green.
Summary
type: "object", using the same synchronous error as the existing Zod v4 path acrosszodResponseFormat,zodTextFormat,zodFunction, andzodResponsesFunction.openaiStrictModeand perform it before root naming, schema-definition expansion, or$refwrapping, preserving valid named, lazy, recursive, refined, transformed, and defaulted object roots.Why
The vendored Zod v3 converter previously returned invalid strict root schemas unchecked. The four strict public helpers therefore emitted schemas that Structured Outputs cannot accept, while the equivalent Zod v4 conversion already failed synchronously. Valid Zod v4 optional object roots remain accepted because v4 normalizes them to an actual root object; the unsupported Zod v3 representation is correctly rejected.
Validation
mainbefore the fix.pnpm test -- tests/helpers/zod-root-schema-validation.test.ts— 77 passing tests.pnpm test:unit— 2,167 passing tests across 71 files.pnpm formatandpnpm lint.pnpm exec tsc.pnpm build, including CommonJS/ESM SDK and Bedrock import checks../node_modules/typescript-4-9/bin/tsc --project dist/src/tsconfig.json --noEmit../node_modules/typescript/bin/tsc --project dist/src/tsconfig.json --noEmit.pnpm exec publint dist.node scripts/utils/attw-report.cjs—Types ok!.node --experimental-strip-types scripts/test-packed-package.ts— offline CommonJS/ESM consumer and both compiler versions; 263/300 source checks across 1,200 source maps.zodRealtimeFunctionremains non-strict.