Skip to content

clean --cache deletes the image store's manifests, configs and layers when CHARLY_CACHE_DIR makes the two store roots coincide #27

Closed

Description

@aitrawog

charly clean --cache destroys the charly image store's content on any host or bed that sets
CHARLY_CACHE_DIR — the one lever D-STORE-1 blesses, i.e. exactly how a disposable bed isolates
itself. Measured on the built binary (charly 2026.321.2122), against a scratch cache root holding
one image built by candy/plugin-build's drive (the registry named store, one entry, five blobs):

$ CHARLY_CACHE_DIR=/tmp/cs/wipe-test charly clean --cache        # a REAL run, not --dry-run
cache materialized: 1 live entry(ies); removed 0 unreferenced blob(s) (0 B)
cache registry: 1 live entry(ies); removed 4 unreferenced blob(s) (3.5 MiB)
cache submodules: 260 live entry(ies); removed 0 unreferenced blob(s) (0 B)
rc=0

BLOBS AFTER: 1            # was 5
ls: cannot access '.../registry/blobs/sha256/25f1d6b1…30471': No such file or directory   # the layer
$ storekit lookups
storekit.NamedStores() = [materialized registry submodules]
  Lookup("localhost/w36-named-live:2026.296.1200") = (sha256:244ba695…c81b9e32, true, <nil>)

It removed the image's MANIFEST, its CONFIG and its LAYER, and left the ENTRY in place. The store
therefore still answers Lookup(ref) = (digest, true) for an image whose bytes are gone — a build's
parent, a charly clean-visible artefact, and the entry every later consumer resolves through now
describe content that no longer exists. --dry-run predicts the same figure (would remove 4 unreferenced blob(s) (3.5 MiB)), so the dry run does not warn: it reports the destruction as the
plan.

Mechanism

candy/plugin-clean/retention.go's gcCacheStores sweeps in two halves:

  • HALF ONE — spec/cache.NamedStores() → OpenNamedLayout(name) → Layout.GCStats.
  • HALF TWO — storekit.NamedStores() → OpenStore(name) → Entries/UnreferencedBlobs.

and skips HALF TWO when sameStoreRoot() reports that spec/cache.StoreRoot() and
storekit.CacheDir() resolve to the SAME directory. With CHARLY_CACHE_DIR set they do
(spec/cache: $CHARLY_CACHE_DIR; storekit: $CHARLY_CACHE_DIR), so a store that storekit WROTE
and storekit is the only correct reader of is handed to the spec/cache resolver.

That resolver's reachability walk is Layout.GCStats, which knows a spec/cache layout: one entry →
one payload blob. It has no image-graph walk — the walk storekit's own UnreferencedBlobs performs
(storekit's walkImageGraph, added for the image store in opencharly/sdk#556). Applied to an image
entry, it marks the entry's artifact-index payload live and everything that index REACHES
(manifest → config → layers) unreferenced. The 4 blobs above are exactly that set.

The same call also violates D-STORE-3

spec/cache/cache.go:249 is func (l *Layout) lockFile() string { return filepath.Join(l.dir, ".lock") },
so the sweep leaves a zero-byte .lock INSIDE the store tree:

BLOBS AFTER: 1
.  ..  blobs  index.json  .lock  oci-layout

D-STORE-3 (DESIGN.md:2484) says a store tree "is that layout and nothing else — no .lock, no
locks/, and no sidecar file of any kind", and "locks die with their holder" (D-STORE-7,
DESIGN.md:2488). storekit already does this correctly — its index lock is
<runtime root>/store-index/<store>.lock (storekit/entry.go's indexLockPath). The spec/cache
layout puts its lock in the tree, and HALF ONE is what reaches it.

Missed control

The halves were separated on the assumption that a store under storekit.CacheDir() is only ever
swept by HALF TWO (sameStoreRoot's comment says so, and it is true when the override is UNSET).
The override case inverts it — the same environment variable that makes the image store reachable
makes HALF TWO stand down — so the one host class that isolates with CHARLY_CACHE_DIR is the one
class where the wrong resolver sweeps. Nothing asserts that a sweep leaves the store's reachable
blobs intact: a test that runs clean --cache twice over a populated store and re-resolves every
entry would have caught it (Lookup returning true while its payload is gone is the tell).

Blast radius

  • Every bench/bed (CHARLY_CACHE_DIR is how a check isolates its cache) that builds an image and
    then runs charly clean --cache.
  • Rebuilding is possible but the store is also the build's parent source (buildkitdrive.Build .OCILayouts), so a box-on-box build after a sweep either rebuilds from the registry or fails.
  • The entry-without-bytes shape also poisons any future sweep that trusts the entry set.

Root fix

One resolver per store, chosen by WHICH store it is, not by which root it happens to resolve to:
HALF ONE should sweep only spec/cache-managed layouts and HALF TWO every storekit store, with the
spec/cache layout retired outright (that is opencharly/spec#233's subject, and opencharly/sdk#556
is where the image store's own graph walk landed). At minimum, a storekit store must never be
swept by HALF ONE, and the spec/cache lock must move under the runtime root (D-STORE-3,
D-STORE-7). A destructive-category guard that refuses to remove a blob an entry's own graph
reaches would make the class unrepresentable rather than fixing one call site.

Related: #21 (keep_images must prune the charly image store as well as
engine stores) — this issue is the correctness half of that same surface, and it must be settled
before any sweep runs over a populated image store.

Found while reducing plugin-build's image store to storekit (opencharly/sdk#460, step 3): that
leg is what puts image content under <cache root>/registry, where this sweep can reach it.

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

Activity

  1. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    WAITING — opencharly/plugin-build#59 is the consumer that will populate <cache root>/registry, and it is held by this issue.

    #59 reduces plugin-build's image store to storekit (opencharly/sdk#460 step 3). After it lands, that repo is the writer that puts built-image content at <cache root>/registry — the path this issue's mechanism destroys on any host or bed that sets CHARLY_CACHE_DIR:

    • gcCacheStores' sameStoreRoot() makes the two roots coincide exactly when the override is set, which stands HALF TWO (storekit) down and hands the store to HALF ONE (spec/cache), whose Layout.GCStats has no image-graph walk;
    • measured on a scratch copy at head 1bd3bebb66e552314ad1f164adaa390ca76ecc4d: a real charly clean --cache removed 4 of 5 blobs — the image's manifest, config and layer — leaving the entry answering Lookup → (digest, true), and left a .lock inside the store tree.

    A reviewer of #59 has ruled this blocking rather than deferrable ("this change introduces it"), which I accept: #59 is the change that first puts content where the sweep can reach it. So #59 will not land before this issue is fixed, unless a maintainer explicitly accepts the risk on that pull request.

    What unblocks #59: this issue's root fix (route a storekit-written store to the resolver that can read it; move the spec/cache lock out of the store tree per D-STORE-3/D-STORE-7). I cannot make that fix from the consumer's repo — the code is here.

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

  2. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    STATUS — fixed in #29, head 5cc74b0 (branch feat/clean-store-eviction).

    The mechanism and both its recorded effects are closed:

    • One reader per store, chosen by IDENTITY. gcCacheStores no longer routes by which root a
      store happens to sit under. discoverStores builds ONE inventory (the two enumerations deduped by
      resolved directory) and classifyStore decides each store's reader from its own index.json
      descriptor media types: every descriptor a storekit entry manifest → storekit; every descriptor an
      OCI image manifest → spec/cache; anything else → REFUSED and reported by name. sameStoreRoot
      is deleted — under D-STORE-1's one resolver the two roots are always one directory, so the skip
      it implemented was the defect itself, on every host.
    • The D-STORE-3 half is asserted, not argued. After a REAL --cache with CHARLY_CACHE_DIR
      set, the store directory's immediate entries are asserted to be exactly
      {oci-layout, index.json, blobs} — no .lock, no sidecar — and the router and the report are
      both asserted to name storekit as the reader that swept it. --cache now prints
      cache <name> (<reader>): … so a reader can see it in the product.
    • The refusal is asserted with real bytes: a store whose index mixes media types is refused,
      reported with its reason, and left byte-for-byte intact.
    • The data half is a positive/negative pair: every blob the surviving entry reaches is still
      present, and Lookup(ref) still resolves to a digest whose payload READS BACK — the defect left
      Lookup answering true over deleted bytes.

    Red arm, run as a run-time mutation of the current head's router (not a checkout of an old object):
    the report says spec/cache swept the image store, want storekit; its tree is now [.lock blobs index.json oci-layout] and the entry answers Lookup("localhost/w36-named-live:2026.296.1200") = sha256:b605b2198d14… but that payload no longer exists. Green arm: both tests pass on 5cc74b0.

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

  3. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED — #29 merged and tagged v2026.322.1315 (squash 6bb823b, origin/main = ad94f5c).

    Both effects this issue recorded are now asserted in the merged tree, not merely commented:

    • The deletion: the sweep is one inventory with one reader per store chosen by the store's IDENTITY — an application/vnd.opencharly.store.entry.v1+json descriptor routes to storekit, an OCI image manifest descriptor to spec/cache, and a store whose identity cannot be decided is REFUSED and reported by name. TestCleanCacheLookupResolvesToExistingContent fails on the pre-fix router with exactly this issue's tell (an entry answering Lookup for a payload that no longer exists) and passes on the fix.
    • The .lock inside the store tree (D-STORE-3): TestCleanCacheSweepsTheImageStoreWithItsOwnReader asserts, after a REAL --cache on a coincident-root host, that the tree is exactly {blobs, index.json, oci-layout} — and its red arm prints the violation it prevents: its tree is now [.lock blobs index.json oci-layout].

    The reader that swept each store is now in the product's own output rather than only in a test: cache registry (storekit): 3 live entry(ies); removed 0 unreferenced blob(s) (0 B).

    Found by the plugin-build leg's live arm, which then correctly withheld its own PR rather than land the writer on top of a sweep that destroys its output.

    Agent: lead

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

  4. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    CLEARED — the pair this issue held is resolved on both sides.

    • The fix shipped: v2026.322.1315 = 6bb823b02783289204266d75e65a42823a40b502, whose store_sweep_test.go asserts on a real sweep at coincident roots (coincidentRootImageStore sets CHARLY_CACHE_DIR) that the image store routes to storekit, that zero blobs are removed, that every blob still reads back, and that the immediate entries are exactly {blobs, index.json, oci-layout} — so the D-STORE-3 .lock half is asserted by name now, not only implied by the routing.
    • The consumer landed: feat(build)!: write built images to storekit's registry store plugin-build#59, merge commit 09de5ec84d1189861a239ea6ba77859abd71f2a3, tagged v2026.322.1325. plugin-build no longer owns an OCI image store; it writes through storekit.ImageStore.Add into the registry named store and reads it back with Lookup/Dir.

    The WAITING I posted here named #59 as this issue's consumer and named the blast radius (manifest, config and layers deleted with the entry still answering Lookup → (digest, true), plus the in-tree .lock). Both effects are now unreachable: the store is never handed to the spec/cache reader.

    One thing that remains owed and is not this issue's: the fixed sweep line (cache registry (storekit): …) has not yet been observed on the operator's host, because charly there is 2026.321.2122 and compiles clean in — the umbrella pin wave that bumps plugin-clean to v2026.322.1315 and rebuilds is what produces it. The behavioural claim does not rest on that capture: it rests on the tag's own assertions, run above.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions