{"record":{"id":"a31d2437dd48c34e","repo":"stablyai/orca","slug":"projection-mismatch-at-agents-agents","errorCode":null,"errorMessage":"projection mismatch at ${agents} agents","messagePattern":"projection mismatch at (.+?) agents","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/mobile-agent-status-projection-benchmark.mjs","lineNumber":176,"sourceCode":"    for (let index = 0; index < ITERATIONS; index += 1) {\n      current = ping(current, index)\n      build(current)\n    }\n    samples.push((performance.now() - start) / ITERATIONS)\n  }\n  samples.sort((a, b) => a - b)\n  return samples[2]\n}\n\nconst pad = (value, width) => String(value).padStart(width)\nconsole.log('Mobile agent-status projection, per status ping (one agent changed)')\nconsole.log(`bucket=${BUCKET_MS}ms iterations=${ITERATIONS} warmup=${WARMUP} (median of 5 rounds)`)\nconsole.log(`${pad('agents', 8)} ${pad('full', 11)} ${pad('cached', 11)} ${pad('speedup', 9)}`)\nfor (const agents of [3, 8, 20, 40]) {\n  const map = makeMap(agents)\n  const cachedBuilder = makeCachedBuilder()\n  if (buildFull(map) !== cachedBuilder(map)) {\n    throw new Error(`projection mismatch at ${agents} agents`)\n  }\n  // Why also after a ping: the cold call reuses nothing, so a stale-row bug would\n  // only surface once the cache is actually exercised.\n  const pinged = ping(map, 0)\n  if (buildFull(pinged) !== cachedBuilder(pinged)) {\n    throw new Error(`projection mismatch after a ping at ${agents} agents`)\n  }\n  const full = measure(buildFull, map)\n  const cached = measure(makeCachedBuilder(), map)\n  console.log(\n    `${pad(agents, 8)} ${pad(`${full.toFixed(4)} ms`, 11)} ${pad(`${cached.toFixed(4)} ms`, 11)} ${pad(`${(full / cached).toFixed(1)}x`, 9)}`\n  )\n}\nconsole.log(\n  '\\nThis runs on the global store subscriber, so the cost is paid per status ping\\nand scales with the number of agents running in parallel — the workload this\\napp exists for.'\n)\n","sourceCodeStart":158,"sourceCodeEnd":193,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/mobile-agent-status-projection-benchmark.mjs#L158-L193","documentation":"Correctness assertion in the projection benchmark: the cached projection builder (makeCachedBuilder) must produce byte-identical output to buildFull for the same agent map. A mismatch means the incremental cache has a correctness bug — measuring its speed would be measuring wrong output. Fires on the cold call (no prior ping) for agent counts 3/8/20/40.","triggerScenarios":"cachedBuilder(map) returns a different string than buildFull(map) for a freshly-constructed map of N agents, before any ping.","commonSituations":"Refactoring makeCachedBuilder and forgetting a cache key; changing the projection format in buildFull without updating the cached variant; a stale cache surviving between iterations because makeCachedBuilder is hoisted out of the loop.","solutions":["Diff the two output strings character-by-character to localize the divergence","Audit makeCachedBuilder's cache key against every field buildFull reads","Ensure makeCachedBuilder is called fresh inside the agents loop (no cross-iteration cache leakage)","Add a focused unit test on the cached builder for the failing agent count"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertProjectionMatches(builder, cached, map, agents) {\n  if (builder(map) !== cached(map)) {\n    throw new Error(`cached projection diverges at ${agents} agents (cold) — do not trust timings`)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the equality assertion before measuring; never disable it to get numbers","Keep makeCachedBuilder inside the agents loop so no cross-iteration cache leaks","Add a focused unit test for the cached builder at each agent count"],"tags":["correctness","benchmark","caching","regression"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}