{"record":{"id":"44ac112661387eba","repo":"stablyai/orca","slug":"projection-mismatch-after-a-ping-at-agents-agen","errorCode":null,"errorMessage":"projection mismatch after a ping at ${agents} agents","messagePattern":"projection mismatch after a ping at (.+?) agents","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/mobile-agent-status-projection-benchmark.mjs","lineNumber":182,"sourceCode":"  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":164,"sourceCodeEnd":193,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/mobile-agent-status-projection-benchmark.mjs#L164-L193","documentation":"Same correctness invariant as 153 but exercised AFTER a ping (one agent's status changed). The cold call after an incremental update is where stale-cache bugs hide: the cache may serve a row computed before the ping. Fires for agent counts 3/8/20/40.","triggerScenarios":"buildFull(pinged) !== cachedBuilder(pinged) where pinged = ping(map, 0). The cached builder served a pre-ping row for agent 0 (or failed to invalidate dependent rows).","commonSituations":"Cache invalidation keyed only on the changed agent without propagating to derived rows; updatedAtBucket changes but the cache key omits it; the ping mutates the map in place but the cache holds a reference to the old shape.","solutions":["Confirm ping invalidates the cache entry for agent 0 and any row derived from it","Verify the cache key includes updatedAtBucket (the value BUCKET_MS is parsed for)","Make cachedBuilder copy-on-write so map mutation does not corrupt cached state","Add a regression test that pings each agent index, not just 0"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function assertProjectionAfterPing(builder, cached, map, idx, agents) {\n  const pinged = ping(map, idx)\n  if (builder(pinged) !== cached(pinged)) {\n    throw new Error(`cached projection diverges after ping(${idx}) at ${agents} agents`)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include updatedAtBucket in the cache key — ping changes it","Use copy-on-write in the cached builder so map mutation does not corrupt cached state","Test ping at every agent index, not just 0, to catch per-row invalidation bugs"],"tags":["correctness","benchmark","caching","incremental","cache-invalidation"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}