Skip to content

fix(zod): prevent generated definition name collisions - #2346

Merged
HAYDEN-OAI merged 1 commit into
mainfrom
agent/hayden-oai-zod-v3-definition-collisions-20260814-ykferedw
Aug 15, 2026
Merged

HAYDEN-OAI merged 1 commit into
mainfrom
agent/hayden-oai-zod-v3-definition-collisions-20260814-ykferedw

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Fix silent Zod v3 structured-output/tool schema corruption when distinct schema paths flatten to the same generated definition name. For example, repeated a.b string and a_properties_b number schemas previously both referenced the same overwritten definition, so the model-visible schema required a number while the local Zod parser required a string. This affected zodResponseFormat, zodTextFormat, zodFunction, zodResponsesFunction, and zodRealtimeFunction.

  • Preserve existing readable names when available, reuse a name only for the identical underlying Zod definition, and choose deterministic _1, _2, ... suffixes for distinct generated or caller-provided definitions.
  • Reserve the actual root definition without accidentally binding nested supplied definitions to it; retain recursive root references and safe own-key checks.
  • Copy caller-provided definitions only for the extract-to-root + duplicate-ref strategy that can mutate them, supporting frozen maps while preserving identity-dependent behavior in all other converter modes.
  • Add one dedicated handwritten regression suite covering every v3/v4 helper, successful parsing and correct wire-schema targets, multiple suffix collisions, identical schema/raw-definition reuse, inherited/null-prototype maps, nested/recursive/root definitions, and caller-map immutability.

Only handwritten vendored converter files and a new handwritten test file are changed; none has a Castiron generated header or appears in the generated/legacy file inventory.

Additional context & links

Regression-first baseline on untouched main: the initial eight targeted tests failed, reproducing all five public-helper collisions, supplied-definition overwrite/mutation, frozen-map failure, and the reserved-root collision.

Verification

  • pnpm test:unit tests/helpers/zod-definition-collisions.test.ts tests/helpers/zod.test.ts — 66 passed, including 24 focused collision regressions.
  • pnpm test:unit — 2,114 passed across 71 handwritten test files.
  • pnpm lint — passed across 609 files.
  • pnpm exec tsc — passed.
  • pnpm exec oxfmt --check src/_vendor/zod-to-json-schema/parseDef.ts src/_vendor/zod-to-json-schema/Options.ts tests/helpers/zod-definition-collisions.test.ts — passed.
  • pnpm build — passed, including CJS/ESM package import smoke checks.
  • ./node_modules/typescript-4-9/bin/tsc --project dist/src/tsconfig.json --noEmit — passed.
  • ./node_modules/typescript/bin/tsc --project dist/src/tsconfig.json --noEmit — passed.
  • pnpm exec publint dist — passed with the existing non-fatal vendored CommonJS default-export advisory.
  • Direct built-package smoke test verified all five v3 helper schemas and preservation of frozen caller definitions.

@openai-sdks

openai-sdks Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 237/237 SDK tests passed in 9.448s for Node SDK PR #2346.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 110ms
tests/chat-completions-create.test.ts ✅ Passed 201ms
tests/chat-completions-stream.test.ts ✅ Passed 227ms
tests/files-content-binary.test.ts ✅ Passed 116ms
tests/files-create-multipart.test.ts ✅ Passed 174ms
tests/files-list-pagination.test.ts ✅ Passed 166ms
tests/initialize-config.test.ts ✅ Passed 129ms
tests/instance-isolation.test.ts ✅ Passed 80ms
tests/models-list.test.ts ✅ Passed 212ms
tests/responses-background-lifecycle.test.ts ✅ Passed 191ms
tests/responses-body-method-errors.test.ts ✅ Passed 267ms
tests/responses-cancel-timeout.test.ts ✅ Passed 190ms
tests/responses-cancel.test.ts ✅ Passed 229ms
tests/responses-compact-retries.test.ts ✅ Passed 229ms
tests/responses-compact.test.ts ✅ Passed 185ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 85ms
tests/responses-create-advanced.test.ts ✅ Passed 140ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.165s
tests/responses-create-errors.test.ts ✅ Passed 159ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 240ms
tests/responses-create-retries.test.ts ✅ Passed 203ms
tests/responses-create-stream-failures.test.ts ✅ Passed 261ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.154s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.154s
tests/responses-create-stream.test.ts ✅ Passed 57ms
tests/responses-create-terminal-states.test.ts ✅ Passed 189ms
tests/responses-create-timeout.test.ts ✅ Passed 200ms
tests/responses-create.test.ts ✅ Passed 158ms
tests/responses-delete.test.ts ✅ Passed 158ms
tests/responses-input-items-errors.test.ts ✅ Passed 201ms
tests/responses-input-items-list.test.ts ✅ Passed 140ms
tests/responses-input-items-options.test.ts ✅ Passed 91ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 205ms
tests/responses-input-tokens-count.test.ts ✅ Passed 271ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.762s
tests/responses-not-found-errors.test.ts ✅ Passed 224ms
tests/responses-parse.test.ts ✅ Passed 169ms
tests/responses-retrieve-retries.test.ts ✅ Passed 234ms
tests/responses-retrieve.test.ts ✅ Passed 220ms
tests/responses-stored-method-errors.test.ts ✅ Passed 509ms
tests/retry-behavior.test.ts ✅ Passed 3.136s
tests/sdk-error-shape.test.ts ✅ Passed 269ms

View OkTest run #31830683405

SDK merge (d320f3a7a667) · head (2f157b217728) · base (53dd7236e807) · OkTest (a845fa206fa4)

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 2f157b2. The Zod v3 definition-name allocator now distinguishes real roots from flattened nested collisions, reuses true aliases by underlying definition identity, and skips occupied caller/generated/root names deterministically with own-property-safe lookup. Caller definition maps are cloned only for the mutating extraction strategy, preserving frozen inputs and the behavior of other strategies; Zod v4 remains isolated. Focused public-helper coverage is comprehensive, strict thermo is clean, and all applicable exact-head CI is green.

@HAYDEN-OAI
HAYDEN-OAI added this pull request to the merge queue Aug 15, 2026
Merged via the queue into main with commit 0844573 Aug 15, 2026
27 checks passed
@HAYDEN-OAI
HAYDEN-OAI deleted the agent/hayden-oai-zod-v3-definition-collisions-20260814-ykferedw branch August 15, 2026 02:18
@openai-sdks openai-sdks Bot mentioned this pull request Aug 15, 2026

This branch was previously deployed

1 inactive deployment
ci — 2f157b21 Deployed Aug 14, 2026 by HAYDEN-OAI via examples #7630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants