{"record":{"id":"40397422ce40fd3c","repo":"stablyai/orca","slug":"normalizer-mismatch-at-kb-kb","errorCode":null,"errorMessage":"normalizer mismatch at ${kb} KB","messagePattern":"normalizer mismatch at (.+?) KB","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/scripts/agent-hook-normalizer-roundtrip-benchmark.mjs","lineNumber":185,"sourceCode":"  const samples = []\n  for (let round = 0; round < 5; round += 1) {\n    const start = performance.now()\n    for (let index = 0; index < ITERATIONS; index += 1) {\n      fn(payload)\n    }\n    samples.push((performance.now() - start) / ITERATIONS)\n  }\n  samples.sort((a, b) => a - b)\n  return samples[2]\n}\n\nconst rows = []\nfor (const kb of [4, 16, 64, 256]) {\n  const payload = makePayload(kb * 1024)\n  const before = validateViaRoundTrip(payload)\n  const after = validateDirect(payload)\n  if (JSON.stringify(before) !== JSON.stringify(after)) {\n    throw new Error(`normalizer mismatch at ${kb} KB`)\n  }\n  rows.push({\n    label: `${kb} KB`,\n    beforeUs: measure(validateViaRoundTrip, payload) * 1000,\n    afterUs: measure(validateDirect, payload) * 1000\n  })\n}\n\nconst pad = (value, width) => String(value).padStart(width)\nconsole.log('Agent-status payload validation, per hook event')\nconsole.log(\n  `field cap=${ASSISTANT_MESSAGE_CAP} iterations=${ITERATIONS} warmup=${WARMUP} (median of 5 rounds)`\n)\nconsole.log(\n  `${pad('payload', 9)} ${pad('round trip', 12)} ${pad('direct', 10)} ${pad('speedup', 9)}`\n)\nfor (const row of rows) {\n  console.log(","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/agent-hook-normalizer-roundtrip-benchmark.mjs#L167-L203","documentation":"Thrown by the agent-hook-normalizer benchmark as a correctness guard: at each payload size (4/16/64/256 KB) it runs the production-modeled round-trip validator (serialize -> scan -> parse -> normalizeObject) and the direct validator (normalizeObject directly), then JSON.stringifies both results. If they differ, the benchmark's mirrored direct path has drifted from the round-trip path and the timing comparison is meaningless.","triggerScenarios":"normalizeObject or normalizeField in the benchmark was edited and no longer matches what the round trip produces; the ASSISTANT_MESSAGE_CAP read from agent-status-types.ts changed and now the two paths clamp differently; the field list in normalizeObject drifted from the production normalizer.","commonSituations":"Refactor of the benchmark's normalizeObject that added/removed a field; AGENT_STATUS_ASSISTANT_MESSAGE_MAX_LENGTH changed upstream and the benchmark re-read it but the round-trip arm still uses a stale value somewhere; newline-run handling in normalizeField diverged from production.","solutions":["Diff normalizeObject/normalizeField in the benchmark against the production normalizer in agent-hook-listener.ts and re-align them.","Confirm ASSISTANT_MESSAGE_CAP is read from the same source both arms use (it is — readMirroredConstant reads agent-status-types.ts).","Re-run after each edit to normalizeObject until all four payload sizes match.","If the mismatch is intentional (you are demonstrating a behavior change), update the comparison expectation rather than removing the guard."],"exampleFix":"// before — benchmark's normalizeObject dropped the toolInput field\n// -> 'normalizer mismatch at 4 KB'\n\n// after — restore the field so both arms agree\n// function normalizeObject(payload) {\n//   return {\n//     state: payload.state,\n//     prompt: normalizeField(payload.prompt, ASSISTANT_MESSAGE_CAP),\n//     agentType: payload.agentType,\n//     toolName: normalizeField(payload.toolName, ASSISTANT_MESSAGE_CAP),\n//     toolInput: normalizeField(payload.toolInput, ASSISTANT_MESSAGE_CAP),\n//     lastAssistantMessage: normalizeField(payload.lastAssistantMessage, ASSISTANT_MESSAGE_CAP)\n//   }\n// }","handlingStrategy":"validation","validationCode":"function assertBothArmsAgree(payload) {\n  const before = validateViaRoundTrip(payload)\n  const after = validateDirect(payload)\n  if (JSON.stringify(before) !== JSON.stringify(after)) {\n    throw new Error('Normalizer arms disagree — direct path drifted from round trip')\n  }\n}\n// run for each payload size before the timing loop","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When editing normalizeObject/normalizeField in the benchmark, re-run all four payload sizes immediately to catch divergence.","Keep the benchmark's normalizeObject field list identical to the production normalizer's field list.","Re-read ASSISTANT_MESSAGE_CAP from the source constant every run (already done) so a cap change cannot silently desync the arms."],"tags":["benchmark","correctness-guard","agent-status","normalizer","drift"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}