{"record":{"id":"537cdc3d58d47ce4","repo":"ruvnet/RuView","slug":"maxoutputbytes-must-be-a-positive-safe-integer","errorCode":null,"errorMessage":"maxOutputBytes must be a positive safe integer","messagePattern":"maxOutputBytes must be a positive safe integer","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"harness/homecore/src/process-runner.js","lineNumber":106,"sourceCode":"\nexport function runProcess(command, args = [], {\n  cwd,\n  input = '',\n  timeoutMs = 120_000,\n  signal,\n  maxOutputBytes = 1_048_576,\n  env = process.env,\n  envAllowlist = DEFAULT_ENV_ALLOWLIST,\n} = {}) {\n  if (!command || typeof command !== 'string') throw new TypeError('command must be a non-empty string');\n  if (!Array.isArray(args) || !args.every((arg) => typeof arg === 'string')) {\n    throw new TypeError('args must be an array of strings');\n  }\n  if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1_000 || timeoutMs > 1_800_000) {\n    throw new RangeError('timeoutMs must be a safe integer between 1000 and 1800000');\n  }\n  if (!Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1) {\n    throw new RangeError('maxOutputBytes must be a positive safe integer');\n  }\n  const childEnv = scrubEnvironment(env, envAllowlist);\n\n  return new Promise((resolve, reject) => {\n    const child = spawn(command, args, {\n      cwd,\n      env: childEnv,\n      detached: process.platform !== 'win32',\n      shell: false,\n      windowsHide: true,\n      stdio: ['pipe', 'pipe', 'pipe'],\n    });\n    const stdout = [];\n    const stderr = [];\n    let outputBytes = 0;\n    let overflow = false;\n    let timedOut = false;\n    let settled = false;","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/homecore/src/process-runner.js#L88-L124","documentation":"runProcess() caps captured child output with maxOutputBytes and requires a positive safe integer (>= 1, integral, <= Number.MAX_SAFE_INTEGER). Values of 0, negatives, fractions, NaN, Infinity, or numbers beyond the safe-integer range throw this RangeError before the child spawns.","triggerScenarios":"{maxOutputBytes: 0} intending 'unlimited', {maxOutputBytes: NaN} from arithmetic on undefined, {maxOutputBytes: 1e21} beyond the safe-integer range, or negative values from subtraction.","commonSituations":"Using 0 to disable the cap (unsupported), computing the cap from float math or user input, Infinity defaults leaking into options via object spread.","solutions":["Pass an explicit positive integer cap such as the default 1_048_576 or 2_097_152","Validate computed values with Number.isSafeInteger(v) && v >= 1 before the call","Do not use 0 or Infinity to mean unlimited; choose the largest acceptable cap explicitly"],"exampleFix":"// before\nawait runProcess('cargo', ['test'], { maxOutputBytes: 0 }); // meant unlimited\n\n// after\nawait runProcess('cargo', ['test'], { maxOutputBytes: 2_097_152 });","handlingStrategy":"validation","validationCode":"function normalizeMaxOutputBytes(value, fallback = 1_048_576) {\n  return Number.isSafeInteger(value) && value >= 1 ? value : fallback;\n}\n// use: runProcess(cmd, args, { maxOutputBytes: normalizeMaxOutputBytes(cfg.limit) })","typeGuard":"/** @param {unknown} v @returns {v is number} */\nfunction isValidMaxOutputBytes(v) {\n  return Number.isSafeInteger(v) && v >= 1;\n}","tryCatchPattern":"try {\n  await runProcess(cmd, args, { maxOutputBytes });\n} catch (error) {\n  if (error instanceof RangeError && error.message.includes('maxOutputBytes')) {\n    throw new Error(`maxOutputBytes=${maxOutputBytes} must be a positive safe integer`);\n  }\n  throw error;\n}","preventionTips":["Never use 0 or Infinity to request unlimited output — pick an explicit large cap","Treat any NaN from computed limits as a configuration bug and fall back to a sane default before calling","Remember the cap exists to bound memory: size it to the largest real output you expect"],"tags":["validation","process","rangeerror","limits"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}