{"record":{"id":"e282136c65f4317f","repo":"mastra-ai/mastra","slug":"observational-memory-is-not-enabled-for-this-agent","errorCode":null,"errorMessage":"Observational Memory is not enabled for this agent","messagePattern":"Observational Memory is not enabled for this agent","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":689,"sourceCode":"      if (await isGatewayAgentAsync(agent)) {\n        const gwClient = getGatewayClient();\n        if (gwClient && resourceId && threadId) {\n          const [recordResult, historyResult] = await Promise.all([\n            gwClient.getObservationRecord(threadId, resourceId),\n            gwClient.getObservationHistory(threadId, { resourceId, limit: historyLimit, from, to, offset }),\n          ]);\n          return {\n            record: recordResult.record ? toLocalOMRecord(recordResult.record) : null,\n            history: historyResult.records?.length > 0 ? historyResult.records.map(toLocalOMRecord) : undefined,\n          };\n        }\n        // No threadId or resourceId yet (e.g. /chat/new) — return empty\n        return { record: null, history: undefined };\n      }\n\n      const omConfig = await getOMConfigFromAgent(agent, requestContext);\n      if (!omConfig?.enabled) {\n        throw new HTTPException(400, { message: 'Observational Memory is not enabled for this agent' });\n      }\n\n      // Get storage from the agent's memory (not mastra.getStorage())\n      // This ensures we use the same storage the agent uses for OM\n      const memory = await getMemoryFromContext({ mastra, agentId, requestContext });\n      if (!memory) {\n        throw new HTTPException(400, { message: 'Memory is not configured for this agent' });\n      }\n\n      let memoryStore: MemoryStorage | undefined;\n      try {\n        memoryStore = await memory.storage.getStore('memory');\n      } catch {\n        throw new HTTPException(400, { message: 'Memory storage is not initialized' });\n      }\n      if (!memoryStore) {\n        throw new HTTPException(400, { message: 'Memory storage is not initialized' });\n      }","sourceCodeStart":671,"sourceCodeEnd":707,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L671-L707","documentation":"Thrown when the resolved agent exists but its Observational Memory config is absent or has `enabled: false`. The OM history endpoint requires an agent explicitly configured with OM, so it rejects the request with 400.","triggerScenarios":"Requesting OM history for an agent whose Memory/Memory options don't include `observationalMemory: { enabled: true }` (or equivalent config resolved by getOMConfigFromAgent), or whose thread/resource has no OM config at all.","commonSituations":"Forgetting to enable OM in agent memory options after upgrading; OM enabled globally but disabled for this specific agent/thread; calling OM endpoints for regular memory agents; config read from requestContext overriding the default.","solutions":["Enable Observational Memory on the agent's Memory instance (e.g. `new Memory({ options: { observationalMemory: { enabled: true, ... } } })`).","Verify requestContext isn't overriding/disabling the OM config for this request.","Only call OM history endpoints for agents that actually have OM configured.","Check thread-level OM settings that may disable OM for the specific threadId."],"exampleFix":"// before\nconst memory = new Memory({ options: {} }); // OM off -> 400\n// after\nconst memory = new Memory({\n  options: { observationalMemory: { enabled: true } },\n});","handlingStrategy":"validation","validationCode":"const agent = mastra.getAgent(agentId);\nconst om = agent?.getModelList?.() ?? null; // placeholder guard\nconst omConfig = /* from memory options */ (agent as any)?.__omConfig;\nif (!omConfig?.enabled) throw new Error(`OM is not enabled for agent '${agentId}'; enable observationalMemory in its Memory options`);","typeGuard":"function hasOmEnabled(memory: Memory | undefined): boolean {\n  return !!memory?.getOptions?.()?.observationalMemory?.enabled;\n}","tryCatchPattern":"try {\n  const rec = await fetchOmHistory(agentId);\n} catch (e) {\n  if (isHttpError(e, 400) && /Observational Memory/.test(e.message)) {\n    // disable OM UI features for this agent instead of calling the endpoint\n  }\n  throw e;\n}","preventionTips":["Gate OM UI/endpoints behind a capability flag derived from the agent's memory options.","Enable observationalMemory explicitly in agent Memory config when OM features are used.","Check requestContext overrides don't silently disable OM."],"tags":["memory","observational-memory","http-400","configuration"],"backgroundTag":"observational-memory-not-enabled","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}