mastra-ai/mastra · error · HTTPException
Memory is not initialized
Error message
Memory is not initialized
What it means
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.
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.
Example fix
// before
export const mastra = new Mastra({ agents });
// after
export const mastra = new Mastra({ agents, storage: new LibSQLStore({ url: 'file:./mastra.db' }) }); Defensive patterns
Strategy: validation
Validate before calling
// before listing threads, confirm storage exists on the Mastra instance
if (!mastra.getStorage?.()) {
throw new Error('Mastra has no storage configured; /memory/threads will 400');
} Type guard
function mastraHasStorage(m: unknown): boolean {
return !!m && typeof (m as any).getStorage === 'function' && !!(m as any).getStorage();
} Try / catch
try {
const res = await fetch('/api/memory/threads?resourceId=' + resourceId);
if (!res.ok) {
const body = await res.json().catch(() => null);
if (body?.message === 'Memory is not initialized') {
return { threads: [], page: 0, total: 0, hasMore: false }; // degraded UI state
}
}
return await res.json();
} catch (e) {
console.error('listThreads failed', e);
return { threads: [], page: 0, total: 0, hasMore: false };
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Memory is not configured on this AgentController
- Memory requires a storage provider to function. Add a…
- Memory storage domain is not available on
- MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER
- SEMANTIC_RECALL_MISSING_STORAGE_ADAPTER
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/474fdc9a0f29a5ab.
Report an issue: GitHub.
Appendix: source
Thrown at packages/server/src/server/handlers/memory.ts:973
);
if (!shouldFilterThreadsWithFGA(mastra, requestContext)) {
return result;
}
const accessibleThreads = await filterAccessibleThreads({
mastra,
requestContext,
threads: result.threads,
});
return paginateThreads({
threads: accessibleThreads,
page,
perPage,
});
}
}
throw new HTTPException(400, { message: 'Memory is not initialized' });
} catch (error) {
return handleError(error, 'Error listing threads');
}
},
});
export const GET_THREAD_BY_ID_ROUTE = createRoute({
method: 'GET',
path: '/memory/threads/:threadId',
responseType: 'json',
pathParamSchema: threadIdPathParams,
queryParamSchema: getThreadByIdQuerySchema,
responseSchema: getThreadByIdResponseSchema,
summary: 'Get thread by ID',
description: 'Returns details for a specific conversation thread',
tags: ['Memory'],
requiresAuth: true,
handler: async ({ mastra, agentId, threadId, resourceId, requestContext }) => {View on GitHub (pinned to 75dd419e61)