{"record":{"id":"34403e66fd920ee0","repo":"mastra-ai/mastra","slug":"workflow-run-not-found","errorCode":null,"errorMessage":"Workflow run not found","messagePattern":"Workflow run not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/workflows.ts","lineNumber":455,"sourceCode":"        throw new HTTPException(400, { message: 'Run ID is required' });\n      }\n\n      const { workflow } = await listWorkflowsFromSystem({ mastra, workflowId });\n\n      if (!workflow) {\n        throw new HTTPException(404, { message: 'Workflow not found' });\n      }\n\n      // Parse fields parameter (comma-separated string)\n      const fieldList = fields ? (fields.split(',').map((f: string) => f.trim()) as WorkflowStateField[]) : undefined;\n\n      const run = await workflow.getWorkflowRunById(runId, {\n        withNestedWorkflows: withNestedWorkflows !== 'false', // Default to true unless explicitly 'false'\n        fields: fieldList,\n      });\n\n      if (!run) {\n        throw new HTTPException(404, { message: 'Workflow run not found' });\n      }\n\n      await validateRunOwnership(run, effectiveResourceId);\n\n      return run;\n    } catch (error) {\n      return handleError(error, 'Error getting workflow run');\n    }\n  },\n});\n\nexport const DELETE_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({\n  method: 'DELETE',\n  path: '/workflows/:workflowId/runs/:runId',\n  responseType: 'json',\n  pathParamSchema: workflowRunPathParams,\n  responseSchema: workflowControlResponseSchema,\n  summary: 'Delete workflow run by ID',","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/workflows.ts#L437-L473","documentation":"This 404 is thrown when the workflow exists but `workflow.getWorkflowRunById(runId, { withNestedWorkflows, fields })` returns null/undefined because no persisted run matches the `runId`. The handler first confirms the workflow, then looks up the run from storage, and throws this if the storage lookup misses. It also fires if a nested-workflow run is requested with `withNestedWorkflows=false` (default) and the run is not directly addressable.","triggerScenarios":"GET /api/workflows/{workflowId}/runs/{runId} with a runId never created, a run already deleted, a run belonging to a different workflowId, or a nested-workflow child runId fetched with withNestedWorkflows=false.","commonSituations":"Client constructing runIds instead of using the value returned by createRun; storage backend switched (e.g. from default in-memory to Postgres) so old run IDs are gone; run purged by retention/cleanup; typos from copying run ID across environments.","solutions":["Use the exact runId returned from workflow.createRun()/the start call; never fabricate one.","Confirm the runId belongs to this workflowId (runs are keyed per workflow).","Check the server's storage is the same backend the run was written to; re-run against the original environment.","If fetching a nested-workflow run, pass withNestedWorkflows=true (omit the param, since it defaults to true) so child runs resolve."],"exampleFix":"// before\nconst res = await fetch(`/api/workflows/myWorkflow/runs/${someGeneratedId}`);\n// after\nconst { runId } = await client.getWorkflow('myWorkflow').createRun({});\nconst run = await client.getWorkflowRun('myWorkflow', runId);","handlingStrategy":"try-catch","validationCode":"if (!runId || typeof runId !== 'string') {\n  throw new Error('runId must be the id returned by createRun()');\n}\nif (!runIdCache.has(`${workflowId}:${runId}`) && !allowMiss) return null;","typeGuard":"function hasRunId(v: { runId?: string } | undefined): v is { runId: string } {\n  return typeof v?.runId === 'string' && v.runId.length > 0;\n}","tryCatchPattern":"try {\n  return await client.getWorkflowRun(workflowId, runId);\n} catch (e) {\n  if (e instanceof MastraClientError && e.status === 404) {\n    return null; // run never created or already deleted\n  }\n  throw e;\n}","preventionTips":["Always store the runId returned by createRun()/start() instead of generating one.","Persist runId→workflowId mapping so you never look a run up under the wrong workflow.","Keep the same storage backend across restarts; don't switch storage without migration.","Pass withNestedWorkflows=true when fetching nested/child run IDs."],"tags":["http-404","workflow-run","storage","rest-api"],"backgroundTag":"run-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}