{"record":{"id":"6f1012cd2d39fcd2","repo":"JuliusBrussee/caveman","slug":"caveman-agent-latency-guardrail-requires-positive","errorCode":null,"errorMessage":"caveman agent: latency guardrail requires positive integer p95_ms","messagePattern":"caveman agent: latency guardrail requires positive integer p95_ms","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/primitives.ts","lineNumber":454,"sourceCode":"  approved?: boolean;\n  required?: boolean;\n  input: unknown;\n  tools?: { mode: \"fixture\" | \"live\"; sandbox?: string };\n  quality: QualityGrader[];\n  guardrails?: EvalGuardrail[];\n}): EvalDefinition {\n  if (options.id.trim() === \"\") throw new Error(\"caveman agent: eval id is required\");\n  if (options.quality.length === 0) throw new Error(\"caveman agent: eval needs at least one quality grader\");\n  const known = new Set([\"contains\", \"tool_called\", \"exact_match\", \"json_schema\"]);\n  for (const grader of options.quality) {\n    if (!known.has(grader.type)) {\n      throw new Error(`caveman agent: unknown grader ${(grader as { type: string }).type}`);\n    }\n  }\n  for (const guardrail of options.guardrails ?? []) {\n    if (guardrail.type === \"latency_threshold\" &&\n        (!Number.isSafeInteger(guardrail.p95_ms) || guardrail.p95_ms <= 0)) {\n      throw new Error(\"caveman agent: latency guardrail requires positive integer p95_ms\");\n    }\n    if (guardrail.type === \"error_rate\" &&\n        (!Number.isFinite(guardrail.max) || guardrail.max < 0 || guardrail.max > 1)) {\n      throw new Error(\"caveman agent: error-rate guardrail max must be in [0,1]\");\n    }\n  }\n  const tools = options.tools ?? { mode: \"fixture\" as const };\n  if (tools.mode === \"live\" && !tools.sandbox) {\n    throw new Error(\"caveman agent: live eval tools require an explicit sandbox\");\n  }\n  return Object.freeze({\n    kind: \"eval\",\n    id: options.id,\n    approved: options.approved ?? false,\n    required: options.required ?? true,\n    input: options.input,\n    tools,\n    quality: Object.freeze([...options.quality]),","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/agent/src/primitives.ts#L436-L472","documentation":"Thrown by evalFixture() when a guardrail of type 'latency_threshold' has a p95_ms that is not a safe positive integer. The latency guardrail asserts a p95 latency budget in whole milliseconds, so 0, negatives, fractions, and NaN are rejected when the fixture is defined.","triggerScenarios":"Passing guardrails: [{ type: 'latency_threshold', p95_ms: 0 }], p95_ms: -1000, p95_ms: 1500.5, or p95_ms from unparsed string config.","commonSituations":"Converting seconds-based SLOs ('0.5s') to milliseconds and passing 0.5*1000 as a float is fine — but passing 0.5 (forgot to multiply) or a seconds value (500 meaning ms) misconfigures the budget; strings from JSON SLO files.","solutions":["Pass a whole positive millisecond count, e.g. p95_ms: 2000","Convert and round other units at the boundary: p95_ms: Math.max(1, Math.round(sloSeconds * 1000))","Validate guardrail objects from config against the p95_ms > 0 integer rule before building fixtures"],"exampleFix":"// before\nevalFixture({ id: 'e1', input: q, quality: q1, guardrails: [{ type: 'latency_threshold', p95_ms: 0.5 }] });\n\n// after\nevalFixture({ id: 'e1', input: q, quality: q1, guardrails: [{ type: 'latency_threshold', p95_ms: 500 }] });","handlingStrategy":"validation","validationCode":"function toP95Ms(raw: unknown): number {\n  const n = typeof raw === 'number' ? raw : Number(raw);\n  if (!Number.isSafeInteger(n) || n <= 0) throw new Error(`p95_ms must be a positive integer (milliseconds), got ${String(raw)}`);\n  return n;\n}","typeGuard":"function isP95Ms(value: unknown): value is number { return typeof value === 'number' && Number.isSafeInteger(value) && value > 0; }","tryCatchPattern":null,"preventionTips":["Store SLOs in milliseconds as integers from the start","Math.round(seconds * 1000) at the config boundary","Reject 0 and negative SLOs in the loader with context"],"tags":["validation","eval","guardrail","latency","numeric"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}