mastra-ai/mastra · error · HTTPException
Memory storage is not initialized
Error message
Memory storage is not initialized
What it means
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.
Source
Thrown at packages/server/src/server/handlers/memory.ts:703
}
const omConfig = await getOMConfigFromAgent(agent, requestContext);
if (!omConfig?.enabled) {
throw new HTTPException(400, { message: 'Observational Memory is not enabled for this agent' });
}
// Get storage from the agent's memory (not mastra.getStorage())
// This ensures we use the same storage the agent uses for OM
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
if (!memory) {
throw new HTTPException(400, { message: 'Memory is not configured for this agent' });
}
let memoryStore: MemoryStorage | undefined;
try {
memoryStore = await memory.storage.getStore('memory');
} catch {
throw new HTTPException(400, { message: 'Memory storage is not initialized' });
}
if (!memoryStore) {
throw new HTTPException(400, { message: 'Memory storage is not initialized' });
}
// Determine the resourceId to use
const effectiveResourceId = resourceId;
if (!effectiveResourceId) {
throw new HTTPException(400, { message: 'resourceId is required for observational memory lookup' });
}
// For resource-scoped OM, lookup by resourceId only (threadId=null)
const omThreadId = omConfig.scope === 'resource' ? null : (threadId ?? null);
// Get current record
const record = await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId);
// Get historyView on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const memory = new Memory({ options: {...} }); // no storage -> 400
// after
const memory = new Memory({
storage: new PgStorage(process.env.DATABASE_URL),
options: {...},
}); Defensive patterns
Strategy: validation
Validate before calling
const memory = await agent.getMemory();
try {
const store = await memory.storage.getStore('memory');
if (!store) throw new Error('Memory storage not initialized; configure a storage backend on Memory');
} catch (err) {
throw new Error(`Memory storage failed to initialize: ${err instanceof Error ? err.message : err}`);
} Type guard
async function hasMemoryStore(memory: Memory): Promise<boolean> {
try {
return !!(await memory.storage.getStore('memory'));
} catch {
return false;
}
} Try / catch
try {
const history = await fetchOmHistory(agentId);
} catch (e) {
if (isHttpError(e, 400) && /storage is not initialized/.test(e.message)) {
// check DB connectivity/env vars and Memory storage config
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Memory storage is not configured for agent "${agent.id}"
- @mastra/opencode: failed to initialize memory storage from $
- GithubIntegration storage has not been initialized.
- GithubIntegration source-control storage has not been initia
- sendStateSignal could not load thread ${threadId}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5d96a9389fa11232.
Report an issue: GitHub.