{"record":{"id":"e469d2e8f1230b66","repo":"mastra-ai/mastra","slug":"resourceid-is-required-for-observational-memory-lo","errorCode":null,"errorMessage":"resourceId is required for observational memory lookup","messagePattern":"resourceId is required for observational memory lookup","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/memory.ts","lineNumber":712,"sourceCode":"      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      }\n\n      // Determine the resourceId to use\n      const effectiveResourceId = resourceId;\n      if (!effectiveResourceId) {\n        throw new HTTPException(400, { message: 'resourceId is required for observational memory lookup' });\n      }\n\n      // For resource-scoped OM, lookup by resourceId only (threadId=null)\n      const omThreadId = omConfig.scope === 'resource' ? null : (threadId ?? null);\n\n      // Get current record\n      const record = await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId);\n\n      // Get history\n      const history = await memoryStore.getObservationalMemoryHistory(\n        omThreadId,\n        effectiveResourceId,\n        historyLimit,\n        historyOptions,\n      );\n\n      return {\n        record: record ?? null,","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/memory.ts#L694-L730","documentation":"The GET observational-memory handler requires a resourceId query parameter, because OM records are always keyed by resource. The request omitted it (or it was an empty string), so the lookup was rejected before touching storage.","triggerScenarios":"GET /api/memory/observational-memory?agentId=...&threadId=... without a resourceId query param — e.g. a UI calls the route from a 'new chat' page where only a thread exists, or a client drops the resourceId param entirely.","commonSituations":"Frontend built against an older route shape that didn't require resourceId; opening OM panel before a resource is established; empty string params stripped by an HTTP client; confusion between thread-scoped and resource-scoped OM lookup keys.","solutions":["Add the resourceId query parameter identifying the OM resource you want the record for.","If resourceId isn't known yet, defer the call until the chat/resource is established (mirror the gateway branch which returns an empty record for /chat/new).","Validate params in the client and skip the request when resourceId is missing."],"exampleFix":"// before\nfetch(`/api/memory/observational-memory?agentId=${agentId}&threadId=${threadId}`);\n// after\nfetch(`/api/memory/observational-memory?agentId=${agentId}&threadId=${threadId}&resourceId=${resourceId}`);","handlingStrategy":"validation","validationCode":"if (!resourceId) {\n  // skip the request entirely\n  return { record: null, history: undefined };\n}\nconst url = `/api/memory/observational-memory?agentId=${agentId}&resourceId=${encodeURIComponent(resourceId)}${threadId ? `&threadId=${threadId}` : ''}`;","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(url);\n  if (res.status === 400) return { record: null, history: undefined };\n  return await res.json();\n} catch (e) {\n  return { record: null, history: undefined };\n}","preventionTips":["Treat resourceId as mandatory for all OM routes","Don't render the OM panel until a resource id exists","Encode query params and check for empty strings","Add a client-side param schema check before fetching"],"tags":["validation","observational-memory","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}