Skip to content

Commit 837b6d6

Browse files
committed
fix(run-store): union the id-less pending-waitpoint count so a drain mirror counts once
1 parent 877e600 commit 837b6d6

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

internal-packages/run-store/src/runOpsStore.shardMap.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ describe("RoutingRunStore countPendingWaitpoints — disjoint-sum partition", ()
647647
expect(await router.countPendingWaitpoints(["b:w9"], undefined, "a:run")).toBe(0);
648648
});
649649

650+
it("id-less count unions a drain-mirrored cuid to one, never sums it to two", async () => {
651+
// No runId: fans over distinct stores. A cuid pending on BOTH gen-1 stores is one waitpoint.
652+
const { router } = partitionRouter({ new: ["cuid_w1"], legacy: ["cuid_w1"] });
653+
expect(await router.countPendingWaitpoints(["cuid_w1"])).toBe(1);
654+
});
655+
650656
it("returns the true total for a mixed gen-2 and cuid set with no double count", async () => {
651657
const { router } = partitionRouter({
652658
b: ["b:w1"],

internal-packages/run-store/src/runOpsStore.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,10 +1402,20 @@ export class RoutingRunStore implements RunStore {
14021402
runId?: string
14031403
): Promise<number> {
14041404
if (runId === undefined) {
1405+
// No run id to partition on: query every distinct store and UNION by id, matching the routed
1406+
// path below. A drain-mirrored cuid pending on both gen-1 stores must count once, not twice —
1407+
// summing raw counts here would reintroduce the double count this method exists to remove.
14051408
const legs = await this.#fanOut(this.#probeOrder, (store) =>
1406-
store.countPendingWaitpoints(waitpointIds, RoutingRunStore.#ownPrimary(store, client))
1409+
store.countPendingWaitpointsWithPresence(
1410+
waitpointIds,
1411+
RoutingRunStore.#ownPrimary(store, client)
1412+
)
14071413
);
1408-
return legs.reduce((sum, leg) => sum + leg, 0);
1414+
const union = new Set<string>();
1415+
for (const leg of legs) {
1416+
for (const id of leg.pendingIds) union.add(id);
1417+
}
1418+
return union.size;
14091419
}
14101420

14111421
if (waitpointIds.length === 0) {

0 commit comments

Comments
 (0)