Skip to content

Issue with Zod 4.4.x -> Invalid input: expected nonoptional, received undefined #1901

@ziyak97

Description

@ziyak97

Sharing what i believe could be the cause of this issue -

const EventResultResolveWireSchema = z.object({
  event: EventSchema.optional(),
  run: WorkflowRunSchema.optional(),
  step: StepWireSchema.optional(),
  hook: HookSchema.optional(),
  events: z.array(EventSchema).optional(),
});
For some events, including run_started, Workflow validates the response from Vercel using WorkflowRunSchema. That schema is here:

export const WorkflowRunSchema = z.discriminatedUnion('status', [
  WorkflowRunBaseSchema.extend({
    status: z.enum(['pending', 'running']),
    output: z.undefined(),
    error: z.undefined(),
    completedAt: z.undefined(),
  }),
  ...
]);
That means: when a run is pending or running, Workflow expects output, error, and completedAt to be undefined.

But with your top-level zod@4.4.2, Zod is treating these missing fields as required/nonoptional, so when Vercel returns a running run like:

{
  status: "running",
  // no output
  // no error
  // no completedAt
}
Zod throws:

run.output: expected nonoptional, received undefined
run.error: expected nonoptional, received undefined
run.completedAt: expected nonoptional, received undefined

I have added this comment on a Zod issue as well -> colinhacks/zod#5917 (comment)

Using workflow 5.0.0-beta-4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions