Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(compare-runs): pair newest completed run per workflow by head SHA

Steven Enamakeld3b311795681
diff --git a/scripts/__tests__/self-hosted-lanes.test.mjs b/scripts/__tests__/self-hosted-lanes.test.mjs
index f2a05576c6..e9fcf6d886 100644
--- a/scripts/__tests__/self-hosted-lanes.test.mjs
+++ b/scripts/__tests__/self-hosted-lanes.test.mjs
@@ -279,3 +279,44 @@ test("runner: a failure never stops later checks, blocks its dependants, and gat
assert.match(summary, /\| a \| needs-failed \| blocked \|/);
fs.rmSync(out, { recursive: true, force: true });
});
+
+test("compare-runs pairs the newest completed run per workflow by head SHA", async () => {
+ const { pairRuns, laneMinutes, minutesBetween } =
+ await import("../ci/self-hosted/compare-runs.mjs");
+ const run = (sha, createdAt, updatedAt, status = "completed") => ({
+ headSha: sha,
+ createdAt,
+ updatedAt,
+ status,
+ conclusion: "success",
+ });
+ const rows = pairRuns({
+ lite: [run("a", "2026-09-01T00:00:00Z", "2026-09-01T01:30:00Z")],
+ ex63: [
+ run("a", "2026-09-01T00:00:00Z", "2026-09-01T00:40:00Z"),
+ run("a", "2026-09-01T02:00:00Z", "2026-09-01T02:20:00Z"),
+ run("a", "2026-09-01T03:00:00Z", "2026-09-01T03:05:00Z", "in_progress"),
+ ],
+ hosted: [run("b", "2026-09-01T00:00:00Z", "2026-09-01T00:10:00Z")],
+ });
+ assert.equal(rows.length, 1, "b has no CI Lite run, so it is not paired");
+ assert.equal(
+ minutesBetween(rows[0].ex63.createdAt, rows[0].ex63.updatedAt),
+ 20,
+ );
+ assert.deepEqual(
+ laneMinutes({
+ lanes: [
+ {
+ name: "rust-cov",
+ checks: [
+ { start: "2026-09-01T00:00:00Z", end: "2026-09-01T00:05:00Z" },
+ { start: "2026-09-01T00:05:00Z", end: "2026-09-01T00:30:00Z" },
+ { start: null, end: null },
+ ],
+ },
+ ],
+ }),
+ { "rust-cov": 30 },
+ );
+});
diff --git a/scripts/ci/self-hosted/compare-runs.mjs b/scripts/ci/self-hosted/compare-runs.mjs
index 9c6fd4f1d3..a3bbcf0ce2 100644
--- a/scripts/ci/self-hosted/compare-runs.mjs
+++ b/scripts/ci/self-hosted/compare-runs.mjs
@@ -10,7 +10,13 @@
// downloads each fast run's ci-timings.json and prints per-lane durations.
// Needs an authenticated `gh`.
import { execFileSync } from "node:child_process";
-import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
+import {
+ mkdtempSync,
+ readFileSync,
+ readdirSync,
+ rmSync,
+ statSync,
+} from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
@@ -44,22 +50,35 @@ export function pairRuns(runsByKind) {
for (const r of runs) {
if (r.status !== "completed") continue;
const row = bySha.get(r.headSha) ?? { sha: r.headSha };
- if (!row[kind] || Date.parse(r.createdAt) > Date.parse(row[kind].createdAt)) row[kind] = r;
+ if (
+ !row[kind] ||
+ Date.parse(r.createdAt) > Date.parse(row[kind].createdAt)
+ )
+ row[kind] = r;
bySha.set(r.headSha, row);
}
}
return [...bySha.values()]
.filter((row) => row.lite && (row.ex63 || row.hosted))
- .sort((a, b) => Date.parse(b.lite.createdAt) - Date.parse(a.lite.createdAt));
+ .sort(
+ (a, b) => Date.parse(b.lite.createdAt) - Date.parse(a.lite.createdAt),
+ );
}
/** Per-lane wall-clock minutes from a ci-timings.json object. */
export function laneMinutes(timings) {
const out = {};
for (const lane of timings.lanes ?? []) {
- const starts = lane.checks.map((c) => c.start).filter(Boolean).sort();
- const ends = lane.checks.map((c) => c.end).filter(Boolean).sort();
- if (starts.length) out[lane.name] = minutesBetween(starts[0], ends[ends.length - 1]);
+ const starts = lane.checks
+ .map((c) => c.start)
+ .filter(Boolean)
+ .sort();
+ const ends = lane.checks
+ .map((c) => c.end)
+ .filter(Boolean)
+ .sort();
+ if (starts.length)
+ out[lane.name] = minutesBetween(starts[0], ends[ends.length - 1]);
}
return out;
}
@@ -68,8 +87,16 @@ function listRuns(repo, workflow, limit) {
try {
return JSON.parse(
gh([
- "run", "list", "-R", repo, "--workflow", workflow, "--limit", String(limit),
- "--json", "databaseId,headSha,createdAt,updatedAt,status,conclusion,event",
+ "run",
+ "list",
+ "-R",
+ repo,
+ "--workflow",
+ workflow,
+ "--limit",
+ String(limit),
+ "--json",
+ "databaseId,headSha,createdAt,updatedAt,status,conclusion,event",
]),
);
} catch {
@@ -82,7 +109,8 @@ function findTimings(dir) {
for (const entry of readdirSync(dir)) {
const p = join(dir, entry);
if (statSync(p).isDirectory()) found.push(...findTimings(p));
- else if (entry === "ci-timings.json") found.push(JSON.parse(readFileSync(p, "utf8")));
+ else if (entry === "ci-timings.json")
+ found.push(JSON.parse(readFileSync(p, "utf8")));
}
return found;
}
@@ -90,7 +118,17 @@ function findTimings(dir) {
function downloadTimings(repo, runId) {
const dir = mkdtempSync(join(tmpdir(), "ci-timings-"));
try {
- gh(["run", "download", String(runId), "-R", repo, "-p", "ci-out-*", "-D", dir]);
+ gh([
+ "run",
+ "download",
+ String(runId),
+ "-R",
+ repo,
+ "-p",
+ "ci-out-*",
+ "-D",
+ dir,
+ ]);
return findTimings(dir);
} catch {
return [];
@@ -110,29 +148,42 @@ function main(argv) {
else throw new Error(`unknown argument ${argv[i]}`);
}
const runs = Object.fromEntries(
- Object.entries(WORKFLOWS).map(([kind, wf]) => [kind, listRuns(repo, wf, limit)]),
+ Object.entries(WORKFLOWS).map(([kind, wf]) => [
+ kind,
+ listRuns(repo, wf, limit),
+ ]),
);
const rows = pairRuns(runs);
if (rows.length === 0) {
console.log("No commit has both a CI Lite run and a lane-flow run yet.");
return;
}
- const fmt = (r) => (r ? `${minutesBetween(r.createdAt, r.updatedAt)}m ${r.conclusion}` : "—");
- console.log("| sha | CI Lite | CI Fast (EX63) | CI Fast (hosted) | EX63 speed-up |");
+ const fmt = (r) =>
+ r ? `${minutesBetween(r.createdAt, r.updatedAt)}m ${r.conclusion}` : "—";
+ console.log(
+ "| sha | CI Lite | CI Fast (EX63) | CI Fast (hosted) | EX63 speed-up |",
+ );
console.log("| --- | --- | --- | --- | --- |");
for (const row of rows) {
const lite = minutesBetween(row.lite.createdAt, row.lite.updatedAt);
- const ex = row.ex63 ? minutesBetween(row.ex63.createdAt, row.ex63.updatedAt) : null;
+ const ex = row.ex63
+ ? minutesBetween(row.ex63.createdAt, row.ex63.updatedAt)
+ : null;
const speed = ex ? `${Math.round((lite / ex) * 10) / 10}x` : "—";
- console.log(`| ${row.sha.slice(0, 10)} | ${fmt(row.lite)} | ${fmt(row.ex63)} | ${fmt(row.hosted)} | ${speed} |`);
+ console.log(
+ `| ${row.sha.slice(0, 10)} | ${fmt(row.lite)} | ${fmt(row.ex63)} | ${fmt(row.hosted)} | ${speed} |`,
+ );
if (lanes) {
for (const kind of ["ex63", "hosted"]) {
if (!row[kind]) continue;
for (const t of downloadTimings(repo, row[kind].databaseId)) {
- const per = Object.entries(laneMinutes(t)).map(([k, v]) => `${k}=${v}m`).join(" ");
+ const per = Object.entries(laneMinutes(t))
+ .map(([k, v]) => `${k}=${v}m`)
+ .join(" ");
const hits = t.sccache?.stats?.cache_hits?.counts?.Rust;
const misses = t.sccache?.stats?.cache_misses?.counts?.Rust;
- const sc = hits != null ? ` sccache rust hits=${hits} misses=${misses}` : "";
+ const sc =
+ hits != null ? ` sccache rust hits=${hits} misses=${misses}` : "";
console.log(`| ↳ ${kind} lanes | ${per}${sc} | | | |`);
}
}