Repository navigation
feat(clean): reclaim the builder's persistent cache with --build-cache - #25
Conversation
buildkitdrive owns the buildkitd daemon's persistent --root at CacheDir()/buildkitd (StateRoot). It is not one of charly's stores — a store tree IS an OCI Image Layout and nothing else (D-STORE-3), while this root carries no oci-layout marker and MUST carry buildkitd.lock — so no category could see it: --images prunes the engine's storage, --check sweeps .check/, --deep purges dangling engine images, --cache walks the OCI-layout stores, --scopes reaps systemd build scopes. Measured on one host: the live root held 50 GiB and a quarantined sibling held 105 GiB that took a hand-written sudo rm -rf over 301 708 container-owned files, because nothing in the tree even emitted that .broken-* name. That improvised path is the R3 workaround this category deletes (#23). Two instruments, one category. The LIVE root is removed only when no daemon owns it: a running buildkitd holds an exclusive flock on <root>/buildkitd.lock for its whole life, which is why the sweep SEIZES that lock before touching the root (so no daemon can start halfway through) and refuses — naming the daemon by its lock and socket — when it cannot. A lock dies with its holder (D-STORE-7), so a store left by a crashed daemon is reclaimable without asking anyone. Every quarantined sibling (buildkitd.broken-*) is reclaimed unconditionally: a store is only quarantined once it has been abandoned, so there is nothing to race. Bytes are reported per root, --dry-run reports the same figures and touches nothing (it does not even create the lock file to ask who owns the root), and the category never fires on a bare charly clean. A tree this user cannot delete WHOLE is reported BY NAME with the blocking path and the uid that owns it, and left exactly as it was — the measuring walk also decides whether a whole-tree removal is possible, so a store is never half-deleted. Both paths come from sdk/buildkitdrive; nothing here builds a <cache>/buildkitd path by hand. The category set itself moves into the schema: schema/clean.cue now declares #CleanPlugin.categories (flag, contract, bare:, implies:), and the Go grammar is derived from it — one flag per row with the row's contract as its help text, and the "naming a category suppresses the default set" / "--deep also reaps scopes" discipline as data instead of the hand-written anyCategory chain. A category is now a row, not an edit to a rule every reader had to re-derive. Agent: clean-buildkit Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)
Review — BLOCKHead SHA: Change class: code/config (Go plugin + CUE schema + docs). Security screen: PASS — no secrets, no exfiltration, no guardrail weakening; placement is entirely in the Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Both findings are about the PR BODY's account of the evidence, not about the tree: the R10 section called `check-commands-local` "the R10 witness" although neither of its clean steps invokes `--build-cache`, and a surfaced `go mod tidy -diff` finding was narrated in prose instead of being filed. The tree is unchanged, which is what this empty re-freeze commit records: it moves the head so the org-required validator re-reads the corrected body. Agent: clean-buildkit Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)
|
Agent: clean-buildkit Round 1 RCA — both findings were about the body's account of the evidence, and each names a missed controlBoth blocks are answered in one new commit ( Finding 1 — a surfaced finding was narrated instead of filedMechanism. Running Missed control. My pre-push pass checked that every rule row was ANSWERED, and it did not check Root fix. The sentence is deleted; the finding is filed as #26 (with the Finding 2 — the named witness does not exercise the changed categoryMechanism. This repo's Missed control. I treated "the repo declares a witness" as "the witness covers this change", Root fix. The body no longer offers the bed as the category's witness. It states the category's Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system) |
Review — PASSHead SHA: Security screen: PASS — no secrets/exfiltration, no guardrail weakening, no supply-chain drift; all placement is in Comment dispositions: prior BLOCK (6978105632) finding #1 (go.sum parking phrase) — resolved: the phrase is gone and the finding is filed as #26 under Checklist: All applicable rules PASS or NA (R1 round evidence present; R5 grep self-test pasted and consistent; R10 coverage proven by mutation arms + fresh-rebuild live runs + plan check; placement CORRECT). Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
charly cleancould not reclaim the buildkitd daemon's persistent--root, so a corrupt store costa hand-written
sudo rm -rfover 301 708 container-owned files and 105 GiB(#23).
sdk/buildkitdriveowns that root atCacheDir()/buildkitd(
StateRoot). It is not one of charly's stores — a store tree IS an OCI Image Layout and nothingelse (D-STORE-3), while this tree carries no
oci-layoutmarker and MUST carrybuildkitd.lock—so every existing category missed it by construction:
--imagesprunes the engine's storage,--checksweeps.check/run dirs,--deeppurges dangling engine images,--cachewalks theOCI-layout stores under the cache root,
--scopesreaps systemd build scopes.This change adds the
--build-cachecategory, with two instruments behind one flag:buildkitdholds anexclusive flock on
<root>/buildkitd.lockfor its whole life — that lock is how BuildKitenforces one daemon per root — so the lock IS the holder's liveness signal. The sweep SEIZES it
before it touches the root (so no daemon can start halfway through) and refuses, naming the
daemon by its lock and its socket, when it cannot. A lock dies with its holder (D-STORE-7), so a
store left by a crashed daemon is reclaimable without asking anyone.
buildkitd.broken-*), reclaimed unconditionally: a store is onlyquarantined once it has been abandoned, so there is nothing to race. The category recognizes the
name without producing it — quarantining is a recovery decision for the store's owner — which is
what gives an improvised directory an owner instead of leaving a corpse nobody dares touch.
Bytes are reported per root,
--dry-runreports the same figures and touches nothing (it does noteven create the lock file to ask who owns the root), and a bare
charly cleannever runs it. Atree this user cannot delete WHOLE — a rootless build leaves its store owned by container-mapped
UIDs — is reported BY NAME with the blocking path and the uid that owns it, and left exactly as it
was: the walk that measures a root also decides whether a whole-tree removal is possible, so a store
is never half-deleted. Both paths come from
sdk/buildkitdrive; nothing here builds a<cache>/buildkitdpath by hand, and the category needs neither the container engine nor theresolved keep-defaults.
The category set itself moves into the schema.
schema/clean.cuedeclares#CleanPlugin.categories— one row per category with its flag word, its one-line contract,bare:(a plain
charly cleanruns it) andimplies:(naming this one also runs those) — and the Gogrammar is DERIVED from it:
newCleanFlagSetregisters one flag per row with the row's contract asits help text, and
cleanCategoriesresolves the run set frombare:/implies:. The oldhand-written
anyCategory := …chain anddoScopes = …rule are gone, so a category is now a rowinstead of an edit to a discipline every reader had to re-derive.
Head
5452a7f450b9100b010e54d9ca33bd566bdad0c5— 12 files, +1648 −139 (this head is the re-freeze commit on top of10ec47d15dba09155cbcc19fdfc3c613589b5ac6;git diff --statbetween the two prints nothing, so every pasted run below is aboutthe same tree). Three files are new
(
buildcache.gowith itsbuildcache_test.go, andcategories.go); the rest are the derivedgrammar in
command.go, the outcome plumbing inretention.go, the declared set inschema/clean.cue, the candy's description and ADE plan, and the prose that carried the oldhand-written rule (
README.mdand the repo's owncleanskill).How tested
Every gate below ran on the committed tree
5452a7f450b9100b010e54d9ca33bd566bdad0c5, incandy/plugin-clean/unless a command says otherwise.The module gates, with
GOTMPDIR=$HOME/.cache/go-tmp(the sandboxed/tmpis quota-capped here):git status --short,go build ./...andgofmt -l .print nothing and exit 0. The module runs 54test functions at this head, 13 of them new: the lock guard, the seize-before-remove path, the dry
run, the quarantine discovery, the ownership rules, the refusal-by-name, the wire boundary, the
engine-free property, the layout wiring, and the declared-set derivation.
The structural gate, at the repo root:
Coverage that fails without the change — three mutations, each applied to the committed tree and
reverted with
git checkout --.Arm 0, the unmutated tree:
Arm 1 — the live-store guard removed, so a held lock no longer stops the removal (
buildcache.go:the
ErrLockBusyrefusal and its error path deleted):Arm 2 — the whole-tree preflight removed, so an undeletable root is half-deleted (
buildcache.go:the
blocker != ""early return deleted):Arm 3 — the declared default set changed in the schema, so
scopesis no longer part of a barecharly clean(schema/clean.cue: thescopesrow'sbare: truechanged tofalse):After the third revert the full suite is green again:
The changed path executed live. The plugin is compiled into charly, so a released binary would
have run the released plugin — not this branch. The binary under test is therefore a worktree-local
stamped build of
charly/charlyin a scratchgo.workthat lists THIS plugin worktree, so thecompiled-in
command:cleanis the code in this PR. No tracked file in any other repository changed(
git -C charly status --shortand the umbrella's own tracked status are both empty):Its flag grammar is the declared set, with the rows' own contracts as help text:
Four live runs, all against an INJECTED cache root (
CHARLY_CACHE_DIR, the one override D-STORE-1names), so the host's real 50 GiB store was never in reach. Program chatter (plugin views) goes to
stderr and is dropped here with
2>/dev/null.A — the dry run reports each root and touches nothing:
B — the same report with the daemon's own lock HELD by a real flock (the holder is a separate
process taking the same
flock(2)a running buildkitd takes):The live store is untouched, the dead corpse is still reported, and the refusal names the holder.
Once the holder exits the kernel drops its flock, and the same root becomes reclaimable — the lock
dies with its holder (D-STORE-7).
C — the real removal, with bytes per root:
Both roots are gone and the cache root is left empty: the category removed its own two roots and
nothing else.
D — the candy plan's own
--build-cachecheck, run verbatim against a second injected root:The R10 proof for
--build-cacheis A–D above plus the candy's own plan check, not a bed.check-commands-localis this repo's declared witness for thecharly cleanCOMMAND surface, andit is worth pasting because it exercises the changed grammar end to end — but it does NOT invoke
--build-cache(clean-dry-run-runsis a bare--dry-run,clean-deep-dry-run-runsis--deep --dry-run), so a green bed could not have failed on this category and the bed is notoffered as its gate. The category's gate is: the ADE plan check
clean-build-cache-dry-runincandy/plugin-clean/charly.yml, which drivescharly clean --build-cache --dry-runagainst aninjected cache root and asserts the tree survives (proof D), plus the four live runs A–D on the
binary rebuilt from this tree — the live root with and without a competing holder, the quarantined
sibling, the per-root byte figures, and the dry run's "touch nothing" property. Adding a
--build-cachestep to that bed is a change toopencharly/charly/charly.yml, a differentrepository and outside this PR's scope.
The bed itself, driven by the same binary so that its clean steps dispatch THIS plugin: both clean
steps pass; the bed as a whole FAILS on one step that exercises
box reconcile, and that step redsidentically on the shipped binary, which carries no plugin-clean change:
Inside
check-live, the two steps this repo'sAGENTS.mdnames as its R10 witness both pass, andso does every other step but one. The verdict lines, verbatim from that log (the whole log is at
.check/check-commands-local/2026.322.1148/check-live.log):So the derived grammar and the whole
charly cleansurface pass the bed on this tree. The red stepis
box reconcile, a different command and a different plugin, and the RCA (below, and recorded onopencharly/charly#1137) shows it fails on its own comparison of non-deterministic startup chatter:
the step's
report()strips only the git-metadata lines, whilecharlyalso prints a reorderedplugin …: served from …block on stdout, so the two runs disagree on the preamble while theirreconcile answers are byte-identical. Reproduced with the SHIPPED binary (control) and then with
this PR's binary (treatment), same verdict in both:
Both commands exit 0 and print the same reconcile verdict; only the plugin-resolution preamble
differs, in which of its two names it uses per line and in their order.
Rulebook compliance
R0 — skills first. Nine skills were loaded before the first tool action:
/charly-core:clean,/charly-internals:plugin,/charly-internals:go,/charly-internals:git-workflow,/charly-internals:strict-policy,/charly-internals:root-cause-analyzer,/charly-internals:cutover-policy,/charly-check:check,/charly-internals:disposable, plus thisrepo's own
AGENTS.md(read from the worktree). No source was read before they were loaded.R1 — RCA every anomaly, then fix it or file it. Four anomalies surfaced and each was
root-caused before any remediation. (1) The first bed attempt was refused:
charly check runrejects an unstamped binary, because a bed asserts on the version it bakes into tags and cache keys,
so the build was redone the way
scripts/bootstrap-charly.shstamps it (-ldflags "-X main.BuildCalVer=…"). (2) The live--helpprinted-build-cache <cache root>/buildkitd,because Go's
flagpackage reads a backtick-quoted word in a usage string as the flag's VALUE NAME;the contract carried one, so it was rewritten in prose with the reason recorded beside it. (3) The
first live report printed the quarantine count line AFTER its item lines;
buildCacheLineswasreordered and the report test now asserts the exact line order rather than membership. (4) The R10
bed failed on its
box reconcilestep — root-caused, reproduced with the shipped binary as acontrol, and filed with the measured evidence on the existing opencharly/charly#1137 (see
## Filed issues). (5) Runninggo mod tidy -diffsurfaced twogo.sumlines describing asuperseded
opencharly/sdkversion that tidy would delete. By R1's own discriminator it isnon-blocking — this change adds no module, and its gates are green without the fix — so it takes
R1's FILE path rather than being folded in: #26 carries the tidy diff and the
mechanism. It is listed under
## Filed issueswith the rest; nothing surfaced in this cutover isleft undisposed.
R2 — no duplication. One implementation of every mechanism. The two buildkitd paths come from
sdk/buildkitdrive(StateRoot,SocketPath,LockName) rather than a second hand-built<cache>/buildkitd, and the roots behind them are the contract resolver's. The flock liveness ruleis
spec/lock's, taken with the production primitivekit.AcquireFileLock. One engine serves bothinstruments (
sweepBuildCache→reclaimBuildCacheTree). The category set has one declaration(
schema/clean.cue) and one word-to-field binding table, which a test pins against the declarationin both directions.
R3 — no workarounds. No sleep, retry, magic number or ad-hoc infrastructure command: the mutual
exclusion is the daemon's own
flock, taken with the production primitive and held across theremoval, and a holder that cannot be excluded is reported rather than raced. The measured manual
recovery (
sudo rm -rfof a quarantined root) is precisely what this category replaces.R4 — product before prose. The behaviour was implemented and executed before any prose was
written;
README.mdand this repo's owncleanskill were then brought into line with what exists.Every step works with nothing but the
charlybinary.R5 — delete legacy completely. The hand-written category discipline is gone, not shadowed:
anyCategory := images || check || deep || cacheGC || scopesanddoScopes = scopes || deep || !anyCategoryno longer exist in Go, and the prose that taught them(
README.md,.agents/skills/clean/SKILL.md) states the declared rule instead. Two function namesthe skill documented and the tree had already deleted (
cleanMakepkgArtifacts,fetchRetentionDefaults) went with the paragraph that carried them. The claim sweep:Every surviving hit is a sentence stating what was REPLACED, never a live rule.
R6 — preserve user work and Git safety.
git statuswas clean before any edit; the work wentinto the session worktree
.worktrees/clean-store/plugin-cleanonfeat/clean-buildkit-storesofforigin/main(a6b0c2a, still the merge base, so the branch is not behind), and no tracked file inany other repository changed. No reset, no force-push, no hook bypass, nothing pushed to
main.R7 — prove behaviour, not compilation. The three mutation arms are the negative proof and the
four live runs are the positive one, on the binary built from the committed tree. The emitted
surfaces are validated at their boundary:
charly box validatecompiles the candy, itsplugin:block and the CUE schema, and the live binary's flag set is the schema's declared rows.
R8 — live or skip, never fake. The flock holder in proof B is a real process taking the real
lock; nothing about the daemon, the filesystem or the report is mocked. The one test that needs an
unprivileged user (
TestBuildCache_NamesAnUndeletableTreeAndLeavesItWhole) skips VISIBLY under rootwith its reason, because root can empty any tree and the situation cannot be built there.
R9 — binary equals source. All Go ran under a worktree-local build with
GOTMPDIR=$HOME/.cache/go-tmp, and the live-proof binary is a stamped build of the exact pluginworktree under test (
charly version=2026.322.0915). No new runtime OS dependency was added —the category shells out to nothing.
R10 — fresh disposable proof. The R10 witness is the
check-commands-localbed inopencharly/charly(adisposable: truehost: localdeploy), driven by the stampedworktree-local binary so its
charly cleansteps dispatch THIS plugin. Both clean steps pass(
clean-dry-run-runs,clean-deep-dry-run-runs), and so do eight of the other nine steps; the bed'sverdict is FAIL solely because of
box-reconcile-remote-cached, which reds identically on theshipped binary (control arm pasted above) on its own comparison of non-deterministic startup
chatter, and which is filed on opencharly/charly#1137. Because the bed as a whole did not pass, the
tier claimed below is the lower one the table names for this state.
CONC — concurrency proven, no forbidden framing. The race being closed is a build starting
while the sweep deletes its store. It is closed at the cause: the sweep takes the daemon's own
buildkitd.lockwith a non-blockingflock(2)and holds it across the whole removal, so a daemoncannot start mid-delete, and a daemon already running answers
EWOULDBLOCK, which IS the refusalrather than a retry.
TestBuildCache_RefusesWhileADaemonOwnsTheRootexercises this with a REALcompeting holder and then with that holder gone (the same root is then reclaimed), and
TestBuildCache_TakesTheLockBeforeRemovingcovers the arm where the root has no lock file yet, soan absent lock is not an escape from the guard. No sleep, no bounded retry, no suppression.
Change classification
Purely additive: a new category flag (
--build-cache), a newly declared category set, and prose.Nothing was removed from any consumer-visible surface — no flag, label, YAML field, wire type or
exit code changed — so no
charly migrateentry is due, and there is no rollback beyond revertingthe commit.
spec.RetentionRequest/spec.RetentionReplyare untouched: the new category travels asa CLI-only field beside the wire reply, exactly as
scopesdoes, so no peer plugin sees it and nospec pin moves. This repo's only workflow is
tag-on-merge.yml, so the merge gate is the org-widerequired
validate / validatecheck, not a per-repo gate.Breaking change + rollback: none — the change adds a flag and moves an internal discipline into
the schema; every invocation that existed before this change resolves to exactly the categories it
resolved to before, which
the category-resolution table (arm 0 above) pins case for case.
Filed issues
check-commands-local'sbox-reconcile-remote-cachedstep false-reds on a moving external state; this run adds a SECOND, independent cause (its equality check comparescharly's non-deterministic plugin-resolution preamble), with the measured control arm.go mod tidyis not a no-op on a clean tree #26 — twogo.sumlines for a supersededopencharly/sdkversion thatgo mod tidy -diffwould delete; surfaced by this cutover's gate run, non-blocking (this change adds no module), and filed rather than folded in so its own verification stays with its own change.Agent: clean-buildkit
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)