{"record":{"id":"ddabadb56bf70c76","repo":"mastra-ai/mastra","slug":"snapshot-not-found-for-runid-runid","errorCode":null,"errorMessage":"Snapshot not found for runId ${runId}","messagePattern":"Snapshot not found for runId (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/workflows/inmemory.ts","lineNumber":224,"sourceCode":"\n    if (!run) {\n      return {};\n    }\n\n    let snapshot: WorkflowRunState;\n    if (!run.snapshot) {\n      snapshot = createEmptyWorkflowSnapshot(run.run_id);\n\n      this.db.workflows.set(key, {\n        ...run,\n        snapshot,\n      });\n    } else {\n      snapshot = typeof run.snapshot === 'string' ? JSON.parse(run.snapshot) : run.snapshot;\n    }\n\n    if (!snapshot || !snapshot?.context) {\n      throw new Error(`Snapshot not found for runId ${runId}`);\n    }\n\n    const context = mergeWorkflowStepResult({ snapshot, stepId, result, requestContext });\n\n    this.db.workflows.set(key, {\n      ...run,\n      snapshot: snapshot,\n    });\n\n    return cloneRunData(context);\n  }\n\n  async updateWorkflowState({\n    workflowName,\n    runId,\n    opts,\n  }: {\n    workflowName: string;","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/workflows/inmemory.ts#L206-L242","documentation":"`updateWorkflowResults` merges a step result into the run's stored snapshot. If the run record exists but has no snapshot (or the snapshot has no `context`), it throws 'Snapshot not found for runId'. The snapshot is the workflow execution state that step results are merged into, so updating results without one is impossible.","triggerScenarios":"Calling `updateWorkflowResults(runId, stepId, result, ...)` for a runId whose stored workflow run has no snapshot persisted (never created, cleared, or saved without a `context` object).","commonSituations":"Writing step results before the run's initial snapshot was persisted, pointing at the wrong runId (typo or stale reference), a run record created by an older version of the library that stored snapshots differently, or external code wiping the snapshot column.","solutions":["Ensure the workflow run was started and its snapshot persisted (via the run-creation path) before updating results.","Verify the runId passed matches an existing run (fetch the run first and check `snapshot`).","Re-run the workflow if its snapshot was lost; snapshots are not reconstructible after the fact.","If migrating storage, confirm snapshots were carried over in the same format (object or JSON string with `context`)."],"exampleFix":"// before\nawait storage.updateWorkflowResults(runId, 'step-1', { output: 42 }); // run may not have snapshot\n// after\nconst run = await storage.getWorkflowRunById({ runId });\nif (run?.snapshot) {\n  await storage.updateWorkflowResults(runId, 'step-1', { output: 42 });\n}","handlingStrategy":"try-catch","validationCode":"async function canUpdateResults(storage, runId: string) {\n  const run = await storage.getWorkflowRunById({ runId });\n  if (!run) return false;\n  const snap = typeof run.snapshot === 'string' ? JSON.parse(run.snapshot) : run.snapshot;\n  return Boolean(snap?.context);\n}","typeGuard":"function hasSnapshotContext(run: { snapshot?: unknown } | undefined): boolean {\n  if (!run?.snapshot) return false;\n  const snap = typeof run.snapshot === 'string' ? safeParse(run.snapshot) : run.snapshot;\n  return Boolean((snap as any)?.context);\n}","tryCatchPattern":"try {\n  await storage.updateWorkflowResults(runId, stepId, result, requestContext);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Snapshot not found for runId')) {\n    logger.warn(`No snapshot for run ${runId}; skipping step-result update`);\n    return;\n  }\n  throw err;\n}","preventionTips":["Only update step results for runs created and snapshotted through the workflow engine.","Verify runId existence and snapshot presence before direct storage updates.","Use persistent storage if runIds must survive process restarts."],"tags":["workflow","missing-state","snapshot"],"backgroundTag":"workflow-snapshot-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}