{"record":{"id":"474fdc9a0f29a5ab","repo":"mastra-ai/mastra","slug":"memory-is-not-initialized","errorCode":null,"errorMessage":"Memory is not initialized","messagePattern":"Memory is not initialized","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":973,"sourceCode":"          );\n          if (!shouldFilterThreadsWithFGA(mastra, requestContext)) {\n            return result;\n          }\n\n          const accessibleThreads = await filterAccessibleThreads({\n            mastra,\n            requestContext,\n            threads: result.threads,\n          });\n          return paginateThreads({\n            threads: accessibleThreads,\n            page,\n            perPage,\n          });\n        }\n      }\n\n      throw new HTTPException(400, { message: 'Memory is not initialized' });\n    } catch (error) {\n      return handleError(error, 'Error listing threads');\n    }\n  },\n});\n\nexport const GET_THREAD_BY_ID_ROUTE = createRoute({\n  method: 'GET',\n  path: '/memory/threads/:threadId',\n  responseType: 'json',\n  pathParamSchema: threadIdPathParams,\n  queryParamSchema: getThreadByIdQuerySchema,\n  responseSchema: getThreadByIdResponseSchema,\n  summary: 'Get thread by ID',\n  description: 'Returns details for a specific conversation thread',\n  tags: ['Memory'],\n  requiresAuth: true,\n  handler: async ({ mastra, agentId, threadId, resourceId, requestContext }) => {","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L955-L991","documentation":"GET /memory/threads exhausted every source of thread data: the agent's memory was absent, and the Mastra-level storage fallback also had no storage instance or no memory store. The endpoint cannot list threads without at least one of these, so it throws this final 400.","triggerScenarios":"GET /api/memory/threads when the Mastra instance has no storage configured and the agent has no memory; getMemoryFromContext (with allowMissingAgent) returns undefined AND getStorageFromContext returns undefined or a store-less storage.","commonSituations":"Minimal Mastra setups (`new Mastra({ agents })`) with no storage key; agents configured without memory; DB not configured in the deployed environment; listing the threads panel before any storage is wired up.","solutions":["Configure storage on the Mastra instance: new Mastra({ ..., storage: new LibSQLStore({ url: ... }) }).","Or attach a Memory (with storage) to the agent being queried.","Verify env vars/DB availability in the target environment so storage initializes.","Client-side: catch the 400 and show an empty threads list / config-needed state."],"exampleFix":"// before\nexport const mastra = new Mastra({ agents });\n// after\nexport const mastra = new Mastra({ agents, storage: new LibSQLStore({ url: 'file:./mastra.db' }) });","handlingStrategy":"validation","validationCode":"// before listing threads, confirm storage exists on the Mastra instance\nif (!mastra.getStorage?.()) {\n  throw new Error('Mastra has no storage configured; /memory/threads will 400');\n}","typeGuard":"function mastraHasStorage(m: unknown): boolean {\n  return !!m && typeof (m as any).getStorage === 'function' && !!(m as any).getStorage();\n}","tryCatchPattern":"try {\n  const res = await fetch('/api/memory/threads?resourceId=' + resourceId);\n  if (!res.ok) {\n    const body = await res.json().catch(() => null);\n    if (body?.message === 'Memory is not initialized') {\n      return { threads: [], page: 0, total: 0, hasMore: false }; // degraded UI state\n    }\n  }\n  return await res.json();\n} catch (e) {\n  console.error('listThreads failed', e);\n  return { threads: [], page: 0, total: 0, hasMore: false };\n}","preventionTips":["Always pass storage to new Mastra in server deployments","Give agents memory+storage if the threads panel should work per-agent","Add an integration test hitting /memory/threads in CI","Render an explicit 'storage not configured' empty state in UIs"],"tags":["memory","storage","configuration","threads"],"backgroundTag":"memory-storage-not-initialized","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}