mastra-ai/mastra · error

observation.blockAfter (${this.observationConfig.blockAfter}

Error message

observation.blockAfter (${this.observationConfig.blockAfter}) must be >= messageTokens (${observationThreshold})

What it means

observation.blockAfter marks a token position after which observation blocking (skipping reflection on older content) begins. It only makes sense if it is at or beyond the messageTokens threshold — otherwise every batch would immediately qualify for blocking — and it only applies when async buffering (bufferTokens) is enabled. Both conditions are validated at construction time.

Source

Thrown at packages/memory/src/processors/observational-memory/observational-memory.ts:1018

      if (this.observationConfig.bufferActivation > 1 && this.observationConfig.bufferActivation < 1000) {
        throw new Error(
          `observation.bufferActivation must be <= 1 (ratio) or >= 1000 (absolute token retention), got ${this.observationConfig.bufferActivation}`,
        );
      }
      if (
        this.observationConfig.bufferActivation >= 1000 &&
        this.observationConfig.bufferActivation >= observationThreshold
      ) {
        throw new Error(
          `observation.bufferActivation as absolute retention (${this.observationConfig.bufferActivation}) must be less than messageTokens (${observationThreshold})`,
        );
      }
    }

    // Validate observation blockAfter
    if (this.observationConfig.blockAfter !== undefined) {
      if (this.observationConfig.blockAfter < observationThreshold) {
        throw new Error(
          `observation.blockAfter (${this.observationConfig.blockAfter}) must be >= messageTokens (${observationThreshold})`,
        );
      }
      if (!this.observationConfig.bufferTokens) {
        throw new Error(
          `observation.blockAfter requires observation.bufferTokens to be set (blockAfter only applies when async buffering is enabled)`,
        );
      }
    }

    // Validate observer context optimization options
    if (
      this.observationConfig.previousObserverTokens !== undefined &&
      this.observationConfig.previousObserverTokens !== false
    ) {
      if (
        !Number.isFinite(this.observationConfig.previousObserverTokens) ||
        this.observationConfig.previousObserverTokens < 0

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Set blockAfter to a value >= the messageTokens threshold (e.g. threshold * 2).
  2. Ensure observation.bufferTokens is also set, since blockAfter requires async buffering.
  3. Remove blockAfter if you don't need observation blocking.

Example fix

// before
new ObservationalMemory({ observation: { messageTokens: 4000, blockAfter: 2000 } });
// after
new ObservationalMemory({ observation: { messageTokens: 4000, bufferTokens: 1000, blockAfter: 8000 } });
Defensive patterns

Strategy: validation

Validate before calling

const observationThreshold = getMaxThreshold(observationConfig.messageTokens);
if (observationConfig.blockAfter !== undefined && observationConfig.blockAfter < observationThreshold) {
  throw new Error(`blockAfter (${observationConfig.blockAfter}) must be >= messageTokens (${observationThreshold})`);
}

Prevention

When it happens

Trigger: new ObservationalMemory({ observation: { messageTokens: 4000, blockAfter: 2000, bufferTokens: 1000 } }) — blockAfter below the threshold; or setting blockAfter without bufferTokens (see sibling error for that case).

Common situations: Setting blockAfter as 'how many tokens back to block' instead of an absolute position >= threshold; enabling blockAfter on a synchronous (unbuffered) setup where it has no effect.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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