{"record":{"id":"3967f301f84acae4","repo":"mastra-ai/mastra","slug":"agent-with-id-id-not-found","errorCode":null,"errorMessage":"Agent with id ${id} not found","messagePattern":"Agent with id (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/agents/inmemory.ts","lineNumber":92,"sourceCode":"    await this.createVersion({\n      id: versionId,\n      agentId: agent.id,\n      versionNumber: 1,\n      ...snapshotConfig,\n      changedFields: Object.keys(snapshotConfig),\n      changeMessage: 'Initial version',\n    });\n\n    // Return the thin agent record (activeVersionId remains null)\n    return this.deepCopyAgent(newAgent);\n  }\n\n  async update(input: StorageUpdateAgentInput): Promise<StorageAgentType> {\n    const { id, ...updates } = input;\n\n    const existingAgent = this.db.agents.get(id);\n    if (!existingAgent) {\n      throw new Error(`Agent with id ${id} not found`);\n    }\n\n    const { authorId, visibility, activeVersionId, metadata, status } = updates;\n\n    const updatedAgent: StorageAgentType = {\n      ...existingAgent,\n      ...(authorId !== undefined && { authorId }),\n      ...(visibility !== undefined && { visibility }),\n      ...(activeVersionId !== undefined && { activeVersionId }),\n      ...(metadata !== undefined && {\n        metadata: { ...existingAgent.metadata, ...metadata },\n      }),\n      ...(status !== undefined && { status }),\n      updatedAt: new Date(),\n    };\n\n    this.db.agents.set(id, updatedAgent);\n    return this.deepCopyAgent(updatedAgent);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/agents/inmemory.ts#L74-L110","documentation":"`update` looks up the agent by `id` in the in-memory map and throws when no row exists. Updates never create agents implicitly.","triggerScenarios":"Calling `update({ id, ... })` with an ID that was never created, was created in a different store instance, or belongs to an in-memory store that was reset (process restart loses all data).","commonSituations":"Updating an agent after a dev-server restart wiped the in-memory DB; using an ID from a different environment/store; race where another caller deleted the agent first; typo in the agent ID.","solutions":["Verify the agent exists (get by ID) before updating, or create it if missing","Ensure you are using the same store instance that holds the agent (in-memory data does not survive restarts)","Log/validate the incoming `id` — check for typos or IDs from another environment"],"exampleFix":"// before\nawait agents.update({ id: 'agent-1', name: 'new-name' });\n// after\nif (await agents.get({ agentId: 'agent-1' })) {\n  await agents.update({ id: 'agent-1', name: 'new-name' });\n}","handlingStrategy":"try-catch","validationCode":"const existing = await agentsDomain.get({ agentId: id });\nif (!existing) {\n  // create the agent first or surface a 404 to the caller\n}","typeGuard":"null","tryCatchPattern":"try {\n  await agentsDomain.update({ id, ...updates });\n} catch (e) {\n  if (e instanceof Error && /Agent with id .* not found/.test(e.message)) {\n    throw new NotFoundError(`Agent ${id} does not exist in this store`);\n  }\n  throw e;\n}","preventionTips":["Remember in-memory stores reset on process restart — recreate or reseed before updates","Verify the ID comes from the same store/environment","Check for typos in agent IDs","Use get-before-update in flows where deletion can race the update"],"tags":["storage","not-found","in-memory"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}