{"record":{"id":"ac44c87b5e3b08ae","repo":"stablyai/orca","slug":"orca-pty-bench-pty-count-must-be-positive-receive","errorCode":null,"errorMessage":"ORCA_PTY_BENCH_PTY_COUNT must be positive, received ${PTY_COUNT}","messagePattern":"ORCA_PTY_BENCH_PTY_COUNT must be positive, received (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/pty-batch-flush-benchmark.mjs","lineNumber":21,"sourceCode":"import v8 from 'node:v8'\n\nconst PTY_COUNT = Number.parseInt(process.env.ORCA_PTY_BENCH_PTY_COUNT ?? '24', 10)\nconst PAYLOAD_CHARS = Number.parseInt(process.env.ORCA_PTY_BENCH_PAYLOAD_CHARS ?? '262144', 10)\nconst RUNS = Number.parseInt(process.env.ORCA_PTY_BENCH_RUNS ?? '30', 10)\nconst MEASURE_TIMER_DELAYS = process.env.ORCA_PTY_BENCH_MEASURE_TIMER_DELAYS !== '0'\nconst INGRESS_CHUNKS = Number.parseInt(process.env.ORCA_PTY_BENCH_INGRESS_CHUNKS ?? '96', 10)\nconst INGRESS_CHUNK_CHARS = Number.parseInt(process.env.ORCA_PTY_BENCH_INGRESS_CHARS ?? '65536', 10)\nconst CHUNK_CHARS = 16 * 1024\nconst MAX_WRITES_PER_SLICE = 2\nconst RECENT_PTY_OUTPUT_LIMIT = 4096\nconst MAX_TAIL_LINES = 2000\nconst MAX_TAIL_CHARS = 256 * 1024\nconst MAX_TAIL_PARTIAL_CHARS = 4000\nconst OSC_TITLE_RE = /\\x1b\\]([012]);([^\\x07\\x1b]*?)(?:\\x07|\\x1b\\\\)/g\nconst URL_CANDIDATE_PATTERN = /\\bhttps?:\\/\\/[^\\s<>\"'`]+/gi\n\nif (!Number.isInteger(PTY_COUNT) || PTY_COUNT <= 0) {\n  throw new Error(`ORCA_PTY_BENCH_PTY_COUNT must be positive, received ${PTY_COUNT}`)\n}\nif (!Number.isInteger(PAYLOAD_CHARS) || PAYLOAD_CHARS <= 0) {\n  throw new Error(`ORCA_PTY_BENCH_PAYLOAD_CHARS must be positive, received ${PAYLOAD_CHARS}`)\n}\nif (!Number.isInteger(RUNS) || RUNS <= 0) {\n  throw new Error(`ORCA_PTY_BENCH_RUNS must be positive, received ${RUNS}`)\n}\nif (!Number.isInteger(INGRESS_CHUNKS) || INGRESS_CHUNKS <= 0) {\n  throw new Error(`ORCA_PTY_BENCH_INGRESS_CHUNKS must be positive, received ${INGRESS_CHUNKS}`)\n}\nif (!Number.isInteger(INGRESS_CHUNK_CHARS) || INGRESS_CHUNK_CHARS <= 0) {\n  throw new Error(`ORCA_PTY_BENCH_INGRESS_CHARS must be positive, received ${INGRESS_CHUNK_CHARS}`)\n}\n\nfunction makePendingData() {\n  const pending = new Map()\n  for (let index = 0; index < PTY_COUNT; index++) {\n    pending.set(`pty-${index}`, `${index}:`.padEnd(PAYLOAD_CHARS, 'x'))","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/pty-batch-flush-benchmark.mjs#L3-L39","documentation":"Thrown by config/scripts/pty-batch-flush-benchmark.mjs at startup when the ORCA_PTY_BENCH_PTY_COUNT environment variable fails the guard `!Number.isInteger(PTY_COUNT) || PTY_COUNT <= 0`. PTY_COUNT drives how many pseudo-terminal slots the PTY batch-flush benchmark simulates (default 24), so a non-positive or non-integer value would make the benchmark loop degenerate. Because Number.parseInt returns NaN for non-numeric input and Number.isInteger(NaN) is false, garbage values trip the same guard as zero or negative ones.","triggerScenarios":"Run `node config/scripts/pty-batch-flush-benchmark.mjs` with ORCA_PTY_BENCH_PTY_COUNT set to `0`, `-1`, `2.5` (parseFloat would differ but parseInt floors), an empty string, or any non-numeric token like `abc`. The module-level parse at line 5 runs unconditionally before any benchmark logic, so the throw happens before main() executes.","commonSituations":"A developer shells out with a typo'd env var (e.g. `ORCA_PTY_BENCH_PTY_COUNT=zero`), copies a CI snippet that leaves the value blank (`PTY_COUNT=`), or reuses a harness that previously set the count to 0 to skip a run. Exporting the var via a script that conditionally sets it to an empty string also hits this.","solutions":["Unset ORCA_PTY_BENCH_PTY_COUNT to fall back to the default of 24, or set it to a positive integer.","If scripting, default the value explicitly: `PTY_COUNT=${ORCA_PTY_BENCH_PTY_COUNT:-24}` before invoking.","Validate the env in your wrapper before running: reject non-integer or non-positive values with a clear message."],"exampleFix":"// before\nORCA_PTY_BENCH_PTY_COUNT=0 node config/scripts/pty-batch-flush-benchmark.mjs\n\n// after\nORCA_PTY_BENCH_PTY_COUNT=24 node config/scripts/pty-batch-flush-benchmark.mjs","handlingStrategy":"validation","validationCode":"// Validate before running the benchmark script\nconst raw = process.env.ORCA_PTY_BENCH_PTY_COUNT\nif (raw !== undefined && (!Number.isInteger(Number(raw)) || Number(raw) <= 0)) {\n  throw new Error(`Refusing to run: ORCA_PTY_BENCH_PTY_COUNT='${raw}' must be a positive integer`)\n}","typeGuard":"function isPositiveIntEnv(value) {\n  if (value === undefined) return true // default applies\n  const n = Number(value)\n  return Number.isInteger(n) && n > 0\n}","tryCatchPattern":null,"preventionTips":["Default unset benchmark env vars explicitly in your shell: `ORCA_PTY_BENCH_PTY_COUNT=${ORCA_PTY_BENCH_PTY_COUNT:-24}`.","Never set benchmark counts to 0 to 'skip' a run — unset them instead.","Add a preflight env-validation step in CI before invoking the benchmark."],"tags":["benchmark","env","config","pty","validation"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}