{"record":{"id":"0e094b3a8c5641d5","repo":"mastra-ai/mastra","slug":"schedules-missing-resource-id-0e094b","errorCode":"SCHEDULES_MISSING_RESOURCE_ID","errorMessage":"schedules.create requires `resourceId` when `threadId` is set.","messagePattern":"schedules\\.create requires `resourceId` when `threadId` is set\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":400,"severity":"error","filePath":"packages/core/src/schedules/schedules.ts","lineNumber":285,"sourceCode":"    }\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) {\n      const offenders: string[] = [];\n      if (input.signalType !== undefined) offenders.push('signalType');\n      if (input.ifActive !== undefined) offenders.push('ifActive');\n      if (input.ifIdle !== undefined) offenders.push('ifIdle');\n      if (input.resourceId !== undefined) offenders.push('resourceId');\n      if (offenders.length > 0) {\n        throw new MastraError({\n          id: 'SCHEDULES_THREADLESS_OPTIONS',\n          domain: ErrorDomain.AGENT,\n          category: ErrorCategory.USER,","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/schedules/schedules.ts#L267-L303","documentation":"Like definition-time validation, the runtime `create` path (`#createAgentSchedule`, packages/core/src/schedules/schedules.ts:285) rejects an agent schedule that sets `threadId` without `resourceId`. A memory thread is always scoped to a resource, so `SCHEDULES_MISSING_RESOURCE_ID` is thrown at create time with HTTP-style status 400 rather than allowing an unresolvable thread reference to be stored.","triggerScenarios":"Calling `schedules.create({ agentId, prompt, cron, threadId: '...' })` with no `resourceId` — the `input.threadId && !input.resourceId` check throws immediately after the target-id and cron checks pass.","commonSituations":"Attaching conversation memory to scheduled agent prompts and copying only the threadId from a previous run; dynamic inputs where resourceId is conditionally undefined; teams adding thread persistence to an existing schedule and forgetting the resource field.","solutions":["Pass `resourceId` alongside `threadId` in the create input.","Drop `threadId` if the schedule does not need a memory thread.","Centralize schedule-creation inputs through a validated factory that enforces threadId ⇒ resourceId."],"exampleFix":"// before\nawait schedules.create({\n  agentId: 'assistant',\n  prompt: 'Summarize the conversation',\n  cron: '0 9 * * *',\n  threadId: 'thread_123',\n});\n\n// after\nawait schedules.create({\n  agentId: 'assistant',\n  prompt: 'Summarize the conversation',\n  cron: '0 9 * * *',\n  threadId: 'thread_123',\n  resourceId: 'user_42',\n});","handlingStrategy":"validation","validationCode":"function canCreateAgentSchedule(input) {\n  return Boolean(input.agentId) && !(input.threadId && !input.resourceId);\n}\nif (!canCreateAgentSchedule(input)) {\n  throw new Error('resourceId is required when threadId is set');\n}","typeGuard":"function hasResourceForThread(input: { threadId?: string; resourceId?: string }):\n  input is typeof input & { resourceId: string } {\n  return !input.threadId || (typeof input.resourceId === 'string' && input.resourceId.length > 0);\n}","tryCatchPattern":"try {\n  await schedules.create(input);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'SCHEDULES_MISSING_RESOURCE_ID') {\n    throw new Error('Provide resourceId alongside threadId for this agent schedule');\n  }\n  throw e;\n}","preventionTips":["Enforce threadId ⇒ resourceId in your schedule-creation factory.","Reuse the same validation for both create-time and definition-time paths.","Capture resourceId in config alongside threadId so they are always set together."],"tags":["schedules","validation","memory","user-error"],"backgroundTag":"missing-required-field","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}