mastra-ai/mastra · error · Error

Subconscious activity.recentUpdates must be an integer betwe

Error message

Subconscious activity.recentUpdates must be an integer between 1 and ${MAX_RECENT_UPDATES}.

What it means

The Subconscious constructor validates config.activity.recentUpdates: when activity is enabled (not false), recentUpdates must be a positive integer no greater than MAX_RECENT_UPDATES, or exactly false to disable. Any other value (non-integer, 0, too large) throws. This bounds how many recent memory updates are injected into prompts.

Source

Thrown at packages/memory/src/processors/observational-memory/subconscious/index.ts:105

  readonly resolved: Readonly<ResolvedSubconsciousConfig>;

  constructor(config: SubconsciousConfig = {}) {
    const observation = config.observation ?? ['capture', 'remind'];
    const reflection = config.reflection ?? ['curate', 'learn'];
    assertUniqueNames(observation, 'observation');
    assertUniqueNames(reflection, 'reflection');

    const maxSteps = config.maxSteps === undefined ? undefined : boundedSteps(config, DEFAULT_MAX_STEPS);
    for (const entry of observation) this.#validateObservationEntry(entry);
    for (const entry of reflection) this.#validateReflectionEntry(entry);

    const recentUpdates =
      config.activity === false ? false : (config.activity?.recentUpdates ?? DEFAULT_RECENT_UPDATES);
    if (
      recentUpdates !== false &&
      (!Number.isInteger(recentUpdates) || recentUpdates < 1 || recentUpdates > MAX_RECENT_UPDATES)
    ) {
      throw new Error(`Subconscious activity.recentUpdates must be an integer between 1 and ${MAX_RECENT_UPDATES}.`);
    }

    const pins =
      config.pins === undefined || config.pins === false
        ? false
        : {
            maxPins: (config.pins === true ? undefined : config.pins.maxPins) ?? DEFAULT_MAX_PINS,
            maxCharacters:
              (config.pins === true ? undefined : config.pins.maxCharacters) ?? DEFAULT_PINNED_MAX_CHARACTERS,
            capturePinning: (config.pins === true ? undefined : config.pins.capturePinning) ?? false,
          };
    if (pins !== false) {
      if (!Number.isInteger(pins.maxPins) || pins.maxPins < 1) {
        throw new Error('Subconscious pins.maxPins must be a positive integer.');
      }
      if (
        !Number.isInteger(pins.maxCharacters) ||
        pins.maxCharacters < 1 ||

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Set activity.recentUpdates to a positive integer within [1, MAX_RECENT_UPDATES], or false to disable.
  2. Parse and coerce config values (Number(), strict boolean handling) before constructing Subconscious.
  3. Omit recentUpdates to use DEFAULT_RECENT_UPDATES.

Example fix

// before
new Subconscious({ activity: { recentUpdates: 0 } })
// after
new Subconscious({ activity: { recentUpdates: 5 } })
Defensive patterns

Strategy: validation

Validate before calling

const ru = config.activity === false ? false : config.activity?.recentUpdates;
if (ru !== false && ru !== undefined && (!Number.isInteger(ru) || ru < 1 || ru > MAX_RECENT_UPDATES)) {
  throw new Error(`recentUpdates must be an integer between 1 and ${MAX_RECENT_UPDATES}, or false`);
}

Type guard

function isValidRecentUpdates(v: unknown): v is number | false {
  return v === false || (Number.isInteger(v) && (v as number) >= 1 && (v as number) <= MAX_RECENT_UPDATES);
}

Try / catch

try {
  const sub = new Subconscious(config);
} catch (err) {
  if (err.message.includes('recentUpdates')) {
    throw new ConfigError('Invalid activity.recentUpdates in Subconscious config');
  } else throw err;
}

Prevention

When it happens

Trigger: Configuring activity: { recentUpdates: 0 }, a float, a non-integer, or a value above MAX_RECENT_UPDATES; passing a string from parsed JSON/env config.

Common situations: JSON config parsed from a file yielding a string like "10"; tuning the value upward past the cap; confusing 'false' (string) with false (boolean) from env vars.

Related errors


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