{"record":{"id":"de6218481ab46640","repo":"mastra-ai/mastra","slug":"schedules-missing-target-id","errorCode":"SCHEDULES_MISSING_TARGET_ID","errorMessage":"schedules.create requires `agentId` or `workflowId`.","messagePattern":"schedules\\.create requires `agentId` or `workflowId`\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":400,"severity":"error","filePath":"packages/core/src/schedules/schedules.ts","lineNumber":275,"sourceCode":"    const canonical = canonicalizeScheduleId(trimmed, AGENT_SCHEDULE_PREFIX);\n    if (!canonical || canonical === trimmed) return null;\n    return store.getSchedule(canonical);\n  }\n\n  async create(input: CreateAgentScheduleInput): Promise<AgentSchedule>;\n  async create(input: CreateWorkflowScheduleInput): Promise<WorkflowSchedule>;\n  async create(input: CreateScheduleInput): Promise<AnySchedule> {\n    if ('workflowId' in input && input.workflowId) {\n      return this.#createWorkflowSchedule(input);\n    }\n    return this.#createAgentSchedule(input as CreateAgentScheduleInput);\n  }\n\n  async #createAgentSchedule(input: CreateAgentScheduleInput): Promise<AgentSchedule> {\n    validateCron(input.cron, input.timezone);\n\n    if (!input.agentId) {\n      throw new MastraError({\n        id: 'SCHEDULES_MISSING_TARGET_ID',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        details: { status: 400 },\n        text: 'schedules.create requires `agentId` or `workflowId`.',\n      });\n    }\n\n    if (input.threadId && !input.resourceId) {\n      throw new MastraError({\n        id: 'SCHEDULES_MISSING_RESOURCE_ID',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        details: { status: 400 },\n        text: 'schedules.create requires `resourceId` when `threadId` is set.',\n      });\n    }\n    if (!input.threadId) {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/schedules/schedules.ts#L257-L293","documentation":"`#createAgentSchedule` in packages/core/src/schedules/schedules.ts:275 validates that an agent-targeted schedule names the agent it should run. A schedule must target exactly one execution target, so if `agentId` is absent on an agent-schedule input (and no workflow target was chosen), `SCHEDULES_MISSING_TARGET_ID` is thrown. The message mentions `agentId` or `workflowId` because `create` dispatches between the two target kinds and one of them is required.","triggerScenarios":"Calling `schedules.create({ prompt, cron, ... })` with neither `agentId` nor `workflowId` set — e.g. the input lacks `agentId`, so the create dispatcher routes it to `#createAgentSchedule`, which immediately fails the `if (!input.agentId)` check.","commonSituations":"Omitting the target when scaffolding a schedule from a template; a typo like `agent` instead of `agentId`; dynamically building the create input where the agent id is undefined at runtime; porting workflow schedules to agent schedules (or vice versa) and dropping the id field.","solutions":["Add `agentId` to the create input to target an agent: `schedules.create({ agentId: 'assistant', prompt, cron })`.","Alternatively target a workflow by passing `workflowId` instead of `agentId`.","Check for typos or undefined variables feeding the agentId field before calling create."],"exampleFix":"// before\nawait schedules.create({ prompt: 'Run nightly summary', cron: '0 3 * * *' });\n\n// after\nawait schedules.create({ agentId: 'assistant', prompt: 'Run nightly summary', cron: '0 3 * * *' });","handlingStrategy":"validation","validationCode":"function hasScheduleTarget(input) {\n  return Boolean(input.agentId) || Boolean(input.workflowId);\n}\nif (!hasScheduleTarget(input)) throw new Error('schedules.create requires agentId or workflowId');","typeGuard":"type ScheduleTarget = { agentId: string } | { workflowId: string };\nfunction hasTarget(input: Record<string, unknown>): input is ScheduleTarget & Record<string, unknown> {\n  return typeof input.agentId === 'string' || typeof input.workflowId === 'string';\n}","tryCatchPattern":"try {\n  await schedules.create(input);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'SCHEDULES_MISSING_TARGET_ID') {\n    throw new Error('Add agentId (or workflowId) to the schedule create input');\n  }\n  throw e;\n}","preventionTips":["Always pass exactly one of agentId or workflowId to schedules.create.","Type the create input as a discriminated union so TS enforces a target.","Watch for typos (e.g. 'agent') and undefined runtime values feeding agentId."],"tags":["schedules","validation","user-error","config"],"backgroundTag":"missing-required-field","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}