{"record":{"id":"1900aba634a29a50","repo":"mastra-ai/mastra","slug":"message-history-missing-storage-adapter","errorCode":"MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER","errorMessage":"Using Mastra Memory message history requires a storage adapter but no attached adapter was detected.","messagePattern":"Using Mastra Memory message history requires a storage adapter but no attached adapter was detected\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"critical","filePath":"packages/core/src/memory/memory.ts","lineNumber":791,"sourceCode":"        processors.push(\n          new WorkingMemory({\n            storage: memoryStore,\n            template,\n            scope: typeof effectiveConfig.workingMemory === 'object' ? effectiveConfig.workingMemory.scope : undefined,\n            useVNext:\n              typeof effectiveConfig.workingMemory === 'object' &&\n              'version' in effectiveConfig.workingMemory &&\n              effectiveConfig.workingMemory.version === 'vnext',\n            templateProvider: this,\n          }),\n        );\n      }\n    }\n\n    const lastMessages = effectiveConfig.lastMessages;\n    if (lastMessages) {\n      if (!memoryStore)\n        throw new MastraError({\n          category: 'USER',\n          domain: ErrorDomain.STORAGE,\n          id: 'MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER',\n          text: 'Using Mastra Memory message history requires a storage adapter but no attached adapter was detected.',\n        });\n\n      // Check if user already manually added MessageHistory\n      const hasMessageHistory = configuredProcessors.some(p => !isProcessorWorkflow(p) && p.id === 'message-history');\n\n      // Check if ObservationalMemory is present (via processor or config) - it handles its own message loading and saving\n      const hasObservationalMemory =\n        configuredProcessors.some(p => !isProcessorWorkflow(p) && p.id === 'observational-memory') ||\n        isObservationalMemoryEnabled(effectiveConfig.observationalMemory);\n\n      // Skip MessageHistory input processor if ObservationalMemory handles message loading\n      if (!hasMessageHistory && !hasObservationalMemory) {\n        processors.push(\n          new MessageHistory({","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/memory/memory.ts#L773-L809","documentation":"The lastMessages feature (recent message history recall) reads prior messages from storage. getInputProcessors throws this MastraError (MESSAGE_HISTORY_MISSING_STORAGE_ADAPTER, category USER, domain STORAGE) when lastMessages is configured but memoryStore is undefined when building the message-history input processor.","triggerScenarios":"Setting options.lastMessages to a number (or true) on a Memory instance that has no storage adapter attached directly or inherited from the Mastra instance, then running an agent turn that builds input processors.","commonSituations":"Adding lastMessages to an existing Memory after upgrade without adding storage; Mastra instance lacking storage; test scaffolding with options-only Memory.","solutions":["Attach a storage adapter to Memory config, e.g. storage: new LibSQLStore({ url: 'file:memory.db' }).","Or configure storage on the parent Mastra instance so Memory inherits it.","If history recall is not needed, remove the lastMessages option."],"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 assertLastMessagesStorage(memoryConfig) {\n  if (memoryConfig?.options?.lastMessages && !memoryConfig?.storage) {\n    throw new Error('lastMessages requires a storage adapter on Memory (or inherited from Mastra)');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat lastMessages and storage as a mandatory pair in Memory configs.","Set storage once on the Mastra instance and register Memory there.","Add startup validation that constructs Memory with production config before serving traffic."],"tags":["memory","message-history","storage","configuration"],"backgroundTag":"missing-storage-adapter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}