{"record":{"id":"8bf5b1b5a3c261fe","repo":"mastra-ai/mastra","slug":"durable-agent-recover-invalid-snapshot","errorCode":"DURABLE_AGENT_RECOVER_INVALID_SNAPSHOT","errorMessage":"DurableAgent \"${this.name}\" recover(${runId}): persisted snapshot does not contain a durable-agent workflow input.","messagePattern":"DurableAgent \"(.+?)\" recover\\((.+?)\\): persisted snapshot does not contain a durable-agent workflow input\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/durable/durable-agent.ts","lineNumber":723,"sourceCode":"    if (!persisted) {\n      throw new MastraError({\n        id: 'DURABLE_AGENT_RECOVER_SNAPSHOT_NOT_FOUND',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text:\n          `DurableAgent \"${this.name}\" recover(${runId}): no persisted workflow snapshot found. ` +\n          `The run may have already completed or been cleaned up.`,\n        details: { agentName: this.name, runId },\n      });\n    }\n\n    const snapshot =\n      typeof persisted.snapshot === 'string'\n        ? (JSON.parse(persisted.snapshot) as WorkflowRunState)\n        : persisted.snapshot;\n    const workflowInput = snapshot?.context?.input as DurableAgenticWorkflowInput | undefined;\n    if (!workflowInput || workflowInput.__workflowKind !== 'durable-agent') {\n      throw new MastraError({\n        id: 'DURABLE_AGENT_RECOVER_INVALID_SNAPSHOT',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.SYSTEM,\n        text: `DurableAgent \"${this.name}\" recover(${runId}): persisted snapshot does not contain a durable-agent workflow input.`,\n        details: { agentName: this.name, runId },\n      });\n    }\n\n    if (workflowInput.agentId !== this.id) {\n      throw new MastraError({\n        id: 'DURABLE_AGENT_RECOVER_AGENT_MISMATCH',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: `DurableAgent \"${this.name}\" recover(${runId}): persisted run belongs to agent \"${workflowInput.agentId}\", not \"${this.id}\".`,\n        details: { agentName: this.name, runId, ownerAgentId: workflowInput.agentId },\n      });\n    }\n","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/durable/durable-agent.ts#L705-L741","documentation":"After loading a persisted run, #loadRecoverableWorkflowInput parses the snapshot and reads snapshot.context.input, requiring it to exist and carry __workflowKind === 'durable-agent'. If the snapshot lacks a durable-agent workflow input, the stored run is not a durable-agent run (or is corrupt), and recover() throws this SYSTEM-category error.","triggerScenarios":"Calling agent.recover(runId) on a run whose snapshot (a) has no context.input, (b) has input without __workflowKind 'durable-agent' — e.g. the runId belongs to a plain workflow run, or the snapshot was written by an older/incompatible version or corrupted (truncated JSON).","commonSituations":"Passing a regular workflow runId (or another agent's run kind) to recover(); upgrading Mastra where snapshot schema changed and old runs no longer match; corrupted rows from a failed write or manual storage migration.","solutions":["Verify the runId refers to a durable-agent run (created by this agent's AGENTIC_LOOP), not a plain workflow run.","Inspect the persisted snapshot: confirm snapshot.context.input.__workflowKind === 'durable-agent'.","If the run predates the current schema (version mismatch), re-run the task instead of recovering the old-format run.","If the snapshot JSON is corrupt, restore from a storage backup or discard the run."],"exampleFix":"// before\nawait agent.recover(workflowRunId); // actually a plain workflow run\n// after\nconst run = await workflowsStore.getWorkflowRunById({ runId: workflowRunId, workflowName: DurableStepIds.AGENTIC_LOOP });\nconst snap = typeof run?.snapshot === 'string' ? JSON.parse(run.snapshot) : run?.snapshot;\nif (snap?.context?.input?.__workflowKind === 'durable-agent') {\n  await agent.recover(workflowRunId);\n}","handlingStrategy":"type-guard","validationCode":"const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: DurableStepIds.AGENTIC_LOOP });\nconst snap = typeof run?.snapshot === 'string' ? JSON.parse(run.snapshot) : run?.snapshot;\nconst input = snap?.context?.input;\nif (input?.__workflowKind !== 'durable-agent') throw new Error(`Run ${runId} is not a durable-agent run.`);","typeGuard":"function isDurableAgentSnapshot(snap: unknown): boolean {\n  const input = (snap as any)?.context?.input;\n  return !!input && input.__workflowKind === 'durable-agent';\n}","tryCatchPattern":"try {\n  await agent.recover(runId);\n} catch (e) {\n  if (String(e?.id) === 'DURABLE_AGENT_RECOVER_INVALID_SNAPSHOT') {\n    // old-schema or non-durable run: re-run the task instead of recovering\n    await restartOriginalTask(runId);\n  } else throw e;\n}","preventionTips":["Only pass runIds produced by the durable-agent AGENTIC_LOOP workflow to recover().","After Mastra upgrades, validate old snapshots against the current schema before recovering.","Guard against corrupted snapshots with JSON parse + shape checks before recovery."],"tags":["durable-agent","recovery","snapshot","schema-mismatch","data-corruption"],"backgroundTag":"workflow-snapshot-invalid","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}