Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ Applying the kit never touches an agent already created from it, so an instance
crosses a version only when its operator walks it through these steps, in the
direct session.

## 6.16.0 — 2026-11-10

**Prune the free slots' build output when the disk runs low.** Two optional
keys: `prune`, the command that deletes a checkout's rebuildable build output,
and `prune_below_gb`, default 20. With less free than that, `start` runs
`prune` in the checkout and in every slot no run holds, each slot locked while
it runs; a held slot and the run's own are left alone. Without `prune`,
nothing changes.

**Upgrade:** optional, in the direct session — add `- prune: <command>` to
`work/CONFIG.md`.

## 6.15.2 — 2026-11-05

**A demo shows the change for real, or there is none.** A demo Environment
Expand Down
2 changes: 2 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ a line in any other shape is invisible, not wrong.
take no new item; missing: none ([`docs/runs.md`](docs/runs.md) → **Slots**).
`babysit_max_hours` — default 4: how long a run may `wait` in its turn. `stuck_after_min` — default 120: every slot held and a
run silent this long lets a diagnostic run through.
`prune` — deletes a slot's rebuildable output, below `prune_below_gb` (default 20)
GiB free ([`docs/runs.md`](docs/runs.md) → **Slots**); missing: nothing is.
- `work_repo` — `owner/name`, private, holding the backup of `work/`
([`docs/persistence.md`](docs/persistence.md) → **Backup**). Missing: none.
`work_account` — the GitHub account (`gh auth status`) the backup acts as,
Expand Down
5 changes: 4 additions & 1 deletion ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ that is not one of them fails verification, because nothing would ever read it:
- slots_closed: <slot numbers that take no new work yet, e.g. 4 5>
- babysit_max_hours: 4
- stuck_after_min: 120
- prune: <what deletes a checkout's rebuildable build output>
- prune_below_gb: 20
- work_repo: owner/name-work
- work_account: <the GitHub account that reaches work_repo, when not the active one>
- slack_channel: C0123ABCD
Expand All @@ -234,7 +236,8 @@ neither check, or no path that needs one, `verify_required_paths`; with no
Environment at all, `label_ui_review`; with no
review label, `label_review`; with no backup, leave out `work_repo` and `work_account`; when the active account reaches it, `work_account`; with no Slack, leave out `slack_channel`, `slack_handoff`, `slack_ui_review` and `slack_automerge`;
with every slot open, `slots_closed`; for the default grill skills, `skill_grill` and `skill_file_issue`; leave
`repos_also` out when the work never leaves `repo`.
`repos_also` out when the work never leaves `repo`; leave `prune` and
`prune_below_gb` out when builds leave little behind.

`slots`, `babysit_max_hours`, `stuck_after_min` and `environments_max` are not
questions for the user: write the defaults. Lower `slots` when the sandbox cannot run that many builds at once;
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.15.2
6.16.0
47 changes: 46 additions & 1 deletion app/src/developer/run-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@
// quiet live runs silent for stuck_after_min, one a line
// diagnosed the precheck let a diagnostic run through
// show all of it, for a human
import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statfsSync, statSync } from "node:fs";
import { join, relative } from "node:path";
import type { Command, Deps } from "../factory/context.ts";
import { Exit } from "../factory/context.ts";
import type { Conditional } from "../factory/github.ts";
import { kv, readText, writeKv } from "../factory/kv.ts";
import { BOOKING_GRACE_MIN, MESSAGE_GRACE_MIN, waiterAlive } from "../factory/locks.ts";
import { run } from "../factory/proc.ts";
import { ATTENDED } from "../factory/runtime.ts";
import { epoch, iso, nowSeconds } from "../factory/time.ts";
import { persistTo } from "./backup.ts";
Expand Down Expand Up @@ -319,10 +320,54 @@ class RunState {
babysat_out: "-",
updated_at: now,
});
this.pruneFree(k);
this.out(`slot ${k}: ${join(this.kit.slots, k)} on ${branch}`);
return 0;
}

/** Whole GiB free on the disk work/ is on; undefined when it cannot be read. */
private freeGb(): number | undefined {
const fake = this.deps.env.SD_FREE_GB;
if (fake !== undefined && fake !== "") return /^[0-9]+$/.test(fake) ? Number(fake) : undefined;
try {
const f = statfsSync(this.kit.work);
return Math.floor((f.bavail * f.bsize) / 1024 ** 3);
} catch {
return undefined;
}
}

/**
* With `prune` set and the disk below `prune_below_gb`, `prune` runs in the
* checkout and in every other slot no run holds, each slot taken for it so
* no run starts there meanwhile. A held slot's build output is its run's,
* and the run's own slot is about to be used: neither is touched.
*/
private pruneFree(mine: string): void {
const cmd = this.kit.cfg.get("prune");
if (!cmd) return;
const min = this.kit.cfg.int("prune_below_gb", 20);
const free = this.freeGb();
if (free === undefined) {
this.say("free disk was not measured — prune skipped");
return;
}
if (free >= min) return;
this.say(`${String(free)} GiB free, under ${String(min)} — pruning the checkout and the free slots`);
const prune = (cwd: string) => run("bash", ["-c", cmd], { cwd, env: this.deps.env }).code === 0;
if (!prune(this.kit.checkout)) this.say("prune failed in the checkout");
for (let j = 1; j <= this.kit.slotCount; j++) {
const c = String(j);
const dir = join(this.kit.slots, c);
if (c === mine || !existsSync(dir)) continue;
if (!this.locks.take(`slot-${c}`, { slot: c })) continue;
if (!prune(dir)) this.say(`prune failed in slot ${c}`);
this.locks.drop(`slot-${c}`);
}
const after = this.freeGb();
if (after !== undefined) this.say(`${String(after)} GiB free after the prune`);
}

/** One more repository a run takes beside its slot, in a worktree of its own on the slot's branch. */
async also(args: readonly string[]): Promise<number> {
const raw = args[0];
Expand Down
3 changes: 3 additions & 0 deletions app/src/developer/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const KNOWN = [
"slots_closed",
"babysit_max_hours",
"stuck_after_min",
"prune",
"prune_below_gb",
"work_repo",
"work_account",
"slack_channel",
Expand Down Expand Up @@ -191,6 +193,7 @@ function configChecks(kit: Kit, r: Report): void {
};
whole("stuck_after_min", true, "a whole number of minutes", "write 120, or more");
whole("babysit_max_hours", false, "a whole number of hours", "write 4, or leave it out");
whole("prune_below_gb", true, "a whole number of GiB", "write 20, or leave it out");
whole("slots", false, "a whole number of slots", "write 3, or leave it out");
const closed = cfg.list("slots_closed");
const most = cfg.int("slots", 3, 1);
Expand Down
32 changes: 32 additions & 0 deletions app/test/run-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,3 +1255,35 @@ test("room with nothing to take back waits, and says once a day which pull reque
r = await as(s, "sess-a", "room");
assert.match(r.err, /notify:/, "what holds them changed");
}));

test("with prune set and the disk low, start prunes the checkout and the free slots, never a held one", () =>
inSandbox(async (s) => {
world(s);
s.originCheckout();
s.config("- prune: touch .pruned");
await as(s, "sess-a", "start", "7", "feat/7");
await as(s, "sess-b", "start", "8", "feat/8");
await as(s, "sess-b", "finish", "nothing");
// room enough: nothing is touched
let r = await s.run(runState, ["start", "9", "feat/9"], { CLAUDE_CODE_SESSION_ID: "sess-c", SD_FREE_GB: "50" });
assert.equal(r.rc, 0, r.err);
assert.ok(!existsSync(join(s.work, "slots", "2", ".pruned")));
await as(s, "sess-c", "finish", "nothing");
// low: the checkout and free slot 2 are pruned; held slot 1 and the run's own slot are kept
r = await s.run(runState, ["start", "9", "feat/9"], { CLAUDE_CODE_SESSION_ID: "sess-c", SD_FREE_GB: "5" });
assert.equal(r.rc, 0, r.err);
assert.match(r.err, /5 GiB free, under 20/);
const mine = /slot (\d+):/.exec(r.out)?.[1] ?? "";
assert.ok(existsSync(join(s.work, "widgets", ".pruned")), "checkout not pruned");
assert.ok(!existsSync(join(s.work, "slots", "1", ".pruned")), "pruned a held slot");
assert.ok(!existsSync(join(s.work, "slots", mine, ".pruned")), "pruned the run's own slot");
for (const k of ["2", "3"].filter((k) => k !== mine && existsSync(join(s.work, "slots", k))))
assert.ok(existsSync(join(s.work, "slots", k, ".pruned")), `free slot ${k} not pruned`);
assert.deepEqual(
locks(s)
.filter((l) => l.startsWith("slot-"))
.sort(),
["slot-1", `slot-${mine}`].sort(),
"a prune lock was left behind",
);
}));
5 changes: 5 additions & 0 deletions docs/runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ removes untracked files there, never ignored ones. It prefers the slot the item
last used. `finish` detaches a saved slot, so the branch is free for any slot
next time.

That build output fills the disk. With `prune` set and less than
`prune_below_gb` GiB free, `start` runs `prune` in the checkout and in every
other slot no run holds, taking each slot's lock while it runs; a held slot is
its run's, and is left alone. `prune` deletes only what a build makes again.

**A closed slot**, one `slots_closed` names, finishes what it holds and takes
no new item: `start` passes it by, and the precheck counts only the open ones
as free. It keeps its worktree and its build output, so opening it again is
Expand Down
Loading