Dedupe job runs by runId to fix duplicate keys

The same run can appear under multiple job COBs at a commit, causing an
each_key_duplicate crash. Keep one view per runId, letting a terminal
status override a stale "started" one.
This commit is contained in:
Rūdolfs Ošiņš
2026-05-29 17:15:04 +02:00
parent 5c1efdeaa6
commit 50bd93e550
+25 -2
View File
@@ -65,6 +65,10 @@
return run.runId.slice(0, 8);
}
function isTerminal(status: Status): boolean {
return status === "succeeded" || status === "failed";
}
function aggregateStatus(c: Counts): Status {
if (c.failed) return "failed";
if (c.started) return "started";
@@ -92,7 +96,11 @@
function groupJobs(jobs: Job[]): NodeGroup[] {
const byNode: Record<
string,
{ author: Author; byHost: Record<string, RunView[]> }
{
author: Author;
byHost: Record<string, RunView[]>;
seen: Map<string, RunView>;
}
> = {};
const nodeOrder: string[] = [];
for (const job of jobs) {
@@ -109,10 +117,25 @@
const key = run.node.did;
let entry = byNode[key];
if (!entry) {
entry = { author: run.node, byHost: {} };
entry = { author: run.node, byHost: {}, seen: new Map() };
byNode[key] = entry;
nodeOrder.push(key);
}
const existing = entry.seen.get(run.runId);
if (existing) {
// The same run can appear under multiple job COBs. Keep one view
// per runId, but let a terminal status override a stale "started"
// one when COBs polled at different times disagree. We mutate the
// existing view in place because it is the same object referenced
// from its host bucket below.
if (!isTerminal(existing.run.status) && isTerminal(run.status)) {
existing.run = run;
existing.label = view.label;
existing.safeLog = view.safeLog;
}
continue;
}
entry.seen.set(run.runId, view);
const bucket = entry.byHost[host] ?? (entry.byHost[host] = []);
bucket.push(view);
}