commit d5532f6cc30951d0a3a0cd98323e5bda0273525f
parent 15594467bcc2306cb389c22cde614112f8ee2607
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 17:01:44 -0500
umtool: the disk guard, still under its threshold after pruning takes' work files, has the render pool give back what only it holds
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md
@@ -1984,7 +1984,8 @@ stopped mid-render and run again finds every chunk it finished, in its own `out/
- **Disk:** `UMTOOL_RENDER_POOL_MAX_GB` (default 30) caps the bytes only the pool holds -- objects no
take links. Over it, the least recently used go first, at the end of a build (at most hourly) or by
`umtool pool prune`; an object a take links -- a pinned or picked take's, a running build's -- is
- never evicted.
+ never evicted. The disk guard before a render, still under its threshold after pruning takes'
+ work files, has the pool give back what only it holds, by the deficit.
- **`umtool pool [stats|prune|verify] [--json]`:** what it holds by kind, its hits and misses
(`--since 7d`), the biggest objects; an eviction down to the cap (`--max-gb`, `--dry-run`); a check
of a sample (`--sample N`, `--all`) against the sha256 each file was put in with.
diff --git a/umtool/lib/report/takePrune.mjs b/umtool/lib/report/takePrune.mjs
@@ -1045,7 +1045,7 @@ export class DiskGuardRefused extends Error {}
* free?: (dir: string) => Promise<number | null>, pruneAll?: () => Promise<{ freedBytes: number, results: any[] }> }} o
* @returns {Promise<{ checked: boolean, freeBefore: number | null, freeAfter: number | null, freedBytes: number }>}
*/
-export async function diskGuard({ dirs, env = process.env, say = () => {}, free = freeBytesAt, pruneAll = () => pruneAllProjects({ by: "disk-guard" }) }) {
+export async function diskGuard({ dirs, env = process.env, say = () => {}, free = freeBytesAt, pruneAll = () => pruneAllProjects({ by: "disk-guard" }), prunePool = poolDeficitPrune }) {
const s = guardSettings(env);
if (!s.enabled) return { checked: false, freeBefore: null, freeAfter: null, freedBytes: 0 };
const least = async () => {
@@ -1069,7 +1069,16 @@ export async function diskGuard({ dirs, env = process.env, say = () => {}, free
} catch (err) {
say(`disk guard: the prune failed — ${err instanceof Error ? err.message : err}`);
}
- const after = await least();
+ let after = await least();
+ // Still under: the render pool gives back what only it holds, least recently used first.
+ if (after.min !== null && after.min < s.thresholdBytes) {
+ const r = await prunePool({ dirs, env, deficit: s.thresholdBytes - after.min }).catch(() => null);
+ if (r?.evicted) {
+ say(`disk guard: the render pool evicted ${r.evicted} object(s), ${fmtBytes(r.bytes)}`);
+ freedBytes += r.bytes;
+ after = await least();
+ }
+ }
if (after.min !== null && after.min < s.floorBytes) {
throw new DiskGuardRefused(
`disk guard: only ${fmtBytes(after.min)} free under ${after.at}, under the ${fmtBytes(s.floorBytes)} a render needs — nothing was rendered. ` +
@@ -1080,6 +1089,21 @@ export async function diskGuard({ dirs, env = process.env, say = () => {}, free
return { checked: true, freeBefore: before.min, freeAfter: after.min, freedBytes };
}
+/**
+ * The disk guard's last resort before refusing: the render pool (render-pool.mjs)
+ * of the first of `dirs` it serves, pruned by `deficit` bytes of what only it holds.
+ */
+async function poolDeficitPrune({ dirs, env, deficit }) {
+ const { poolFor, poolPrune, poolStats } = await import("umtool-report-to-video/render-pool");
+ for (const d of dirs) {
+ const pool = d ? await poolFor(d, env) : null;
+ if (!pool) continue;
+ const st = await poolStats(pool);
+ return poolPrune(pool, { maxBytes: Math.max(0, st.onlyPool - deficit) });
+ }
+ return null;
+}
+
/** For build-video's CLI: the guard over its --out (or its manifest's directory) and the projects root. */
export async function guardBeforeRender({ out, manifestPath, env = process.env, say }) {
const where = out ? path.resolve(/* turbopackIgnore: true */ out) : path.dirname(/* turbopackIgnore: true */ path.resolve(/* turbopackIgnore: true */ manifestPath));
diff --git a/umtool/lib/report/takePrune.test.mjs b/umtool/lib/report/takePrune.test.mjs
@@ -484,3 +484,22 @@ test("the names it prunes by are its writers' names", async () => {
assert.equal(ce.CHUNKS_DIR, "chunks");
assert.equal(ce.HASH_MEMO_FILE, ".content-hashes.json");
});
+
+test("the disk guard: still under the threshold after the takes' prune, the render pool gives back what only it holds", async () => {
+ const GB = 1024 ** 3;
+ const said = [];
+ let free = 8 * GB;
+ let asked = null;
+ const r = await diskGuard({
+ dirs: ["/x"], env: {}, free: async () => free, say: (l) => said.push(l),
+ pruneAll: async () => ({ freedBytes: 0, results: [] }),
+ prunePool: async ({ deficit }) => {
+ asked = deficit;
+ free += 15 * GB;
+ return { evicted: 3, bytes: 15 * GB };
+ },
+ });
+ assert.equal(asked, 22 * GB, "the deficit to the 30 GB threshold");
+ assert.equal(r.freedBytes, 15 * GB);
+ assert.ok(said.some((l) => /the render pool evicted 3 object\(s\), 15\.0 GiB/.test(l)), said.join("\n"));
+});