{"record":{"id":"e39fd8bf97288d64","repo":"mastra-ai/mastra","slug":"version-with-id-to-not-found-for-agent-agenti","errorCode":null,"errorMessage":"Version with id ${to} not found for agent ${agentId}","messagePattern":"Version with id (.+?) not found for agent (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/agent-versions.ts","lineNumber":545,"sourceCode":"      }\n      const agent = await agentsStore.getById(agentId);\n      assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n      // Get both versions\n      const fromVersion = await agentsStore.getVersion(from);\n      if (!fromVersion) {\n        throw new HTTPException(404, { message: `Version with id ${from} not found` });\n      }\n      if (fromVersion.agentId !== agentId) {\n        throw new HTTPException(404, { message: `Version with id ${from} not found for agent ${agentId}` });\n      }\n\n      const toVersion = await agentsStore.getVersion(to);\n      if (!toVersion) {\n        throw new HTTPException(404, { message: `Version with id ${to} not found` });\n      }\n      if (toVersion.agentId !== agentId) {\n        throw new HTTPException(404, { message: `Version with id ${to} not found for agent ${agentId}` });\n      }\n\n      // Extract config fields from both versions (top-level, no .snapshot)\n      const fromConfig = extractConfigFromVersion(\n        fromVersion as unknown as Record<string, unknown>,\n        SNAPSHOT_CONFIG_FIELDS,\n      );\n      const toConfig = extractConfigFromVersion(\n        toVersion as unknown as Record<string, unknown>,\n        SNAPSHOT_CONFIG_FIELDS,\n      );\n\n      // Compute diffs on the config fields\n      const diffs = computeVersionDiffs(fromConfig, toConfig);\n\n      return {\n        diffs,\n        fromVersion,","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/agent-versions.ts#L527-L563","documentation":"Thrown by the GET /stored/agents/:agentId/versions/compare handler when the `to` version exists in storage but belongs to a different agent than the :agentId path parameter. Returned as 404 to avoid leaking cross-agent version existence.","triggerScenarios":"Calling compare-versions with a `to` version id owned by another agent, e.g. GET /stored/agents/agent-a/versions/compare?from=<agent-a-version>&to=<agent-b-version>. Also occurs when both versions come from different agents' version lists.","commonSituations":"Comparing versions across two agents by mistake (e.g. diffing prod agent vs staging agent ids); copy/paste errors in multi-agent admin UIs; tests parameterized over versions of multiple agents.","solutions":["Ensure both `from` and `to` version ids belong to the same :agentId in the path","Fix the path agentId if cross-agent comparison was unintentional via the wrong route","Refetch version lists per-agent and compare only within one agent"],"exampleFix":"// before\nGET /stored/agents/agent-a/versions/compare?from=va1&to=vb2  // vb2 belongs to agent-b\n// after\nGET /stored/agents/agent-b/versions/compare?from=vb1&to=vb2","handlingStrategy":"validation","validationCode":"const [fromList, toList] = await Promise.all([\n  fetch(`/api/stored/agents/${fromAgentId}/versions`).then(r => r.json()),\n  fetch(`/api/stored/agents/${toAgentId}/versions`).then(r => r.json()),\n]);\nif (fromAgentId !== toAgentId) {\n  throw new Error('Cross-agent version comparison is not supported');\n}","typeGuard":"function sameAgent(from: { agentId: string }, to: { agentId: string }, agentId: string): boolean {\n  return from.agentId === agentId && to.agentId === agentId;\n}","tryCatchPattern":"try {\n  const res = await compareVersions(agentId, fromId, toId);\n} catch (e) {\n  if (isHttpException(e, 404)) {\n    // both ids must resolve within this agent's version list; reselect\n  }\n}","preventionTips":["Keep per-agent version pickers isolated in UIs — one picker per agent","Parameterize tests by agent so version ids never leak across cases","Validate both ids against the same version list before calling compare"],"tags":["http-404","agent-versions","rest-api","ownership"],"backgroundTag":"version-not-found-for-agent","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}