{"record":{"id":"eba175883a772c95","repo":"mastra-ai/mastra","slug":"stored-agent-with-id-storedagentid-not-found-eba175","errorCode":null,"errorMessage":"Stored agent with id ${storedAgentId} not found","messagePattern":"Stored agent with id (.+?) not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/stored-agents.ts","lineNumber":518,"sourceCode":"  tags: ['Stored Agents'],\n  requiresAuth: true,\n  handler: async ({ mastra, requestContext, storedAgentId, status }) => {\n    try {\n      const storage = mastra.getStorage();\n\n      if (!storage) {\n        throw new HTTPException(500, { message: 'Storage is not configured' });\n      }\n\n      const agentsStore = await storage.getStore('agents');\n      if (!agentsStore) {\n        throw new HTTPException(500, { message: 'Agents storage domain is not available' });\n      }\n\n      const agent = await agentsStore.getByIdResolved(storedAgentId, { status });\n\n      if (!agent) {\n        throw new HTTPException(404, { message: `Stored agent with id ${storedAgentId} not found` });\n      }\n      assertStoredResourceScope(agent, await getStoredResourceScope(mastra, requestContext));\n\n      // Throws 404 if the caller isn't the owner, admin, `stored-agents:read[:<id>]`\n      // holder, and the record isn't public/legacy-unowned.\n      assertReadAccess({ requestContext, resource: 'stored-agents', resourceId: storedAgentId, record: agent });\n\n      const authors = await prepareAuthorEnrichment(mastra, requestContext, [agent.authorId]);\n      const withFavorite = await enrichOrStripFavorites(mastra, requestContext, 'agent', agent);\n      return attachAuthor(withFavorite, authors);\n    } catch (error) {\n      return handleError(error, 'Error getting stored agent');\n    }\n  },\n});\n\n/**\n * POST /stored/agents - Create a new stored agent","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-agents.ts#L500-L536","documentation":"GET /stored/agents/:storedAgentId returns 404 when getByIdResolved finds no agent for the id at the requested status (published default, or draft with ?status=draft). Because of visibility scoping, a private agent you can't read also surfaces as 404 rather than 403, so this error can mean 'doesn't exist' or 'exists but not visible to you'.","triggerScenarios":"GET /stored/agents/:id with an unknown id; id exists only as a draft while requesting published (default); agent deleted; requesting another user's private agent without admin rights or stored-agents:read permission (assertReadAccess/scoping converts it to 404).","commonSituations":"Playground UI stale link after agent deletion; querying ?status=published for an agent never published; cross-tenant id in multi-tenant deployment; wrong environment (agent exists in prod, queried in staging).","solutions":["Retry with ?status=draft to check whether only a draft version exists","List GET /stored/agents to confirm the id is visible to your credentials","Verify permissions: owner/admin or stored-agents:read[:<id>] plus a public/legacy-unowned record is required for non-owner reads","Confirm you're querying the environment whose storage actually holds the agent"],"exampleFix":"// before\nget(`/stored/agents/${id}`); // 404, only draft exists\n// after\nget(`/stored/agents/${id}?status=draft`);","handlingStrategy":"try-catch","validationCode":"const list = await get('/stored/agents');\nconst visible = list.agents.some(a => a.id === id);\nif (!visible) throw new Error(`Agent ${id} not visible/absent for current credentials`);","typeGuard":"function isAgentNotFound(e: unknown): boolean {\n  return (e as any)?.status === 404 && /Stored agent with id .* not found/.test((e as any)?.message ?? '');\n}","tryCatchPattern":"try {\n  return await get(`/stored/agents/${id}`);\n} catch (e) {\n  if (isAgentNotFound(e)) {\n    // retry as draft before giving up\n    return get(`/stored/agents/${id}?status=draft`).catch(() => null);\n  }\n  throw e;\n}","preventionTips":["Refresh cached ids after agent deletion; handle stale links","Remember 404 can mean 'private, not yours' — check permissions before concluding deletion","Request ?status=draft for unpublished agents","Verify environment/storage target matches where the agent was created"],"tags":["http-404","stored-agents","authorization"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}