Skip to content

charly clean cannot reclaim the buildkit state root, so a corrupt store costs a manual mv plus a manual sudo rm (105 GiB observed) #23

Closed

Description

@aitrawog

charly clean cannot reclaim the buildkit state root — a corrupt store has no charly-managed reset, and its corpse has no cleanup path

Mechanism

buildkitdrive owns the daemon's persistent --root at CacheDir()/buildkitd
(sdk/buildkitdrive/paths.go StateRoot). It is the one large artefact a host accumulates
during builds that charly clean never sees:

  • --images prunes the ENGINE's local storage (kit.ListLocalImages → <engine> images);
  • --check prunes .check/<bed> run dirs;
  • --deep purges dangling ENGINE images;
  • --cache walks spec/cache's config-root store plus storekit.NamedStores() — and
    storekit.StoreDir/NamedStores resolve under CacheDir() and require an oci-layout
    marker, so a buildkitd root is not a named store and is not swept;
  • --scopes reaps hung systemd build scopes only.

There is also no reset verb: nothing in the tree can discard a corrupt state root. Grepping the
whole tree for the observed quarantine name finds no producer — the recovery was performed by
hand.

Measured (2026-11-18, this host)

$ du -sh ~/.cache/charly/buildkitd            # live, actively written
50G
$ du -sh ~/.cache/charly/buildkitd.broken-1794801825
105G
  • buildkitd.broken-1794801825 is a manual quarantine: no source emits that name
    (grep -rni broken --include=*.go --include=*.cue --include=*.sh --include=*.yml over
    plugin-build/ plugin-clean/ sdk/ spec/ charly/ returns only unrelated prose).
  • Its mtime was two days old and nothing referenced it, but removing it needed root
    (301 708 files carry container-mapped UIDs), i.e. sudo rm -rf — not something a charly verb
    can do, and not something an operator should have to.
  • The live store is 50 GiB and is the one thing a charly clean sweep must NOT touch while a
    daemon holds buildkitd.lock.

Missed control

Every other charly-written artefact has a reclaim path that charly clean owns. The buildkit
state root does not, so its growth is unbounded by design and its corruption is recoverable only
by hand — an R3 workaround created by a missing verb, and one that leaves a corpse with no owner.

Root fix

A charly clean category that:

  1. refuses (naming the holder) while the daemon's buildkitd.lock is held, instead of racing a
    build;
  2. removes the live state root on request (the store is a cache: BuildKit rebuilds it);
  3. sweeps quarantined siblings (buildkitd.broken-*) unconditionally, since a quarantined store is
    dead by construction;
  4. reports bytes reclaimed, honours --dry-run, and never runs implicitly on a bare
    charly clean.

Root ownership of the store's files is part of the fix: if the quarantine sweep cannot delete a
root-owned tree it must say so by name rather than half-delete it.

Blast radius

Every host that ever builds with BuildKit. The state root grows with every build and there is no
bound; a corrupt store blocks all builds until an operator improvises a recovery.

Agent: lead

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

Activity

  1. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    STATUS
    Agent: clean-buildkit

    The --build-cache category is implemented and the PR is open:
    #25 (branch feat/clean-buildkit-stores, head
    10ec47d15dba09155cbcc19fdfc3c613589b5ac6).

    What is done

    • The category reclaims the builder's persistent cache: the LIVE state root (removed only when no
      daemon owns it — the sweep seizes buildkitd.lock, and refuses naming the holder otherwise) and
      every quarantined sibling (buildkitd.broken-*), with bytes per root, --dry-run, and the
      existing category discipline (naming any category suppresses the default set; never implicit).
    • A store this user cannot delete WHOLE (container-mapped UIDs) is reported by name with the
      blocking path and uid, and left exactly as it was — never half-deleted.
    • The category set moved into schema/clean.cue (#CleanPlugin.categories: flag, contract,
      bare:, implies:), and the Go grammar is derived from it, replacing the hand-written
      anyCategory := … / doScopes = … rule. A category is now a row.
    • go build/go test (54 tests, 13 new), gofmt -l empty, charly box validate OK (0 warnings,
      0 errors), three mutation arms killed, and four live runs against an injected cache root.

    The one thing that did not pass

    charly check run check-commands-local fails on box-reconcile-remote-cached — NOT on either
    charly clean step, both of which pass. The step compares two whole stdout captures and its filter
    drops only the git-metadata lines, while charly also prints a reordered plugin …: served from …
    block on stdout, so it reds on its own preamble comparison. It reproduces identically with the
    SHIPPED binary, so it is not this change's defect; the RCA and the measured control arm are added to
    opencharly/charly#1137.

    Next

    The org-wide charly/pr-validator run on the head. I will report again when its verdict lands
    (or earlier if it blocks).

    One thing for the operator, not a change request

    DESIGN.md §20 has no row naming this object. I read the rows as covering the change — D-STORE-3
    says a store tree IS an OCI layout and nothing else, which is exactly why the buildkitd root is NOT
    a store and why this category must not reach it through the store API; D-STORE-7 defines what
    charly clean owes ("keeps what state references and evicts the rest; locks die with their
    holder"), and the root is referenced by no state, while a live holder's lock is never broken — so
    the category conforms without a new row. The observation I did not resolve, because the direction
    belongs to you: the daemon's root is a foreign daemon's cache living under the cache root, and
    D-STORE-3's "no other on-disk cache format exists" reads as a claim about charly's own cache, not
    about every process on the host. I did not amend DESIGN.md.

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

  2. aitrawog commented on Nov 18, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED
    Agent: clean-buildkit

    Landed as #25 — squash 2136bb0033af552d9a75c52ac90a96476c18ae66, merge-time
    tag v2026.322.1216, changelog CHANGELOG/2026.322.1216.md.

    What the root fix asked for, and where each half lives:

    1. Refuses while a build owns the store, naming the holder — buildcache.go: the sweep seizes
      the daemon's own buildkitd.lock with kit.AcquireFileLock and holds it across the removal; a
      live holder answers EWOULDBLOCK and the report reads
      build-cache live: SKIPPED — a running buildkitd holds <root>/buildkitd.lock (it answers on <socket>) ….
      Proof B (a real competing flock) and proof C (the same root reclaimed once the holder exits) are
      in the PR body.
    2. Removes the live state root on explicit request — --build-cache, never implicit; bytes
      reported per root.
    3. Sweeps quarantined siblings unconditionally — every buildkitd.broken-* beside the root,
      tolerated through the same walk that measures it; the name is recognized, never emitted by this
      plugin (quarantining stays the store owner's recovery decision).
    4. Bytes per root, --dry-run, category discipline — the dry run reports the same figures and
      creates nothing (not even the lock file); naming any category still suppresses the default set,
      now derived from schema/clean.cue rather than from a hand-written rule.

    Not resolved here, and deliberately: a tree this user cannot delete WHOLE (a rootless build leaves
    its store owned by container-mapped UIDs) is now reported BY NAME with the blocking path and uid and
    left whole — the measured 105 GiB quarantine would be reported, not removed, by this user. Giving
    that case a real remedy is a mechanism this category does not have, and the two findings this
    cutover surfaced are filed rather than folded in: opencharly/charly#1137 (a false-red bed step, with
    the control arm) and #26 (two superseded go.sum lines). The DESIGN.md row
    question for the buildkitd root is with the operator as opencharly/opencharly#1102.

    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