// THE HEAVY SLOT, for a render (scripts/queue-lock.mjs, `pnpm heavy`). // // A render of the cut -- the segments' encodes, the deck's HyperFrames // render, the overlay pass -- is one heavy job machine-wide, started only // above the memory floor, like an e2e run or a `next build` (two OOMs took the // desktop session down, 2026-10-08). build-video's CLI runs its rendering // runs through `withRenderSlot`; a fetch, the lint, `--only`, the chapters and // the thumbnail do not take it. // // Loaded only by build-video's CLI, by a path built at run time, never by the // umtool app that imports build-video.mjs: queue-lock.mjs is a CLI of the // checkout, not a module of the bundle. // // THE LOCK FILE. queue-lock finds its lock in the git common dir of the // process's cwd. A render's cwd is usually a report workspace -- outside the // checkout, or a repository of its own -- whose lock no e2e run or build would // ever see. So unless HEAVY_LOCK_FILE is set, it is pinned here to the one in // THIS checkout's git common dir, the file every other heavy entry point // takes. HEAVY=0 bypasses the slot and the floor; HEAVY_HELD (set inside the // slot, e.g. under an e2e run or `pnpm heavy -- …`) passes straight through. import { execFileSync } from "node:child_process"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; /** This checkout's root: two levels above this file (umtool/report-to-video/). */ export function checkoutRoot() { return path.resolve(/* turbopackIgnore: true */ path.dirname(/* turbopackIgnore: true */ fileURLToPath(import.meta.url)), "..", ".."); } /** The heavy slot's lock file for this checkout, or null outside a git checkout. */ export function heavyLockFile(root = checkoutRoot()) { try { const common = execFileSync("git", ["-C", root, "rev-parse", "--path-format=absolute", "--git-common-dir"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], }).trim(); return common ? path.join(/* turbopackIgnore: true */ common, "heavy-queue.lock") : null; } catch { return null; } } /** * Run `fn` in the heavy slot. `cmd` names the work to anyone waiting behind * it. With no gate to load (a copy of the directory without the checkout's * scripts/), says so and runs: the slot is a safety net, not a correctness lock. * * `estimateMb` declares the job's memory (queue-lock's weighted admission): it * then runs BESIDE others while MemAvailable minus every running estimate stays * at or above the floor, and waits otherwise. Without one it runs alone. A * render declares one (render-estimate.mjs), and so does the bench's prep * (lib/report/benchPrep.mjs). * * @template T * @param {string[]} cmd * @param {() => Promise} fn * @param {{ env?: NodeJS.ProcessEnv, root?: string, say?: (line: string) => void, estimateMb?: number | null }} [opts] * @returns {Promise} */ export async function withRenderSlot(cmd, fn, { env = process.env, root = checkoutRoot(), say, estimateMb } = {}) { const note = say ?? ((line) => process.stderr.write(`${line}\n`)); if (env.HEAVY === "0" || env.HEAVY_HELD) return fn(); let gate; try { const file = path.join(/* turbopackIgnore: true */ root, "scripts", "queue-lock.mjs"); gate = await import(/* webpackIgnore: true */ pathToFileURL(file).href); } catch (err) { note(`heavy: no heavy-slot gate in this checkout (${err?.message ?? err}) — rendering without it`); return fn(); } if (!env.HEAVY_LOCK_FILE) { const lock = heavyLockFile(root); if (lock) env.HEAVY_LOCK_FILE = lock; } return gate.withHeavy({ cmd, ...(Number(estimateMb) > 0 ? { estimateMb: Number(estimateMb) } : {}) }, fn); }