Skip to content

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

feat(self-hosted): add heavy-compile slot scheduling and memory reporting

Steven Enamakel240b94997d73
diff --git a/scripts/__tests__/self-hosted-lanes.test.mjs b/scripts/__tests__/self-hosted-lanes.test.mjs
index a2f18a07a7..39f61d34f3 100644
--- a/scripts/__tests__/self-hosted-lanes.test.mjs
+++ b/scripts/__tests__/self-hosted-lanes.test.mjs
@@ -17,7 +17,9 @@ import {
validatePlan,
} from "../ci/self-hosted/lanes-plan.mjs";
import {
+ PrioritySemaphore,
Runner,
+ defaultHeavySlots,
foldLine,
gatingFailures,
renderLaneTable,
@@ -277,7 +279,10 @@ test("runner: a failure never stops later checks, blocks its dependants, and gat
assert.deepEqual(gatingFailures({ lanes }), ["a:fails", "a:needs-failed"]);
assert.match(fs.readFileSync(path.join(out, "logs", "a.log"), "utf8"), /ran/);
const summary = renderSummary({ lanes });
- assert.match(summary, /\| a \| report-only \| failure \(report-only\) \|/);
+ assert.match(
+ summary,
+ /\| a \| report-only \| failure \(report-only\) \| \S+ \|/,
+ );
assert.match(summary, /\| a \| needs-failed \| blocked \|/);
fs.rmSync(out, { recursive: true, force: true });
});
@@ -360,3 +365,56 @@ test("step-per-lane mode: args, folded check groups and the lane table", () => {
assert.doesNotMatch(table, /off/);
assert.match(table, /bench 9s \(report-only\)/);
});
+
+test("heavy-compile slots: priority order, FIFO within a priority, sized from RAM", async () => {
+ const sem = new PrioritySemaphore(1);
+ const order = [];
+ await sem.acquire(5); // holder
+ const waits = [
+ sem.acquire(9).then(() => order.push("bench")),
+ sem.acquire(1).then(() => order.push("lint")),
+ sem.acquire(0).then(() => order.push("cov")),
+ sem.acquire(1).then(() => order.push("gatesoff")),
+ ];
+ for (let i = 0; i < 4; i++) {
+ sem.release();
+ await new Promise((r) => setImmediate(r));
+ }
+ sem.release();
+ await Promise.all(waits);
+ assert.deepEqual(order, ["cov", "lint", "gatesoff", "bench"]);
+
+ assert.equal(defaultHeavySlots(24 * 1024), 2);
+ assert.equal(defaultHeavySlots(28 * 1024), 3);
+ assert.equal(defaultHeavySlots(48 * 1024), 5);
+ assert.equal(defaultHeavySlots(4 * 1024), 1);
+});
+
+test("runner: heavy lanes wait for a slot, light lanes never do", async () => {
+ const out = fs.mkdtempSync(path.join(os.tmpdir(), "lanes-heavy-"));
+ fs.mkdirSync(path.join(out, "logs"));
+ const check = (name) => ({ name, run: "sleep 0.2", when: true, needs: [] });
+ const plan = {
+ profile: "ex63",
+ lanes: [
+ { name: "h1", heavy: 0, active: true, checks: [check("x")] },
+ { name: "h2", heavy: 1, active: true, checks: [check("x")] },
+ { name: "light", active: true, checks: [check("x")] },
+ ],
+ };
+ const lanes = await new Runner(plan, {
+ out,
+ maxParallel: 0,
+ maxHeavy: 1,
+ }).run();
+ const by = Object.fromEntries(lanes.map((l) => [l.name, l]));
+ assert.equal(by.h1.heavyWaitS, 0);
+ assert.ok(
+ Date.parse(by.h2.checks[0].start) >= Date.parse(by.h1.checks[0].end),
+ );
+ assert.equal(by.light.heavyWaitS, null);
+ assert.ok(
+ Date.parse(by.light.checks[0].start) < Date.parse(by.h1.checks[0].end),
+ );
+ fs.rmSync(out, { recursive: true, force: true });
+});
diff --git a/scripts/ci/self-hosted/lanes.mjs b/scripts/ci/self-hosted/lanes.mjs
index 372a868f27..cde17e99d1 100644
--- a/scripts/ci/self-hosted/lanes.mjs
+++ b/scripts/ci/self-hosted/lanes.mjs
@@ -143,9 +143,18 @@ export function renderSummary(results) {
c.reportOnly && c.status === "failure"
? "failure (report-only)"
: c.status;
- rows.push(`| ${lane.name} | ${c.name} | ${outcome} | ${time} |`);
+ const rss = c.peakRssMiB
+ ? `${(c.peakRssMiB / 1024).toFixed(1)} GiB`
+ : "—";
+ rows.push(`| ${lane.name} | ${c.name} | ${outcome} | ${time} | ${rss} |`);
}
}
+ const mem = results.memory;
+ if (mem?.totalMiB)
+ rows.push(
+ "",
+ `VM memory: ${(mem.totalMiB / 1024).toFixed(1)} GiB, lowest available ${mem.minAvailableMiB == null ? "?" : `${(mem.minAvailableMiB / 1024).toFixed(1)} GiB`}; heavy-compile slots: ${results.heavySlots ?? "uncapped"}.`,
+ );
rows.push(
"",
"`skipped` = area untouched; `blocked` = a check it needs did not succeed. Neither is a pass for the check itself.",
@@ -309,7 +318,11 @@ export class Runner {
/** Sample VM memory and each running check's process-group RSS. */
sampleMemory() {
const { available } = memInfoMiB();
- if (available != null && (this.memory.minAvailableMiB == null || available < this.memory.minAvailableMiB))
+ if (
+ available != null &&
+ (this.memory.minAvailableMiB == null ||
+ available < this.memory.minAvailableMiB)
+ )
this.memory.minAvailableMiB = available;
if (this.running.size === 0) return;
const rss = rssByProcessGroup();
@@ -363,7 +376,9 @@ export class Runner {
let heavyWaitS = null;
if (lane.heavy != null && Number.isFinite(this.maxHeavy)) {
const w0 = Date.now();
- log(`lane ${lane.name}: waiting for a heavy-compile slot (priority ${lane.heavy})`);
+ log(
+ `lane ${lane.name}: waiting for a heavy-compile slot (priority ${lane.heavy})`,
+ );
await this.heavy.acquire(lane.heavy);
heavyWaitS = Math.round((Date.now() - w0) / 1000);
log(`lane ${lane.name}: got a heavy-compile slot after ${heavyWaitS}s`);
@@ -543,12 +558,16 @@ function printRunnerTail(out) {
/** Per-check table for one lane, as plain step output. */
export function renderLaneTable(lane) {
- const wait = lane.heavyWaitS ? ` (waited ${lane.heavyWaitS}s for a heavy-compile slot)` : "";
+ const wait = lane.heavyWaitS
+ ? ` (waited ${lane.heavyWaitS}s for a heavy-compile slot)`
+ : "";
const rows = [`lane ${lane.name}:${wait}`];
for (const c of lane.checks) {
if (c.status === "skipped") continue;
const time = c.durationS == null ? "" : ` ${c.durationS}s`;
- const mem = c.peakRssMiB ? ` peak ${(c.peakRssMiB / 1024).toFixed(1)} GiB` : "";
+ const mem = c.peakRssMiB
+ ? ` peak ${(c.peakRssMiB / 1024).toFixed(1)} GiB`
+ : "";
const note = c.reportOnly && c.status === "failure" ? " (report-only)" : "";
rows.push(` ${c.status.padEnd(9)} ${c.name}${time}${mem}${note}`);
}