{"record":{"id":"b589cf56393d91f6","repo":"mastra-ai/mastra","slug":"schedule-not-found","errorCode":null,"errorMessage":"Schedule not found","messagePattern":"Schedule not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/schedules.ts","lineNumber":85,"sourceCode":"async function hydrateScheduleResponse(\n  mastra: Mastra,\n  schedule: AnySchedule,\n): Promise<AgentSchedule | (WorkflowSchedule & { lastRun?: RunSummary })> {\n  if (!schedule.workflowId || !schedule.lastRunId) {\n    return schedule;\n  }\n  const lastRun = await fetchRunSummary(mastra, schedule.workflowId, schedule.lastRunId);\n  return lastRun ? { ...schedule, lastRun } : schedule;\n}\n\n/**\n * Resolve a schedule by id via `mastra.schedules`. Returns 404 for missing\n * rows so handlers surface a clean HTTP error instead of a service error.\n */\nasync function loadSchedule(mastra: Mastra, scheduleId: string): Promise<AnySchedule> {\n  const schedule = await mastra.schedules.get(scheduleId);\n  if (!schedule) {\n    throw new HTTPException(404, { message: 'Schedule not found' });\n  }\n  return schedule;\n}\n\nexport const LIST_SCHEDULES_ROUTE = createRoute({\n  method: 'GET',\n  path: '/schedules',\n  responseType: 'json' as const,\n  queryParamSchema: listSchedulesQuerySchema,\n  responseSchema: listSchedulesResponseSchema,\n  summary: 'List schedules',\n  description:\n    'Returns all schedules — agent schedules and workflow schedules — optionally filtered by agentId, workflowId, or status. Agent schedules can additionally be filtered by threadId, resourceId, or name.',\n  tags: ['Schedules'],\n  requiresAuth: true,\n  handler: async ({ mastra, agentId, workflowId, status, threadId, resourceId, name }) => {\n    const schedulesStore = await mastra.getStorage()?.getStore('schedules');\n    if (!schedulesStore) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/schedules.ts#L67-L103","documentation":"loadSchedule resolves a schedule by id via mastra.schedules.get and throws a clean HTTP 404 'Schedule not found' when no row exists, so GET/UPDATE/DELETE/PAUSE/RESUME/RUN schedule routes surface a proper 404 instead of an internal service error.","triggerScenarios":"Any schedule route taking :scheduleId (GET one, PUT update, DELETE, pause, resume, run) with an id that has no corresponding row in the schedules storage.","commonSituations":"Client kept a schedule id after the schedules table was reset/migrated; typo'd or URL-encoded id mismatch; schedule deleted by another process between listing and acting on it.","solutions":["List schedules (GET /api/schedules) and use an id from the current list.","Verify the schedules storage backend the server reads from is the one your schedule was created in.","Create the schedule again if it was deleted (mastra.schedules.create or the POST route)."],"exampleFix":"// before\nawait client.getSchedule('nightly-job') // table was wiped\n// after\nconst { schedules } = await client.getSchedules()\nconst s = schedules.find(s => s.id === 'nightly-job')\nif (s) await client.getSchedule(s.id)","handlingStrategy":"try-catch","validationCode":"const schedules = await client.getSchedules();\nif (!schedules.some(s => s.id === scheduleId)) {\n  return null; // schedule absent; skip GET/UPDATE/DELETE\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await client.getSchedule(scheduleId);\n} catch (e) {\n  if (isHttpError(e, 404)) return null;\n  throw e;\n}","preventionTips":["Refresh schedule ids from the list endpoint instead of hardcoding them.","Handle 404 in clients that act on schedules picked earlier (TOCTOU).","Verify the server points at the same schedules storage in every environment."],"tags":["http-404","schedules","server"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}