commit e1e8b7aebf4305bbbe4a26b13dd23064e2ee30d0
parent 17949856828aff12ef97f8aa37a8bf942694015b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 14:12:42 -0500
common: housekeeping's gate fails closed, --grace passes through, and a take kept since the plan is said, not failed
Review of lane/housekeeping:
- The gate fails CLOSED. heavyQueue.mjs reads a file it cannot read as
"nothing there", which for a deleter is "go"; checkSlotFiles reads the
slot's own files first (the lock's directory, the running and waiting
tickets, each e2e suite's holder, render mode's state) and the run is
skipped, exit 75 and recorded, when any does not read or parse, when
the checkout is not a git checkout, or when the slot cannot be read at
all.
- `--grace <age>` (default 7d) passes through to `umtool prune --versions`;
the run and its summary carry it.
- A take umtool kept because it was claimed or built in since the plan is a
note ("… kept: …"), not a failure: umtool exits 0 for it, so the unit does
not go failed.
Docs: OPERATING.md "Free disk" (the grace, the verdicts, the notes re-read,
the fail-closed gate, the worktrees' ignored content), COMMANDS.md
regenerated, the changelog bullet. Tests: an unreadable slot skips (75),
checkSlotFiles over each file kind, --grace passed and checked, raced
entries summarised as kept.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 145 insertions(+), 30 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -110,7 +110,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer service restart` | `[--apps <a,b>] [--dry-run]` | restart the installed units (all, or the named apps: editor, umtool, site-<id>, docker) — the editor's running jobs are stopped by its shutdown reaper; never the housekeeping pair (restarting its oneshot would run it) |
| `archilyzer service uninstall` | `[--mode docker\|host] [--apps <a,b>] [--dry-run]` | stop, disable and remove the units (volumes, builds and the corpus are untouched) |
| `archilyzer service storage-overlay` | `[--corpus <dir>] [--out <file>] [--check] [--dry-run]` | write docker-compose.storage.yml: every storage location's root, and every channel media link or saved-video store link no location covers, bind-mounted into the editor and umtool at the SAME absolute path (the links are absolute); --corpus also mounts a host corpus at /data/transcripts in place of the volume; read off the corpus disk only (no media drive is touched) |
-| `archilyzer housekeeping` | `[--dry-run] [--json] [--idle 3d] [--skip takes,work,worktrees] [--by cli\|timer]` | free disk over the apps' own commands: whole superseded takes (`umtool prune --all --versions`: per version line — the take id, digits folded, letters never — the newest built is kept, and any take picked, pinned, rendering, a base, noted on or refused by `umtool takes delete`), every project's takes' work files by its prune policy and an idle project's newest and picked takes' too (`--idle-work`), and merged, clean, idle worktrees nobody works in (`pnpm wt prune`: `git worktree remove`, branches kept); a project or worktree touched within --idle is left alone. SKIPPED, not queued, while render mode is on, a job runs in the heavy slot or an e2e suite holds its queue. Prints what each part freed and kept (by reason) and the home filesystem's free space before and after, and appends the run to $XDG\_STATE\_HOME/archilyzer/housekeeping.json (the last 52; ARCHILYZER\_HOUSEKEEPING\_RECORD overrides). --dry-run deletes nothing and records nothing. `archilyzer service install` runs it weekly (archilyzer-housekeeping.timer) |
+| `archilyzer housekeeping` | `[--dry-run] [--json] [--idle 3d] [--grace 7d] [--skip takes,work,worktrees] [--by cli\|timer]` | free disk over the apps' own commands: whole superseded takes (`umtool prune --all --versions`: per version line — the take id, digits folded, letters never — the highest built number is kept, the older ones until it is --grace old, and any take picked, judged, pinned, rendering, a base, noted on or refused by `umtool takes delete`; a project whose verdicts.json cannot be read is skipped), every project's takes' work files by its prune policy and an idle project's newest and picked takes' too (`--idle-work`), and merged, clean, idle worktrees nobody works in (`pnpm wt prune`: `git worktree remove`, branches kept); a project or worktree touched within --idle is left alone. SKIPPED (exit 75), not queued, while render mode is on, a job runs in the heavy slot or an e2e suite holds its queue, or when that state cannot be read. Prints what each part freed and kept (by reason) and the home filesystem's free space before and after, and appends the run to $XDG\_STATE\_HOME/archilyzer/housekeeping.json (the last 52; ARCHILYZER\_HOUSEKEEPING\_RECORD overrides). --dry-run deletes nothing and records nothing. `archilyzer service install` runs it weekly (archilyzer-housekeeping.timer) |
| `archilyzer doctor` | `[--json]` | read-only report: node, the checkout, the corpus, settings, every tool, the port block; exit 1 on a failure |
| `archilyzer release show` | `[editor\|export]` | latest release, its date, how many bullets wait under \[Unreleased\] |
| `archilyzer release cut` | `<editor\|export\|all> <X.Y.Z\|next\|next-minor> [--commit] [--date YYYY-MM-DD]` | \[Unreleased\] -> a dated heading; all = both, one version, two commits |
diff --git a/OPERATING.md b/OPERATING.md
@@ -960,10 +960,10 @@ pnpm ops delete-iteration --json '{"id":"example-article","n":3}'
```sh
pnpm archilyzer housekeeping --dry-run # what would go, what stays and why; deletes and records nothing
pnpm archilyzer housekeeping # do it (skipped while a render or an e2e/heavy job runs)
-pnpm archilyzer housekeeping --json --idle 7d --skip worktrees
+pnpm archilyzer housekeeping --json --idle 7d --grace 14d --skip worktrees
pnpm archilyzer service status # the weekly timer: next and last run, the last run's result
# one part at a time, each a dry run unless --yes:
-node umtool/bin/umtool.mjs prune --all --versions [--idle 3d] [--json] # superseded takes
+node umtool/bin/umtool.mjs prune --all --versions [--idle 3d] [--grace 7d] [--json] # superseded takes
node umtool/bin/umtool.mjs prune --all --idle-work 3d [--json] # takes' work files
pnpm wt prune --dry-run [--json] # worktrees that are done
```
@@ -973,18 +973,23 @@ pnpm wt prune --dry-run [--json] # w
starts the oneshot `archilyzer-housekeeping.service`. `--no-housekeeping` leaves them out; `systemctl --user
start archilyzer-housekeeping.service` runs it now.
- **Never beside a render or an e2e/heavy job.** With render mode on, a job in the heavy slot or an e2e suite
- holding its queue, a run is skipped (exit 75), not queued; the unit tries again hourly for a day, and the record
- folds the skips into one entry.
+ holding its queue — or when the slot's files cannot be read — a run is skipped (exit 75), not queued; the unit
+ tries again hourly for a day, and the record folds the skips into one entry.
- **Superseded takes** (whole takes, through `umtool takes delete`): per version line — the take id with its digits
folded (`draft-3` and `draft-4` are `draft-#`); a letter is never folded (`v6c` ≠ `v6d`, `release-6u` ≠
- `release-6`) — the newest built take stays, and so does any take picked, pinned, rendering, a build's or a
- render's base, the project's manifest's, with operator notes on it, or refused by `takes delete` (a project
- reached through a link). A project touched within `--idle` (default 3 days) is skipped whole.
+ `release-6`) — the highest built number stays (`draft-10` over `draft-9`; a rebuilt `draft-3` does not supersede
+ `draft-4`), and the older ones stay until it is `--grace` old (default 7 days). So does any take picked, pinned,
+ with any verdict (like, maybe, no, a verdict note), rendering, a build's or a render's base, the project's
+ manifest's, with operator notes on it, or refused by `takes delete` (a project reached through a link). A project
+ touched within `--idle` (default 3 days: any of its files but render scratch and fetched media, its notes, a take's
+ patch or manifest) is skipped whole, and so is one whose `takes/verdicts.json` cannot be read. Picks, verdicts and
+ notes are read again right before each delete; a take claimed since the plan is kept and said, not failed.
- **Work files** (segments, chrome frames, crossfade batches, encode chunks, the rail's `prerail` base): every
project by its prune policy, and in a project idle that long the newest and picked takes' work too. Renders,
previews, take.json and the manifests are never touched; a pin in `takes/prune.json` and a running build keep
theirs. umtool's [report-video.md](umtool/docs/report-video.md), "A take's work files, and pruning them".
-- **Worktrees**: merged into `main`, clean (no change, no untracked file), no process in them, idle; `git worktree
+- **Worktrees**: merged into `main`, clean (no change, no untracked file), no ignored content that is somebody's (a
+ real `transcripts/`, an `.env*`, a changed `settings.json`, a nested repo), no process in them, idle; `git worktree
remove`, never `--force`, branches kept. Every other worktree's port block is recorded first, so no running suite
loses its ports. [WORKTREES.md](WORKTREES.md), "Removing the worktrees that are done".
- **The record**: `~/.local/state/archilyzer/housekeeping.json` (`$XDG_STATE_HOME`; `ARCHILYZER_HOUSEKEEPING_RECORD`
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -1234,13 +1234,14 @@ export const COMMANDS: Command[] = [
{
path: ["housekeeping"],
usage:
- "[--dry-run] [--json] [--idle 3d] [--skip takes,work,worktrees] [--by cli|timer] free disk over the apps' own commands: whole superseded takes (`umtool prune --all --versions`: per version line — the take id, digits folded, letters never — the newest built is kept, and any take picked, pinned, rendering, a base, noted on or refused by `umtool takes delete`), every project's takes' work files by its prune policy and an idle project's newest and picked takes' too (`--idle-work`), and merged, clean, idle worktrees nobody works in (`pnpm wt prune`: `git worktree remove`, branches kept); a project or worktree touched within --idle is left alone. SKIPPED, not queued, while render mode is on, a job runs in the heavy slot or an e2e suite holds its queue. Prints what each part freed and kept (by reason) and the home filesystem's free space before and after, and appends the run to $XDG_STATE_HOME/archilyzer/housekeeping.json (the last 52; ARCHILYZER_HOUSEKEEPING_RECORD overrides). --dry-run deletes nothing and records nothing. `archilyzer service install` runs it weekly (archilyzer-housekeeping.timer)",
- flags: { "dry-run": "boolean", json: "boolean", idle: "string", skip: "string", by: "string" },
+ "[--dry-run] [--json] [--idle 3d] [--grace 7d] [--skip takes,work,worktrees] [--by cli|timer] free disk over the apps' own commands: whole superseded takes (`umtool prune --all --versions`: per version line — the take id, digits folded, letters never — the highest built number is kept, the older ones until it is --grace old, and any take picked, judged, pinned, rendering, a base, noted on or refused by `umtool takes delete`; a project whose verdicts.json cannot be read is skipped), every project's takes' work files by its prune policy and an idle project's newest and picked takes' too (`--idle-work`), and merged, clean, idle worktrees nobody works in (`pnpm wt prune`: `git worktree remove`, branches kept); a project or worktree touched within --idle is left alone. SKIPPED (exit 75), not queued, while render mode is on, a job runs in the heavy slot or an e2e suite holds its queue, or when that state cannot be read. Prints what each part freed and kept (by reason) and the home filesystem's free space before and after, and appends the run to $XDG_STATE_HOME/archilyzer/housekeeping.json (the last 52; ARCHILYZER_HOUSEKEEPING_RECORD overrides). --dry-run deletes nothing and records nothing. `archilyzer service install` runs it weekly (archilyzer-housekeeping.timer)",
+ flags: { "dry-run": "boolean", json: "boolean", idle: "string", grace: "string", skip: "string", by: "string" },
run: async ({ flags }) =>
(await import("./housekeeping")).main({
dryRun: flags["dry-run"] === true,
json: flags.json === true,
idle: str(flags.idle),
+ grace: str(flags.grace),
skip: str(flags.skip),
by: str(flags.by),
}),
diff --git a/common/bin/housekeeping.test.ts b/common/bin/housekeeping.test.ts
@@ -15,6 +15,7 @@ import path from "node:path";
import { fileURLToPath } from "node:url";
import {
RECORD_KEEP,
+ checkSlotFiles,
SKIPPED_EXIT,
appendRecord,
housekeeping,
@@ -27,6 +28,7 @@ import {
summarizeWorktrees,
type HousekeepingDeps,
type HousekeepingRun,
+ type SlotRead,
type SlotState,
} from "./housekeeping";
@@ -80,7 +82,7 @@ const WT_DRY = {
type Call = { cmd: string; args: string[]; cwd: string };
-function rig(opts: { slot?: SlotState | null; prune?: object; wt?: object } = {}) {
+function rig(opts: { slot?: SlotRead; prune?: object; wt?: object } = {}) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "housekeeping-test-"));
const calls: Call[] = [];
const lines: string[] = [];
@@ -107,8 +109,10 @@ function rig(opts: { slot?: SlotState | null; prune?: object; wt?: object } = {}
}
test("the gate: render mode, a job in the heavy slot, an e2e suite — each says why; an idle slot passes", () => {
- assert.equal(slotBusy(null), null);
assert.equal(slotBusy(IDLE_SLOT), null);
+ // Fail closed: a slot that cannot be read is a slot that says not now.
+ assert.match(slotBusy(null) ?? "", /could not be read: not deleting blind/);
+ assert.match(slotBusy({ error: "a running job's ticket x does not parse" }) ?? "", /could not be read \(a running job's ticket x does not parse\)/);
assert.equal(slotBusy({ ...IDLE_SLOT, render: { held: true, what: "umtool take p --id t" } }), "render mode is on (umtool take p --id t)");
assert.match(slotBusy({ ...IDLE_SLOT, running: [{ what: "render of t (p)", pid: 7 }] }) ?? "", /heavy slot is busy: render of t \(p\) \(pid 7\)/);
assert.match(slotBusy({ ...IDLE_SLOT, suites: [{ suite: "e2e-editor", pid: 8 }] }) ?? "", /e2e suite is running: e2e-editor/);
@@ -127,6 +131,40 @@ test("a run the slot turns away is SKIPPED with exit 75: nothing runs, the recor
assert.equal(runs[0].firstSkippedAt, "2026-11-08T05:00:00.000Z");
});
+test("an unreadable slot skips the run (exit 75) like a busy one", async () => {
+ const r = rig({ slot: { error: "the heavy slot's directory /x is not there" } });
+ const { code, run } = await housekeeping({}, r.deps);
+ assert.equal(code, SKIPPED_EXIT);
+ assert.equal(r.calls.length, 0);
+ assert.match(run.skipped ?? "", /could not be read \(the heavy slot's directory \/x is not there\)/);
+ assert.equal(readRecord(r.deps.recordFile)[0].skipped, run.skipped);
+});
+
+test("checkSlotFiles believes the slot's files only when they read: the directory, the tickets, the holders, render mode", () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "housekeeping-slot-"));
+ try {
+ const lock = path.join(root, "heavy-queue.lock");
+ const render = `${lock}.render.json`;
+ assert.throws(() => checkSlotFiles(path.join(root, "gone", "heavy-queue.lock"), render), /directory .* is not there/);
+ checkSlotFiles(lock, render); // nothing there yet: an idle slot
+ fs.mkdirSync(`${lock}.jobs`);
+ fs.writeFileSync(path.join(`${lock}.jobs`, "1.json"), JSON.stringify({ pid: 1 }));
+ checkSlotFiles(lock, render);
+ fs.writeFileSync(path.join(`${lock}.jobs`, "2.json"), "{ half");
+ assert.throws(() => checkSlotFiles(lock, render), /a running job's ticket .*2\.json does not parse/);
+ fs.rmSync(path.join(`${lock}.jobs`, "2.json"));
+ fs.writeFileSync(path.join(root, "e2e-editor-queue.lock.holder.json"), "nope");
+ assert.throws(() => checkSlotFiles(lock, render), /a queue's holder file .* does not parse/);
+ fs.rmSync(path.join(root, "e2e-editor-queue.lock.holder.json"));
+ fs.writeFileSync(render, "{}");
+ assert.throws(() => checkSlotFiles(lock, render), /render mode's state .* is not one/);
+ fs.writeFileSync(render, JSON.stringify({ token: "t", until: "2099-01-01T00:00:00Z" }));
+ checkSlotFiles(lock, render);
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+});
+
test("a dry run with the slot busy still plans, says a real run would be skipped, and records nothing", async () => {
const r = rig({ slot: { ...IDLE_SLOT, suites: [{ suite: "e2e-umtool", pid: 9 }] } });
const { code, run } = await housekeeping({ dryRun: true }, r.deps);
@@ -142,7 +180,7 @@ test("the parts and their arguments: one umtool run (versions, then idle work),
const r = rig();
const { code, run } = await housekeeping({ idle: "5d" }, r.deps);
assert.equal(code, 0);
- assert.deepEqual(r.calls[0].args.slice(1), ["prune", "--all", "--json", "--yes", "--versions", "--idle", "5d", "--idle-work", "5d"]);
+ assert.deepEqual(r.calls[0].args.slice(1), ["prune", "--all", "--json", "--yes", "--versions", "--idle", "5d", "--grace", "7d", "--idle-work", "5d"]);
assert.equal(r.calls[0].args[0], path.join("/repo", "umtool", "bin", "umtool.mjs"));
assert.deepEqual(r.calls[1].args.slice(1), ["prune", "--json", "--idle", "5d"]);
assert.equal(r.calls[1].cwd, "/repo");
@@ -162,6 +200,10 @@ test("the parts and their arguments: one umtool run (versions, then idle work),
await assert.rejects(housekeeping({ skip: "disk" }, rig().deps), /--skip takes takes, work, worktrees/);
await assert.rejects(housekeeping({ idle: "soon" }, rig().deps), /not an age/);
+ await assert.rejects(housekeeping({ grace: "later" }, rig().deps), /--grace: "later" is not an age/);
+ const gr = rig();
+ await housekeeping({ grace: "14d" }, gr.deps);
+ assert.deepEqual(gr.calls[0].args.slice(gr.calls[0].args.indexOf("--grace"), gr.calls[0].args.indexOf("--grace") + 2), ["--grace", "14d"]);
});
test("the summaries: what goes, what is kept by reason, the skipped projects, the idle ones", () => {
@@ -179,6 +221,9 @@ test("the summaries: what goes, what is kept by reason, the skipped projects, th
// Applied: the deleted / removed lists, not the plan's.
const applied = summarizePrune({ ...PRUNE_DRY, versions: { totals: {}, projects: [{ ...PRUNE_DRY.versions.projects[0], deleted: [{ id: "draft-1", bytes: 999 }], failed: [] }] }, projects: [{ ...PRUNE_DRY.projects[0], pruned: [] }] } as never, false);
assert.deepEqual(applied.takes.items, [{ what: "a/proj/takes/draft-1", bytes: 999 }]);
+ const raced = summarizePrune({ ...PRUNE_DRY, versions: { totals: {}, projects: [{ ...PRUNE_DRY.versions.projects[0], deleted: [], failed: [], raced: [{ id: "draft-1", why: "picked since the plan — kept" }] }] }, projects: [{ ...PRUNE_DRY.projects[0], pruned: [], failed: [{ path: "takes/x/", error: "a build started in it (or from it) since the plan: kept", raced: true }] }] } as never, false);
+ assert.ok(raced.takes.notes.includes("a/proj/takes/draft-1 kept: picked since the plan — kept"));
+ assert.ok(raced.work.notes.some((n) => /a\/proj\/takes\/x\/ kept: a build started/.test(n)));
assert.deepEqual(applied.work.items, []);
});
@@ -197,7 +242,7 @@ test("a part that gives no JSON fails the run (exit 1) and says so; the others s
test("the record: newest last, the last 52, at XDG_STATE_HOME unless overridden", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "housekeeping-record-"));
const file = path.join(root, "r.json");
- const run = (i: number): HousekeepingRun => ({ at: `t${i}`, finishedAt: `t${i}`, by: "timer", dryRun: false, idle: "3d", skipped: null, free: { path: "/h", before: 1, after: 2 }, parts: {} as never, freedBytes: i, errors: [] });
+ const run = (i: number): HousekeepingRun => ({ at: `t${i}`, finishedAt: `t${i}`, by: "timer", dryRun: false, idle: "3d", grace: "7d", skipped: null, free: { path: "/h", before: 1, after: 2 }, parts: {} as never, freedBytes: i, errors: [] });
for (let i = 0; i < RECORD_KEEP + 3; i++) appendRecord(file, run(i));
const runs = readRecord(file);
assert.equal(runs.length, RECORD_KEEP);
diff --git a/common/bin/housekeeping.ts b/common/bin/housekeeping.ts
@@ -45,6 +45,8 @@ export type HousekeepingOptions = {
dryRun?: boolean;
json?: boolean;
idle?: string;
+ // How old the take superseding another must be before that one goes (umtool --grace).
+ grace?: string;
skip?: string;
// Who ran it: "cli" (default) or "timer" (the unit passes --by timer).
by?: string;
@@ -59,6 +61,8 @@ export type SlotState = {
running: { what: string; pid: number }[];
suites: { suite: string; pid: number }[];
};
+/** The slot, or why it could not be read (the gate then fails closed). */
+export type SlotRead = SlotState | { error: string } | null;
export type HousekeepingDeps = {
env: NodeJS.ProcessEnv;
@@ -67,7 +71,7 @@ export type HousekeepingDeps = {
now: () => Date;
run: (cmd: string, args: string[], cwd: string) => RunResult;
freeBytes: (dir: string) => number | null;
- slot: () => SlotState | null;
+ slot: () => SlotRead;
// The repository whose worktrees `wt prune` judges (the checkout itself).
worktreeRepo: string;
// Where /home's free space is read (the user's home).
@@ -85,7 +89,7 @@ export function recordFileFor(env: NodeJS.ProcessEnv, home = os.homedir()): stri
export async function defaultDeps(): Promise<HousekeepingDeps> {
const { REPO_ROOT } = await import("./_spawnBin");
const { readHeavyQueue } = await import("../lib/heavyQueue.mjs");
- const { heavyLockFile } = await import("../lib/renderPriority.mjs");
+ const { heavyLockFile, renderPriorityFile } = await import("../lib/renderPriority.mjs");
const home = os.homedir();
return {
env: process.env,
@@ -104,9 +108,13 @@ export async function defaultDeps(): Promise<HousekeepingDeps> {
},
slot: () => {
try {
- return readHeavyQueue({ heavyLock: heavyLockFile(process.env, { root: REPO_ROOT }) }) as SlotState;
- } catch {
- return null;
+ if (!process.env.HEAVY_LOCK_FILE && !gitCommonDirOf(REPO_ROOT)) throw new Error(`${REPO_ROOT} is not a git checkout: the heavy slot's lock cannot be found`);
+ const heavyLock = heavyLockFile(process.env, { root: REPO_ROOT });
+ const renderFile = renderPriorityFile(process.env, { heavyLock });
+ checkSlotFiles(heavyLock, renderFile);
+ return readHeavyQueue({ heavyLock, renderFile }) as SlotState;
+ } catch (e) {
+ return { error: e instanceof Error ? e.message : String(e) };
}
},
home,
@@ -137,9 +145,60 @@ export function runToFile(cmd: string, args: string[], cwd: string, dir: string,
}
}
-/** Why the slot says not now, or null. */
-export function slotBusy(s: SlotState | null): string | null {
- if (!s) return null;
+function gitCommonDirOf(root: string): string | null {
+ const r = spawnSync("git", ["-C", root, "rev-parse", "--path-format=absolute", "--git-common-dir"], { encoding: "utf8" });
+ return r.status === 0 && r.stdout.trim() ? r.stdout.trim() : null;
+}
+
+/**
+ * The slot's own files, checked before they are believed: the lock's directory
+ * is there; the running and waiting ticket directories, when present, can be
+ * listed and every ticket in them parses; every e2e suite's holder file
+ * parses; render mode's state file, when present, parses as one. Throws the
+ * first that does not -- heavyQueue.mjs reads an unreadable file as "nothing
+ * there", which for a deleter would be "go".
+ */
+export function checkSlotFiles(heavyLock: string, renderFile: string): void {
+ const dir = path.dirname(heavyLock);
+ if (!fs.statSync(dir, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`the heavy slot's directory ${dir} is not there`);
+ const parses = (file: string, what: string) => {
+ let text: string;
+ try {
+ text = fs.readFileSync(file, "utf8");
+ } catch (e) {
+ if ((e as NodeJS.ErrnoException).code === "ENOENT") return; // gone since it was listed: its job ended
+ throw new Error(`${what} ${file} cannot be read (${(e as Error).message})`);
+ }
+ try {
+ JSON.parse(text);
+ } catch {
+ throw new Error(`${what} ${file} does not parse`);
+ }
+ };
+ for (const [d, what] of [[`${heavyLock}.jobs`, "a running job's ticket"], [`${heavyLock}.waiting`, "a waiting job's ticket"]] as const) {
+ if (!fs.existsSync(d)) continue;
+ let names: string[];
+ try {
+ names = fs.readdirSync(d);
+ } catch (e) {
+ throw new Error(`${d} cannot be listed (${(e as Error).message})`);
+ }
+ for (const n of names) if (n.endsWith(".json")) parses(path.join(d, n), what);
+ }
+ for (const n of fs.readdirSync(dir)) {
+ if (/^e2e(-[a-z0-9-]+)?-queue\.lock\.holder\.json$/.test(n) || n === `${path.basename(heavyLock)}.holder.json`) parses(path.join(dir, n), "a queue's holder file");
+ }
+ if (fs.existsSync(renderFile)) {
+ parses(renderFile, "render mode's state");
+ const j = JSON.parse(fs.readFileSync(renderFile, "utf8"));
+ if (!j || typeof j !== "object" || typeof j.token !== "string") throw new Error(`render mode's state ${renderFile} is not one`);
+ }
+}
+
+/** Why the slot says not now, or null. A slot that cannot be read says not now too (fail closed). */
+export function slotBusy(s: SlotRead): string | null {
+ if (!s) return "the heavy slot's state could not be read: not deleting blind";
+ if ("error" in s) return `the heavy slot's state could not be read (${s.error}): not deleting blind`;
if (s.render?.held) return `render mode is on${s.render.what ? ` (${s.render.what})` : ""}`;
if (s.running?.length) return `the heavy slot is busy: ${s.running.map((r) => `${r.what} (pid ${r.pid})`).join("; ")}`;
if (s.suites?.length) return `an e2e suite is running: ${s.suites.map((x) => `${x.suite} (pid ${x.pid})`).join("; ")}`;
@@ -147,8 +206,8 @@ export function slotBusy(s: SlotState | null): string | null {
}
/** An age as the apps take it: 3d, 12h, 90m, or a number of days. */
-export function checkAge(v: string): string {
- if (!/^\d+(\.\d+)?(d|h|m)?$/.test(v)) throw new Error(`--idle: "${v}" is not an age (3d, 12h, 90m)`);
+export function checkAge(v: string, flag = "--idle"): string {
+ if (!/^\d+(\.\d+)?(d|h|m)?$/.test(v)) throw new Error(`${flag}: "${v}" is not an age (3d, 12h, 90m)`);
return v;
}
@@ -176,6 +235,7 @@ type VersionProject = {
lines?: { takes: VersionTake[] }[];
deleted?: { id: string; bytes: number }[];
failed?: { id: string; error: string }[];
+ raced?: { id: string; why: string }[];
};
type WorkTake = { id: string; status: string; keep: { code: string }[]; freedBytes: number | null };
type WorkProject = {
@@ -184,7 +244,7 @@ type WorkProject = {
idle?: { idle: boolean };
takes?: WorkTake[];
pruned?: { id: string; freedBytes: number }[];
- failed?: { path: string; error: string }[];
+ failed?: { path: string; error: string; raced?: boolean }[];
freedBytes?: number;
};
type PruneJson = { versions?: { totals: Record<string, number>; projects: VersionProject[] }; projects?: WorkProject[]; versionsFreedBytes: number; workFreedBytes: number };
@@ -231,6 +291,7 @@ export function summarizePrune(j: PruneJson, dryRun: boolean): { takes: PartSumm
all.push(...ts);
const gone = dryRun ? ts.filter((t) => t.action === "delete").map((t) => ({ id: t.id, bytes: t.bytes })) : p.deleted ?? [];
for (const d of gone) takes.items.push({ what: `${p.project.id}/takes/${d.id}`, bytes: d.bytes });
+ for (const r of p.raced ?? []) takes.notes.push(`${p.project.id}/takes/${r.id} kept: ${r.why}`);
for (const f of p.failed ?? []) takes.notes.push(`${p.project.id}/takes/${f.id} not deleted: ${f.error}`);
}
takes.kept = tally(all.filter((t) => t.action === "keep").flatMap((t) => t.keep.map((r) => r.code)));
@@ -251,7 +312,7 @@ export function summarizePrune(j: PruneJson, dryRun: boolean): { takes: PartSumm
: p.pruned ?? [];
for (const g of gone) work.items.push({ what: `${p.project.id}/takes/${g.id} (work files${p.idle?.idle ? ", an idle project" : ""})`, bytes: g.freedBytes });
for (const t of p.takes ?? []) if (t.status === "kept") kept.push(...t.keep.map((r) => r.code));
- for (const f of p.failed ?? []) work.notes.push(`${p.project.id}/${f.path} not removed: ${f.error}`);
+ for (const f of p.failed ?? []) work.notes.push(f.raced ? `${p.project.id}/${f.path} kept: ${f.error}` : `${p.project.id}/${f.path} not removed: ${f.error}`);
}
work.kept = tally(kept);
if (idle) work.notes.push(`${idle} idle project(s): their newest and picked takes' work goes too`);
@@ -276,6 +337,7 @@ export type HousekeepingRun = {
by: string;
dryRun: boolean;
idle: string;
+ grace: string;
skipped: string | null;
free: { path: string; before: number | null; after: number | null };
parts: Record<Part, PartSummary>;
@@ -331,6 +393,7 @@ function parseJson<T>(r: RunResult, what: string): T {
export async function housekeeping(opts: HousekeepingOptions, deps: HousekeepingDeps): Promise<{ code: number; run: HousekeepingRun }> {
const dryRun = opts.dryRun === true;
const idle = checkAge(opts.idle ?? "3d");
+ const grace = checkAge(opts.grace ?? "7d", "--grace");
const skip = parseSkip(opts.skip);
const at = deps.now();
const parts = { takes: blank(), work: blank(), worktrees: blank() } as Record<Part, PartSummary>;
@@ -347,7 +410,7 @@ export async function housekeeping(opts: HousekeepingOptions, deps: Housekeeping
// takes + work: one umtool run (versions first, then the work files).
if (!skip.has("takes") || !skip.has("work")) {
const args = [path.join(deps.repoRoot, "umtool", "bin", "umtool.mjs"), "prune", "--all", "--json", dryRun ? "--dry-run" : "--yes"];
- if (!skip.has("takes")) args.push("--versions", "--idle", idle);
+ if (!skip.has("takes")) args.push("--versions", "--idle", idle, "--grace", grace);
if (!skip.has("work")) args.push("--idle-work", idle);
try {
const r = deps.run(node, args, deps.repoRoot);
@@ -381,6 +444,7 @@ export async function housekeeping(opts: HousekeepingOptions, deps: Housekeeping
by: opts.by ?? "cli",
dryRun,
idle,
+ grace,
skipped,
free: { path: deps.home, before, after: deps.freeBytes(deps.home) },
parts,
@@ -403,7 +467,7 @@ const WORDS: Record<Part, string> = { takes: "superseded takes", work: "work fil
/** The run as lines for a person. */
export function summaryLines(run: HousekeepingRun, recordFile: string | null): string[] {
const b = (n: number | null) => (n === null ? "?" : formatBytes(n));
- const out = [`housekeeping ${run.at.slice(0, 16).replace("T", " ")}${run.dryRun ? " — dry run, nothing deleted" : ""} (idle ${run.idle})`];
+ const out = [`housekeeping ${run.at.slice(0, 16).replace("T", " ")}${run.dryRun ? " — dry run, nothing deleted" : ""} (idle ${run.idle}, grace ${run.grace})`];
out.push(`${run.free.path}: ${b(run.free.before)} free`);
if (run.skipped) out.push(run.skipped);
for (const p of PARTS) {
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -1,7 +1,7 @@
# Changelog
## [Unreleased]
-- **Free disk, weekly, with one command: `archilyzer housekeeping`.** On 6 Nov /home was at 37 GB free, and a session freed 83 GB by hand. The operator: "We should build a regularly run command for this after we're done." It runs three passes of the apps' own commands. **Superseded takes:** `umtool prune --versions` deletes whole takes through `umtool takes delete`. Per version line it keeps the newest built take; the line is the take id with its digits folded (`draft-3` and `draft-4`), and a letter is never folded (`v6c` is not `v6d`, `release-6u` is not `release-6`). It also keeps any take picked, pinned, rendering, a build's base, the manifest's, with operator notes on it, or refused by `takes delete`. **Work files:** every project's takes' work files by its prune policy; in a project idle 3 days, the newest and picked takes' work goes too (`--idle-work`). **Worktrees:** `pnpm wt prune` removes merged, clean, idle worktrees with no process in them, keeping their branches. A project or worktree touched in the last 3 days is left alone, and a run is skipped while a render, an e2e suite or a heavy job runs. Each run is recorded in `~/.local/state/archilyzer/housekeeping.json`. **Worktree ports no longer move:** a worktree's port block is recorded when it is added, so removing another worktree cannot shift a running suite's ports. **Upgrading:** `archilyzer service install` (host mode) now also installs `archilyzer-housekeeping.timer`, weekly; `--dry-run` shows it first, and `--no-housekeeping` leaves it out. OPERATING.md, "Free disk".
+- **Free disk, weekly, with one command: `archilyzer housekeeping`.** On 6 Nov /home was at 37 GB free, and a session freed 83 GB by hand. The operator: "We should build a regularly run command for this after we're done." It runs three passes of the apps' own commands. **Superseded takes:** `umtool prune --versions` deletes whole takes through `umtool takes delete`. Per version line it keeps the highest built number; the line is the take id with its digits folded (`draft-3` and `draft-4`), and a letter is never folded (`v6c` is not `v6d`, `release-6u` is not `release-6`). An older take goes only once the newer one is 7 days old (`--grace`). It also keeps any take picked, pinned, given any verdict, rendering, a build's base, the manifest's, with operator notes on it, or refused by `takes delete`, and skips a project whose verdicts file cannot be read. **Work files:** every project's takes' work files by its prune policy; in a project idle 3 days, the newest and picked takes' work goes too (`--idle-work`). **Worktrees:** `pnpm wt prune` removes merged, clean, idle worktrees with no process in them and no ignored files of anyone's (a corpus, an env file, a changed settings file, a nested repository), keeping their branches. A project or worktree touched in the last 3 days is left alone, and a run is skipped while a render, an e2e suite or a heavy job runs, or when that cannot be checked. Each run is recorded in `~/.local/state/archilyzer/housekeeping.json`. **Worktree ports no longer move:** a worktree's port block is recorded when it is added, so removing another worktree cannot shift a running suite's ports. **Upgrading:** `archilyzer service install` (host mode) now also installs `archilyzer-housekeeping.timer`, weekly; `--dry-run` shows it first, and `--no-housekeeping` leaves it out. OPERATING.md, "Free disk".
- **Sync new and Resume backfill are separate actions for an X or Bluesky channel.** A fetch meant to get new posts could walk old history instead. If an account's full-history walk had stopped part-way, the next plain fetch, from Sync or the schedule too, resumed that walk and skipped the newest posts. On 6 Nov one such fetch read 100 posts the archive already held, stopped as "caught up" with 0 new, and missed 85 newer posts. It then cleared the walk's saved place, so the place was lost as well. The operator: "We should have distinct 'sync new' and 'resume backfill' actions, they are different actions for different purposes". **Sync new** (the channel page's first button; a plain `fetch-posts`, Sync and the scheduler) now always reads from the newest post down to the newest one archived, and never moves or clears the backfill's place. A sync that stops part-way keeps its own place and finishes on the next sync. **Resume backfill** (the button, shown only when a full-history walk is unfinished; `pnpm ops resume-backfill`, or `fetch-posts "backfill": true`; `--backfill` on `archilyzer posts fetch`; `backfill` on the MCP enqueue tool) continues that walk and does nothing else. When one is unfinished, the channel page says so: "backfill unfinished — N archived; Resume backfill continues it". The job log's first line names the mode. Resume backfill is refused when no walk is unfinished, and on a forum thread, which already reads its newest pages before its history. An X search channel has one walk and refuses it too. Re-fetch full history and Fetch older posts are unchanged. **Upgrading:** a `posts-state.json` from before this keeps one `cursor`. It is read as the unfinished backfill's place, so nothing is lost, and the next fetch rewrites it. Needs a restart of the editor.
- **Archived posts can be packaged as timestamped evidence.** The operator wanted public evidence that Mr. Obvious's X posts existed, and Save Page Now refuses x.com as a site (HTTP 523); he chose "the timestamped evidence package". `archilyzer evidence pack <channel>[,<channel>…] [--handle <h>] [--since/--until YYYY-MM-DD] [--out <dir>] [--no-media] [--no-stamp] [--dry-run] [--json]` writes, read only over the corpus, a self-contained folder (default `~/reports/evidence/<handle>-<date>/`): `posts.jsonl` (one record a post, deduped across the channels, every archived field kept under `raw`, the capture record and availability check, and the archived record of a post it answers or quotes as `context`), `posts.csv`, the post media copied byte for byte from `posts-media/` (each hash checked against its `capture.json`), `pack.json`, a README saying how to verify, `SHA256SUMS` over every file, and an OpenTimestamps proof of it (`SHA256SUMS.ots`, the official `ots` client, one request to each calendar). `evidence upgrade <dir>` fetches the Bitcoin attestation a few hours later, `evidence verify <dir>` checks every file and the stamp, `evidence stamp <dir>` stamps an unstamped one. Refused inside the corpus or a channel's media, over a non-empty dir, and for a channel whose text is unreadable. OPERATING.md, "Package posts as timestamped evidence".
- **Save Page Now works without archive.org keys, and a whole list of pages can be archived politely, with an evidence file.** The operator wanted every Mr. Obvious post on a public archive ("I'm just trying to make sure evidence of the pages exist"), and Save Page Now refused without S3 keys. With no keys configured it now asks archive.org's public endpoint anonymously (`"mode": "anonymous"` in the log and result; with keys, SPN2 as before, `"mode": "keys"`), and the channel page's Save Page Now panel says which. Every save in the editor takes turns through one pacer: one at a time, at least 60 s apart anonymous (10 s with keys), and a 429/503 or archive.org's "slow down" rests it (Retry-After, else 2 min doubling to 1 h). `pnpm ops save-page-now-batch --json '{"file":"/abs/urls.json"}'` runs ONE resumable job over a list: each URL looked up first (the Wayback CDX and archive.today's timemap, paced) and skipped when a copy shows it, else saved; at most 150 saves a day without keys (archive.org allows 200); progress and an ETA on /jobs; cancel, a restart or `{"batch": "<id>"}` continue from the first pending URL. Its evidence JSON + CSV (default `<transcripts>/.spn-batches/<batch>.evidence.*`, or `evidence`) names, per URL, the status, the Wayback and archive.today copy URLs, the capture time and the HTTP status the archive recorded. archive.today and Ghostarchive are looked up only, never asked to save (their forms put a CAPTCHA in front). Save Page Now refuses x.com as a site today (HTTP 523, "limitations when it comes to archiving this site"): a batch asks such a site once, then only looks its other URLs up and records them as not asked. OPERATING.md, "Archive a list of pages politely (evidence)".