{"record":{"id":"7214456b41fdde38","repo":"mastra-ai/mastra","slug":"observationalmemory-experimental-subconscious-must","errorCode":null,"errorMessage":"observationalMemory.experimental_subconscious must be a Subconscious instance.","messagePattern":"observationalMemory\\.experimental_subconscious must be a Subconscious instance\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/index.ts","lineNumber":384,"sourceCode":"    if (this._omEngineInstance) {\n      this._omEngineInstance.__registerMastra(mastra);\n    } else {\n      void this._omEngine?.then(engine => engine?.__registerMastra(mastra));\n    }\n  }\n\n  public override getMergedThreadConfig(config?: MemoryConfigInternal): MemoryConfigInternal {\n    const merged = super.getMergedThreadConfig(config);\n    return this.applyManagedWorkingMemoryDefaults(this.applySubconsciousDefaults(merged));\n  }\n\n  private applySubconsciousDefaults(config: MemoryConfigInternal): MemoryConfigInternal {\n    const omConfig = normalizeObservationalMemoryConfig(\n      config.observationalMemory as boolean | MemoryObservationalMemoryOptions | undefined,\n    );\n    if (!omConfig?.experimental_subconscious) return config;\n    if (!(omConfig.experimental_subconscious instanceof Subconscious)) {\n      throw new Error('observationalMemory.experimental_subconscious must be a Subconscious instance.');\n    }\n\n    const observation = (omConfig.observation ?? {}) as NonNullable<ObservationalMemoryConfig['observation']>;\n    const extract = observation.extract ?? [];\n    const existingSlugs = new Set(extract.map(extractor => extractor.slug));\n    const subconsciousExtractors = omConfig.experimental_subconscious\n      .createObservationExtractors(observation.model ?? omConfig.model)\n      .filter(extractor => !existingSlugs.has(extractor.slug));\n\n    return {\n      ...config,\n      observationalMemory: {\n        ...omConfig,\n        observation: {\n          ...observation,\n          extract: [...extract, ...subconsciousExtractors],\n        },\n      },","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/index.ts#L366-L402","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nobservationalMemory: { experimental_subconscious: Subconscious }\n// after\nobservationalMemory: { experimental_subconscious: new Subconscious({ model: 'openai/gpt-4o' }) }","handlingStrategy":"type-guard","validationCode":"const sub = config.observationalMemory?.experimental_subconscious;\nif (sub !== undefined && !(sub instanceof Subconscious)) {\n  throw new TypeError('experimental_subconscious must be created with new Subconscious(...)');\n}","typeGuard":"function isSubconscious(v: unknown): v is Subconscious {\n  return v instanceof Subconscious;\n}","tryCatchPattern":"try {\n  const memory = new Memory({ ...opts });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('must be a Subconscious instance')) {\n    // replace the config value with new Subconscious({...}) and rebuild\n  } else throw err;\n}","preventionTips":["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"],"tags":["configuration","validation","typescript","observational-memory"],"backgroundTag":"invalid-instance-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}