{"record":{"id":"f812c1a4c76fd576","repo":"mastra-ai/mastra","slug":"subconscious-capture-requires-an-active-memory-ins","errorCode":null,"errorMessage":"Subconscious capture requires an active Memory instance.","messagePattern":"Subconscious capture requires an active Memory instance\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/capture.ts","lineNumber":93,"sourceCode":"function requireScopeContext(context: ExtractorRuntimeContext): KnowledgeScope {\n  const organizationId = context.requestContext?.get('organizationId');\n  if (typeof organizationId !== 'string' || !organizationId.trim()) {\n    throw new Error(\n      'Subconscious requires requestContext.organizationId to derive scoped knowledge. Set organizationId on the request context for this conversation.',\n    );\n  }\n  const resourceId = resolveKnowledgeResourceId(context.requestContext, context.resourceId);\n  if (!resourceId) {\n    throw new Error('Subconscious requires resourceId to derive scoped knowledge.');\n  }\n  if (!context.threadId) {\n    throw new Error('Subconscious requires threadId to derive scoped knowledge.');\n  }\n  return [`org:${organizationId}`, `resource:${resourceId}`, `thread:${context.threadId}`];\n}\n\nasync function getKnowledgeStore(context: ExtractorRuntimeContext): Promise<KnowledgeStorage> {\n  if (!context.memory) throw new Error('Subconscious capture requires an active Memory instance.');\n  const store = await context.memory.storage.getStore('knowledge');\n  if (!store) {\n    throw new Error(\n      'Subconscious requires a knowledge storage domain. Configure a storage adapter that provides stores.knowledge.',\n    );\n  }\n  return store;\n}\n\nfunction parseWhen(value: string | undefined): Date | undefined {\n  if (!value) return undefined;\n  const when = new Date(value);\n  if (Number.isNaN(when.getTime())) throw new Error(`Invalid Subconscious record time: ${value}`);\n  return when;\n}\n\nexport interface CaptureExtractorOptions {\n  config?: SubconsciousCaptureConfig;","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/capture.ts#L75-L111","documentation":"getKnowledgeStore needs context.memory — an active Memory instance — to access storage. Without it Subconscious capture cannot persist knowledge, so it throws immediately.","triggerScenarios":"Subconscious capture/extractor invoked with an ExtractorRuntimeContext whose memory field is undefined — e.g. processor wired without a Memory instance, or custom pipeline omitting memory.","commonSituations":"Constructing ObservationalMemory/Subconscious processors manually without wiring memory; DI/config mistakes in mastra setup; tests constructing a bare runtime context.","solutions":["Pass the Memory instance into the processor/agent configuration (new Mastra({ memory }))","Verify the processor receives runtime context including memory (check custom wiring)","In tests, provide a Memory (e.g. with InMemoryStorage) in the runtime context"],"exampleFix":"// before\nnew ObservationalMemory({}) // no memory wired\n// after\nnew ObservationalMemory({ memory: mastra.getMemory() })","handlingStrategy":"validation","validationCode":"const memory = mastra.getMemory(); if (!memory) throw new Error('Wire a Memory instance before enabling Subconscious');","typeGuard":"const hasMemory = (ctx: { memory?: Memory }) => !!ctx.memory;","tryCatchPattern":"try { await capture(ctx) } catch (e) { if (String(e).includes('active Memory')) { logWiringBug(e); } else throw e; }","preventionTips":["Register Memory via new Mastra({ memory }) so it's always injected","In tests, construct runtime contexts with a Memory instance","Fail fast at startup if Subconscious is enabled without memory"],"tags":["configuration","memory","subconscious","storage"],"backgroundTag":"missing-dependency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}