{"record":{"id":"e36c112c0854e058","repo":"stablyai/orca","slug":"orca-replay-bench-seconds-must-be-positive-receiv","errorCode":null,"errorMessage":"ORCA_REPLAY_BENCH_SECONDS must be positive, received ${SECONDS}","messagePattern":"ORCA_REPLAY_BENCH_SECONDS must be positive, received (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/relay-replay-buffer-benchmark.mjs","lineNumber":21,"sourceCode":"//\n// appendReplayBuffer did `buffered += data` then, over the cap, `buffered.slice(-CAP)`.\n// Once a PTY has produced CAP bytes -- which a long-lived shell does almost immediately\n// -- every subsequent chunk flattened and copied the whole 100 KB window. The append is\n// called per raw node-pty emission, before batching, so it is per chunk, not per flush.\n//\n// The fix reuses RecentPtyOutputBuffer: keep chunks, drop from the head, and defer the\n// join to read(), which only attach/adopt/revive call.\n//\n// Both arms are compared for an identical retained tail before timing.\n//\n// Run with:  node config/scripts/relay-replay-buffer-benchmark.mjs\nimport { readFileSync } from 'node:fs'\nimport { performance } from 'node:perf_hooks'\n\nconst ROUNDS = 6\nconst SECONDS = Number(process.env.ORCA_REPLAY_BENCH_SECONDS ?? '1')\nif (!Number.isFinite(SECONDS) || SECONDS <= 0) {\n  throw new Error(`ORCA_REPLAY_BENCH_SECONDS must be positive, received ${SECONDS}`)\n}\n\n// Why re-read the sources: the claim is that the relay now appends into a chunk deque\n// with the relay's own cap. If either reverts, these numbers stop meaning what they say.\nconst HANDLER_SOURCE = readFileSync(\n  new URL('../../src/relay/pty-handler.ts', import.meta.url),\n  'utf8'\n)\nif (!/managed\\.buffered\\.append\\(/.test(HANDLER_SOURCE)) {\n  throw new Error('relay no longer appends into a chunk deque; this benchmark is stale')\n}\nconst capMatch = HANDLER_SOURCE.match(/REPLAY_BUFFER_MAX = ([\\d *]+)/)\nif (!capMatch) {\n  throw new Error('REPLAY_BUFFER_MAX not found; this benchmark is stale')\n}\n// The regex admits only digits, spaces, and `*`, so the literal is a plain product.\nconst REPLAY_BUFFER_MAX = capMatch[1]\n  .split('*')","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/relay-replay-buffer-benchmark.mjs#L3-L39","documentation":"Thrown by the relay replay-buffer benchmark when ORCA_REPLAY_BENCH_SECONDS is not a finite positive number. The env var scales the per-second PTY chunk count into a fixture (chunksPerSecond * SECONDS), so zero/negative would build an empty fixture and non-numeric would propagate NaN into the timing loop. The default is '1'.","triggerScenarios":"Running the benchmark with ORCA_REPLAY_BENCH_SECONDS set to '0', a negative number like '-2', or a non-numeric string like 'fast' or ''. The check uses Number.isFinite() so Infinity and NaN both fail.","commonSituations":"A developer sets the value to 0 trying to run a quick sanity check, or leaves an empty assignment (ORCA_REPLAY_BENCH_SECONDS=) in a shell command, or typos the value.","solutions":["Omit the env var entirely to use the default of '1' second of simulated output.","Set ORCA_REPLAY_BENCH_SECONDS to a positive integer or decimal, e.g. ORCA_REPLAY_BENCH_SECONDS=2."],"exampleFix":"// before\nORCA_REPLAY_BENCH_SECONDS=0 node config/scripts/relay-replay-buffer-benchmark.mjs\n// after\nORCA_REPLAY_BENCH_SECONDS=2 node config/scripts/relay-replay-buffer-benchmark.mjs","handlingStrategy":"validation","validationCode":"const raw = process.env.ORCA_REPLAY_BENCH_SECONDS ?? '1'\nconst seconds = Number(raw)\nif (!Number.isFinite(seconds) || seconds <= 0) {\n  throw new Error(`Set ORCA_REPLAY_BENCH_SECONDS to a positive number, got ${raw}`)\n}","typeGuard":"function isPositiveFinite(value) {\n  return typeof value === 'number' && Number.isFinite(value) && value > 0\n}","tryCatchPattern":null,"preventionTips":["Wrap env-var reads in a shared positive-number validator so all benchmarks reject bad values consistently.","Document default values in the script header comment so developers know they can omit the var."],"tags":["benchmark","env-var","validation","relay"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}