mastra-ai/mastra · error · Error

Failed to rehydrate registry entry for run ${runId}. Cannot

Error message

Failed to rehydrate registry entry for run ${runId}. Cannot resume.

What it means

After loading the persisted snapshot and calling prepare() to rebuild non-serializable runtime state, the code re-reads the in-memory run registry. If the entry still isn't there, rehydration failed and this Error is thrown from durable-agent.ts:1997.

Source

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

        : undefined;
      const memory = threadId
        ? {
            ...options?.memory,
            thread: threadId,
            resource: resourceId ?? options?.memory?.resource,
          }
        : options?.memory;

      await this.prepare([], {
        ...(options as AgentExecutionOptions<TOutput>),
        runId,
        requestContext: options?.requestContext ?? snapshotRequestContext,
        memory,
      });
      entry = this.#runRegistry.get(runId);
    }
    if (!entry) {
      throw new Error(`Failed to rehydrate registry entry for run ${runId}. Cannot resume.`);
    }

    const memoryInfo = this.#runRegistry.getMemoryInfo(runId);
    const registeredMemory = memoryInfo?.threadId
      ? ({
          ...options?.memory,
          thread: memoryInfo.threadId,
          resource: memoryInfo.resourceId ?? options?.memory?.resource,
        } as DurableAgentStreamOptions<TOutput>['memory'])
      : options?.memory;

    const resolvedOptions = (await this.#resolveExecutionOptions({
      ...(options as DurableAgentStreamOptions<TOutput>),
      requestContext:
        options?.requestContext ??
        (entry.requestContext as DurableAgentStreamOptions<TOutput>['requestContext'] | undefined),
      memory: registeredMemory ?? options?.memory,
    })) as DurableAgentResumeOptions<TOutput>;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure the durable agentic-loop workflow is registered on the Mastra instance used at resume time.
  2. Avoid calling resume() concurrently for the same runId; serialize resumes or gate on run state.
  3. Retry the resume once — transient rehydration races often succeed on a second attempt.
  4. If it persists, check prepare()/internal registration logs and upgrade to a version with the rehydration fix.

Example fix

// before
await agent.resume(runId, data);
// after
try {
  await agent.resume(runId, data);
} catch (e) {
  if (String(e).includes('Failed to rehydrate registry entry')) await new Promise(r => setTimeout(r, 250)) || await agent.resume(runId, data);
  throw e;
}
Defensive patterns

Strategy: retry

Try / catch

let lastErr;
for (let i = 0; i < 3; i++) {
  try { return await agent.resume(runId, data); }
  catch (e) {
    if (!String(e).includes('Failed to rehydrate registry entry')) throw e;
    lastErr = e;
    await new Promise(r => setTimeout(r, 200 * (i + 1)));
  }
}
throw lastErr;

Prevention

When it happens

Trigger: prepare() did not register the run (e.g. internal setup failed silently or skipped registration); a concurrent resume raced the rehydration pass; the run registry dropped the entry immediately after rehydration (TTL/eviction); getWorkflowRunById returned a snapshot but the workflow registration itself is missing on this Mastra instance.

Common situations: Resuming a run for a durable workflow that isn't registered in the current Mastra instance's workflow map; racing resume() calls from multiple handlers right after a process restart; registry cleared by hot reload in dev.

Related errors


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