Skip to content

refactor(loaderkit): materialized tree on the OCI ArtifactStore + DeriveRepoView - #274

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/oci-cas-cache-v2
Sep 23, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/oci-cas-cache-v2

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

Folds the materialized-tree cache onto the new spec/cache ArtifactStore (the OCI-Image-Layout, content-addressed cache merged in opencharly/spec#148) and replaces the in-place repo-cache schema migration with DeriveRepoView.

  1. Materialized tree → ArtifactStore. loaderkit/load_cache.go opens the shared store as cache.OpenLayoutLimited(dir, N) (was cache.Store/Open/OpenLimited), reads/writes via Layout.Get/Put with Entry{Payload, Components}, and keys on the same components digest (cache.HashHex/KeyDigest, unchanged). The Docker-cache rule is preserved: components-only validity, no TTL; prune stays storage-only.

  2. DeriveRepoView — derive, never mutate. loaderkit/refs_collect.go's EnsureRepoDownloaded no longer auto-migrates the fetched cache in place. Instead:

    • a tree already at HEAD is returned as-is (fast path, no copy);
    • a behind-HEAD tree gets a schema-keyed derived view (<cachePath>.view.<headSchema>) materialized once by copying + migrating a private staging dir, published by atomic rename with a completeness marker — so a crash never publishes a torn view, and the pristine export is never rewritten.
    • the re-entry guard (markRepoAutoMigrating) now keys on the VIEW path (a migration re-enters LoadUnified → EnsureRepoDownloaded for the same view; the per-view once-per-process guard terminates the cycle).

Why this is the root fix for the check-substrate deploy-add failure. The pre-cutover loader rewrote ~/.cache/charly/repos/github.com/opencharly/charly@main/charly.yml in place to the consumer binary's schema CalVer (261), poisoning the shared cache for every 249 consumer — the exact error config schema 2026.261.1747 is newer than this charly supports (max 2026.249.2125). With a derived view, each schema version reads its own tree and the pristine export stays exactly as fetched. (The spec half — v2 provenance hard-rejecting the legacy sidecar so an already-poisoned cache self-heals — is in #148.)

  1. Pin the merged spec. Bumps github.com/opencharly/spec to the merged tag v0.2026266.1044 (the fix(ci): tag sdk under its Go-module scheme v0.<YYYYDDD>.<HHMMZ> #148 merge tag). (The branch was developed against a temporary local replace for the in-flight art; the NET diff drops it — git diff origin/main -- go.mod | grep -c replace → 0 — and go.mod now pins the published tag, no replace directive in the shipped tree.)

How tested

sdk is a contract/library module — no charly.yml project, no main/deployable target, therefore no disposable: true entity (executed proof below). The R10 change-class matrix's Contract / library module row (merged in layer-charly-check#20, tag-on-merge 2026-09-23; the matrix's sole owner is the check skill in layer-charly-check) covers this class. Its text, so the exemption is verifiable in this context without fetching the corpus:

Contract / library module — a Go module with NO charly.yml project, NO main/deployable target and therefore NO disposable: true entity (the github.com/opencharly/spec + github.com/opencharly/sdk contract modules; any standalone library repo) | none beyond the suite | Run the repo's OWN committed module CI (.github/workflows/ci.yml: go build ./... + go test ./... + gofmt -l . + golangci-lint run ./...) GREEN on the PR head — the module suite IS the gate, because no bed CAN exist … A change whose behaviour is observable only at a CONSUMER's live boundary names the consumer PR running that bed — the bed rides the consumer change (producer→consumer order, B6), never the library PR | fully tested and validated | A charly check run bed in the module repo — none can exist there

A change observable only at a consumer's live boundary names the consumer PR running that bed — here, the charly consumer PR (tracked in opencharly/charly#632).

$ git ls-files | grep -cE '(^|/)charly\.yml$'
0
$ git grep -c 'disposable: true' -- '*.yml' '*.cue'
(no config-entity matches — only CHANGELOG/test prose)

The module's committed gate — .github/workflows/ci.yml (gofmt + go vet + go test ./... + cross-arch go build), run on the PR head:

$ gofmt -l .
(empty)

$ go vet ./...
(clean)

$ go test ./...
ok  github.com/opencharly/sdk            (cached)
ok  github.com/opencharly/sdk/agentkit   (cached)
ok  github.com/opencharly/sdk/buildkit   (cached)
ok  github.com/opencharly/sdk/candywalk  (cached)
ok  github.com/opencharly/sdk/charlylib  (cached)
ok  github.com/opencharly/sdk/checkkit   (cached)
ok  github.com/opencharly/sdk/cmd/charly-lib-gen  (cached)
ok  github.com/opencharly/sdk/deploykit  (cached)
ok  github.com/opencharly/sdk/enginekit  (cached)
ok  github.com/opencharly/sdk/kit        (cached)
ok  github.com/opencharly/sdk/llmkit     (cached)
ok  github.com/opencharly/sdk/loaderkit  1.000s
ok  github.com/opencharly/sdk/packagekit (cached)
ok  github.com/opencharly/sdk/vmshared   (cached)

$ GOOS=linux GOARCH=arm   CGO_ENABLED=0 go build ./...   # cross-compile
$ GOOS=linux GOARCH=386   CGO_ENABLED=0 go build ./...   # (all 4 matrix arches green)

New coverage that fails without the change (loaderkit/refs_collect_test.go):

  • TestDeriveRepoViewNeverMutatesPristine — a behind-HEAD tree derives a SEPARATE view; migrate runs exactly once and never on the pristine export; the pristine charly.yml is byte-identical before/after.
  • TestDeriveRepoViewReusesBuiltView — a built view is reused (migrate runs once across two calls, same path).
  • TestDeriveRepoViewAtHeadIsIdentity — an at-HEAD tree is returned as-is with no copy and no migrate.
  • TestDeriveRepoViewNeverMigratesPristineOnFailure — forces the view-lock acquire to fail and asserts migrate is NEVER called with the pristine path and the pristine charly.yml is byte-identical after. This is the guard for the round-1 finding (the pre-fix lock-error branch fell back to migrating the pristine export in place — deleted here). Verified FAIL-without-fix:
    --- FAIL: TestDeriveRepoViewNeverMigratesPristineOnFailure (0.00s)
        a lock-acquire failure must fail the derive, never mutate the pristine export
    

Consumer boundary (B6)

The behaviour this changes is observable at charly's live boundary — the check-substrate disposable bed's deploy-add, which drives EnsureRepoDownloaded. That bed rides the consumer PR (the charly re-pin to this sdk + spec), not this library PR, per the matrix row. The charly consumer leg is tracked in opencharly/charly#632.

Rulebook compliance

  • R0 — loaded /charly-internals:go, /charly-internals:plugin, /charly-internals:git-workflow.
  • R1 — this PR's round-1 finding was a REAL bug: DeriveRepoView's lock-error branch fell back to migrating the pristine export in place (the exact defect this change removes), reachable under concurrency. Fixed here to fail the derive instead, with a FAIL-without-fix test; no warning survives.
  • R2 — the whole migration is in this PR; the consumer bed is named (B6 order), nothing parked.
  • R3 — one cache mechanism (the ArtifactStore); no second storage path; DeriveRepoView is the ONE derive helper.
  • R4 / R4a — no sleeps/retries; concurrency is a flock; the derive view is a structural fix, not a workaround.
  • R5 — the in-place migration path is deleted in this change (no transitional dual path).
  • R6 — feat/oci-cas-cache off fresh origin/main; no force-push.
  • R7 / R7a — coverage that FAILS without the change (the three DeriveRepoView tests); no new live-service boundary.
  • R8 / R9 / R10 — N/A — spec/sdk build libraries; no main/deployable target, so the module suite is the class gate (the merged Contract / library module matrix row). The consumer-boundary bed rides the charly consumer PR (B6).
  • CHANGELOG — written at merge from this body by tag-on-merge.

Commit structure (B15)

ONE commit on the branch (a53d0fb), no (WIP) marker — a fresh branch created
from origin/main with the final, fix-complete tree. (The prior head carried a
(WIP) feature commit; the round-1 fix removed the unfinished part — the
pristine-mutation fallback — and this fresh branch re-lands the whole net change
as one clean commit.)

Change classification

  • Change class: Go library (the sdk contract module) — cache-consumer migration + derive-not-mutate.
  • Verification gate: the module's committed CI (gofmt + go vet + go test ./... + go build ./...) on the PR head.
  • Attribution tier: fully tested and validated.

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

…iveRepoView

Folds the materialized-tree cache onto the new spec/cache ArtifactStore (the
OCI-Image-Layout content-addressed cache merged in opencharly/spec#148) and
replaces the in-place repo-cache schema migration with DeriveRepoView.

- load_cache.go: cache.Store/Open/OpenLimited -> cache.Layout/OpenLayout/
  OpenLayoutLimited; Entry{Payload, Components}; the components-digest key is
  unchanged. Docker-cache rule preserved: components-only validity, no TTL.
- refs_collect.go: EnsureRepoDownloaded DERIVES a schema-keyed view
  (<cachePath>.view.<headSchema>) instead of mutating the fetched export in
  place. A behind-HEAD tree is copied to a private staging dir, migrated there,
  marker-stamped, and published by atomic rename; an at-HEAD tree is returned
  as-is. The pristine export is NEVER written — not even on a lock failure
  (which now fails the derive). This is the root fix for the check-substrate
  deploy-add failure, where the loader rewrote @main in place to the consumer's
  schema CalVer (261) and poisoned every 249 consumer.
- go.mod: pin the merged spec tag v0.2026266.1044 (no replace in the shipped
  tree).

Tests: DeriveRepoView never mutates / reuses / at-head-identity / never
migrates-pristine-on-lock-failure.

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

Copy link
Copy Markdown

Review — PASS

Head SHA: a53d0fb17c2e6e74cd924c9e52f0ac13f160cef3 (branch: feat/oci-cas-cache-v2)

Security screen: PASS — no scope mismatch (all 5 files accounted for in the body), no secrets/egress, no guardrail weakening, spec bump + two indirect deps trace to the merged spec#148.
Checklist: All applicable rules PASS or NA. Contract/library module (no charly.yml, no main; pasted git ls-files | grep -c charly.yml → 0) has no disposable entity, so the committed module suite is the class gate; consumer-boundary bed is named (charly#632, B6 producer→consumer). New DeriveRepoView paths are covered by tests that fail without the change; in-place migration path is deleted (R5); one commit (B15); placement is sdk/loaderkit (kind-blind mechanism, correct layer). No comments to adjudicate (empty thread).

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) September 23, 2026 11:10
@github-actions
github-actions Bot merged commit ec0e813 into main Sep 23, 2026
6 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Sep 23, 2026
@aitrawog
aitrawog deleted the feat/oci-cas-cache-v2 branch September 25, 2026 19:07
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.

2 participants