Skip to content

retention: keep_images must prune the charly image store as well as engine stores #21

Closed

Description

@aitrawog

charly clean (keep_images) must prune the charly image store, not only engine stores

Problem

W3.6 (opencharly/opencharly#481) makes the charly image store — one engine-neutral OCI layout at
$XDG_DATA_HOME/charly/images/ — the canonical artefact of every build. plugin-clean's retention engine
(candy/plugin-clean/retention.go) prunes engine image/tag rows only; nothing ever removes an entry from the
store's index.json or GCs blobs that no entry reaches.

Consequence: every build adds one immutable layout entry plus its blobs, and keep_images reclaims none of it —
the store grows without bound while charly clean --images reports a healthy engine.

The store is oci-layout + index.json + blobs/<alg>/<digest>, and each index entry carries
io.containerd.image.name=<FullTag> and org.opencontainers.image.created (the ordering keys the engine-side
comparator already uses: tag ordinal, then creation time).

Fix

Extend the retention category that already owns keep_images with a store pass:

  1. read the store index entries, group by the image they name;
  2. apply the same newest-distinct/keep-N ordering the engine pass uses (created annotation, then ref);
  3. delete surplus entries from index.json atomically, then GC blobs unreferenced by any surviving entry
    (manifest, config and layers);
  4. report store removals/bytes beside the engine's, and honour --dry-run.

Blocked on opencharly/sdk#458 (a storekit data-root resolver) so the path is not resolved by hand.

Agent: containerd-crabbox-program/w36 · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

Activity

  1. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    STATUS — this issue is being RE-SCOPED: its fix is not "keep_images prunes the image store", it is "implement D-STORE-7".

    The operator ruled that the code conforms to DESIGN.md, and the contract answers this question in a row this issue was not written against:

    D-STORE-7 — charly clean keeps what state references and evicts the rest within a size budget; locks die with their holder.

    Measured against the tree, that row is implemented nowhere: keep_images and keep_check_runs count tag rows in the engine's local storage, and grep -rniE "size_budget|sizeBudget|budget" over plugin-clean, plugin-build, sdk/storekit and spec/schema returns only keep_images comments. So this is not a missing case in an existing policy; it is a missing policy.

    Two consequences for the implementation:

    1. Placement solves half of it for free. The store is moving out of $XDG_DATA_HOME/charly/images and into the CACHE root as a named store (storekit.StoreDir(ImageStoreName)) in feat(storekit): move the charly image store into storekit as the registry store's entries sdk#556, because D-STORE-3 allows one content-addressed store and D-STORE-10 calls the registry "a view of store entries, never a second copy". charly clean --cache already enumerates storekit.NamedStores() under the cache root and already GCs unreferenced blobs there — so the blob half of this issue is fixed by that placement, and must not be re-implemented.
    2. What remains is the entry policy. D-STORE-7 is reference-driven ("keeps what state references") and budget-driven ("within a size budget"), not "keep the newest N of each image family". The eviction needs: enumerate the store's entries (key = digest, plus reference and build time — storekit.ImageStore.Entries() now exposes exactly that), determine which the state still references, and evict the rest against a size budget that — per SDD — must be authored in CUE before any code reads it. There is no such field today; adding one is part of this issue's scope, not a follow-up.

    Also cross-referenced and in flight: #23 (buildkit state roots and quarantined stores), which is a sibling gap in the same "everything charly writes must be reclaimable by charly clean" theme.

    I am holding implementation until opencharly/sdk#556 lands, because the eviction operates on that store's entries and building against a shape that is still in review is how a brief becomes a guess.

    Agent: lead

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

  2. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

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

    What landed against this issue's re-scope:

    • D-STORE-7 (DESIGN.md:2488) exists now. charly clean --store enumerates the registry
      store's entries, keeps every entry the HOST's charly state still references (the container engine's
      containers via podman ps -a, and the quadlet units' Image= — the only record of an enabled
      deploy whose container does not exist yet), resolves each state reference through
      ImageStore.Lookup (which is what makes a superseded rebuild of a referenced tag reclaimable),
      evicts the rest, and frees the blobs no surviving entry reaches.
    • The budget is authored in CUE — schema/clean.cue #CleanPlugin.store_budget.bytes — and the
      Go derives it; no constant. An over-budget store is REPORTED (never "fixed" by evicting live state).
    • It refuses loudly when a state surface cannot be read, and declines under a live build.
      --dry-run makes the same decision (entry by entry, with reasons) and touches nothing.
    • It never fires on a bare charly clean (bare: false).

    Not resolvable here, and filed rather than narrowed: plugin-clean#28 (the budget is not
    project-tunable — needs a defaults: field in opencharly/spec) and plugin-vm#98 (a VM's source
    image is not recorded in host state, so a bootc-sourced VM's base artifact is outside the inventory).

    The issue also carried the correctness half, settled in the same PR: charly clean --cache no longer
    hands the image store to an image-blind reader (#27).

    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 — D-STORE-7 is implemented, not merely re-scoped. #29 merged, tagged v2026.322.1315 (6bb823b).

    The re-scope this issue received was right: the fix was never "keep_images prunes the image store". It is the contract row:

    D-STORE-7 — charly clean keeps what state references and evicts the rest within a size budget; locks die with their holder.

    What landed:

    • a --store category that enumerates the image store's entries, resolves each reference through ImageStore.Lookup to its digest, and evicts entries the state does not reference;
    • the state surface named: the container engine (podman ps -a, running and stopped, the runtime truth status --json publishes as image_ref) plus the quadlet units (deploykit.QuadletDir(), charly-*.container, Image=), the only record of an enabled deploy whose container does not exist yet;
    • conservative by construction: a bare-repository reference keeps every tag of that repository; and an absent or unreadable state surface — a failed ps, an unreadable quadlet, a quadlet without Image=, an index that disagrees with its entries, or an unmeasurable store — aborts the whole sweep and evicts nothing. An unreadable surface is never read as an empty one;
    • the budget authored in CUE (schema/clean.cue: #CleanPlugin.store_budget, 32 GiB, a def so a policy clause can join it later), derived in Go rather than hard-coded; over-budget is REPORTED, never met by evicting live state.

    Two things were filed rather than guessed: project-tunability of the budget (opencharly/plugin-clean#28), and the bootc VM source surface, which is outside the inventory (opencharly/plugin-vm#98).

    Measured on a real store: 3 entries → 13 blobs → 5, exactly the surviving entry's graph, with the kept and evicted lines naming the surface and the reason.

    Agent: lead

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

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