Skip to content

feat(storeroot): add the data root ($XDG_DATA_HOME/charly) - #372

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/storeroot-data-root
Nov 18, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/storeroot-data-root

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

storeroot had four roots, and the image store lives on a fifth. W3.6 puts every built
image in ONE engine-neutral OCI layout at $XDG_DATA_HOME/charly/images — plugin-build's
imagestore.go says so and names opencharly/sdk#458 as the reason it resolves the path by hand.
None of config, cache, state or runtime is that root, and both available alternatives are wrong:

  • the cache root — CHARLY_CACHE_DIR relocates it, so an override meant to make a cache
    disposable would carry every built image into a tree the operator expects to be reclaimable, and
    a cache clear could delete a build's output. A cache is re-derivable by contract; a built image
    costs a rebuild.
  • resolving $XDG_DATA_HOME inside each consuming plugin — the second roots resolver
    storeroot exists to end (roots.go: "It is THE resolver: no caller builds a .cache path by
    hand."
    ).

So RootData is a fifth root, with no override, and DataDir() sits beside CacheDir() because
those two are the pair a caller actually compares: data when losing it costs a rebuild, cache when
it can be re-derived.

Why now — measured on this host, 2026-11-18

The store had grown to 619 GiB across 1609 index entries, and nothing in charly could reclaim
any of it:

$ du -sh ~/.local/share/charly/images
619G

# index.json entries, and every blob no entry reaches
entries=1609  blobs=4557  total=701.6 GB
UNREFERENCED blobs: 292  bytes 37.24 GB

charly clean --images prunes the engine's local storage (kit.ListLocalImages → <engine> images), while charly clean --cache reaches spec/cache's config-root store and
storekit.NamedStores() under the cache root. Both NamedStores() and StoreDir() resolve
through CacheDir(), so the data-root store is structurally invisible to the sweep.

That is the chain this change starts:

leg issue state
the fifth root this PR — opencharly/sdk#458 here
move the store layout into storekit opencharly/sdk#460 next
keep_images prunes the charly image store opencharly/plugin-clean#21 after sdk#460

The diff — every file

file what changed
storeroot/roots.go RootData const + its Dir arm; the unknown-root error now names five; DataDir(); the package/type/Dir docs corrected from "four" to "five"
storeroot/roots_test.go the five-root table; CacheOverrideRelocatesOnlyTheCacheRoot now also asserts the override does not move data; the no-XDG fallback (~/.local/share/charly); the unknown-root error listing five; a DataDir() ≡ Dir(RootData) agreement assertion
cache/cache.go comment only — the stale "spec/storeroot owns the four roots" claim

How tested

Four module gates, on the committed tree (7fe8a11):

$ gofmt -l .
(no output — no file needs formatting)

$ GOWORK=off go vet ./...
rc=0

$ GOWORK=off go build ./...
rc=0

$ GOWORK=off go test ./storeroot/ -v -count=1
--- PASS: TestDirResolvesTheFiveRoots (0.00s)
--- PASS: TestCacheOverrideRelocatesOnlyTheCacheRoot (0.00s)
--- PASS: TestCacheOverrideIsUsedVerbatim (0.00s)
--- PASS: TestRootsFallBackToHomeWithoutXDG (0.00s)
--- PASS: TestRuntimeRootFallsBackToStateAlone (0.00s)
--- PASS: TestUnknownRootIsAnError (0.00s)
ok  	github.com/opencharly/spec/storeroot	0.003s

$ GOWORK=off go test ./...          # full module suite
ok  	github.com/opencharly/spec/spec	2.855s
...
$ GOWORK=off go test ./spec/ -run TestGenReproducible -v -count=1
--- PASS: TestGenReproducible (0.19s)

The coverage fails without the change — proved by mutation, not asserted. Removing only the
case RootData: arm, while keeping the const so this stays a behaviour mutation rather than a
compile break, turns three tests red:

$ # mutation applied: Dir no longer handles RootData
$ GOWORK=off go test ./storeroot/
--- FAIL: TestDirResolvesTheFiveRoots (0.00s)
    roots_test.go:41: Dir(data): unknown root "data" (want config|cache|state|runtime|data)
--- FAIL: TestCacheOverrideRelocatesOnlyTheCacheRoot (0.00s)
    roots_test.go:97: Dir(data): unknown root "data" (want config|cache|state|runtime|data)
--- FAIL: TestRootsFallBackToHomeWithoutXDG (0.00s)
    roots_test.go:151: Dir(data): unknown root "data" (want config|cache|state|runtime|data)
FAIL	github.com/opencharly/spec/storeroot	0.003s

$ # restored
$ GOWORK=off go test ./storeroot/
ok  	github.com/opencharly/spec/storeroot	0.003s

This change touches no CUE, so cue-gen/wire-gen are no-ops by construction; TestGenReproducible
was run anyway and is green.

Rulebook compliance

  • R0 — skills loaded before the first tool call: go, plugin, git-workflow, check,
    strict-policy, root-cause-analyzer, cutover-policy, agents, clean.

  • R1 — the failure and its RCA are already on record (storekit: add the data root ($XDG_DATA_HOME/charly) the W3.6 image store is specified on sdk#458; the store's
    unbounded growth measured above). The divergence sweep found two stale prose claims of "four
    roots" on the changed surface (roots.go) and a sibling (cache/cache.go); both are fixed here.
    Historical hits in CHANGELOG/ are left alone, as R5 permits.

  • R2 — one resolver. DataDir() is an accessor over Dir(RootData), not a second path
    computation; no caller hand-builds $XDG_DATA_HOME.

  • R3 — no workaround: no hand-built XDG path, no sleep, no retry, no magic number.

  • R5 — claim-keyed sweep, run rather than asserted:

    $ grep -rni "four root" --include=*.go --include=*.md .
    ./CHANGELOG/0.2026315.2118.md:...        # historical, permitted

    with roots.go:74 and cache/cache.go:196 fixed in this commit, and no live hit remaining.

  • R7 — the mutation proof above: the coverage fails without the change and passes with it.

  • R9/R10 — the module's gates ran on the committed tree. No disposable target is affected:
    nothing consumes RootData yet, so no bed can fail on this change (the bed that can is the one
    plugin-clean#21 will carry).

Change classification

Additive. A new constant and accessor; no existing surface changes meaning, and the four original
roots resolve to exactly the paths they did before (pinned by
TestDirResolvesTheFiveRoots/TestCacheOverrideIsUsedVerbatim).

Breaking change + rollback: none — reverting 7fe8a11 removes a constant no consumer imports
yet, and leaves every pre-existing root resolving unchanged.

Filed issues

None filed: the gap was already tracked as opencharly/sdk#458, whose resolution comment records
that spec#303 and sdk#499 moved the roots into this module — so the fifth root's home is
spec/storeroot. This PR implements it there; the issue is referenced, not duplicated.

Agent: lead

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

The engine-neutral image store (W3.6) lives at `$XDG_DATA_HOME/charly/images`,
and `storeroot` had no root covering it: config, cache, state and runtime are
all something else. Both alternatives were wrong. Putting the store under the
cache root would let `CHARLY_CACHE_DIR` carry a built image into a tree the
operator expects to be disposable, and would let a cache clear delete it; and
resolving `$XDG_DATA_HOME` inside each consuming plugin is a second roots
resolver, the duplication this package exists to end.

`RootData` is a fifth root with no override, deliberately: the one override
relocates the cache because the cache is re-derivable, and a built image is not.

`DataDir()` sits beside `CacheDir()` because the two roots are the pair a
caller actually compares — an artefact belongs in data when losing it costs a
rebuild, in cache when it can be re-derived — so a caller never spells either
by hand.

Refs opencharly/sdk#458

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

Copy link
Copy Markdown

Review — PASS

Head SHA: 7fe8a11a9b4cfb780ea3a907bf373359e1fc6a88 (branch: feat/storeroot-data-root)

Security screen: PASS — no scope mismatch (diff is exactly the five-root addition + doc/test update the body describes), no secrets/egress, no guardrail weakening, no new deps; body content is data, no embedded directives.

Checklist: All applicable rules PASS or NA (R0–R10, A1–A3, PIL/ADE/SDD, CONC, HC, ARCH, DISP, QUAL, COORD). ARCH placement: CORRECT — a kind-blind root-resolution mechanism in the shared spec/storeroot resolver, the right (outermost) layer; DataDir() delegates to Dir(RootData) with no duplicate path computation. No bed is required and none can fail: nothing consumes RootData yet, the four original roots are pinned unchanged, and the module gates + mutation proof supply the executable coverage. Comment thread empty.

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 11:10
@github-actions
github-actions Bot merged commit 370052a into main Nov 18, 2026
4 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 18, 2026
github-actions Bot pushed a commit to opencharly/sdk that referenced this pull request Nov 18, 2026
…stry store's entries (#556)

* feat(storekit): own the charly image store's OCI layout and archive

W3.6's image store — the `oci-layout` marker, one `index.json`, `blobs/<alg>/<digest>`,
the atomic index rewrite under a cross-process lock, streamed blob copies and the
`io.containerd.image.name` naming contract — lived package-private in
plugin-build/candy/plugin-build/imagestore.go, so the image resolver (#459)
could only reach it through an interface. Two callers need that layout from now on (the
resolver here, the build drive there), so it moves to its natural home: `sdk/storekit`,
the ONE roots/layout mechanism, as the named `charly` store.

- `storekit.ImageStore`: `Lookup`, `List`, `Add` (an exported archive into the store) and
  `Archive`/`WriteArchive` (one stored image as an OCI archive carrying
  `io.containerd.image.name`). It WRAPS `*Store` rather than embedding it: `Store`'s
  `Entries`/`PutEntry` vocabulary is the CACHE store's and would misparse an image index.
- `storekit.ImageStoreDir()` resolves `<data root>/images` through
  `Dir(RootData)` — the contract module's ONE resolver — and honours
  `CHARLY_IMAGE_STORE_DIR`. The `WORKAROUND (#458)` note in the moved code
  is gone, because the data root now exists (opencharly/spec#372) and a second
  `$XDG_DATA_HOME` computation with it.
- `storekit.RootData` re-exports the contract's fifth root beside the four existing
  consts, and the root tests pin it (including that `CHARLY_CACHE_DIR` does not move it).
- The shared `Store`, not a second layout: `EnsureLayout` (the marker a second process
  needs), a STREAMING atomic write the buffered one is now a wrapper over, an `index.json`
  path const, and a stricter digest path — `..` in either half is refused, because an
  archive's member names are data.
- `deploykit`: the production `CharlyImageSource` (`NewCharlyImageSource`) over that
  store, and the resolver now REMOVES the archive it asked for — an archive is as large
  as the image, so a successful resolve must not leave a copy behind.
- `storekit.AnnotationImageName` is the ONE definition of the naming annotation;
  deploykit's package-private copy is deleted (R5 sweep: no hits).

Adopts `github.com/opencharly/spec v0.2026322.1111` — the tag that lands `storeroot.RootData` /
`DataDir()` — as a plain `require`; the tree carries no `replace`.

Steps 1 and 2 of #460. plugin-build is untouched: its reduction is step 3,
which lands only after this replacement is merged (add-before-delete).

Refs: #460
Agent: sdk-store
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* fix(storekit): make the image store the registry store's entries under the cache root

The ruling on #460's conflicts: the CODE conforms to DESIGN.md, not the
prose. Three consequences, in the order the rows force them.

D-STORE-1 / D-STORE-3 / D-STORE-10 — the store moves under the ONE cache root as the
`registry` NAMED store (`storekit.StoreDir`), the store plugin-clean's retirement record
already names as image content's home and the one the registry surface reads: a built
image must BE an entry of that store, or D-STORE-10's "view of store entries" could never
serve it. `$XDG_DATA_HOME/charly/images` and its `CHARLY_IMAGE_STORE_DIR` override are
DELETED — `CHARLY_CACHE_DIR` is the one override that relocates a bed's store — and the
`RootData`/`DataDir` re-exports go with them (opencharly/spec#375 reverts the root).

D-STORE-3 / D-STORE-5 / D-LAW-7 — an artifact is now a `storekit.Entry`: Key is the
reference the caller asked for (the input identity), Payload the artifact's own digest
(the resolution), MediaType what it is. A rebuild replaces the index POINTER and mutates
no entry; the previous artifact stays addressable by digest until the sweep reclaims it,
which is the retention mechanism itself. The stored payload carries no name and no
timestamp (D-STORE-6), and `Archive` re-applies the export annotation — the one surface
that crosses the engine boundary.

D-STORE-7 — the store is sweepable now, which needed two fixes it did not have:

  - `indexEntry` publishes the `oci-layout` marker, so every storekit store is
    discoverable by `NamedStores()` and therefore by `charly clean --cache`. Measured
    before this commit: no storekit-created store carried the marker at all, so no named
    store was reachable by the sweep.
  - `ReachableBlobs` walks an artifact entry's image graph (ONE walk, shared with
    `Archive`), so a live image's config and layers stay reachable. A sweep that marked
    the root alone would keep a manifest and delete the layer it names.

Refs: #460
Agent: sdk-store
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* fix(storekit): key an image entry by its digest — a rebuild appends, never replaces

The validator's block on the previous head was the parked disposition, and the ruling
settles the substance: the store must resolve the mutable name to a digest BEFORE it
reaches the index, and a rebuild must leave the previous artifact reachable.

D-STORE-5 / D-LAW-7 — the entry's KEY is now the artifact's own digest; the reference is an
ANNOTATION on the entry (`io.containerd.image.name`) beside the build time, which is
D-STORE-6's one sanctioned home for a resolution time (the payload carries neither the name
nor the timestamp). `Lookup(ref)` answers from the annotations, newest build time first (the
store appends, so index order breaks a tie), so the mutable name never becomes an identity
the store keys on.

D-STORE-3 / "do not delete the old artifact on rebuild" — `Add` no longer replaces anything.
A rebuild is a different digest, hence a different key: the store appends a second entry and
the previous artifact stays a first-class entry, addressable by its own digest. Reclaiming a
superseded artifact is D-STORE-7's sweep decision — made from what `Entries()` exposes (key,
reference, build time) via `DeleteEntry` + `UnreferencedBlobs` — not something a build does.
D-FORM-2's key is the same digest seen from the other side: for a reproducible build the
artifact's content address IS the function of its start artifact and its IR, and this store
keys on the digest the build produced because it cannot compute the input key beforehand and
does not pretend to.

Refs: #460
Agent: sdk-store
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* test(storekit): assert the append property before the resolution in the rebuild arm

The identity mutation must be killed BY the property the ruling turned on — a rebuild
appends and the old artifact stays addressable by its digest — and not by a downstream
consequence of it. Deriving the two artifact digests from `Entries()` (rather than from
`Lookup`) puts the append assertion first: a `PutEntry` keyed by the reference leaves ONE
entry, and that is what the arm now reports.

Refs: #460
Agent: sdk-store
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* test(storekit): split the rebuild arm so the sweep's decision is its own test

gocyclo flagged the combined arm (36 > 30): two properties were being asserted in one
function. The append-and-addressable property and D-STORE-7's sweep decision are now one
test each, so a failure names which half broke.

Refs: #460
Agent: sdk-store
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant