mastra-ai/mastra · error
Invalid notification dispatch time: ${input}
Error message
Invalid notification dispatch time: ${input} What it means
parseNotificationDispatchNow converts an optional string into the dispatch 'now' Date for the notification scheduling workflow. If a string is provided but unparseable by Date, it throws rather than silently using an ambiguous date. Built-in new Date quirks (e.g. partial dates) make explicit validation worthwhile.
Source
Thrown at packages/core/src/notifications/workflow.ts:38
/**
* The dispatcher ticks once a minute, has a single non-suspending step, and is
* never resumed — no code path consumes its snapshot. Opting out of snapshot
* persistence entirely keeps `mastra_workflow_snapshot` from growing by one
* dead row per minute forever (issue #20254).
*/
const NOTIFICATION_DISPATCH_SHOULD_PERSIST_SNAPSHOT = () => false;
export type NotificationDispatchConfig = {
/** Defaults to true. Set false to opt out of automatic scheduled dispatch. */
enabled?: boolean;
cron?: string;
batchSize?: number;
};
export function parseNotificationDispatchNow(input?: string): Date {
const now = input ? new Date(input) : new Date();
if (Number.isNaN(now.getTime())) {
throw new Error(`Invalid notification dispatch time: ${input}`);
}
return now;
}
/**
* Builds the imperative schedule row that drives the notification dispatcher.
* Created lazily by `Mastra.__ensureNotificationDispatchReady()` on the first
* deferred notification, rather than declared on the workflow, so idle apps
* never start the scheduler.
*/
export function buildNotificationDispatchSchedule({
cron = NOTIFICATION_DISPATCH_DEFAULT_CRON,
batchSize = NOTIFICATION_DISPATCH_DEFAULT_BATCH_SIZE,
}: Omit<NotificationDispatchConfig, 'enabled'> = {}): Schedule {
const now = Date.now();
return {
id: NOTIFICATION_DISPATCH_SCHEDULE_ROW_ID,
target: {View on GitHub (pinned to 75dd419e61)
Solutions
- Pass a valid ISO 8601 string (e.g. new Date().toISOString()) or omit the argument to use the current time
- Validate the date string with new Date(v) and Number.isNaN(check.getTime()) before calling
- Sanitize config/env inputs that feed the dispatch time
- Parse user-facing dates with a dedicated parser (e.g. temporal or date-fns parse) before conversion
Example fix
// before
parseNotificationDispatchNow('next tuesday');
// after
const iso = new Date(Date.now() + 7 * 864e5).toISOString();
parseNotificationDispatchNow(iso); Defensive patterns
Strategy: validation
Validate before calling
function toSafeDispatchNow(input?: string): Date {
if (!input) return new Date();
const d = new Date(input);
if (Number.isNaN(d.getTime())) throw new TypeError(`Invalid dispatch time: ${input}`);
return d;
} Type guard
function isValidDateString(v: unknown): v is string {
return typeof v === 'string' && !Number.isNaN(new Date(v).getTime());
} Try / catch
try {
const now = parseNotificationDispatchNow(rawTime);
} catch (e) {
logger.error('Bad dispatch time, falling back to now', { rawTime, e });
const now = new Date();
} Prevention
- Only pass ISO 8601 strings (Date.prototype.toISOString output)
- Validate date config values at startup, not at dispatch time
- Use a date library to parse user-supplied schedule text before conversion
When it happens
Trigger: Calling parseNotificationDispatchNow (or the notification workflow with a dispatch-time override) with a malformed string like 'next tuesday', '2026-13-45', or an ISO string with a bad timezone.
Common situations: Passing user-supplied free-text schedule times instead of ISO 8601; locale-dependent date strings; env/config values with typos (e.g. '20260829T010101Z' missing separators in some engines).
Related errors
- notification-inbox search requires query
- Invalid Subconscious record time: ${value}
- Invalid createdAt
- ClaudeSDKAgent resumeData must include sessionId or continue
- CursorSDKAgent resumeData must include a message.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/1655aac0009ad559.
Report an issue: GitHub.