mastra-ai/mastra · error · HTTPException

Version with id ${from} not found for agent ${agentId}

Error message

Version with id ${from} not found for agent ${agentId}

What it means

Thrown by the GET /stored/agents/:agentId/versions/compare handler when the `from` version id exists in storage but is owned by a different agent than the :agentId path parameter. The server deliberately returns a 404 (rather than 403) so it does not leak the existence of another agent's versions.

Source

Thrown at packages/server/src/server/handlers/agent-versions.ts:537

      if (!storage) {
        throw new HTTPException(500, { message: 'Storage is not configured' });
      }

      const agentsStore = await storage.getStore('agents');
      if (!agentsStore) {
        throw new HTTPException(500, { message: 'Agents storage domain is not available' });
      }
      const agent = await agentsStore.getById(agentId);
      assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));

      // Get both versions
      const fromVersion = await agentsStore.getVersion(from);
      if (!fromVersion) {
        throw new HTTPException(404, { message: `Version with id ${from} not found` });
      }
      if (fromVersion.agentId !== agentId) {
        throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });
      }

      const toVersion = await agentsStore.getVersion(to);
      if (!toVersion) {
        throw new HTTPException(404, { message: `Version with id ${to} not found` });
      }
      if (toVersion.agentId !== agentId) {
        throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });
      }

      // Extract config fields from both versions (top-level, no .snapshot)
      const fromConfig = extractConfigFromVersion(
        fromVersion as unknown as Record<string, unknown>,
        SNAPSHOT_CONFIG_FIELDS,
      );
      const toConfig = extractConfigFromVersion(
        toVersion as unknown as Record<string, unknown>,
        SNAPSHOT_CONFIG_FIELDS,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the `from` version id belongs to the same agent as the :agentId path parameter (list versions via GET /stored/agents/:agentId/versions first)
  2. Correct the agentId path parameter if you actually meant the other agent
  3. Clear stale cached version ids in the client and refetch the version list for the target agent

Example fix

// before
GET /stored/agents/agent-b/versions/compare?from=ver-of-agent-a&to=ver-of-agent-b
// after
GET /stored/agents/agent-a/versions/compare?from=ver-of-agent-a&to=ver-of-agent-a-other
Defensive patterns

Strategy: validation

Validate before calling

const versions = await fetch(`/api/stored/agents/${agentId}/versions`).then(r => r.json());
if (!versions.some(v => v.id === fromId)) {
  throw new Error(`Version ${fromId} does not belong to agent ${agentId}`);
}

Type guard

function belongsToAgent(version: { agentId: string } | null, agentId: string): version is { agentId: string } {
  return version !== null && version.agentId === agentId;
}

Try / catch

try {
  const res = await compareVersions(agentId, fromId, toId);
} catch (e) {
  if (isHttpException(e, 404)) {
    // refetch version list for this agent and prompt user to reselect
  }
}

Prevention

When it happens

Trigger: Calling compare-versions with a `from` version id that belongs to agent A while the route targets agent B, e.g. GET /stored/agents/agent-b/versions/compare?from=<agent-a-version-id>&to=<agent-b-version-id>. Also happens after copying a version id from another agent's version list, or when the agentId path param is stale after the agent was re-created under a different id.

Common situations: Multi-agent dashboards where version ids from one agent's table are passed into another agent's compare endpoint; cached version ids in a frontend after an agent was deleted and recreated; mixing up similarly-named agents in scripts or tests.

Related errors


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