commit 9499cc168ddba48dbbf256d8e64086f4c972f2f6
parent 046d603c207808c711351ae45ebe8b2496bf8e28
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 10 Oct 2026 14:25:55 -0400
e2e: the editor suite's heavy-slot estimate is per worker (--scale-by E2E_WORKERS)
A suite on three workers runs three server sets; its ticket now says 4500 MB,
not 1500, so the jobs admitted beside it count what it really holds. `auto`
counts as the cap (3): the count is decided after admission.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/WORKTREES.md b/WORKTREES.md
@@ -190,7 +190,8 @@ through ONE more machine-global gate, the **heavy slot**, which admits a job **b
- A job that **declares an estimate** is admitted while
`MemAvailable − Σ(estimates of the jobs already running) ≥ HEAVY_MIN_FREE_MB` (6000 MB).
- An e2e suite declares 1.5 GB (`--estimate 1500` in each package's script); a `next build`
+ An e2e suite declares 1.5 GB (`--estimate 1500` in each package's script — the editor's
+ per worker, `--scale-by E2E_WORKERS`, `auto` counting as 3); a `next build`
run under `systemd-run … -p MemoryMax=5G` declares its cap (the e2e build does).
- **One `next build` at a time stays a hard rule**, whatever the memory: a build waits for
the build slot, including one started from inside an admitted run.
diff --git a/editor/package.json b/editor/package.json
@@ -10,7 +10,7 @@
"build": "next build",
"start": "UV_THREADPOOL_SIZE=${UV_THREADPOOL_SIZE:-16} next start --port ${EDITOR_PORT:-3001}",
"test": "tsx --test \"app/**/*.test.ts\" \"e2e/*.unit.ts\"",
- "e2e": "node ../scripts/queue-lock.mjs --name e2e-editor --estimate 1500 --prebuild editor --ports PORT:3011,EXPORT_PORT:3010,OLLAMA_STUB_PORT:11435 -- playwright test",
+ "e2e": "node ../scripts/queue-lock.mjs --name e2e-editor --estimate 1500 --scale-by E2E_WORKERS --prebuild editor --ports PORT:3011,EXPORT_PORT:3010,OLLAMA_STUB_PORT:11435 -- playwright test",
"e2e:ui": "playwright test --ui"
},
"dependencies": {
diff --git a/scripts/queue-lock.mjs b/scripts/queue-lock.mjs
@@ -116,6 +116,9 @@ function parseArgv(argv) {
// it is a `next build`, and the package whose e2e build to ensure first.
// Unset means "infer from the command" (resolveJob).
estimateMb: undefined,
+ // `--scale-by E2E_WORKERS`: the estimate is per worker, times that
+ // variable's number of workers (`auto`: the editor's cap, 3).
+ scaleBy: null,
build: undefined,
prebuild: null,
// Unset unless --timeout: the e2e queue defaults it from E2E_QUEUE_TIMEOUT,
@@ -139,6 +142,7 @@ function parseArgv(argv) {
}
}
else if (f === "--build") opts.build = true;
+ else if (f === "--scale-by") opts.scaleBy = flags[++i];
else if (f === "--prebuild") opts.prebuild = flags[++i];
else {
process.stderr.write(`queue-lock: unknown flag '${f}'\n`);
@@ -1177,6 +1181,17 @@ export async function withHeavy(opts, fn) {
}
}
+// How many server sets a suite runs: `--scale-by E2E_WORKERS` reads the
+// editor suite's worker count (a number; `auto` counts as its cap, 3 —
+// editor/e2e/servers.ts — since the count is decided after admission).
+export function workerScale(envVar, env = process.env) {
+ if (!envVar) return 1;
+ const raw = String(env[envVar] ?? "").trim().toLowerCase();
+ if (raw === "auto") return 3;
+ const n = Number(raw);
+ return Number.isInteger(n) && n > 1 ? Math.min(n, 8) : 1;
+}
+
// The default queue name, and the one older copies of this file use. A run
// under it keeps the old order — the heavy slot first, then the queue — so it
// can never wait in a cycle with an older run that holds the slot and waits
@@ -1198,7 +1213,11 @@ export async function withQueue(opts, fn) {
const ports = parsePorts(opts.portSpec ?? null);
const graceMs = opts.portGraceMs ?? Number(process.env.E2E_PORT_GRACE_MS ?? DEFAULT_PORT_GRACE_MS);
const timeoutMs = opts.timeoutMs ?? defaultTimeoutMs();
- const heavyOpts = { timeoutMs, cmd: opts.cmd ?? [name], estimateMb: opts.estimateMb };
+ const heavyOpts = {
+ timeoutMs,
+ cmd: opts.cmd ?? [name],
+ estimateMb: opts.estimateMb && opts.estimateMb * workerScale(opts.scaleBy),
+ };
// A nested invocation: the parent holds the queue (and the slot) already.
if (process.env[HELD_ENV] === name) {
diff --git a/scripts/queue-lock.test.mjs b/scripts/queue-lock.test.mjs
@@ -20,6 +20,7 @@ import {
parseMeminfo,
readTickets,
resolveJob,
+ workerScale,
waitForAdmission,
waitForMemory,
} from "./queue-lock.mjs";
@@ -770,3 +771,20 @@ test("a waiter stopped by SIGTERM leaves no holder file behind", async () => {
assert.equal(fs.existsSync(`${env.HEAVY_LOCK_FILE}.admit.holder.json`), false);
assert.equal((await first.done).code, 0);
});
+
+test("--scale-by: an estimate per worker, times the editor suite's E2E_WORKERS", async () => {
+ assert.equal(workerScale(null, { E2E_WORKERS: "3" }), 1);
+ assert.equal(workerScale("E2E_WORKERS", {}), 1);
+ assert.equal(workerScale("E2E_WORKERS", { E2E_WORKERS: "2" }), 2);
+ assert.equal(workerScale("E2E_WORKERS", { E2E_WORKERS: "auto" }), 3);
+ assert.equal(workerScale("E2E_WORKERS", { E2E_WORKERS: "99" }), 8);
+ const dir = tmpDir();
+ const env = heavyEnv(dir, { E2E_QUEUE_LOCK_FILE: path.join(dir, "q.lock"), E2E_WORKERS: "3" });
+ const jobs = path.join(dir, "heavy.lock.jobs");
+ const cmd = [process.execPath, "-e", "setTimeout(()=>{},400)"];
+ const run = startLock(["--name", "e2e-x", "--estimate", "1500", "--scale-by", "E2E_WORKERS", "--", ...cmd], env);
+ await until(() => fs.existsSync(jobs) && fs.readdirSync(jobs).some((n) => n.endsWith(".json")));
+ const ticket = JSON.parse(fs.readFileSync(path.join(jobs, fs.readdirSync(jobs).find((n) => n.endsWith(".json"))), "utf8"));
+ assert.equal(ticket.estimateMb, 4500);
+ assert.equal((await run.done).code, 0);
+});