{"record":{"id":"138f2b9054e0c358","repo":"mastra-ai/mastra","slug":"schedules-id-exists","errorCode":"SCHEDULES_ID_EXISTS","errorMessage":"schedules.create: a schedule with id \"${id}\" already exists. Use update() to modify it or choose a different id.","messagePattern":"schedules\\.create: a schedule with id \"(.+?)\" already exists\\. Use update\\(\\) to modify it or choose a different id\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":409,"severity":"error","filePath":"packages/core/src/schedules/schedules.ts","lineNumber":401,"sourceCode":"      target,\n      cron: input.cron,\n      timezone: input.timezone,\n      status: input.status ?? 'active',\n      nextFireAt,\n      createdAt: now,\n      updatedAt: now,\n      ...(input.metadata ? { metadata: input.metadata } : {}),\n    };\n\n    const created = await store.createSchedule(schedule);\n    return toWorkflowSchedule(created)!;\n  }\n\n  async #assertIdAvailable(store: SchedulesStorage, id: string, callerProvided: boolean): Promise<void> {\n    if (!callerProvided) return;\n    const existing = await store.getSchedule(id);\n    if (existing) {\n      throw new MastraError({\n        id: 'SCHEDULES_ID_EXISTS',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        details: { status: 409 },\n        text: `schedules.create: a schedule with id \"${id}\" already exists. Use update() to modify it or choose a different id.`,\n      });\n    }\n  }\n\n  async get(id: string): Promise<AnySchedule | null> {\n    const schedule = await this.#load(id);\n    if (!schedule) return null;\n    return toScheduleView(schedule);\n  }\n\n  async list(filter?: ListSchedulesFilter): Promise<AnySchedule[]> {\n    const store = await this.#getStore();\n    const schedules = await store.listSchedules({","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/schedules/schedules.ts#L383-L419","documentation":"create() was called with a caller-supplied id that already exists in the schedules storage. The library treats create as create-only for explicit ids and throws a 409-class error directing you to update() instead.","triggerScenarios":"Calling schedules.create() (or #createAgentSchedule/#createWorkflowSchedule) with an explicit id for which store.getSchedule(id) already returns a schedule.","commonSituations":"Re-running bootstrap/seed scripts that create schedules on every startup; deploying two instances that both create the same schedule id; typo where a schedule was created earlier and now is re-created with the same name.","solutions":["Call schedules.update(id, patch) instead of create() when the schedule may already exist.","Check existence first with getSchedule(id) (or a get/list call) and branch between create and update.","Delete the existing schedule if recreation is intended, or choose a unique id."],"exampleFix":"// before\nawait schedules.create({ id: 'daily-report', cron: '0 8 * * *' });\n// after\nconst existing = await schedules.get('daily-report');\nif (existing) {\n  await schedules.update('daily-report', { cron: '0 8 * * *' });\n} else {\n  await schedules.create({ id: 'daily-report', cron: '0 8 * * *' });\n}","handlingStrategy":"fallback","validationCode":"const existing = await schedules.get('daily-report');\nif (existing) throw new Error('exists — use update()');","typeGuard":null,"tryCatchPattern":"try {\n  await schedules.create({ id, ...config });\n} catch (e) {\n  if (String((e as Error).message).includes('already exists')) {\n    await schedules.update(id, config);\n  } else throw e;\n}","preventionTips":["Make seed/bootstrap scripts idempotent with get-then-create-or-update.","Use upsert-style helpers instead of raw create in deploy pipelines.","Namespace schedule ids per environment to avoid cross-env collisions."],"tags":["schedules","conflict","duplicate-id"],"backgroundTag":"duplicate-key-conflict","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}