Skip to content

chore: upgrade to zod v4#4039

Draft
carderne wants to merge 6 commits into
mainfrom
chore/zod-4
Draft

chore: upgrade to zod v4#4039
carderne wants to merge 6 commits into
mainfrom
chore/zod-4

Conversation

@carderne

@carderne carderne commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Zod v4 compatibility

Upgrades the monorepo's internal zod version from 3.x to 4.4.3 and widens the peer
dependency on all published packages to "^3.25.0 || ^4.0.0".

For library consumers

No breaking change if you are on zod 3.25+. The peer dependency range is widened, not
narrowed — your existing zod 3.25+ install continues to satisfy it and the library code
is runtime-compatible with both versions. Zod 4.x is now also supported. Bumped as minor
across all affected packages.

Minimum zod 3 version is 3.25.0 (not 3.0.0).

API compatibility

Zod types appear in the public API of @trigger.dev/core and @trigger.dev/redis-worker
(generic constraints like T extends z.ZodTypeAny, exported schema values typed as
z.ZodType<T>, and WorkerCatalog's schema field). These types exist in both zod 3 and
zod 4, so TypeScript consumers on either version should resolve them without errors —
the shapes are structurally compatible across versions.

If you pass your own zod schemas into library APIs (e.g. zodfetch, zodShapeStream,
WorkerCatalog), schemas from zod 3.25+ and zod 4.x are both accepted.

WorkerCatalog uses z.ZodFirstPartySchemaTypes, which is present in zod 4 via a
compatibility alias but marked @deprecated. This is intentional — the type is still
fully functional, and we've left it in place to avoid a breaking API change.

TODO list before merging

  • bump @trigger.dev/platform dep to 1.2.1 when that becomes available

@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4aac7ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@trigger.dev/core Minor
@trigger.dev/sdk Minor
trigger.dev Minor
@trigger.dev/redis-worker Minor
@trigger.dev/schema-to-json Minor
@trigger.dev/build Minor
@trigger.dev/plugins Minor
@trigger.dev/python Minor
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@trigger.dev/rbac Minor
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@trigger.dev/sso Minor
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker Patch
@internal/dashboard-agent Patch
@internal/sdk-compat-tests Patch
@trigger.dev/react-hooks Minor
@trigger.dev/rsc Minor
@trigger.dev/database Minor
@trigger.dev/otlp-importer Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Package manifests and overrides update Zod versions, peer ranges, and dependency placement across the workspace. Core and webapp schemas switch to explicit string-keyed records and adjust a few field shapes. Webapp routes and components migrate to parseWithZod, getFormProps, and .errors-based rendering. Several helpers and runtime paths add casts or updated type aliases to match Zod v4 APIs.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the Zod v4 upgrade, but it does not follow the required template or include the checklist, testing, changelog, or screenshots sections. Add the template sections: Closes #, checklist items, Testing, Changelog, and Screenshots, and fill in the required details.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately states the main change: upgrading the monorepo to Zod v4.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/zod-4

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@4aac7ae

trigger.dev

npm i https://pkg.pr.new/trigger.dev@4aac7ae

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@4aac7ae

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@4aac7ae

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@4aac7ae

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@4aac7ae

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@4aac7ae

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@4aac7ae

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@4aac7ae

commit: 4aac7ae

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":500,"request":{"method":"PATCH","url":"https://api.github.com/repos/triggerdotdev/trigger.dev/issues/comments/4799766654","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- review_stack_entry_start -->\n\n[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/triggerdotdev/trigger.dev/pull/4039?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)\n\n<!-- review_stack_entry_end -->\n<!-- This is an auto-generated comment: review in progress by coderabbit.ai -->\n\n> [!NOTE]\n> Currently processing new changes in this PR. This may take a few minutes, please wait...\n> \n> <details>\n> <summary>⚙️ Run configuration</summary>\n> \n> **Configuration used**: Repository UI\n> \n> **Review profile**: CHILL\n> \n> **Plan**: Pro\n> \n> **Run ID**: `8fad56a2-0f47-4f9f-b9bc-59ba132bf08d`\n> \n> </details>\n> \n> <details>\n> <summary>📥 Commits</summary>\n> \n> Reviewing files that changed from the base of the PR and between d565949205ab1fefbc2cbf8bf5ab826207f3192e and 3d5ccd22d7736c6a1545298e1da9626a721e55ac.\n> \n> </details>\n> \n> <details>\n> <summary>⛔ Files ignored due to path filters (1)</summary>\n> \n> * `pnpm-lock.yaml` is excluded by `!**/pnpm-lock.yaml`\n> \n> </details>\n> \n> <details>\n> <summary>📒 Files selected for processing (82)</summary>\n> \n> * `.changeset/zod-4-support.md`\n> * `apps/supervisor/package.json`\n> * `apps/webapp/app/components/metrics/QueryWidget.tsx`\n> * `apps/webapp/app/models/orgIntegration.server.ts`\n> * `apps/webapp/app/models/vercelIntegration.server.ts`\n> * `apps/webapp/app/models/vercelSdkRecovery.server.ts`\n> * `apps/webapp/app/presenters/v3/MetricDashboardPresenter.server.ts`\n> * `apps/webapp/app/presenters/v3/SpanPresenter.server.ts`\n> * `apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables.new/route.tsx`\n> * `apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query/route.tsx`\n> * `apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.billing-alerts/route.tsx`\n> * `apps/webapp/app/routes/account._index/route.tsx`\n> * `apps/webapp/app/routes/account.tokens/route.tsx`\n> * `apps/webapp/app/routes/admin.feature-flags.tsx`\n> * `apps/webapp/app/routes/api.v1.plain.customer-cards.ts`\n> * `apps/webapp/app/routes/api.v1.prompts.$slug.ts`\n> * `apps/webapp/app/routes/api.v1.query.ts`\n> * `apps/webapp/app/routes/api.v1.schedules.ts`\n> * `apps/webapp/app/routes/resources.feedback.ts`\n> * `apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.schedules.new/route.tsx`\n> * `apps/webapp/app/services/apiAuth.server.ts`\n> * `apps/webapp/app/services/authorizationRateLimitMiddleware.server.ts`\n> * `apps/webapp/app/services/queryService.server.ts`\n> * `apps/webapp/app/services/routeBuilders/apiBuilder.server.ts`\n> * `apps/webapp/app/services/routeBuilders/dashboardBuilder.server.ts`\n> * `apps/webapp/app/services/routeBuilders/dashboardBuilder.ts`\n> * `apps/webapp/app/utils/json.ts`\n> * `apps/webapp/app/utils/timeGranularity.ts`\n> * `apps/webapp/app/v3/featureFlags.server.ts`\n> * `apps/webapp/app/v3/featureFlags.ts`\n> * `apps/webapp/app/v3/marqs/types.ts`\n> * `apps/webapp/app/v3/schedules.ts`\n> * `apps/webapp/app/v3/services/aiRunFilterService.server.ts`\n> * `apps/webapp/app/v3/services/replayTaskRun.server.ts`\n> * `apps/webapp/app/v3/utils/zodPubSub.server.ts`\n> * `apps/webapp/app/v3/vercel/vercelProjectIntegrationSchema.ts`\n> * `apps/webapp/package.json`\n> * `internal-packages/clickhouse/package.json`\n> * `internal-packages/clickhouse/src/client/tsql.ts`\n> * `internal-packages/clickhouse/src/tsqlFunctions.test.ts`\n> * `internal-packages/compute/package.json`\n> * `internal-packages/compute/src/types.ts`\n> * `internal-packages/emails/package.json`\n> * `internal-packages/run-engine/package.json`\n> * `internal-packages/run-engine/src/batch-queue/types.ts`\n> * `internal-packages/schedule-engine/package.json`\n> * `internal-packages/tsql/package.json`\n> * `internal-packages/zod-worker/package.json`\n> * `internal-packages/zod-worker/src/index.ts`\n> * `package.json`\n> * `packages/cli-v3/package.json`\n> * `packages/cli-v3/src/cli/common.ts`\n> * `packages/cli-v3/src/commands/analyze.ts`\n> * `packages/cli-v3/src/mcp/tools/agentChat.ts`\n> * `packages/cli-v3/src/utilities/configFiles.ts`\n> * `packages/core/package.json`\n> * `packages/core/src/schemas/eventFilter.ts`\n> * `packages/core/src/schemas/json.ts`\n> * `packages/core/src/v3/apiClient/index.ts`\n> * `packages/core/src/v3/runEngineWorker/supervisor/schemas.ts`\n> * `packages/core/src/v3/schemas/api.ts`\n> * `packages/core/src/v3/schemas/build.ts`\n> * `packages/core/src/v3/schemas/common.ts`\n> * `packages/core/src/v3/schemas/eventFilter.ts`\n> * `packages/core/src/v3/schemas/messages.ts`\n> * `packages/core/src/v3/schemas/openTelemetry.ts`\n> * `packages/core/src/v3/schemas/query.ts`\n> * `packages/core/src/v3/schemas/resources.ts`\n> * `packages/core/src/v3/schemas/runEngine.ts`\n> * `packages/core/src/v3/schemas/schemas.ts`\n> * `packages/core/src/v3/serverOnly/httpServer.ts`\n> * `packages/core/src/v3/types/tools.ts`\n> * `packages/core/src/v3/zodIpc.ts`\n> * `packages/core/src/v3/zodMessageHandler.ts`\n> * `packages/core/src/v3/zodNamespace.ts`\n> * `packages/core/src/v3/zodSocket.ts`\n> * `packages/redis-worker/package.json`\n> * `packages/redis-worker/src/mollifier/schemas.ts`\n> * `packages/redis-worker/src/queue.ts`\n> * `packages/redis-worker/src/worker.ts`\n> * `packages/schema-to-json/package.json`\n> * `packages/trigger-sdk/package.json`\n> \n> </details>\n> \n> \n\n<!-- end of auto-generated comment: review in progress by coderabbit.ai -->\n\n<!-- finishing_touch_checkbox_start -->\n\n<details>\n<summary>✨ Finishing Touches</summary>\n\n<details>\n<summary>📝 Generate docstrings</summary>\n\n- [ ] <!-- {\"checkboxId\": \"7962f53c-55bc-4827-bfbf-6a18da830691\"} --> Create stacked PR\n- [ ] <!-- {\"checkboxId\": \"3e1879ae-f29b-4d0d-8e06-d12b7ba33d98\"} --> Commit on current branch\n\n</details>\n<details>\n<summary>🧪 Generate unit tests (beta)</summary>\n\n- [ ] <!-- {\"checkboxId\": \"f47ac10b-58cc-4372-a567-0e02b2c3d479\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Create PR with unit tests\n- [ ] <!-- {\"checkboxId\": \"6ba7b810-9dad-11d1-80b4-00c04fd430c8\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Commit unit tests in branch `chore/zod-4`\n\n</details>\n\n</details>\n\n<!-- finishing_touch_checkbox_end -->\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=triggerdotdev/trigger.dev&utm_content=4039)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n\n<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>\n\n<!-- tips_end -->"},"request":{"retryCount":3,"signal":{},"retries":3,"retryAfter":16}}}

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@carderne carderne marked this pull request as ready for review June 25, 2026 18:37
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@carderne carderne marked this pull request as draft June 29, 2026 14:35
@carderne carderne force-pushed the chore/zod-4 branch 2 times, most recently from ff82d6c to c60f28b Compare June 30, 2026 15:49
@carderne carderne marked this pull request as ready for review July 3, 2026 15:28
devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 2 new potential issues.

Open in Devin Review

Comment on lines +99 to 123
export function getFlagControlType(schema: z.ZodType): FlagControlType {
// zod v4: schema.def.type is a lowercase tag ("boolean"/"enum"/"number"/...).
const def = schema.def as {
type: string;
checks?: Array<{ _zod?: { def?: { check?: string; value?: number } } }>;
};

if (typeName === "ZodBoolean") {
if (def.type === "boolean") {
return { type: "boolean" };
}

if (typeName === "ZodEnum") {
return { type: "enum", options: schema._def.values as string[] };
if (def.type === "enum") {
return { type: "enum", options: (schema as z.ZodEnum).options as string[] };
}

// z.coerce.number() reports as ZodNumber; pull min/max out of its checks
// so the UI can render a constrained number input instead of free text.
if (typeName === "ZodNumber") {
const checks = (schema._def.checks ?? []) as Array<{ kind: string; value?: number }>;
const min = checks.find((c) => c.kind === "min")?.value;
const max = checks.find((c) => c.kind === "max")?.value;
// z.coerce.number() reports as "number"; pull min/max out of its v4 checks
// (each check carries `_zod.def.{check,value}`) so the UI can render a
// constrained number input instead of free text.
if (def.type === "number") {
const checks = def.checks ?? [];
const min = checks.find((c) => c._zod?.def?.check === "greater_than")?._zod?.def?.value;
const max = checks.find((c) => c._zod?.def?.check === "less_than")?._zod?.def?.value;
return { type: "number", min, max };
}

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.

🟡 Admin feature flag toggles render as text inputs instead of checkboxes for most flags

Coerced boolean and number flags are misidentified as strings (getFlagControlType at apps/webapp/app/v3/featureFlags.ts:106) because z.coerce.boolean() in zod v4 wraps the schema in a pipe, so def.type is "pipe" not "boolean", causing the function to fall through to the "string" default.

Impact: The admin feature-flags page shows plain text fields instead of boolean toggles for 9 flags and instead of number inputs for 2 flags.

Mechanism: zod v4 coerce creates a pipe schema

In zod v3, z.coerce.boolean() produced a schema with _def.typeName === "ZodBoolean". In zod v4, z.coerce.boolean() creates a pipe schema (def.type === "pipe") that first coerces the input through Boolean() then validates as boolean. The same applies to z.coerce.number().

The FeatureFlagCatalog at apps/webapp/app/v3/featureFlags.ts:25-35 defines 9 flags with z.coerce.boolean() (e.g., hasQueryAccess, mollifierEnabled) and 2 flags with z.coerce.number() (e.g., computeMigrationFreePercentage). All of these will have def.type === "pipe" in zod v4, so the checks at lines 106 and 117 will never match, and the function returns { type: "string" } for all of them.

The function needs to unwrap pipe schemas to find the inner type, or check for the coerce wrapper specifically.

(Refers to lines 99-124)

Prompt for agents
The getFlagControlType function in apps/webapp/app/v3/featureFlags.ts needs to handle zod v4 pipe schemas (created by z.coerce.boolean(), z.coerce.number(), etc.). In zod v4, coerced schemas wrap the inner schema in a pipe, so def.type is 'pipe' rather than the inner type like 'boolean' or 'number'. The function should unwrap pipe schemas to find the inner type. For example, check if def.type is 'pipe' and if so, look at the destination/output schema's def.type instead. Similarly, the checks array for min/max on number schemas may be structured differently in zod v4 pipes — the checks live on the inner number schema, not the outer pipe.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

navigation.formAction === "/resources/feedback" &&
navigation.state === "loading" &&
Object.keys(form.allErrors).length === 0
(form.errors === undefined || form.errors.length === 0)

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.

🚩 Feedback dialog close condition changed from allErrors to form.errors

At apps/webapp/app/components/Feedback.tsx:56, the condition changed from Object.keys(form.allErrors).length === 0 to (form.errors === undefined || form.errors.length === 0). In conform v1 (used with @conform-to/zod), form.allErrors was an object mapping field names to error arrays. In the newer conform API used with @conform-to/zod/v4, form.errors is a flat string array of form-level errors. This means the new check only looks at form-level errors, not field-level errors. If a field has a validation error but the form itself doesn't, the dialog would close prematurely. However, this may be intentional — the dialog submits to a server action, and field errors would prevent successful submission, so the navigation.state === "loading" check (indicating the server accepted the form) may be sufficient to gate the close.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@carderne carderne marked this pull request as draft July 3, 2026 16:20
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.

1 participant