Skip to content

feat(clean): reclaim the builder's persistent cache with --build-cache - #25

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/clean-buildkit-stores
Nov 18, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/clean-buildkit-stores

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

charly clean could not reclaim the buildkitd daemon's persistent --root, so a corrupt store cost
a hand-written sudo rm -rf over 301 708 container-owned files and 105 GiB
(#23). sdk/buildkitdrive owns that 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 tree carries no oci-layout marker and MUST carry buildkitd.lock —
so every existing category missed it by construction: --images prunes the engine's storage,
--check sweeps .check/ run dirs, --deep purges dangling engine images, --cache walks the
OCI-layout stores under the cache root, --scopes reaps systemd build scopes.

This change adds the --build-cache category, with two instruments behind one flag:

  • The live state root, removed only when no daemon owns it. A running buildkitd holds an
    exclusive flock on <root>/buildkitd.lock for its whole life — that lock is how BuildKit
    enforces 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.
  • Every quarantined sibling (buildkitd.broken-*), reclaimed unconditionally: a store is only
    quarantined 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-run reports the same figures and touches nothing (it does not
even create the lock file to ask who owns the root), and a bare charly clean never runs it. A
tree 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>/buildkitd path by hand, and the category needs neither the container engine nor the
resolved keep-defaults.

The category set itself moves into the schema. schema/clean.cue declares
#CleanPlugin.categories — one row per category with its flag word, its one-line contract, bare:
(a plain charly clean runs it) and implies: (naming this one also runs those) — and the Go
grammar is DERIVED from it: newCleanFlagSet registers one flag per row with the row's contract as
its help text, and cleanCategories resolves the run set from bare:/implies:. The old
hand-written anyCategory := … chain and doScopes = … rule are gone, so a category is now a row
instead 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 of
10ec47d15dba09155cbcc19fdfc3c613589b5ac6; git diff --stat between the two prints nothing, so every pasted run below is about
the same tree). Three files are new
(buildcache.go with its buildcache_test.go, and categories.go); the rest are the derived
grammar in command.go, the outcome plumbing in retention.go, the declared set in
schema/clean.cue, the candy's description and ADE plan, and the prose that carried the old
hand-written rule (README.md and the repo's own clean skill).

How tested

Every gate below ran on the committed tree 5452a7f450b9100b010e54d9ca33bd566bdad0c5, in
candy/plugin-clean/ unless a command says otherwise.

The module gates, with GOTMPDIR=$HOME/.cache/go-tmp (the sandboxed /tmp is quota-capped here):

$ git status --short
$ go build ./...
$ go test -count=1 ./...
ok  	github.com/opencharly/plugin-clean/candy/plugin-clean	0.139s
?   	github.com/opencharly/plugin-clean/candy/plugin-clean/cmd/serve	[no test files]
$ gofmt -l .

git status --short, go build ./... and gofmt -l . print nothing and exit 0. The module runs 54
test 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:

$ charly box validate
charly box validate: OK — checked 1 candy, 1 deploy, 6 distros, 7 builders; 0 warnings, 0 errors

Coverage that fails without the change — three mutations, each applied to the committed tree and
reverted with git checkout --.

Arm 0, the unmutated tree:

$ go test -count=1 -run 'TestBuildCache|TestCleanCategories|TestNewCleanFlagSet|TestDefaultBuildCache' ./...
ok  	github.com/opencharly/plugin-clean/candy/plugin-clean	0.013s

Arm 1 — the live-store guard removed, so a held lock no longer stops the removal (buildcache.go:
the ErrLockBusy refusal and its error path deleted):

$ go test -count=1 -run 'TestBuildCache_RefusesWhileADaemonOwnsTheRoot' ./...
--- FAIL: TestBuildCache_RefusesWhileADaemonOwnsTheRoot (0.00s)
    buildcache_test.go:91: the sweep did not decline while a holder owned the lock: {Dir:/home/atrawog/.cache/go-tmp/TestBuildCache_RefusesWhileADaemonOwnsTheRoot2807080991/001/cache/buildkitd Quarantined:false Present:true Bytes:4096 Removed:true Skip:<nil> Blocker:}
FAIL
FAIL	github.com/opencharly/plugin-clean/candy/plugin-clean	0.010s
?   	github.com/opencharly/plugin-clean/candy/plugin-clean/cmd/serve	[no test files]
FAIL

Arm 2 — the whole-tree preflight removed, so an undeletable root is half-deleted (buildcache.go:
the blocker != "" early return deleted):

$ go test -count=1 -run 'TestBuildCache_NamesAnUndeletableTreeAndLeavesItWhole' ./...
--- FAIL: TestBuildCache_NamesAnUndeletableTreeAndLeavesItWhole (0.00s)
    buildcache_test.go:333: a blocked removal deleted /home/atrawog/.cache/go-tmp/TestBuildCache_NamesAnUndeletableTreeAndLeavesItWhole356539252/001/cache/buildkitd/cache.db — the tree must be left whole: stat /home/atrawog/.cache/go-tmp/TestBuildCache_NamesAnUndeletableTreeAndLeavesItWhole356539252/001/cache/buildkitd/cache.db: no such file or directory
FAIL
FAIL	github.com/opencharly/plugin-clean/candy/plugin-clean	0.007s
?   	github.com/opencharly/plugin-clean/candy/plugin-clean/cmd/serve	[no test files]
FAIL

Arm 3 — the declared default set changed in the schema, so scopes is no longer part of a bare
charly clean (schema/clean.cue: the scopes row's bare: true changed to false):

$ go test -count=1 -run 'TestCleanCategories' ./...
--- FAIL: TestCleanCategories (0.00s)
    --- FAIL: TestCleanCategories/no_flags:_full_default_sweep,_scopes_included,_deep_and_build-cache_excluded (0.00s)
        command_test.go:104: cleanCategories(images=false,check=false,deep=false,cache=false,scopes=false,build-cache=false) = {images:true check:true deep:false cache:false scopes:false buildCache:false}, want {images:true check:true deep:false cache:false scopes:true buildCache:false}
--- FAIL: TestCleanCategoriesParseTheFullGrammar (0.00s)
    command_test.go:192: parse [] resolved {images:true check:true deep:false cache:false scopes:false buildCache:false}, want {images:true check:true deep:false cache:false scopes:true buildCache:false}
FAIL
FAIL	github.com/opencharly/plugin-clean/candy/plugin-clean	0.010s
?   	github.com/opencharly/plugin-clean/candy/plugin-clean/cmd/serve	[no test files]
FAIL

After the third revert the full suite is green again:

$ go test -count=1 ./...
ok  	github.com/opencharly/plugin-clean/candy/plugin-clean	0.142s
?   	github.com/opencharly/plugin-clean/candy/plugin-clean/cmd/serve	[no test files]
$ git status --short

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/charly in a scratch go.work that lists THIS plugin worktree, so the
compiled-in command:clean is the code in this PR. No tracked file in any other repository changed
(git -C charly status --short and the umbrella's own tracked status are both empty):

$ CALVER="$(bash scripts/calver.sh)" && cd charly && GOWORK=~/.cache/clean-store-ws/go.work go build -buildvcs=false -ldflags "-X main.BuildCalVer=${CALVER}" -o ~/.cache/clean-store-ws/out/charly .
$ ~/.cache/clean-store-ws/out/charly version
2026.322.0915

Its flag grammar is the declared set, with the rows' own contracts as help text:

$ charly clean --nosuchflag
flag provided but not defined: -nosuchflag
Usage of clean:
  -build-cache
    	Reclaim the builder's persistent cache — the BuildKit daemon's StateRoot() at <cache root>/buildkitd and every quarantined sibling (buildkitd.broken-*). The live root is removed only when no daemon holds its one-instance lock (a running daemon is named and the root is left alone), and a tree this user cannot delete whole is reported by name and left whole. Never fires on a bare run
  -cache
    	Reclaim unreferenced blobs from every named charly cache — the content-addressed store's own GC — and sweep the retired cache roots; reports each store's live entries and the blobs/bytes reclaimed
  -check
    	Only check-run retention: trim each .check/<bed> run dir to the project's keep_check_runs; NOTES.md is always preserved
  -deep
    	Purge EVERY untagged/dangling image in local storage, not only the charly-labeled ones, and report UP TO the summed image size (layers shared with kept images reduce the actual reclaim, so pair it with --invalidate); never fires on a bare run
  -dry-run
    	Print everything that would be removed; touch nothing
  -images
    	Only image-tag retention: prune each box's image tags to the project's keep_images (the newest N distinct images, at most N tags of each), then the charly-labeled dangling-image sweep and the dead buildah staging sweep
  -invalidate string
    	Remove every charly-labeled image tag matching this glob (full ref or last path segment); runs ONLY the invalidation
  -keep int
    	Override the retention count for this run (0 = use defaults:)
  -scopes
    	Reap HUNG transient build scopes — the systemd user scopes buildah/podman put a build container into. A scope is stopped only when it has been active for at least the reaper's age bound (named in the report) AND no buildah/podman builder is alive anywhere on the host; runs on a bare run and with --deep, and any other explicit category suppresses it

Four live runs, all against an INJECTED cache root (CHARLY_CACHE_DIR, the one override D-STORE-1
names), 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:

$ charly clean --build-cache --dry-run 2>/dev/null
build-cache live: would remove /tmp/bcache-proof/buildkitd (4.0 KiB)
build-cache dead: would remove 1 quarantined root(s) (8.0 KiB)
  would remove /tmp/bcache-proof/buildkitd.broken-1794801825 (8.0 KiB)
$ find /tmp/bcache-proof/buildkitd /tmp/bcache-proof/buildkitd.broken-1794801825 -type f | sort
/tmp/bcache-proof/buildkitd.broken-1794801825/blob
/tmp/bcache-proof/buildkitd/export/blob
$ test -e /tmp/bcache-proof/buildkitd/buildkitd.lock && echo "lock file CREATED (defect)" || echo "no lock file created"
no lock file created

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):

$ charly clean --build-cache --dry-run 2>/dev/null
build-cache live: SKIPPED — a running buildkitd holds /tmp/bcache-proof/buildkitd/buildkitd.lock (it answers on /run/user/1000/charly/buildkitd.sock), so a build may be writing this store; stop the daemon or wait for the build to finish, then re-run
build-cache dead: would remove 1 quarantined root(s) (8.0 KiB)
  would remove /tmp/bcache-proof/buildkitd.broken-1794801825 (8.0 KiB)
$ find /tmp/bcache-proof/buildkitd -type f | sort
/tmp/bcache-proof/buildkitd/buildkitd.lock
/tmp/bcache-proof/buildkitd/export/blob

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:

$ charly clean --build-cache 2>/dev/null
build-cache live: removed /tmp/bcache-proof/buildkitd (4.0 KiB)
build-cache dead: removed 1 quarantined root(s) (8.0 KiB)
  removed /tmp/bcache-proof/buildkitd.broken-1794801825 (8.0 KiB)
$ find /tmp/bcache-proof -mindepth 1 -maxdepth 1 | sort

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-cache check, run verbatim against a second injected root:

$ root="$(mktemp -d)" && mkdir -p "$root/buildkitd/export" "$root/buildkitd.broken-1" && printf 'blob' > "$root/buildkitd.broken-1/blob" && CHARLY_CACHE_DIR="$root" charly clean --build-cache --dry-run 2>/dev/null && test -f "$root/buildkitd.broken-1/blob" && echo "the injected tree survived the dry run"
build-cache live: would remove /tmp/tmp.inlprYVMcP/buildkitd (0 B)
build-cache dead: would remove 1 quarantined root(s) (4 B)
  would remove /tmp/tmp.inlprYVMcP/buildkitd.broken-1 (4 B)
the injected tree survived the dry run

The R10 proof for --build-cache is A–D above plus the candy's own plan check, not a bed.
check-commands-local is this repo's declared witness for the charly clean COMMAND surface, and
it is worth pasting because it exercises the changed grammar end to end — but it does NOT invoke
--build-cache (clean-dry-run-runs is a bare --dry-run, clean-deep-dry-run-runs is
--deep --dry-run), so a green bed could not have failed on this category and the bed is not
offered as its gate. The category's gate is: the ADE plan check clean-build-cache-dry-run in
candy/plugin-clean/charly.yml, which drives charly clean --build-cache --dry-run against an
injected 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-cache step to that bed is a change to opencharly/charly/charly.yml, a different
repository 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 reds
identically on the shipped binary, which carries no plugin-clean change:

$ charly check run check-commands-local
charly check run check-commands-local: [deploy-add] PASS after 52.699s (log: .check/check-commands-local/2026.322.1148/deploy-add.log)
charly check run check-commands-local: [bring-up-members] PASS after 2ms
charly check run check-commands-local: [check-live] FAIL after 6m1.009s: exit 2: charly subcommand exited 2 (log: .check/check-commands-local/2026.322.1148/check-live.log)
charly check run check-commands-local: [cleanup] PASS after 33.068s (log: .check/check-commands-local/2026.322.1148/cleanup.log)
charly check run check-commands-local: [cleanup-members] PASS after 0s
charly check run check-commands-local: FAIL (steps=5)

Inside check-live, the two steps this repo's AGENTS.md names as its R10 witness both pass, and
so 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):

  PASS  check command=charly clean --dry-run exits 0 and prints the would-remove retention report (proving the externalized clean command owns the report + reaches the shared retention engine over the "retention" HostBuild seam, touching nothing)  [clean-dry-run-runs]  exit=0
  PASS  check command=charly clean --deep --dry-run exits 0 and reports a count + an upper-bound reclaimable size (actual reclaim may be less — removed images can share layers with the many that remain) of untagged/dangling images STORE-WIDE (proving the --deep purge category reaches the store-wide selectDanglingImages/pruneDeepDanglingImages sweep over the SAME "retention" HostBuild seam — not just the charly-labeled sweep --dry-run above already covers — touching nothing)  [clean-deep-dry-run-runs]  exit=0
  FAIL  check charly box reconcile --remote --dry-run exercises the cached, disk-persisted gitClient().LatestTag path (candy/plugin-box#22, charly#736) on THIS project — the retired raw per-process git ls-remote reintroduced the 90-94 concurrent fanout the cache exists to avoid, and the churn-STABLE way to catch that regression is to require the SECOND --remote run to be served from the persisted cache (no cold "fetching git metadata" burst) and to agree with the first. The step still PRINTS a pin-drift report (the "would rewrite N pin(s)" shape) when upstream has moved; that is upstream's property, refreshed by `charly task sync`, and asserting its ABSENCE made this gate go red the moment any upstream repo published a tag (opencharly/charly#650's class — a gate keyed on a moving external state is a false-red generator). The two invocations run under an ISOLATED cache directory (XDG_CACHE_HOME), because the shared ref cache is mutable by any other charly process on the host — that was this step's last false-red generator, and with an isolated cache the second run is cache-served by construction rather than by luck  [box-reconcile-remote-cached]  exit=1, want 0 (stderr: )

10 steps: 9 passed, 1 failed, 0 skipped

So the derived grammar and the whole charly clean surface pass the bed on this tree. The red step
is box reconcile, a different command and a different plugin, and the RCA (below, and recorded on
opencharly/charly#1137) shows it fails on its own comparison of non-deterministic startup chatter:
the step's report() strips only the git-metadata lines, while charly also prints a reordered
plugin …: served from … block on stdout, so the two runs disagree on the preamble while their
reconcile answers are byte-identical. Reproduced with the SHIPPED binary (control) and then with
this PR's binary (treatment), same verdict in both:

$ first=$(XDG_CACHE_HOME=$cache charly/bin/charly box reconcile --remote --dry-run 2>&1)
$ second=$(XDG_CACHE_HOME=$cache charly/bin/charly box reconcile --remote --dry-run 2>&1)
$ diff <(report "$first") <(report "$second")
1,2c1,2
< plugin plugin-example-kind: served from /tmp/tmp.WuTMPBB4tD/charly/plugin-build/views/plugin-example-kind-c963a799c61dbb81 (build sha256:70a209c258d91abc007e4a719d2b0791e413ac6d5e34c1d50bf3a160e7d22a68); source /home/atrawog/.cache/charly/repos/github.com/opencharly/[email protected]/candy/plugin-example-kind
< plugin github.com/opencharly/plugin-example-structkind/candy/plugin-example-structkind: served from /tmp/tmp.WuTMPBB4tD/charly/plugin-build/views/plugin-example-structkind-8408bb195d4f6668 (build sha256:2d73910192801784591e7eb8a898d2398a4624b617020964b95265084bdb103f); source /home/atrawog/.cache/charly/repos/github.com/opencharly/[email protected]/candy/plugin-example-structkind
---
> plugin plugin-example-structkind: served from /tmp/tmp.WuTMPBB4tD/charly/plugin-build/views/plugin-example-structkind-8408bb195d4f6668 (build sha256:2d73910192801784591e7eb8a898d2398a4624b617020964b95265084bdb103f); source /home/atrawog/.cache/charly/repos/github.com/opencharly/[email protected]/candy/plugin-example-structkind
> plugin github.com/opencharly/plugin-example-kind/candy/plugin-example-kind: served from /tmp/tmp.WuTMPBB4tD/charly/plugin-build/views/plugin-example-kind-c963a799c61dbb81 (build sha256:70a209c258d91abc007e4a719d2b0791e413ac6d5e34c1d50bf3a160e7d22a68); source /home/atrawog/.cache/charly/repos/github.com/opencharly/[email protected]/candy/plugin-example-kind
$ printf '%s\n' "$first" | grep -qE '^already reconciled|^would rewrite [0-9]+ pin\(s\):' && echo MATCHES
MATCHES

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 this
repo'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 run
rejects 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.sh stamps it (-ldflags "-X main.BuildCalVer=…"). (2) The live --help printed -build-cache <cache root>/buildkitd,
because Go's flag package 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; buildCacheLines was
reordered and the report test now asserts the exact line order rather than membership. (4) The R10
bed failed on its box reconcile step — root-caused, reproduced with the shipped binary as a
control, and filed with the measured evidence on the existing opencharly/charly#1137 (see
## Filed issues). (5) Running go mod tidy -diff surfaced two go.sum lines describing a
superseded opencharly/sdk version that tidy would delete. By R1's own discriminator it is
non-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 issues with the rest; nothing surfaced in this cutover is
left 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 rule
is spec/lock's, taken with the production primitive kit.AcquireFileLock. One engine serves both
instruments (sweepBuildCache → reclaimBuildCacheTree). The category set has one declaration
(schema/clean.cue) and one word-to-field binding table, which a test pins against the declaration
in 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 the
removal, and a holder that cannot be excluded is reported rather than raced. The measured manual
recovery (sudo rm -rf of 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.md and this repo's own clean skill were then brought into line with what exists.
Every step works with nothing but the charly binary.

R5 — delete legacy completely. The hand-written category discipline is gone, not shadowed:
anyCategory := images || check || deep || cacheGC || scopes and
doScopes = scopes || deep || !anyCategory no longer exist in Go, and the prose that taught them
(README.md, .agents/skills/clean/SKILL.md) states the declared rule instead. Two function names
the skill documented and the tree had already deleted (cleanMakepkgArtifacts,
fetchRetentionDefaults) went with the paragraph that carried them. The claim sweep:

$ grep -rn 'anyCategory\|doScopes\|cleanMakepkgArtifacts\|fetchRetentionDefaults' --include=*.go --include=*.md --include=*.yml --include=*.cue . | grep -v CHANGELOG | sort
./.agents/skills/clean/SKILL.md:250:resolves it into a `cleanPlan` — the `bare:`/`implies:` discipline as data, no `anyCategory := …`
./.agents/skills/clean/SKILL.md:76:`anyCategory := …` chain.
./candy/plugin-clean/categories.go:15:// discipline lived in code as `anyCategory := images || check || deep || cacheGC || scopes` plus
./candy/plugin-clean/categories.go:16:// `doScopes = scopes || deep || !anyCategory` — a hand-written rule that had to be re-derived by
./candy/plugin-clean/charly.yml:14:            "--deep also reaps build scopes" are declared DATA, not a hand-written `anyCategory := …`
./candy/plugin-clean/charly.yml:15:            chain plus a `doScopes = …` rule that every reader had to re-derive and every new category
./candy/plugin-clean/command.go:36:// `anyCategory := …` chain and no `doScopes = …` rule left in Go — the default set and the

Every surviving hit is a sentence stating what was REPLACED, never a live rule.

R6 — preserve user work and Git safety. git status was clean before any edit; the work went
into the session worktree .worktrees/clean-store/plugin-clean on feat/clean-buildkit-stores off
origin/main (a6b0c2a, still the merge base, so the branch is not behind), and no tracked file in
any 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 validate compiles the candy, its plugin:
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 root
with 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 plugin
worktree 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-local bed in
opencharly/charly (a disposable: true host: local deploy), driven by the stamped
worktree-local binary so its charly clean steps 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's
verdict is FAIL solely because of box-reconcile-remote-cached, which reds identically on the
shipped 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.lock with a non-blocking flock(2) and holds it across the whole removal, so a daemon
cannot start mid-delete, and a daemon already running answers EWOULDBLOCK, which IS the refusal
rather than a retry. TestBuildCache_RefusesWhileADaemonOwnsTheRoot exercises this with a REAL
competing holder and then with that holder gone (the same root is then reclaimed), and
TestBuildCache_TakesTheLockBeforeRemoving covers the arm where the root has no lock file yet, so
an 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 migrate entry is due, and there is no rollback beyond reverting
the commit. spec.RetentionRequest/spec.RetentionReply are untouched: the new category travels as
a CLI-only field beside the wire reply, exactly as scopes does, so no peer plugin sees it and no
spec pin moves. This repo's only workflow is tag-on-merge.yml, so the merge gate is the org-wide
required validate / validate check, 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

Agent: clean-buildkit
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

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)
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 10ec47d15dba09155cbcc19fdfc3c613589b5ac6 (branch: feat/clean-buildkit-stores)

Change class: code/config (Go plugin + CUE schema + docs).

Security screen: PASS — no secrets, no exfiltration, no guardrail weakening; placement is entirely in the candy/plugin-clean layer (correct; no core/sdk capability moved in). No comment-thread items to disposition (thread empty).

Blocks

  1. R1 / CONC(b) — forbidden "pre-existing / unrelated" parking phrase with no filed issue. The Rulebook-compliance section states:

    "One pre-existing observation, not a gate finding: go mod tidy -diff would delete two go.sum lines describing a superseded opencharly/sdk version — unrelated to this change, which adds no module, and outside this repo's declared gates."

    This is a real divergence the author surfaced (a go mod tidy -diff result), dismissed with the exact parking vocabulary CONC(b) bans ("pre-existing", "unrelated", "outside … gates"), and it is not listed under ## Filed issues (which contains only opencharly/charly#1137). Per R1/CONC(b) and the forbidden-framing catalog, an issue surfaced while the cutover is open must be fixed in-tree or filed as a real <repo>#<n> under ## Filed issues. Fix: either delete the two stale go.sum lines in this same commit, or add a real issue entry for it under ## Filed issues.

  2. A2 / R10 — the named R10 witness does not exercise the changed path. The body presents check-commands-local as "The repo's R10 witness," but its clean sub-steps are clean-dry-run-runs (bare --dry-run) and clean-deep-dry-run-runs (--deep --dry-run); neither invokes --build-cache. A bed that never runs the new category cannot fail on this change, so under A2 it "proves nothing" about --build-cache. The actual build-cache proof is the four ad-hoc live runs (A–D) plus the candy plan check clean-build-cache-dry-run, not the cited bed. Fix: either add a --build-cache step to a bed that exercises it, or state explicitly that the four fresh-rebuild, disposable-root live runs (A–D) plus the clean-build-cache-dry-run plan check are the R10 proof — and stop citing a bed that does not touch the change as "the R10 witness."

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

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)
@aitrawog

Copy link
Copy Markdown
Contributor Author

Agent: clean-buildkit

Round 1 RCA — both findings were about the body's account of the evidence, and each names a missed control

Both blocks are answered in one new commit (5452a7f450b9100b010e54d9ca33bd566bdad0c5, a re-freeze
whose tree is identical to 10ec47d1 — git diff --stat between the two prints nothing, so every
pasted run still describes this tree). Neither was a code defect, and neither is being argued away.

Finding 1 — a surfaced finding was narrated instead of filed

Mechanism. Running go mod tidy -diff (a hygiene probe I ran beside the gates) surfaced two
go.sum lines for a superseded opencharly/sdk version. I judged it non-blocking by R1's own
discriminator — this change adds no module, and its gates are green without the fix — and then
disposed of it in a PROSE sentence ("pre-existing observation, not a gate finding … outside this
repo's declared gates") instead of taking R1's one legal path for a non-blocking finding, which is
to file it. R1 defines exactly two dispositions; prose is not one of them, and the words I reached
for are the parking vocabulary the forbidden-framing catalog bans.

Missed control. My pre-push pass checked that every rule row was ANSWERED, and it did not check
that every finding the body MENTIONS carries an issue number or a fix. pr_body_lint cannot see
this: it has rule-coverage and claim-backing checks, but no check for "a body sentence that
classifies a finding". The control that should have caught it is the pre-validator self-audit's
class 4, read as a property of MY OWN body rather than of the diff: every finding named anywhere in
the body must appear under ## Filed issues (or be gone, fixed in the tree).

Root fix. The sentence is deleted; the finding is filed as #26 (with the
tidy diff and the mechanism: a sdk bump without a tidy leaves the old h1: line, and nothing in
this repo's gates runs go mod tidy -diff, so it drifts invisibly), and it appears under
## Filed issues. It is deliberately not fixed inside this PR: it is a separate change to a file
this PR does not otherwise touch, and mixing it in would enlarge a diff whose R10 is already
partial.

Finding 2 — the named witness does not exercise the changed category

Mechanism. This repo's AGENTS.md declares check-commands-local (in opencharly/charly) as
"the R10 witness", and I let that declaration stand in for A2's actual question — can THIS gate
FAIL on THIS change? Its two clean steps are clean-dry-run-runs (bare --dry-run) and
clean-deep-dry-run-runs (--deep --dry-run); neither invokes --build-cache, so a green bed
could not have caught a defect in the new category. Worse, my own paste listed both steps' command
lines: the contradiction sat inside my own evidence, five lines below the claim.

Missed control. I treated "the repo declares a witness" as "the witness covers this change",
and I pasted the bed's steps without reading them back against the sentence above them. The
control that should have caught it is a two-column read of the change class: every changed path
against every gate, asking which gate can turn red on it — and, for a category whose only caller is
its own flag, noticing that no bed anywhere invokes that flag.

Root fix. The body no longer offers the bed as the category's witness. It states the category's
own proof where the R10 row belongs — the ADE plan check clean-build-cache-dry-run (which drives
charly clean --build-cache --dry-run against an injected cache root and asserts the tree
survives, proof D) plus the four live runs A–D on the binary rebuilt from this tree — and describes
check-commands-local only for what it does exercise (the changed grammar and report on a bare run
and on --deep), naming the reason a step cannot be added here: that bed lives in
opencharly/charly/charly.yml.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 5452a7f450b9100b010e54d9ca33bd566bdad0c5 (branch: feat/clean-buildkit-stores)

Security screen: PASS — no secrets/exfiltration, no guardrail weakening, no supply-chain drift; all placement is in candy/plugin-clean (correct candy layer, no core/sdk capability moved 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 ## Filed issues; finding #2 (bed not exercising --build-cache) — resolved: the body now states A–D live runs + the clean-build-cache-dry-run plan check are the R10 proof and no longer offers check-commands-local as the build-cache gate. Author RCA (6978201631, @aitrawog) — coordination/RCA evidence, both missed controls named, no surviving finding.

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.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 18, 2026 12:16
@github-actions
github-actions Bot merged commit 2136bb0 into main Nov 18, 2026
3 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant