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
- Pass an actual instance: `new Subconscious({...})`, not the class or a config object
- Ensure a single copy of the package containing Subconscious is installed (dedupe node_modules)
- Check that the Subconscious import comes from the same package/version Memory uses
- 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
- Always instantiate: new Subconscious(...), never pass the class
- Dedupe the package so only one Subconscious class copy exists (instanceof safety)
- Do not serialize config containing class instances across processes
- Type the config field as Subconscious (not unknown/any) to catch mistakes at compile time
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
- `retrieval: { vector: true }` requires a vector store. Pass
- `retrieval: { vector: true }` requires an embedder. Pass an
- observation.bufferTokens must be > 0, got ${this.observation
- observation.bufferTokens (${this.observationConfig.bufferTok
- observation.bufferActivation must be > 0, got ${this.observa
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/7214456b41fdde38.
Report an issue: GitHub.