{"record":{"id":"4931f157888a10f0","repo":"mastra-ai/mastra","slug":"regexfilterprocessor-streamcarryoversize-must-be-a","errorCode":null,"errorMessage":"RegexFilterProcessor streamCarryoverSize must be a positive safe integer","messagePattern":"RegexFilterProcessor streamCarryoverSize must be a positive safe integer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/processors/regex-filter.ts","lineNumber":331,"sourceCode":"   * through the same callback, driven by the processor runner when it catches\n   * the TripWire.\n   */\n  public onViolation?: (violation: ProcessorViolation) => void | Promise<void>;\n\n  constructor(options: RegexFilterOptions) {\n    const presetRules = (options.presets ?? []).flatMap(preset => PRESET_MAP[preset] ?? []);\n    this.rules = [...presetRules, ...(options.rules ?? [])];\n\n    if (this.rules.length === 0) {\n      throw new Error('RegexFilterProcessor requires at least one rule or preset');\n    }\n\n    this.strategy = options.strategy ?? 'block';\n    this.phase = options.phase ?? 'all';\n    this.includeRedactedValues = options.includeRedactedValues ?? false;\n    this.streamCarryoverSize = options.streamCarryoverSize ?? STREAM_CARRYOVER_SIZE;\n    if (!Number.isSafeInteger(this.streamCarryoverSize) || this.streamCarryoverSize < 1) {\n      throw new Error('RegexFilterProcessor streamCarryoverSize must be a positive safe integer');\n    }\n  }\n\n  /**\n   * Run every rule over the text and collect all matches, grouped by rule in\n   * declaration order. Matches may overlap; callers that rewrite text must\n   * de-overlap them first.\n   */\n  private collectMatches(text: string): RuleMatch[] {\n    const matches: RuleMatch[] = [];\n    for (const rule of this.rules) {\n      const regex = compilePattern(rule);\n      let m: RegExpExecArray | null;\n      while ((m = regex.exec(text)) !== null) {\n        matches.push({ rule, start: m.index, end: m.index + m[0].length });\n        if (!regex.global) break;\n        if (m[0].length === 0) {\n          regex.lastIndex++;","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/processors/regex-filter.ts#L313-L349","documentation":"RegexFilterProcessor keeps a carryover buffer when filtering streamed text so matches spanning chunk boundaries are handled correctly. The `streamCarryoverSize` option must be a positive safe integer (>= 1); anything else (0, negative, NaN, Infinity, non-integer) makes the buffer logic invalid, so the constructor throws. The default is `STREAM_CARRYOVER_SIZE`.","triggerScenarios":"Passing `streamCarryoverSize: 0`, a negative number, a float like `2.5`, `Infinity`, `NaN`, or a string in `new RegexFilterProcessor({ streamCarryoverSize: ... })`. `Number.isSafeInteger` fails for all non-integer/infinite values; `< 1` catches 0 and negatives.","commonSituations":"Reading the value from a config file or env var without parsing (`'1000'` as string is not a safe integer), computing it with division that yields a fraction, or assuming 0 means 'unlimited'.","solutions":["Set `streamCarryoverSize` to a positive whole number (e.g. 256 or 1024).","Omit the option entirely to use the built-in default `STREAM_CARRYOVER_SIZE`.","Parse env/config values with `Number.parseInt`/`Number` and validate with `Number.isSafeInteger(v) && v >= 1` before passing.","Use `Math.max(1, Math.floor(value))` to sanitize computed values."],"exampleFix":"// before\nnew RegexFilterProcessor({ rules, streamCarryoverSize: Number(process.env.CARRYOVER) });\n// after\nconst size = Number.parseInt(process.env.CARRYOVER ?? '', 10);\nnew RegexFilterProcessor({ rules, streamCarryoverSize: Number.isSafeInteger(size) && size >= 1 ? size : undefined });","handlingStrategy":"validation","validationCode":"const size = options.streamCarryoverSize;\nif (size !== undefined && !(Number.isSafeInteger(size) && size >= 1)) {\n  throw new TypeError(`streamCarryoverSize must be a positive safe integer, got ${size}`);\n}","typeGuard":"function isValidCarryoverSize(v: unknown): v is number {\n  return typeof v === 'number' && Number.isSafeInteger(v) && v >= 1;\n}","tryCatchPattern":"try {\n  return new RegexFilterProcessor(opts);\n} catch (e) {\n  if (e.message.includes('streamCarryoverSize')) {\n    return new RegexFilterProcessor({ ...opts, streamCarryoverSize: undefined }); // fall back to default\n  }\n  throw e;\n}","preventionTips":["Parse numeric config with Number()/parseInt and validate before use.","Rely on the default instead of hand-rolling a value unless streaming behavior demands it.","Remember strings from env vars are never safe integers — coerce explicitly."],"tags":["configuration","validation","streaming","constructor"],"backgroundTag":"invalid-parameter-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}