{"record":{"id":"3f1c7fa585614f6c","repo":"mastra-ai/mastra","slug":"observation-previousobservertokens-must-be-false-o","errorCode":null,"errorMessage":"observation.previousObserverTokens must be false or a finite number >= 0, got ${this.observationConfig.previousObserverTokens}","messagePattern":"observation\\.previousObserverTokens must be false or a finite number >= 0, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/observational-memory.ts","lineNumber":1038,"sourceCode":"        );\n      }\n      if (!this.observationConfig.bufferTokens) {\n        throw new Error(\n          `observation.blockAfter requires observation.bufferTokens to be set (blockAfter only applies when async buffering is enabled)`,\n        );\n      }\n    }\n\n    // Validate observer context optimization options\n    if (\n      this.observationConfig.previousObserverTokens !== undefined &&\n      this.observationConfig.previousObserverTokens !== false\n    ) {\n      if (\n        !Number.isFinite(this.observationConfig.previousObserverTokens) ||\n        this.observationConfig.previousObserverTokens < 0\n      ) {\n        throw new Error(\n          `observation.previousObserverTokens must be false or a finite number >= 0, got ${this.observationConfig.previousObserverTokens}`,\n        );\n      }\n    }\n\n    // Validate reflection bufferActivation (0-1 float range)\n    if (this.reflectionConfig.bufferActivation !== undefined) {\n      if (this.reflectionConfig.bufferActivation <= 0 || this.reflectionConfig.bufferActivation > 1) {\n        throw new Error(\n          `reflection.bufferActivation must be in range (0, 1], got ${this.reflectionConfig.bufferActivation}`,\n        );\n      }\n    }\n\n    // Validate reflection blockAfter\n    if (this.reflectionConfig.blockAfter !== undefined) {\n      const reflectionThreshold = getMaxThreshold(this.reflectionConfig.observationTokens);\n      if (this.reflectionConfig.blockAfter < reflectionThreshold) {","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/observational-memory.ts#L1020-L1056","documentation":"observation.previousObserverTokens controls how many tokens from prior observer output are carried into the next observation context. It must be either false (feature disabled) or a finite non-negative number; NaN, Infinity, negative values, or other non-numeric junk are rejected at construction so a broken value can't corrupt observer context assembly.","triggerScenarios":"new ObservationalMemory({ observation: { previousObserverTokens: -100 } }), previousObserverTokens: Infinity/NaN (often from division or parseInt of a bad string), or a non-number like a string '2000' reaching the check.","commonSituations":"Parsing the value from env/config without validation (parseInt returns NaN); computing a limit with division by zero producing Infinity; using -1 to mean 'unlimited' when the API expects false for disabled.","solutions":["Set previousObserverTokens to a finite number >= 0 (e.g. 2000).","Use false to disable carrying previous observer output, instead of -1 or 0-as-disabled.","Validate/parse config values: Number.isFinite(v) && v >= 0 before passing them in."],"exampleFix":"// before\nnew ObservationalMemory({ observation: { previousObserverTokens: -1 } });\n// after\nnew ObservationalMemory({ observation: { previousObserverTokens: false } }); // or 2000","handlingStrategy":"validation","validationCode":"const pot = observationConfig.previousObserverTokens;\nif (pot !== undefined && pot !== false && (!Number.isFinite(pot) || pot < 0)) {\n  throw new Error(`previousObserverTokens must be false or a finite number >= 0, got ${pot}`);\n}","typeGuard":"function isValidPreviousObserverTokens(v: unknown): v is number | false {\n  return v === false || (typeof v === 'number' && Number.isFinite(v) && v >= 0);\n}","tryCatchPattern":null,"preventionTips":["Use false to disable, never -1 or 0.","Guard env-derived values with Number.isFinite before passing them.","Type the config field as `number | false | undefined` so TS catches string values."],"tags":["configuration","validation","observational-memory"],"backgroundTag":"invalid-config-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}