{"record":{"id":"8974fa212e409e6a","repo":"mastra-ai/mastra","slug":"invalid-createdat","errorCode":null,"errorMessage":"Invalid createdAt","messagePattern":"Invalid createdAt","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/workflows.ts","lineNumber":1616,"sourceCode":"  bodySchema: receiveWorkflowEventBodySchema,\n  responseSchema: receiveWorkflowEventResponseSchema,\n  summary: 'Receive a workflow event from a push-mode broker',\n  description:\n    'Push-mode entry point for workflow events. Brokers (GCP Pub/Sub push, SNS, EventBridge) POST each event here; Mastra processes it through the same pipeline as pull-mode workers.',\n  tags: ['Workflows', 'Worker'],\n  requiresAuth: true,\n  // Broker push endpoint: it advances runtime state rather than editing\n  // definitions, so `workflows:execute` is the more accurate fit. `write` is\n  // kept for back-compat with service principals that already grant it.\n  requiresPermission: ['workflows:write', 'workflows:execute'],\n  handler: (async ({ mastra, event }: ReceiveWorkflowEventHandlerArgs) => {\n    try {\n      // The wire schema carries `createdAt` as a string; coerce to Date here\n      // before handing off to the in-process pipeline, which expects an `Event`.\n      const rawCreatedAt = (event as unknown as { createdAt: unknown }).createdAt;\n      const createdAt = rawCreatedAt instanceof Date ? rawCreatedAt : new Date(rawCreatedAt as string);\n      if (Number.isNaN(createdAt.getTime())) {\n        throw new HTTPException(400, { message: 'Invalid createdAt' });\n      }\n      return await mastra.handleWorkflowEvent({ ...event, createdAt });\n    } catch (error) {\n      return handleError(error, 'Error receiving workflow event');\n    }\n  }) as any,\n});\n","sourceCodeStart":1598,"sourceCodeEnd":1624,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/workflows.ts#L1598-L1624","documentation":"Thrown with HTTP 400 when an incoming workflow event's `createdAt` cannot be parsed into a valid Date. The route coerces the wire-format string timestamp to a Date before handing the event to `mastra.handleWorkflowEvent`; an unparsable value means the payload's timestamp field is malformed.","triggerScenarios":"POSTing a workflow event whose `createdAt` is undefined, an empty string, or a non-ISO string that `new Date(...)` cannot parse; producers emitting epoch numbers or locale-formatted dates.","commonSituations":"Custom producers emitting timestamps without toISOString(); forgetting to set createdAt when forwarding events; time libraries serializing with non-ISO formats.","solutions":["Send `createdAt` as an ISO 8601 string (e.g. new Date().toISOString())","Send a Date-serializable value or omit the field only if your version allows it","Validate the timestamp parses before POSTing the event"],"exampleFix":"// before\nbody: { ...event, createdAt: String(Date.now()) }\n// after\nbody: { ...event, createdAt: new Date().toISOString() }","handlingStrategy":"validation","validationCode":"const d = new Date(event.createdAt); if (Number.isNaN(d.getTime())) throw new Error(`Invalid createdAt: ${event.createdAt}`);","typeGuard":"const isValidDateInput = (v: unknown): v is string | Date => typeof v === 'string' ? !Number.isNaN(new Date(v).getTime()) : v instanceof Date && !Number.isNaN(v.getTime());","tryCatchPattern":"try { await postWorkflowEvent(event); } catch (e) { if (isHttpException(e, 400) && /createdAt/.test(e.message)) console.error('Fix event.createdAt to ISO 8601', event.createdAt); else throw e; }","preventionTips":["Always serialize timestamps with toISOString()","Unit-test event payloads for schema compliance","Avoid locale-specific date formatting in producers"],"tags":["http-400","date-parsing","validation"],"backgroundTag":"invalid-timestamp-format","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}