{"record":{"id":"479297943b791a2b","repo":"mastra-ai/mastra","slug":"memory-requires-a-storage-provider-to-function-ad","errorCode":null,"errorMessage":"Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance.\n\nhttps://mastra.ai/en/docs/memory/overview","messagePattern":"Memory requires a storage provider to function\\. Add a storage configuration to Memory or to your Mastra instance\\.\n\nhttps://mastra\\.ai/en/docs/memory/overview","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/core/src/memory/memory.ts","lineNumber":234,"sourceCode":"  }\n\n  /**\n   * Internal method used by Mastra to register itself with the memory.\n   * @param mastra The Mastra instance.\n   * @internal\n   */\n  __registerMastra(mastra: Mastra): void {\n    this.#mastra = mastra;\n  }\n\n  protected _hasOwnStorage = false;\n  get hasOwnStorage() {\n    return this._hasOwnStorage;\n  }\n\n  get storage() {\n    if (!this._storage) {\n      throw new Error(\n        `Memory requires a storage provider to function. Add a storage configuration to Memory or to your Mastra instance.\n\nhttps://mastra.ai/en/docs/memory/overview`,\n      );\n    }\n    return this._storage;\n  }\n\n  public setStorage(storage: MastraCompositeStore) {\n    this._storage = augmentWithInit(storage);\n  }\n\n  public setVector(vector: MastraVector) {\n    this.vector = vector;\n  }\n\n  public setEmbedder(\n    embedder: EmbeddingModelId | MastraEmbeddingModel<string>,","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/memory/memory.ts#L216-L252","documentation":"Memory needs a storage adapter to persist threads and messages; the lazy `storage` getter throws this Error when accessed while `this._storage` is undefined. Storage can be attached directly to Memory or inherited from the Mastra instance. The getter exists so Memory fails with a clear actionable message instead of a confusing null dereference later.","triggerScenarios":"Accessing memory.storage (directly or via internal operations like recall, thread creation, saveMessages) on a Memory instance constructed with no storage config and not attached to a Mastra instance that has storage.","commonSituations":"Standalone Memory usage in tests or scripts where a storage adapter was never configured; constructing `new Memory({ options })` with only semantic-recall/working-memory options; forgetting that Mastra instance-level storage only applies when Memory is registered on that instance.","solutions":["Add a storage adapter to the Memory config, e.g. storage: new LibSQLStore({ url: 'file:memory.db' }).","Or attach Memory to a Mastra instance that has storage configured, so Memory inherits it.","Ensure the code path that accesses memory.storage runs only after the Memory instance is fully constructed/registered."],"exampleFix":"// before\nconst memory = new Memory({ options: { lastMessages: 10 } });\n\n// after\nconst memory = new Memory({\n  storage: new LibSQLStore({ url: 'file:memory.db' }),\n  options: { lastMessages: 10 },\n});","handlingStrategy":"validation","validationCode":"function ensureMemoryStorage(memory) {\n  if (!memory.hasOwnStorage) {\n    // only safe if Memory is registered on a Mastra instance with storage\n    throw new Error('Memory has no storage attached; pass storage or register on Mastra with storage');\n  }\n}","typeGuard":"function hasStorage(m) { return typeof m.hasOwnStorage === 'boolean' && m.hasOwnStorage; }","tryCatchPattern":null,"preventionTips":["Configure storage on the Mastra instance once and let all Memory instances inherit it.","Never construct Memory with options-only config outside tests.","Guard direct memory.storage access behind a helper that validates presence first."],"tags":["memory","storage","configuration","missing-dependency"],"backgroundTag":"missing-storage-adapter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}