{"record":{"id":"66e2d3db659eb028","repo":"JuliusBrussee/caveman","slug":"caveman-build-runner-timeout-must-be-a-positive-i","errorCode":null,"errorMessage":"caveman build: runner timeout must be a positive integer","messagePattern":"caveman build: runner timeout must be a positive integer","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/build.ts","lineNumber":438,"sourceCode":"    ...lockWithoutBuild,\n    build_sha256: buildSha256,\n  };\n  return {\n    ...base,\n    status: \"locked\",\n    best_observed_plan_id: selected.candidate.plan.plan_id,\n    baseline_catalog_cost_usd_per_task: baselineCompleted.costPerTask,\n    selected_catalog_cost_usd_per_task: selected.costPerTask,\n    lock,\n  };\n}\n\nasync function withDeadline<T>(\n  invoke: (signal: AbortSignal) => Promise<T>,\n  timeoutMs: number,\n): Promise<T> {\n  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {\n    throw new Error(\"caveman build: runner timeout must be a positive integer\");\n  }\n  const controller = new AbortController();\n  let timer: NodeJS.Timeout | undefined;\n  const deadline = new Promise<never>((_resolve, reject) => {\n    timer = setTimeout(() => {\n      const error = new Error(\"cave_build_runner_timeout\");\n      controller.abort(error);\n      reject(error);\n    }, timeoutMs);\n  });\n  try {\n    // Abort asks cooperative runners to stop; the independent race prevents an\n    // adapter that ignores AbortSignal from pinning the compiler forever. A late\n    // runner can never mint a lock or known actual cost after this branch returns.\n    return await Promise.race([Promise.resolve().then(() => invoke(controller.signal)), deadline]);\n  } finally {\n    if (timer !== undefined) clearTimeout(timer);\n  }","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/build.ts#L420-L456","documentation":"withDeadline wraps runner invocations with an AbortSignal timeout and first validates timeoutMs. This error means the timeout was not a safe positive integer (it must be a whole number of milliseconds, > 0, within Number.MAX_SAFE_INTEGER). The library throws before starting any runner work.","triggerScenarios":"Calling withDeadline (directly or via compile's runner path) with timeoutMs = 0, negative, fractional (e.g. 1.5), NaN, or Infinity.","commonSituations":"A config timeout expressed in seconds (2) misread as milliseconds then divided (0.002); an unset numeric field defaulting to 0; parsing a duration string with parseFloat yielding a fraction or NaN.","solutions":["Pass a positive integer milliseconds value, e.g. 30_000","Convert with Math.round/ceil and validate with Number.isSafeInteger before calling","Fix duration parsing so unit conversion yields whole milliseconds","Replace unset/0 defaults with an explicit sane timeout"],"exampleFix":"// before\nawait withDeadline(invoke, config.timeoutSeconds * 0.001);\n// after\nawait withDeadline(invoke, Math.ceil(config.timeoutSeconds * 1000));","handlingStrategy":"validation","validationCode":"if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {\n  throw new Error(`runner timeout must be a positive integer ms, got ${timeoutMs}`);\n}","typeGuard":"function isValidTimeoutMs(v: unknown): v is number {\n  return typeof v === \"number\" && Number.isSafeInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await withDeadline(invoke, timeoutMs);\n} catch (e) {\n  if (e instanceof Error && e.message === \"caveman build: runner timeout must be a positive integer\") {\n    // fix the timeout source (unit conversion / unset default)\n  } else throw e;\n}","preventionTips":["Keep all timeouts in whole milliseconds end to end","Convert seconds to ms with Math.ceil before passing","Guard parsed duration strings for NaN/fractions"],"tags":["timeout","validation","integer"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}