{"record":{"id":"766c0e702e4815de","repo":"mastra-ai/mastra","slug":"subconscious-maxsteps-must-be-an-integer-between-1","errorCode":null,"errorMessage":"Subconscious maxSteps must be an integer between 1 and ${MAX_MAX_STEPS}.","messagePattern":"Subconscious maxSteps must be an integer between 1 and (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/index.ts","lineNumber":46,"sourceCode":"\nfunction entryName(entry: string | { name: string }): string {\n  return typeof entry === 'string' ? entry : entry.name.trim();\n}\n\nfunction assertUniqueNames(entries: Array<string | { name: string }>, phase: string): void {\n  const seen = new Set<string>();\n  for (const entry of entries) {\n    const name = entryName(entry);\n    if (!name) throw new Error(`Subconscious ${phase} agent name is required.`);\n    if (seen.has(name)) throw new Error(`Duplicate Subconscious ${phase} agent: ${name}`);\n    seen.add(name);\n  }\n}\n\nfunction boundedSteps(entry: { maxSteps?: number } | undefined, fallback: number): number {\n  const steps = entry?.maxSteps ?? fallback;\n  if (!Number.isInteger(steps) || steps < 1 || steps > MAX_MAX_STEPS) {\n    throw new Error(`Subconscious maxSteps must be an integer between 1 and ${MAX_MAX_STEPS}.`);\n  }\n  return steps;\n}\n\nfunction resolveExtractor(entry: SubconsciousObservationEntry): ResolvedSubconsciousAgent {\n  const config = typeof entry === 'string' ? undefined : entry;\n  const name = entryName(entry);\n  return {\n    name,\n    instructions: config?.instructions,\n    builtIn: name === 'capture',\n  };\n}\n\nfunction resolveAgent(\n  entry: string | { name: string; instructions?: string; model?: any; agent?: any; maxSteps?: number },\n  builtIns: Set<string>,\n  globalModel: SubconsciousConfig['model'],","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/index.ts#L28-L64","documentation":"boundedSteps clamps/validates each Subconscious agent's maxSteps to an integer within [1, MAX_MAX_STEPS]. If a configured maxSteps is a non-integer, zero, negative, or above the hard cap, the constructor/resolver throws. This protects against runaway agent loops.","triggerScenarios":"Setting maxSteps: 0, maxSteps: -1, maxSteps: 2.5, or maxSteps exceeding MAX_MAX_STEPS on any observation/reflection agent entry, or on Subconscious defaults.","commonSituations":"Reading maxSteps from env/config files as strings or floats; copying examples that use very large loop counts; intending 'unlimited' and passing 0 or Infinity.","solutions":["Set maxSteps to a positive integer within the allowed cap (check MAX_MAX_STEPS in the module).","Coerce env/config values with Number() and validate Number.isInteger before constructing.","Omit maxSteps to use the built-in fallback."],"exampleFix":"// before\nnew Subconscious({ observation: [{ name: 'watch', maxSteps: 0 }] })\n// after\nnew Subconscious({ observation: [{ name: 'watch', maxSteps: 5 }] })","handlingStrategy":"validation","validationCode":"function assertBoundedSteps(n: unknown): asserts n is number {\n  if (!Number.isInteger(n) || (n as number) < 1) throw new Error(`maxSteps must be an integer between 1 and ${MAX_MAX_STEPS}`);\n}","typeGuard":"function isValidMaxSteps(n: unknown): n is number {\n  return Number.isInteger(n) && n >= 1 && n <= MAX_MAX_STEPS;\n}","tryCatchPattern":"try {\n  const sub = new Subconscious(config);\n} catch (err) {\n  if (err.message.includes('maxSteps must be an integer')) {\n    throw new ConfigError('Fix maxSteps in Subconscious config (integer within 1..MAX_MAX_STEPS)');\n  } else throw err;\n}","preventionTips":["Coerce env/config values with Number() and validate integrality.","Never use 0/Infinity to mean 'unlimited'; omit maxSteps for the default.","Type maxSteps as a branded positive-int type in your config schema (zod: z.number().int().min(1).max(MAX_MAX_STEPS))."],"tags":["configuration","validation","subconscious"],"backgroundTag":"range-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}