mastra-ai/mastra · error · Error

observationalMemory.experimental_subconscious must be a Subc

Error message

observationalMemory.experimental_subconscious must be a Subconscious instance.

What it means

Memory's observational memory config accepts an `experimental_subconscious` option. At merge/default time, applySubconsciousDefaults normalizes the config and, if a subconscious is provided, asserts it is an actual `instanceof Subconscious`. Passing a plain object, a class reference, or a differently-imported Subconscious fails this check.

Source

Thrown at packages/memory/src/index.ts:384

    if (this._omEngineInstance) {
      this._omEngineInstance.__registerMastra(mastra);
    } else {
      void this._omEngine?.then(engine => engine?.__registerMastra(mastra));
    }
  }

  public override getMergedThreadConfig(config?: MemoryConfigInternal): MemoryConfigInternal {
    const merged = super.getMergedThreadConfig(config);
    return this.applyManagedWorkingMemoryDefaults(this.applySubconsciousDefaults(merged));
  }

  private applySubconsciousDefaults(config: MemoryConfigInternal): MemoryConfigInternal {
    const omConfig = normalizeObservationalMemoryConfig(
      config.observationalMemory as boolean | MemoryObservationalMemoryOptions | undefined,
    );
    if (!omConfig?.experimental_subconscious) return config;
    if (!(omConfig.experimental_subconscious instanceof Subconscious)) {
      throw new Error('observationalMemory.experimental_subconscious must be a Subconscious instance.');
    }

    const observation = (omConfig.observation ?? {}) as NonNullable<ObservationalMemoryConfig['observation']>;
    const extract = observation.extract ?? [];
    const existingSlugs = new Set(extract.map(extractor => extractor.slug));
    const subconsciousExtractors = omConfig.experimental_subconscious
      .createObservationExtractors(observation.model ?? omConfig.model)
      .filter(extractor => !existingSlugs.has(extractor.slug));

    return {
      ...config,
      observationalMemory: {
        ...omConfig,
        observation: {
          ...observation,
          extract: [...extract, ...subconsciousExtractors],
        },
      },

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass an actual instance: `new Subconscious({...})`, not the class or a config object
  2. Ensure a single copy of the package containing Subconscious is installed (dedupe node_modules)
  3. Check that the Subconscious import comes from the same package/version Memory uses
  4. If config crosses a serialization boundary, reconstruct the Subconscious instance on the other side

Example fix

// before
observationalMemory: { experimental_subconscious: Subconscious }
// after
observationalMemory: { experimental_subconscious: new Subconscious({ model: 'openai/gpt-4o' }) }
Defensive patterns

Strategy: type-guard

Validate before calling

const sub = config.observationalMemory?.experimental_subconscious;
if (sub !== undefined && !(sub instanceof Subconscious)) {
  throw new TypeError('experimental_subconscious must be created with new Subconscious(...)');
}

Type guard

function isSubconscious(v: unknown): v is Subconscious {
  return v instanceof Subconscious;
}

Try / catch

try {
  const memory = new Memory({ ...opts });
} catch (err) {
  if (err instanceof Error && err.message.includes('must be a Subconscious instance')) {
    // replace the config value with new Subconscious({...}) and rebuild
  } else throw err;
}

Prevention

When it happens

Trigger: Setting `observationalMemory.experimental_subconscious` in thread/memory config to anything that is not an instance of the Subconscious class — e.g. the class itself instead of `new Subconscious(...)`, a plain-object imitation, or a Subconscious from a different package version (dual instance mismatch).

Common situations: Forgetting `new` when constructing Subconscious; importing Subconscious from two different copies of the package (bundlers/dedupe issues) so instanceof fails; serializing/deserializing config across process boundaries loses the class instance.

Related errors


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