mastra-ai/mastra · error · MastraError

DURABLE_AGENT_RESUME_AGENT_MISMATCH

DURABLE_AGENT_RESUME_AGENT_MISMATCH

Error message

DurableAgent "${this.name}" resume(${runId}): persisted run belongs to agent "${workflowInput.agentId}", not "${this.id}".

What it means

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).

Source

Thrown at packages/core/src/agent/durable/durable-agent.ts:1963

      const snapshot =
        typeof persisted.snapshot === 'string'
          ? (JSON.parse(persisted.snapshot) as WorkflowRunState)
          : persisted.snapshot;
      if (snapshot?.status !== 'suspended') {
        throw new Error('This workflow run was not suspended');
      }
      const workflowInput = snapshot?.context?.input as DurableAgenticWorkflowInput | undefined;
      if (!workflowInput || workflowInput.__workflowKind !== 'durable-agent') {
        throw new MastraError({
          id: 'DURABLE_AGENT_RESUME_INVALID_SNAPSHOT',
          domain: ErrorDomain.AGENT,
          category: ErrorCategory.SYSTEM,
          text: `DurableAgent "${this.name}" resume(${runId}): persisted snapshot does not contain a durable-agent workflow input.`,
          details: { agentName: this.name, runId },
        });
      }
      if (workflowInput.agentId !== this.id) {
        throw new MastraError({
          id: 'DURABLE_AGENT_RESUME_AGENT_MISMATCH',
          domain: ErrorDomain.AGENT,
          category: ErrorCategory.USER,
          text: `DurableAgent "${this.name}" resume(${runId}): persisted run belongs to agent "${workflowInput.agentId}", not "${this.id}".`,
          details: { agentName: this.name, runId, ownerAgentId: workflowInput.agentId },
        });
      }

      const messageListMemoryInfo = (
        workflowInput.messageListState as { memoryInfo?: { threadId?: string; resourceId?: string } } | undefined
      )?.memoryInfo;
      const threadId = workflowInput.state?.threadId ?? messageListMemoryInfo?.threadId;
      const resourceId = workflowInput.state?.resourceId ?? messageListMemoryInfo?.resourceId;
      const snapshotRequestContext = workflowInput.requestContextEntries
        ? new RequestContext<unknown>(Object.entries(workflowInput.requestContextEntries))
        : undefined;
      const memory = threadId
        ? {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Call resume on the same DurableAgent instance (matching id) that started the run.
  2. Look up the owning agent from the error details (ownerAgentId) and use that agent for the resume call.
  3. If the agent id had to change, treat old runs as orphans: finish or abandon them under the old id.
  4. Keep storage backends separate per environment/agent to avoid cross-ownership lookups.

Example fix

// before
await orderAgent.resume(runId, data); // run owned by supportAgent
// after (details: { ownerAgentId: 'supportAgent' })
const owner = mastra.getAgent('supportAgent') as DurableAgent;
await owner.resume(runId, data);
Defensive patterns

Strategy: validation

Validate before calling

const snap = /* parsed snapshot */;
const ownerAgentId = (snap as any)?.context?.input?.agentId;
if (ownerAgentId && ownerAgentId !== agent.id) {
  agent = mastra.getAgent(ownerAgentId); // resume with the owning agent
}

Try / catch

try {
  await agent.resume(runId, data);
} catch (e) {
  if ((e as any).id === 'DURABLE_AGENT_RESUME_AGENT_MISMATCH') {
    const owner = (e as any).details?.ownerAgentId;
    await mastra.getAgent(owner).resume(runId, data);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/2d6f60086d70c629. Report an issue: GitHub.