{"record":{"id":"5d96a9389fa11232","repo":"mastra-ai/mastra","slug":"memory-storage-is-not-initialized","errorCode":null,"errorMessage":"Memory storage is not initialized","messagePattern":"Memory storage is not initialized","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":703,"sourceCode":"      }\n\n      const omConfig = await getOMConfigFromAgent(agent, requestContext);\n      if (!omConfig?.enabled) {\n        throw new HTTPException(400, { message: 'Observational Memory is not enabled for this agent' });\n      }\n\n      // Get storage from the agent's memory (not mastra.getStorage())\n      // This ensures we use the same storage the agent uses for OM\n      const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n      if (!memory) {\n        throw new HTTPException(400, { message: 'Memory is not configured for this agent' });\n      }\n\n      let memoryStore: MemoryStorage | undefined;\n      try {\n        memoryStore = await memory.storage.getStore('memory');\n      } catch {\n        throw new HTTPException(400, { message: 'Memory storage is not initialized' });\n      }\n      if (!memoryStore) {\n        throw new HTTPException(400, { message: 'Memory storage is not initialized' });\n      }\n\n      // Determine the resourceId to use\n      const effectiveResourceId = resourceId;\n      if (!effectiveResourceId) {\n        throw new HTTPException(400, { message: 'resourceId is required for observational memory lookup' });\n      }\n\n      // For resource-scoped OM, lookup by resourceId only (threadId=null)\n      const omThreadId = omConfig.scope === 'resource' ? null : (threadId ?? null);\n\n      // Get current record\n      const record = await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId);\n\n      // Get history","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L685-L721","documentation":"Thrown when the agent's Memory exists but its storage layer cannot be resolved: `memory.storage.getStore('memory')` either throws (caught and rethrown as this 400) or returns undefined. OM history needs a concrete MemoryStorage to query records, so an uninitialized/in-memory-only storage fails.","triggerScenarios":"OM history route where the Memory instance has no storage configured (storage omitted), or the configured storage adapter fails to initialize its 'memory' store (connection failure, unsupported adapter, constructor throwing).","commonSituations":"Using Memory without a storage backend (default volatile setup) and calling OM endpoints; DB not running/misconfigured connection string; storage adapter version that doesn't support getStore('memory'); lazy init failure at first query.","solutions":["Configure a persistent storage backend on Memory: `new Memory({ storage: new PgStorage(connString), ... })`.","Verify the storage connection (DB up, credentials, connection string env vars set) and that the adapter initializes without throwing.","Confirm the installed storage package version supports the memory store API used by core.","Run a smoke query against storage at startup to fail fast on misconfiguration."],"exampleFix":"// before\nconst memory = new Memory({ options: {...} }); // no storage -> 400\n// after\nconst memory = new Memory({\n  storage: new PgStorage(process.env.DATABASE_URL),\n  options: {...},\n});","handlingStrategy":"validation","validationCode":"const memory = await agent.getMemory();\ntry {\n  const store = await memory.storage.getStore('memory');\n  if (!store) throw new Error('Memory storage not initialized; configure a storage backend on Memory');\n} catch (err) {\n  throw new Error(`Memory storage failed to initialize: ${err instanceof Error ? err.message : err}`);\n}","typeGuard":"async function hasMemoryStore(memory: Memory): Promise<boolean> {\n  try {\n    return !!(await memory.storage.getStore('memory'));\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  const history = await fetchOmHistory(agentId);\n} catch (e) {\n  if (isHttpError(e, 400) && /storage is not initialized/.test(e.message)) {\n    // check DB connectivity/env vars and Memory storage config\n  }\n  throw e;\n}","preventionTips":["Always configure a persistent storage adapter (e.g. PgStorage/UpstashStorage) on Memory in production.","Run a storage connectivity smoke test at server startup.","Keep storage packages updated and compatible with the installed @mastra/core.","Externalize DB connection settings via env vars and validate them before boot."],"tags":["memory","storage","http-400","initialization"],"backgroundTag":"storage-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}