Skip to content

fix: avoid deep Deno Zod types#1980

Open
HAYDEN-OAI wants to merge 1 commit into
mainfrom
codex/fix-deno-zod-types
Open

fix: avoid deep Deno Zod types#1980
HAYDEN-OAI wants to merge 1 commit into
mainfrom
codex/fix-deno-zod-types

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • narrow the public zodResponseFormat() generic constraint to the small Zod surface the helper actually needs
  • infer parsed output directly from the schema _output type
  • keep the existing Zod v3/v4 runtime schema conversion unchanged
  • add coverage that the returned parser still preserves inferred output types

Why

Issue #984 reports that deno check can fail with TS2589 or exhaust the JavaScript heap when calling zodResponseFormat(). The previous public signature asked Deno to structurally compare the supplied schema against the complete Zod v3 and v4 type graphs before inferring the output type.

Impact

Deno no longer needs to expand those full Zod graphs at the call site. The helper still accepts Zod v3 and v4 schemas, produces the same JSON Schema at runtime, and preserves the inferred parsed result through _output.

Validation

  • reproduced the Deno 2.9.0 heap exhaustion before the change and verified the same call no longer enters the OOM path afterward
  • pnpm exec jest tests/helpers/zod.test.ts --runInBand
  • pnpm exec tsc --noEmit
  • pnpm run lint

Resolves #984

@openai-sdks

openai-sdks Bot commented Jul 6, 2026

Copy link
Copy Markdown

OkTest Summary

237/237 SDK tests passed in 11.226s for Node SDK PR #1980.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 262ms
tests/chat-completions-create.test.ts ✅ Passed 262ms
tests/chat-completions-stream.test.ts ✅ Passed 267ms
tests/files-content-binary.test.ts ✅ Passed 195ms
tests/files-create-multipart.test.ts ✅ Passed 258ms
tests/files-list-pagination.test.ts ✅ Passed 309ms
tests/initialize-config.test.ts ✅ Passed 164ms
tests/instance-isolation.test.ts ✅ Passed 132ms
tests/models-list.test.ts ✅ Passed 195ms
tests/responses-background-lifecycle.test.ts ✅ Passed 193ms
tests/responses-body-method-errors.test.ts ✅ Passed 307ms
tests/responses-cancel-timeout.test.ts ✅ Passed 197ms
tests/responses-cancel.test.ts ✅ Passed 196ms
tests/responses-compact-retries.test.ts ✅ Passed 253ms
tests/responses-compact.test.ts ✅ Passed 229ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 163ms
tests/responses-create-advanced.test.ts ✅ Passed 172ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.207s
tests/responses-create-errors.test.ts ✅ Passed 189ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 179ms
tests/responses-create-retries.test.ts ✅ Passed 288ms
tests/responses-create-stream-failures.test.ts ✅ Passed 252ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.259s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.683s
tests/responses-create-stream.test.ts ✅ Passed 92ms
tests/responses-create-terminal-states.test.ts ✅ Passed 207ms
tests/responses-create-timeout.test.ts ✅ Passed 210ms
tests/responses-create.test.ts ✅ Passed 274ms
tests/responses-delete.test.ts ✅ Passed 227ms
tests/responses-input-items-errors.test.ts ✅ Passed 363ms
tests/responses-input-items-list.test.ts ✅ Passed 219ms
tests/responses-input-items-options.test.ts ✅ Passed 196ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 225ms
tests/responses-input-tokens-count.test.ts ✅ Passed 232ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.438s
tests/responses-not-found-errors.test.ts ✅ Passed 251ms
tests/responses-parse.test.ts ✅ Passed 182ms
tests/responses-retrieve-retries.test.ts ✅ Passed 262ms
tests/responses-retrieve.test.ts ✅ Passed 237ms
tests/responses-stored-method-errors.test.ts ✅ Passed 599ms
tests/retry-behavior.test.ts ✅ Passed 3.126s
tests/sdk-error-shape.test.ts ✅ Passed 292ms

View OkTest run #28825739887

SDK merge (71f3c7c1fae5) · head (2f8e7ef19a4f) · base (95b54e589491) · OkTest (7fc645091b1a)

@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 the linked issue (#984), its follow-up reports (Deno 1.x/2.x, JSR, and npm with Zod 4), the complete diff, and the surrounding Zod v3/v4 conversion path.

Validation performed against this head:

  • ./node_modules/.bin/jest tests/helpers/zod.test.ts --runInBand — 23/23 passed, including both v3/v4 runtime conversion coverage and the new output inference test.
  • ./scripts/build — CJS/ESM builds and declaration generation passed with 0 errors.
  • DENO_DIR=/tmp/deno-pr1980-cache ./scripts/lint — Prettier, ESLint, type checking, Are The Types Wrong, publint, and jsr publish --dry-run (including JSR slow-public-type analysis) all passed.
  • Deno 2.9.0: the full client.chat.completions.parse(...) call type-checked against the head with a Zod 4.0.10 consumer mapping.
  • Additional Deno compile checks confirmed the _output-based return type preserves transformed output types for both zod/v3 and zod/v4, in both assignability directions.

I also built and checked the base commit using the same local npm-backed setup. That topology did not reproduce the reported TS2589/OOM, so I could not independently recreate the exact deno.land/JSR module-graph failure; however, the JSR slow-type analysis passes on the proposed declaration, and the change removes the full z3.ZodType | z4.ZodType structural comparison that plausibly causes the reported expansion.

Compatibility assessment: existing Zod v3/v4 schemas continue to satisfy the narrower structural contract; runtime schema detection/conversion and parse behavior are unchanged. The signature is technically widened to other objects exposing _output and parse, but that does not break existing callers, and unsupported non-Zod values would still fail in the unchanged conversion path. I found no breaking type/runtime/API change or unhandled Zod v3/v4 regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openai-deno: Type-checking error for zodResponseFormat with Deno and deno.land imports

2 participants