mastra-ai/mastra · error

Subconscious capture requires an active Memory instance.

Error message

Subconscious capture requires an active Memory instance.

What it means

getKnowledgeStore needs context.memory — an active Memory instance — to access storage. Without it Subconscious capture cannot persist knowledge, so it throws immediately.

Source

Thrown at packages/memory/src/processors/observational-memory/subconscious/capture.ts:93

function requireScopeContext(context: ExtractorRuntimeContext): KnowledgeScope {
  const organizationId = context.requestContext?.get('organizationId');
  if (typeof organizationId !== 'string' || !organizationId.trim()) {
    throw new Error(
      'Subconscious requires requestContext.organizationId to derive scoped knowledge. Set organizationId on the request context for this conversation.',
    );
  }
  const resourceId = resolveKnowledgeResourceId(context.requestContext, context.resourceId);
  if (!resourceId) {
    throw new Error('Subconscious requires resourceId to derive scoped knowledge.');
  }
  if (!context.threadId) {
    throw new Error('Subconscious requires threadId to derive scoped knowledge.');
  }
  return [`org:${organizationId}`, `resource:${resourceId}`, `thread:${context.threadId}`];
}

async function getKnowledgeStore(context: ExtractorRuntimeContext): Promise<KnowledgeStorage> {
  if (!context.memory) throw new Error('Subconscious capture requires an active Memory instance.');
  const store = await context.memory.storage.getStore('knowledge');
  if (!store) {
    throw new Error(
      'Subconscious requires a knowledge storage domain. Configure a storage adapter that provides stores.knowledge.',
    );
  }
  return store;
}

function parseWhen(value: string | undefined): Date | undefined {
  if (!value) return undefined;
  const when = new Date(value);
  if (Number.isNaN(when.getTime())) throw new Error(`Invalid Subconscious record time: ${value}`);
  return when;
}

export interface CaptureExtractorOptions {
  config?: SubconsciousCaptureConfig;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass the Memory instance into the processor/agent configuration (new Mastra({ memory }))
  2. Verify the processor receives runtime context including memory (check custom wiring)
  3. In tests, provide a Memory (e.g. with InMemoryStorage) in the runtime context

Example fix

// before
new ObservationalMemory({}) // no memory wired
// after
new ObservationalMemory({ memory: mastra.getMemory() })
Defensive patterns

Strategy: validation

Validate before calling

const memory = mastra.getMemory(); if (!memory) throw new Error('Wire a Memory instance before enabling Subconscious');

Type guard

const hasMemory = (ctx: { memory?: Memory }) => !!ctx.memory;

Try / catch

try { await capture(ctx) } catch (e) { if (String(e).includes('active Memory')) { logWiringBug(e); } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Constructing ObservationalMemory/Subconscious processors manually without wiring memory; DI/config mistakes in mastra setup; tests constructing a bare runtime context.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/f812c1a4c76fd576. Report an issue: GitHub.