Skip to content

feat(storekit): OrphanedLayouts(root) — the ONE orphan-layout discovery both sweep closes need (closes #393) - #394

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/storekit-orphaned-layouts
Oct 14, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/storekit-orphaned-layouts

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

Closes #393. Two closes of one ruling need the same discovery and R2 forbids two copies: charly-registry's store cutover (#12, merged) sweeps the pre-store per-ref layouts a deleted writer left inside the store's own tree, and charly-registry#11 sweeps the pre-rename ~/.cache/charly/images root (measured still present, 3.5M). Discovering orphaned layouts is a property of the store layout, not of any policy a plugin owns, so the boundary law puts it here, beside the store it inspects — one definition, both closes.

type Orphan struct {
	Dir   string
	Bytes int64
}

func OrphanedLayouts(root string) ([]Orphan, error)

Three properties, each deliberate:

  1. The predicate is NamedStores()'s marker test, INVERTED. NamedStores() calls a marker-carrying child of the cache root a store; the same directory inside a store's own tree is junk — a store keeps every byte in blobs/<alg>/<digest> and its entries in index.json and never reads a child layout. One LayoutFile constant, two directions, so the two readings cannot drift — and a test asserts the agreement rather than trusting it.
  2. The CALLER names the root, because liveness is policy and this is mechanism. The function does not decide which layouts are orphaned and cannot: NamedStores() answers nothing here either (it returns exactly the marker-carrying children in question), so a function that tried to guess "no merged writer still writes this" would be policy wearing a mechanism's name. The contract is the opposite: the caller passes a root in which a marker-carrying child cannot be live — a store's own tree (a child layout is an orphan by construction) or a root the migration table retired (the caller's justification, recorded in that migration).
  3. Discovery and sizing only — never deletion. Removing stays with the caller, so a sweep's destructive half lives with the surface that also reports it (--dry-run first, then the removal). A missing root returns (nil, nil), the same shape NamedStores() uses.

Orphan.Bytes counts every file in the tree, the marker included — that is what os.RemoveAll reclaims, and a size that omitted the marker under-reported a real sweep by the marker's own bytes. (I made that exact mistake in the first consumer's assertion; the contract now names it so the next reader does not.)

What this is NOT: not a liveness oracle, not a recursive walker (direct children only, pinned by a test), not a deleter, and not a second copy — the local orphanedLayouts in charly-registry becomes a delegation to this function in the follow-up consumer leg.

BLOCKS

  • Blocked items: plugin-clean applying this to ~/.cache/charly/images (the half that closes charly-registry#11) and charly-registry's cache sweep delegating here instead of keeping its local copy. Blocking artefact: this mechanism's publication — both consumers must depend on a MERGED, TAGGED ref (Policy B), never on a branch or a local copy. Unblocks on: this landing on main and being tagged by the org's tag-on-merge.
  • Posted on sdk#393 with the CLAIM (6178608434), where oci-plugin-lead (this package's owner, task-12) can take the leg instead if it prefers.

How tested

On the committed head 6af34ebaa1d66c5ae7cfad2582e183ea1146aad4 (tree 304aaa27b392d2c7c16dd78e7a3325ea698a8e05):

$ gofmt -l storekit/                                  # empty = clean
$ GOWORK=off go build ./...                           # ok
$ GOWORK=off go vet ./storekit/                       # ok
$ GOWORK=off go test ./...                            # every package ok (the module's own gate)
$ ~/go/bin/golangci-lint run ./storekit/              # v2.13.2 BY PATH
0 issues.
$ GOWORK=off go test ./storekit/ -run Orphan -v
--- PASS: TestOrphanedLayoutsFindsMarkerChildrenAndSizesThem      # the predicate AND the size, incl. a store-shaped root, a non-layout child and a plain file
--- PASS: TestOrphanedLayoutsIsOneLevelOnly                       # depth is the contract, not an accident
--- PASS: TestOrphanedLayoutsOnAnAbsentOrEmptyRootIsNotAnError    # a sweep of a never-populated root is a no-op
--- PASS: TestOrphanedLayoutsOrderIsStable                        # sorted, so pasted evidence does not differ between runs
--- PASS: TestOrphanedLayoutsAgreesWithNamedStoresOnTheMarker      # the inversion, on the very directory NamedStores() calls a store

The coverage fails without the change (mutation, not assertion)

# mutation 1 — drop the marker test (every child becomes a candidate)
--- FAIL: TestOrphanedLayoutsFindsMarkerChildrenAndSizesThem
    orphans_test.go:62: OrphanedLayouts = [{…/blobs Bytes:0} {…/not-a-layout Bytes:4} {…/quay.io_old_shape_v1 Bytes:4126}], want exactly the one marker-carrying child
--- FAIL: TestOrphanedLayoutsIsOneLevelOnly
    orphans_test.go:92: OrphanedLayouts = [{…/group Bytes:46}], want none: `group` carries no marker, and its child is one level too deep

# mutation 2 — exclude the marker file from the size (the under-report the contract names)
--- FAIL: TestOrphanedLayoutsFindsMarkerChildrenAndSizesThem
    orphans_test.go:68: orphan bytes = 4096, want 4126 (marker 30 + payload 4096)
--- FAIL: TestOrphanedLayoutsAgreesWithNamedStoresOnTheMarker
    orphans_test.go:170: OrphanedLayouts = [{…/old_ref_v1 Bytes:6}], want the child layout (36 bytes)

Both mutations were reverted; the suite is green on the committed tree, and discovery deletes nothing — one arm asserts the orphan is still on disk after the call.

Rulebook compliance

  • R0 — /charly-internals:plugin, go and git-workflow loaded; this repo's AGENTS.md read, and its placement rule honoured: a reusable mechanism library consumed by more than one plugin, kind-blind, free of capability code. This is a store-layout mechanism with no policy in it.
  • R1 — one anomaly surfaced and was root-fixed in the artifact rather than annotated: the size assertion that forgot the marker's own bytes (the code was right; the contract now names it). The two storekit findings I filed earlier (sdk#390, sdk#391) are separate mechanisms with their own root fixes and are not touched here.
  • R2 — this PR is the extraction: the second occurrence (the charly-registry#11 sweep) arrives as the trigger, and the copy in charly-registry becomes a delegation rather than staying a sibling implementation.
  • R3 — no workaround, no sleep, no retry, no manual step; the missing-root case is (nil, nil) rather than an error a caller must swallow.
  • R4 — the mechanism's contract is documented where the code carries it (why the caller names the root), so no doc has to route around the boundary.
  • R5 — nothing is deprecated here; the consumer leg deletes the local copy in the same cutover that adopts this (producer-first: this must merge and tag before that leg).
  • R6 — one worktree, one branch, my own; git status checked before staging; no force-push, no amend after the first push.
  • R7 — the coverage fails without the change, twice over, pasted above; the changed path is a library function with no runtime boundary to run live, and its consumers are the live proof (each carries its own bed).
  • R8 — no live service boundary in this change (it touches no registry, no network).
  • R9 — the module's own gates ran with GOWORK=off on the committed tree, so nothing resolved through a workspace the consumers do not have.
  • R10 — this repo's change class is the module's Go gate (build/vet/test + the CI cross-compile matrix), run here on the committed tree with zero warnings; the org charly/pr-validator is the merge gate.

Change classification

A Go mechanism addition in the sdk library (storekit/orphans.go + storekit/orphans_test.go, 258 lines added, no schema and no wire change — the CUE source lives in spec and is untouched). Behavioural dependency for two consumers, both gated on this landing and being tagged (Policy B).

Filed issues

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

…very both sweep closes need

Two closes of one ruling need the same discovery and R2 forbids two copies: the
`charly-registry` store cutover (#12) sweeps the pre-store per-ref layouts a deleted
writer left INSIDE the store's own tree, and `charly-registry#11` sweeps the
pre-rename `~/.cache/charly/images` root. Discovering orphaned layouts is a property
of the store layout, not of any policy a plugin owns, so it belongs here beside the
store it inspects.

- The predicate is `NamedStores()`'s marker test INVERTED: one `LayoutFile` constant
  read two ways — what is a store at a cache root is junk inside a store.
- The CALLER names the root, because liveness is policy and this is mechanism. The
  function cannot answer "no merged writer still writes this" (`NamedStores()` cannot
  either — it returns exactly the marker-carrying children in question), so the
  contract is the opposite: the caller passes a root in which a marker-carrying child
  cannot be live — a store's own tree (orphan by construction) or a root the
  migration table retired.
- Discovery and sizing only, never deletion: the destructive half stays with the
  surface that also reports it (`--dry-run` first).
- `Orphan.Bytes` counts every file in the tree, the marker included — a size that
  omitted it under-reported a real sweep (measured while writing the first consumer's
  assertion).

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

Copy link
Copy Markdown

Review — PASS

Head SHA: 6af34ebaa1d66c5ae7cfad2582e183ea1146aad4 (branch: feat/storekit-orphaned-layouts)

Change class: code (sdk Go mechanism kit storekit; no schema/wire change).

Security screen: PASS — no scope mismatch (diff = the two described files), no secrets/egress/network, no guardrail or supply-chain change, not security machinery.
Checklist: All applicable rules PASS or NA. Cross-checks: Orphan.Bytes/dirBytes and the LayoutFile-inverted predicate match the described contract; the pasted mutation output is internally consistent with the diff (line numbers 62/68/92/170 land on the exact asserted messages; 4126 = 30+4096, 6 vs 36 = marker-excluded vs included; blobs=0, not-a-layout=4); +86/+172 = 258 lines as claimed; head/tree SHAs consistent; placement CORRECT (kind-blind reusable store-layout mechanism, two plugin consumers, sdk-only deps → storekit kit; would NOT be better one layer out, since a candy cannot be shared by two plugins). A2/A3: library gate is the module Go gate + pasted gofmt/build/vet/test/golangci-lint output, changed code path executed live by the unit suite → fully tested and validated justified, not inflated. SDD/RDD/ADE/DISP/R8/R9 NA (no CUE/proto, no new candy, no destroy/rebuild, no service boundary, no deployed binary).
Comments: thread empty (0 comments) — nothing to disposition.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 14, 2026 21:15
@github-actions
github-actions Bot merged commit 2ae5b9f into main Oct 14, 2026
6 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 14, 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

2 participants