fix(schema-to-json): handle Zod 4 dates when converting to JSON Schema - #4944
MauryaQbit wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📜 Recent review details🧰 Additional context used📓 Path-based instructions (5)**Public packages** (`packages/*`): Use `build`.📄 CodeRabbit inference engine (AGENTS.md) Files:
Use vitest for all tests in the Trigger.dev repository📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
Use function declarations instead of default exports📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
Use types over interfaces for TypeScript Avoid using enums; prefer string unions or const objects instead📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs Do not use high-cardinality attributes in OTEL metr...📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc) Files:
🧠 Learnings (1)📚 Learning: 2026-06-16T09:19:47.637ZApplied to files:
🔇 Additional comments (3)
WalkthroughThe Zod 4 converter now maps date schemas to JSON Schema strings with the Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change addresses the reported Zod 4 date-conversion failure, and no concrete unresolved merge-blocking risk is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @MauryaQbit, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
| reused: useReferences ? "ref" : "inline", | ||
| // Dates (and other unrepresentable types) throw by default, which fails the | ||
| // whole conversion. Fall back to `any` and handle dates in override instead. | ||
| unrepresentable: "any", |
There was a problem hiding this comment.
🟡 Unsupported types become unconstrained schemas
For unsupported Zod 4 types, unrepresentable now emits {} instead of failing conversion. Published schemas accept arbitrary JSON that the runtime parser rejects.
Learn more
Zod's unrepresentable: "any" converts every unrepresentable node to an unconstrained JSON Schema. The override repairs dates and rejects undefined, but it leaves other unsupported nodes unconstrained. The resulting schema no longer describes the parser used at runtime. Callers publish this result as task payload and prompt-variable schemas in convertSchemasToJsonSchemas and convertPromptSchemasToJsonSchemas.
Example: A field declared as z.bigint() becomes {}. A client can generate or submit a string or number because the published JSON Schema permits it, but z.bigint() rejects that JSON value.
Recommended fix: Keep the date override, but throw for every other unrepresentable Zod type so existing callers omit the inaccurate schema. If Zod requires unrepresentable: "any" for the date override to run, inspect each generated node in override and whitelist only def.type === "date"; reject the remaining unrepresentable definitions explicitly.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #4939
Hit this when a tool had a z.date() field - the whole tools/list call blew up with Date cannot be represented in JSON Schema, so no tools loaded at all. Turns out toJSONSchema throws on dates by default and that error took down the entire conversion.
Changed convertZod4Schema to pass unrepresentable any and map date fields to string/date-time in the existing override, same as what the Zod 3 path already produces. Other unrepresentable types now fall back to {} instead of killing the whole list too.
Added a test for an object with a date field and ran the schema-to-json suite, 22/22 pass. Also ran oxlint on the touched files, clean.