{"record":{"id":"d08fb76af7cfaa93","repo":"mastra-ai/mastra","slug":"version-with-id-to-not-found","errorCode":null,"errorMessage":"Version with id ${to} not found","messagePattern":"Version with id (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/agent-versions.ts","lineNumber":542,"sourceCode":"      const agentsStore = await storage.getStore('agents');\n      if (!agentsStore) {\n        throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n      }\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","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/agent-versions.ts#L524-L560","documentation":"Thrown by the GET /stored/agents/:agentId/versions/compare handler when the `to` version id cannot be found in the agents storage store at all. It is a plain 404 indicating the requested version row does not exist.","triggerScenarios":"Calling GET /stored/agents/:agentId/versions/compare?from=<valid>&to=<nonexistent-or-deleted-version-id>. Happens when the `to` version was deleted (e.g. draft pruned, stored agent removed), the id is mistyped/truncated, or the id was never created.","commonSituations":"Typos or truncation of version UUIDs in scripts; comparing against a draft version that was overwritten or deleted; environment mismatch (pointing at a database where that version was never persisted); stale bookmarks/links after cleanup jobs.","solutions":["List the agent's versions via GET /stored/agents/:agentId/versions and use an existing version id for `to`","Check the storage backend is the one you expect (connection/config) — the version may exist in a different database","Recreate the deleted version or re-publish so a `to` target exists"],"exampleFix":"// before\nGET /stored/agents/agent-1/versions/compare?from=v1&to=00000000-0000-0000-0000-000000000000\n// after\nGET /stored/agents/agent-1/versions/compare?from=v1&to=<id-from-GET-/stored/agents/agent-1/versions>","handlingStrategy":"validation","validationCode":"const { versions } = await fetch(`/api/stored/agents/${agentId}/versions`).then(r => r.json());\nif (!versions.some(v => v.id === toId)) {\n  throw new Error(`Version ${toId} not found for agent ${agentId}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await compareVersions(agentId, fromId, toId);\n} catch (e) {\n  if (isHttpException(e, 404) && String(e.message).includes(toId)) {\n    // `to` missing: refresh list, ask user to pick an existing version\n  }\n}","preventionTips":["Fetch version ids dynamically rather than persisting them in config/code","Confirm you are connected to the intended storage backend/environment","Handle draft-version deletion (pruning/publishing) by refreshing selections"],"tags":["http-404","agent-versions","rest-api"],"backgroundTag":"version-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}