{"record":{"id":"2d6f60086d70c629","repo":"mastra-ai/mastra","slug":"durable-agent-resume-agent-mismatch","errorCode":"DURABLE_AGENT_RESUME_AGENT_MISMATCH","errorMessage":"DurableAgent \"${this.name}\" resume(${runId}): persisted run belongs to agent \"${workflowInput.agentId}\", not \"${this.id}\".","messagePattern":"DurableAgent \"(.+?)\" resume\\((.+?)\\): persisted run belongs to agent \"(.+?)\", not \"(.+?)\"\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/durable/durable-agent.ts","lineNumber":1963,"sourceCode":"      const snapshot =\n        typeof persisted.snapshot === 'string'\n          ? (JSON.parse(persisted.snapshot) as WorkflowRunState)\n          : persisted.snapshot;\n      if (snapshot?.status !== 'suspended') {\n        throw new Error('This workflow run was not suspended');\n      }\n      const workflowInput = snapshot?.context?.input as DurableAgenticWorkflowInput | undefined;\n      if (!workflowInput || workflowInput.__workflowKind !== 'durable-agent') {\n        throw new MastraError({\n          id: 'DURABLE_AGENT_RESUME_INVALID_SNAPSHOT',\n          domain: ErrorDomain.AGENT,\n          category: ErrorCategory.SYSTEM,\n          text: `DurableAgent \"${this.name}\" resume(${runId}): persisted snapshot does not contain a durable-agent workflow input.`,\n          details: { agentName: this.name, runId },\n        });\n      }\n      if (workflowInput.agentId !== this.id) {\n        throw new MastraError({\n          id: 'DURABLE_AGENT_RESUME_AGENT_MISMATCH',\n          domain: ErrorDomain.AGENT,\n          category: ErrorCategory.USER,\n          text: `DurableAgent \"${this.name}\" resume(${runId}): persisted run belongs to agent \"${workflowInput.agentId}\", not \"${this.id}\".`,\n          details: { agentName: this.name, runId, ownerAgentId: workflowInput.agentId },\n        });\n      }\n\n      const messageListMemoryInfo = (\n        workflowInput.messageListState as { memoryInfo?: { threadId?: string; resourceId?: string } } | undefined\n      )?.memoryInfo;\n      const threadId = workflowInput.state?.threadId ?? messageListMemoryInfo?.threadId;\n      const resourceId = workflowInput.state?.resourceId ?? messageListMemoryInfo?.resourceId;\n      const snapshotRequestContext = workflowInput.requestContextEntries\n        ? new RequestContext<unknown>(Object.entries(workflowInput.requestContextEntries))\n        : undefined;\n      const memory = threadId\n        ? {","sourceCodeStart":1945,"sourceCodeEnd":1981,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/durable/durable-agent.ts#L1945-L1981","documentation":"The persisted durable run's workflow input records which agent (agentId) started it. During resume, if workflowInput.agentId differs from this agent's id, the framework refuses to let a different DurableAgent take over the run, throwing MastraError DURABLE_AGENT_RESUME_AGENT_MISMATCH (category USER).","triggerScenarios":"Calling agentB.resume(runId) where runId was created by agentA; recreating an agent instance with a changed id/name but reusing old persisted runIds; pointing a staging agent at a production storage database.","commonSituations":"Renaming an agent's id during a refactor and then resuming historical runs; multiple agent instances in one Mastra instance and passing the wrong one; one service accidentally resuming runs owned by another service's agent.","solutions":["Call resume on the same DurableAgent instance (matching id) that started the run.","Look up the owning agent from the error details (ownerAgentId) and use that agent for the resume call.","If the agent id had to change, treat old runs as orphans: finish or abandon them under the old id.","Keep storage backends separate per environment/agent to avoid cross-ownership lookups."],"exampleFix":"// before\nawait orderAgent.resume(runId, data); // run owned by supportAgent\n// after (details: { ownerAgentId: 'supportAgent' })\nconst owner = mastra.getAgent('supportAgent') as DurableAgent;\nawait owner.resume(runId, data);","handlingStrategy":"validation","validationCode":"const snap = /* parsed snapshot */;\nconst ownerAgentId = (snap as any)?.context?.input?.agentId;\nif (ownerAgentId && ownerAgentId !== agent.id) {\n  agent = mastra.getAgent(ownerAgentId); // resume with the owning agent\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agent.resume(runId, data);\n} catch (e) {\n  if ((e as any).id === 'DURABLE_AGENT_RESUME_AGENT_MISMATCH') {\n    const owner = (e as any).details?.ownerAgentId;\n    await mastra.getAgent(owner).resume(runId, data);\n  } else throw e;\n}","preventionTips":["Keep a runId -> agentId mapping in your own persistence.","Avoid renaming agent ids while runs are in flight.","Pass the correct agent instance from your agent registry."],"tags":["durable-agent","resume","ownership","agent-mismatch"],"backgroundTag":"resource-ownership-mismatch","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}