commit c043ab89c109450c3243ba3ce1222f6fe95767f8
parent bcd36d02e9f51c64e9e7e9ef8ec61beac8f41a49
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 27 Oct 2026 18:01:24 -0400
Take prune: a segment's records and a batch's .from.json stay; only the encodes go
`umtool trailer --take` maps its beats through segments/<id>.cut.json and
verify-build reads a teaser's segments/<id>.teaser.json, so removing the
whole segments/ directory would have broken both on a pruned take. Work in
segments/ is now its *.mp4 encodes, in xfade-batches/ its batch-*.mov; the
directory and every record in it stay (a "files" work path: matching files
only, never a link, the directory resolved inside the take first). A build
--from a pruned take finds the records but no encode, and encodes it again.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 69 insertions(+), 28 deletions(-)
diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md
@@ -950,9 +950,9 @@ chrome compositions, every small record, and any name not on the list):
| Path | What |
|---|---|
-| `<variant>/segments/` | each clip's encoded segment and its records |
+| `<variant>/segments/*.mp4` | each clip's encoded segment — its records (`<id>.cut.json`, `.teaser.json`, …) stay: `umtool trailer` maps beats through them and verify-build reads a teaser's |
| `<variant>/chrome/<layer>-frames/`, `<variant>/chrome/work-*/` | each layer's PNG sequence; a render's leftovers and `--from`'s `work-from-*` |
-| `<variant>/xfade-batches/` | the crossfade batches |
+| `<variant>/xfade-batches/batch-*.mov` | the crossfade batches (`.from.json` stays) |
| `<variant>/chunks/`, `<variant>/.content-hashes.json` | the chunked final encode and its content-hash memo |
| `<variant>/<slug>.prerail*.mp4` (and `.segments`) | the rail's cached base (`--rail-only`) |
| `.keep-frames/` | layers kept aside for a `--from` |
diff --git a/umtool/lib/report/takePrune.mjs b/umtool/lib/report/takePrune.mjs
@@ -12,8 +12,11 @@
// out/.keep-frames/ layers kept aside for a --from (takeFrom.mjs)
// out/clips-raw/ a real directory of raw clip copies (the
// usual one is a LINK to the project's: not work)
-// out/<variant>/segments/ each clip's encoded segment and its records
-// out/<variant>/xfade-batches/ the crossfade batches
+// out/<variant>/segments/*.mp4 each clip's encoded segment -- its records
+// (<id>.cut.json, .teaser.json, …) stay: a
+// trailer (`umtool trailer`) maps beats through
+// them, verify-build reads a teaser's
+// out/<variant>/xfade-batches/*.mov the crossfade batches (.from.json stays)
// out/<variant>/chunks/ the final encode's chunks (chunked-encode.mjs)
// out/<variant>/.content-hashes.json that encode's content-hash memo
// out/<variant>/chrome/*-frames/ each chrome layer's PNG sequence
@@ -93,9 +96,11 @@ export const DISK_GUARD_DEFAULTS = Object.freeze({ thresholdGB: 30, floorGB: 10
export const KEEP_FRAMES_DIR = ".keep-frames"; // takeFrom.mjs
export const XFADE_FROM_FILE = ".from.json"; // build-video.mjs
const NOT_VARIANTS = new Set(["clips-raw", "narration", "bench-excerpts", "posts-media", KEEP_FRAMES_DIR]);
+// kind "files": the files in that directory whose names match, never the
+// directory or anything else in it.
const IN_VARIANT = [
- { name: "segments", kind: "dir", what: "clip segments" },
- { name: "xfade-batches", kind: "dir", what: "crossfade batches" },
+ { name: "segments", kind: "files", match: /^[^.].*\.mp4$/, glob: "*.mp4", what: "clip segments (the encodes; their records stay)" },
+ { name: "xfade-batches", kind: "files", match: /^batch-.*\.mov$/, glob: "batch-*.mov", what: "crossfade batches" },
{ name: "chunks", kind: "dir", what: "the final encode's chunks" },
{ name: ".content-hashes.json", kind: "file", what: "the encode's content-hash memo" },
];
@@ -328,31 +333,38 @@ async function allowedRootsOf(takeDir, { reportsRoot, mediaRoot }) {
*
* @param {string} takeDir
* @param {{ reportsRoot?: string, mediaRoot?: string }} [opts]
- * @returns {Promise<{ roots: { abs: string, rel: string, kind: "dir" | "file", what: string }[], allowed: string[], notes: string[] }>}
+ * @returns {Promise<{ roots: { abs: string, rel: string, kind: "dir" | "file" | "files", what: string, match?: RegExp }[], allowed: string[], notes: string[] }>}
*/
export async function workPathsOf(takeDir, { reportsRoot = REPORTS_ROOT, mediaRoot = MEDIA_ROOT } = {}) {
const { allowed, out, notes } = await allowedRootsOf(takeDir, { reportsRoot, mediaRoot });
const roots = [];
+ const names = async (dir) => readdir(/* turbopackIgnore: true */ dir, { withFileTypes: true }).catch(() => []);
if (!out) return { roots, allowed, notes };
- const add = async (abs, kind, what) => {
+ const add = async (abs, kind, what, w = null) => {
const st = await lstat(/* turbopackIgnore: true */ abs).catch(() => null);
if (!st || st.isSymbolicLink()) return;
- if (kind === "dir" ? !st.isDirectory() : !st.isFile()) return;
+ if (kind === "file" ? !st.isFile() : !st.isDirectory()) return;
const real = await realpath(/* turbopackIgnore: true */ abs).catch(() => null);
if (!real || !allowed.some((a) => real !== a && inside(a, real))) {
notes.push(`${path.relative(takeDir, abs)} resolves outside the take: not touched`);
return;
}
+ if (kind === "files") {
+ // Only when one is there: a directory of records alone holds no work.
+ const files = (await names(abs)).filter((e) => e.isFile() && w.match.test(e.name));
+ if (!files.length) return;
+ roots.push({ abs, rel: `${path.relative(takeDir, abs)}/${w.glob}`, kind, what, match: w.match });
+ return;
+ }
roots.push({ abs, rel: path.relative(takeDir, abs), kind, what });
};
- const names = async (dir) => readdir(/* turbopackIgnore: true */ dir, { withFileTypes: true }).catch(() => []);
await add(path.join(/* turbopackIgnore: true */ out, KEEP_FRAMES_DIR), "dir", "chrome frames kept aside for --from");
await add(path.join(/* turbopackIgnore: true */ out, "clips-raw"), "dir", "raw clip copies");
for (const v of await names(out)) {
if (!v.isDirectory() || v.name.startsWith(".") || NOT_VARIANTS.has(v.name)) continue;
const vdir = path.join(/* turbopackIgnore: true */ out, v.name);
const inV = await names(vdir);
- for (const w of IN_VARIANT) if (inV.some((e) => e.name === w.name)) await add(path.join(/* turbopackIgnore: true */ vdir, w.name), w.kind, w.what);
+ for (const w of IN_VARIANT) if (inV.some((e) => e.name === w.name)) await add(path.join(/* turbopackIgnore: true */ vdir, w.name), w.kind, w.what, w);
for (const e of inV) if (e.isFile() && PRERAIL.test(e.name)) await add(path.join(/* turbopackIgnore: true */ vdir, e.name), "file", "the rail's cached base");
for (const c of await names(path.join(/* turbopackIgnore: true */ vdir, "chrome"))) {
if (!c.isDirectory()) continue;
@@ -371,7 +383,7 @@ const blocksOf = (st) => (typeof st.blocks === "number" ? st.blocks * 512 : st.s
* link are summed at once; those with more are returned by `dev:ino` with
* their link count and how many of their paths are in these roots.
*
- * @param {{ abs: string, kind: "dir" | "file" }[]} roots
+ * @param {{ abs: string, kind: "dir" | "file" | "files", match?: RegExp }[]} roots
* @returns {Promise<{ single: number, files: number, multi: Map<string, { nlink: number, bytes: number, n: number }>, perRoot: { bytes: number, files: number }[] }>}
*/
export async function measurePaths(roots) {
@@ -411,6 +423,14 @@ export async function measurePaths(roots) {
perRoot.push({ bytes: 0, files: 0 });
continue;
}
+ if (root.kind === "files") {
+ // The matching files only: the directory and its records stay.
+ const entries = (await readdir(/* turbopackIgnore: true */ root.abs, { withFileTypes: true }).catch(() => [])).filter((e) => e.isFile() && root.match?.test(e.name));
+ const sts = await Promise.all(entries.map((e) => lstat(/* turbopackIgnore: true */ path.join(/* turbopackIgnore: true */ root.abs, e.name)).catch(() => null)));
+ for (const st of sts) if (st?.isFile()) take(st);
+ perRoot.push({ bytes: rb, files: rf });
+ continue;
+ }
take(top);
const stack = top.isDirectory() ? [root.abs] : [];
while (stack.length) {
@@ -550,7 +570,7 @@ async function readTakeDirs(projectDir, { host, alive }) {
* builtAt: string | null, modifiedAt: string | null, bases: string[],
* status: "prunable" | "kept" | "no-work",
* keep: KeepReason[], overridden: KeepReason[],
- * roots: { rel: string, kind: "dir" | "file", what: string, bytes: number | null, files: number | null }[],
+ * roots: { rel: string, kind: "dir" | "file" | "files", what: string, bytes: number | null, files: number | null }[],
* workBytes: number | null, freedBytes: number | null, files: number | null,
* notes: string[], pruned: { at: string, freedBytes: number } | null,
* }} TakePlan
@@ -805,6 +825,24 @@ export async function removeWorkPath(abs, allowed) {
return null;
}
+/**
+ * Remove the files in `dir` whose names match (a "files" work path): files
+ * only, never a link or a directory, never `dir` itself; `dir` must resolve
+ * inside `allowed`.
+ * @returns {Promise<string | null>} why not, or null when done
+ */
+export async function removeWorkFiles(dir, match, allowed) {
+ const st = await lstat(/* turbopackIgnore: true */ dir).catch(() => null);
+ if (!st) return null;
+ if (st.isSymbolicLink()) return "a link: not followed, not removed";
+ const real = await realpath(/* turbopackIgnore: true */ dir).catch(() => null);
+ if (!real || !allowed.some((a) => real !== a && inside(a, real))) return "resolves outside the take: not removed";
+ for (const e of await readdir(/* turbopackIgnore: true */ dir, { withFileTypes: true })) {
+ if (e.isFile() && match.test(e.name)) await unlink(/* turbopackIgnore: true */ path.join(/* turbopackIgnore: true */ dir, e.name));
+ }
+ return null;
+}
+
async function removeTree(dir) {
const entries = await readdir(/* turbopackIgnore: true */ dir, { withFileTypes: true });
for (let i = 0; i < entries.length; i += 256) {
@@ -880,7 +918,7 @@ export async function pruneProject(project, opts = {}) {
const gone = [];
for (const r of work.roots) {
try {
- const no = await removeWorkPath(r.abs, work.allowed);
+ const no = r.kind === "files" ? await removeWorkFiles(r.abs, /** @type {RegExp} */ (r.match), work.allowed) : await removeWorkPath(r.abs, work.allowed);
if (no) failed.push({ path: `${TAKES_DIR}/${t.id}/${r.rel}`, error: no });
else gone.push(r.rel);
} catch (err) {
diff --git a/umtool/lib/report/takePrune.test.mjs b/umtool/lib/report/takePrune.test.mjs
@@ -107,8 +107,8 @@ test("work and final: the work is the named build files under out/; the renders,
"out/sourced/chrome/feed-frames",
"out/sourced/chunks",
"out/sourced/fx.prerail-hardcut.mp4",
- "out/sourced/segments",
- "out/sourced/xfade-batches",
+ "out/sourced/segments/*.mp4",
+ "out/sourced/xfade-batches/batch-*.mov",
]);
const r = await pruneProject({ id: "proj", dir }, { ...opts, flags: { keep: 0 }, now: later });
@@ -116,9 +116,11 @@ test("work and final: the work is the named build files under out/; the renders,
for (const f of ["take.json", "preview.mp4", "out/fx.mp4", "out/fx.720p.mp4", "video.manifest.json", "out/sourced/schedule.json", "out/sourced/sync.json", "out/sourced/chapters.ffmeta", "out/sourced/cards/c1.png", "out/sourced/chrome/deck/index.html"]) {
assert.ok(await exists(path.join(t, f)), `${f} is final and stays`);
}
- for (const f of ["out/sourced/segments", "out/sourced/chrome/deck-frames", "out/sourced/xfade-batches", "out/sourced/chunks", "out/sourced/.content-hashes.json"]) {
+ for (const f of ["out/sourced/segments/s01.mp4", "out/sourced/chrome/deck-frames", "out/sourced/xfade-batches/batch-abc.mov", "out/sourced/chunks", "out/sourced/.content-hashes.json"]) {
assert.equal(await exists(path.join(t, f)), false, `${f} is work and goes`);
}
+ // A segment's records stay (a trailer maps its beats through them).
+ assert.ok(await exists(path.join(t, "out", "sourced", "segments", "s01.cut.json")));
assert.ok((await lstat(path.join(t, "out", "clips-raw"))).isSymbolicLink(), "the shared clips-raw link stays");
// A pruned chrome layer stays verifiable: its count and key were recorded.
const deck = path.join(t, "out", "sourced", "chrome", "deck-frames");
@@ -171,7 +173,7 @@ test("hard links: a take built --from another shares its inodes; pruning one fre
const r = await pruneProject(project, { ...opts, now: later });
assert.deepEqual(r.pruned.map((p) => p.id), ["a"]);
assert.equal(r.freedBytes, pa.freedBytes);
- assert.equal(await exists(path.join(va, "segments")), false);
+ assert.equal(await exists(path.join(va, "segments", "s01.mp4")), false);
assert.deepEqual(await readFile(path.join(vb, "segments", "s01.mp4")), seg);
assert.equal((await stat(path.join(vb, "segments", "s01.mp4"))).nlink, 1, "b holds the last link now");
assert.equal((await readdir(path.join(vb, "chrome", "deck-frames"))).length, 4);
@@ -284,9 +286,9 @@ test("a running build: its take and the take it builds from are never pruned, no
const r = await pruneProject(project, { ...opts, processes, flags, now: later });
assert.deepEqual(r.pruned.map((p) => p.id), ["other"]);
- assert.ok(await exists(path.join(twin, "out", "sourced", "segments")));
- assert.ok(await exists(path.join(dir, "takes", "base", "out", "sourced", "segments")));
- assert.ok(await exists(path.join(dir, "takes", "loose", "out", "sourced", "segments")));
+ assert.ok(await exists(path.join(twin, "out", "sourced", "segments", "s01.mp4")));
+ assert.ok(await exists(path.join(dir, "takes", "base", "out", "sourced", "segments", "s01.mp4")));
+ assert.ok(await exists(path.join(dir, "takes", "loose", "out", "sourced", "segments", "s01.mp4")));
// The lock is this process's: removed, and the twin is prunable again.
const { removeBuildLock } = await import("./takePrune.mjs");
await removeBuildLock(path.join(twin, BUILD_LOCK));
@@ -319,6 +321,7 @@ test("the symlink guard: a link is never work and never followed; a path resolvi
assert.ok(await exists(path.join(outside, "window.mp4")), "the corpus file is whole");
assert.ok(await exists(path.join(outside, "frame.png")));
assert.ok((await lstat(path.join(v, "segments"))).isSymbolicLink(), "the link itself was not touched");
+ assert.ok(await exists(path.join(outside, "window.mp4")));
assert.equal(await exists(path.join(t, "out", "clips-raw")), false);
assert.equal(await exists(path.join(v, "chrome", "deck-frames")), false);
@@ -348,7 +351,7 @@ test("the symlink guard: a link is never work and never followed; a path resolvi
await writeFile(path.join(mirror, "sourced", "segments", "s.mp4"), "s");
await symlink(mirror, path.join(c, "out"));
const wc = await workPathsOf(c, { ...opts, mediaRoot: media });
- assert.deepEqual(wc.roots.map((x) => x.rel), ["out/sourced/segments"]);
+ assert.deepEqual(wc.roots.map((x) => x.rel), ["out/sourced/segments/*.mp4"]);
});
test("the disk guard: above the threshold nothing happens; under it the policy runs; still under the floor the render is refused", async () => {
@@ -407,7 +410,7 @@ test("after a take is made: its project pruned by the policy, the new take kept,
assert.equal(lockDuring?.pid, process.pid);
assert.equal(lockDuring?.take, "new");
assert.equal(await readBuildLock(path.join(dir, "takes", "new", BUILD_LOCK)), null, "released after");
- assert.equal(await exists(path.join(old, "out", "sourced", "segments")), false, "the old take's work went");
+ assert.equal(await exists(path.join(old, "out", "sourced", "segments", "s01.mp4")), false, "the old take's work went");
assert.ok(await exists(path.join(old, "preview.mp4")));
assert.ok(logs.some((l) => /^new: prune: freed .* from 1 take\(s\): old/.test(l)), logs.join("\n"));
// Off in takes/prune.json: nothing pruned, nothing said.
@@ -416,7 +419,7 @@ test("after a take is made: its project pruned by the policy, the new take kept,
await writeFile(path.join(dir, "takes", "prune.json"), JSON.stringify({ keep: 0, afterBuild: false }));
logs.length = 0;
await makeTake(dir, { id: "new2", label: "New 2", window: "full" }, { render, probe: async () => 2, log: (l) => logs.push(l) });
- assert.ok(await exists(path.join(old2, "out", "sourced", "segments")));
+ assert.ok(await exists(path.join(old2, "out", "sourced", "segments", "s01.mp4")));
assert.equal(logs.some((l) => /prune:/.test(l)), false);
// pruneAfterBuild never throws: a bad policy file is said.
await writeFile(path.join(dir, "takes", "prune.json"), "{");
@@ -443,7 +446,7 @@ test("the CLI: a dry run by default, --yes frees, --json, and its refusals", asy
assert.match(r.out, /a\s+prunable\s+work .* frees/);
assert.match(r.out, /b\s+kept .* the newest of group "takes" \(keeps 1\)/);
assert.match(r.out, /dry run — nothing deleted\. --yes frees/);
- assert.ok(await exists(path.join(dir, "takes", "a", "out", "sourced", "segments")), "a dry run deletes nothing");
+ assert.ok(await exists(path.join(dir, "takes", "a", "out", "sourced", "segments", "s01.mp4")), "a dry run deletes nothing");
r = await run("proj", "--keep", "1", "--json");
const j = JSON.parse(r.out);
assert.equal(j.dryRun, true);
@@ -452,11 +455,11 @@ test("the CLI: a dry run by default, --yes frees, --json, and its refusals", asy
r = await run("--all", "--keep", "1", "--yes");
assert.equal(r.code, 0, r.err);
assert.match(r.out, /freed a: /);
- assert.equal(await exists(path.join(dir, "takes", "a", "out", "sourced", "segments")), false);
- assert.ok(await exists(path.join(dir, "takes", "b", "out", "sourced", "segments")));
+ assert.equal(await exists(path.join(dir, "takes", "a", "out", "sourced", "segments", "s01.mp4")), false);
+ assert.ok(await exists(path.join(dir, "takes", "b", "out", "sourced", "segments", "s01.mp4")));
r = await run("proj", "--take", "b", "--anyway", "--yes");
assert.equal(r.code, 0, r.err);
- assert.equal(await exists(path.join(dir, "takes", "b", "out", "sourced", "segments")), false);
+ assert.equal(await exists(path.join(dir, "takes", "b", "out", "sourced", "segments", "s01.mp4")), false);
assert.equal((await run()).code, 2);
assert.match((await run("--all", "--take", "a")).err, /names a take of one project/);
assert.match((await run("proj", "--anyway")).err, /name it with --take/);