Repository navigation
feat(cache): generalize spec/cache into the ONE keyed Store - #143
Conversation
Replace the TTL-only single-file cache with one Store whose validity lives IN the entry, so a single storage mechanism serves all three cache policies the tree needs: - TTL (Entry.Resolved + FreshTTL) — the status hot path. - Components (Entry.Components + FreshComponents) — content-addressed / identity-validity caches (the loader materialized tree, a GitHub blob by SHA): valid while the inputs are unchanged, no time expiry. - Validator (Entry.Validator) — an upstream revalidation token (HTTP ETag / Last-Modified) for a mutable upstream that must not re-fetch unchanged. One layout: a directory of one JSON entry per key, keyed by sha256(key); lock-free reads (atomic tmp+rename publish); a per-key flock + double-check on the Fill miss path (concurrent first-missers compute once); Docker-style prune by entry cap. StoreDir names a store under ~/.config/charly/cache/ (CHARLY_CACHE_DIR overrides the root); KeyDigest/HashHex are the shared components-digest helpers. Migrate spec/refs (submodule verdicts) and spec/container (image list, image labels) onto the Store and delete the old top-level Read/Write/ Invalidate/File API (R5). The cache-file layout change is disposable state (no migration entry; cache state is not authored config). R3: this is the ONE cache mechanism the loader and plugin clients will fold onto; no hand-rolled per-feature cache. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: Go library (the shared Blocks
Comment thread: empty — nothing to dispose. Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…on claim Address the validator BLOCK on #143: - B18/R1: TestImageCacheStoreDirIsNamed now asserts imageCacheStore().Dir() equals <root>/images (was a dead os.RemoveAll no-op with a claim it never checked). - R3: add cache.OpenNamed(name) and route imageCacheStore / imageLabelsCacheStore / submoduleCacheStore through it — the store-open block is no longer copied three times. - R1: correct Store.Fill's doc (and signature) — it is the compute-once primitive and never calls fill on a hit; the Validator revalidation path lives in the caller (it Get()s, revalidates upstream, and Put()s the refresh). - B12: add tests for the new exported API — Store.Delete, Store.Dir via OpenNamed, and HashHex. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: Go library (shared I re-derived the single prior comment against the CURRENT state. Its findings 1–5 are all demonstrably fixed in this diff/body; finding 6 survives. Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…ribution evidence) Body-only follow-up to the second validator round: paste the executed R5 sweep plus the consumer origin/main liveness check, and the runtime attribution config. No source change. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Empty commit so the org validator fresh run is keyed to a head whose body is already final (the R5 sweep plus consumer-liveness plus attribution evidence). No source change. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — BLOCKHead SHA: Change class: Go library (the shared Security screen: no T1–T4 finding (no secrets/egress, no guardrail edit, no embedded directive; the cache is not a security gate). Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
Review — BLOCKHead SHA: Change class: Go library (the shared Blocks
Comment dispositions
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…here R1: the package doc claimed the loader materialized-tree cache and a plugin HTTP cache "is a Store" at this head, but only spec/refs and spec/container are migrated here; the others fold onto the Store in their own producer-ordered changes. Reword to that reality. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS — no T1–T4 finding (no secrets/egress, no guardrail or validator-spec edit, no embedded directive; a cache is not a security gate). Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Body-only update (the class gate is now evidenced by the committed ci.yml run green on the head + the merged #143/#144/#145 precedent, and the no-disposable- target proof uses a real path). No source change — this empty commit moves the head so the fresh validator run keys to a head whose body is already final. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (documentation reviewed)
Body-only update (the class gate is now evidenced by the committed ci.yml run green on the head + the merged #143/#144/#145 precedent, and the no-disposable- target proof uses a real path). No source change — this empty commit moves the head so the fresh validator run keys to a head whose body is already final. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (documentation reviewed)
…stry-portable (#148) * feat(cache): OCI Image Layout ArtifactStore — content-addressed, registry-portable Replace the keyed one-JSON-file-per-key cache with ONE content-addressed artifact store whose on-disk form is a standard OCI Image Layout (oci-layout + index.json + blobs/<alg>/<digest>). Each cached artifact is a real OCI manifest: the config blob carries the validity metadata (resolved/components/validator), layers[0] the payload, and annotations the cache key + org.opencontainers.image.ref.name tag. A named cache is one OCI index, so a whole store can be pushed/pulled to a registry unchanged (the verb:oci cache-push/cache-pull transport lands next). The file backend uses stdlib + opencontainers/image-spec + go-digest ONLY; no go-containerregistry in the contract module. The legacy Store API (Open/OpenNamed/OpenLimited/Read/ReadTTL/WriteValue/ PutEntry/entryPath) is DELETED in the same cutover; consumers migrate in this change (refs submodule verdicts, container image list + labels) and in the sdk change (loaderkit materialized tree). repoCacheProvenanceVersion 2 hard-rejects the legacy bare-commit sidecar: a v1 export cannot certify its tree (the pre-cutover loader rewrote it in place — auto-migrating charly.yml to the consumer's schema CalVer), so it is treated as not-cached and re-fetched once pristine. IsRepoCached now enforces this, so immutable-tag caches self-heal too. This is the root-cause fix for the poisoned @main cache that failed check-substrate's deploy-add. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (syntax check only) * fix(cache): clear golangci-lint findings (staticcheck QF1008/SA4000, gocritic, unconvert) - cache.go: drop the redundant Versioned selector on the embedded field. - cache_test.go: derive the determinism check from fresh values (avoid SA4000). - container/engine_ops.go: if/else chain -> tagged switch (gocritic). - container/engine_ops_test.go: drop the unnecessary string() conversions. The two container findings pre-date this branch (they block the module gate, so they are fixed here per R2 rather than deferred). Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (syntax check only) * fix(cache): Fill must stamp Resolved (a zero-Resolved callback result was stored stale) The validator caught a real regression: the new Fill persisted via put(), which preserves the caller's Resolved, whereas the legacy Fill persisted via Put(), which stamped Resolved=now. A fill callback returning an Entry with a zero Resolved (a degrade/empty result) was therefore stored with Resolved=zero: instantly TTL-stale (defeating compute-once for any TTL caller) and sorted as the OLDEST entry for reclamation. Fill now stamps e.Resolved = time.Now() before persisting, matching Put and the legacy contract. The fill guard is also per-key again (locks/<tag>.fill.lock), matching the documented per-key flock rather than the interim store-wide lock. TestFillStampsResolved fails without the stamp: --- FAIL: TestFillStampsResolved (0.00s) Fill must stamp Resolved=now so the entry is TTL-fresh; got 0001-01-01... Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated) * docs(cache): correct Entry.Key doc — Get reconstructs it, put() no longer stamps it The validator found a doc/impl divergence: the Entry.Key comment still claimed "Set by the Store on Put", but the new keyed-by-tag layout reconstructs the key from the manifest annotation on Get and no longer stamps it on write. Fix the comment to match the implementation. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (documentation reviewed) * docs: re-freeze the PR body against the final head Body-only update (the class gate is now evidenced by the committed ci.yml run green on the head + the merged #143/#144/#145 precedent, and the no-disposable- target proof uses a real path). No source change — this empty commit moves the head so the fresh validator run keys to a head whose body is already final. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (documentation reviewed) * docs: re-freeze the PR body against the final head Body-only update (the class gate is now evidenced by the committed ci.yml run green on the head + the merged #143/#144/#145 precedent, and the no-disposable- target proof uses a real path). No source change — this empty commit moves the head so the fresh validator run keys to a head whose body is already final. Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (documentation reviewed) --------- Co-authored-by: Andreas Trawoeger <[email protected]>
Summary
Generalize
github.com/opencharly/spec/cachefrom a TTL-only single-file cacheinto the ONE keyed Store whose validity lives IN the entry, so a single
storage mechanism serves every cache policy the tree needs. This is the shared
mechanism the loader's materialized-tree cache (
sdk/loaderkit) and a pluginHTTP client (
plugin-gh) fold onto instead of hand-rolling a third and fourthcopy (R3).
Validity lives in the entry, never in the mechanism. Three interchangeable
modes, one layout:
Entry.Resolved+FreshTTL(the status hot path: image list,image labels, submodule verdicts, substrate probes).
Entry.Components+FreshComponents(content-addressed /identity validity: a GitHub blob keyed by SHA, the loader's walk envelope).
No time validity: valid while the inputs are unchanged.
Entry.Validator(an upstream revalidation token, e.g. anHTTP ETag) for a mutable upstream that must not re-fetch while unchanged.
One storage layout (
Store): a directory of one JSON entry per key, keyedby
sha256(key); lock-free atomic reads (tmp + rename publish); a per-keyadvisory flock with a double-check on the
Fillmiss path (concurrentfirst-missers compute once); Docker-style prune by entry cap.
StoreDir(name)names a store under
~/.config/charly/cache/<name>/(CHARLY_CACHE_DIRoverrides the root);
OpenNamed(name)is the one-shot open idiom;HashHex/KeyDigestare the shared components helpers.Fillis thecompute-once primitive (a hit never calls it); a caller that must REVALIDATE a
mutable upstream reads the entry, revalidates, and puts the refresh.
Consumers migrated onto the Store in THIS change, old API deleted (R5):
spec/refs(submodule-populated verdicts) andspec/container(image list,image labels). The former top-level
Read/Write/Invalidate/FileAPI isgone, and the three store-open sites share
OpenNamed(no copy-paste). Theloader (
sdk/loaderkit) andplugin-ghfold onto the same Store in their ownproducer-ordered changes — the package doc states exactly this scope. The
cache-file layout change is disposable local state (no migration entry; cache
state is not authored config).
How tested
New
cache/cache_test.gopins each behaviour (each fails without it):TestTTLValidity/TestComponentsValidity/TestValidatorRoundTrip— thethree modes.
TestFillComputesOnceUnderConcurrency— 16 goroutines, ONE fill: the per-keyflock serializes first-missers.
TestFillReturnsExistingWithoutCallingFill— a hit never runs fill.TestPruneReclaimsOldest— the entry cap reclaims the oldest.TestInertStoreNeverErr— an empty dir degrades to compute-without-caching.TestDeleteRemovesEntry/TestOpenNamedResolvesUnderRoot/TestHashHex—the new exported API (Delete, Dir via OpenNamed, HashHex).
TestKeyDigestStableAndOrdered— the components digest is order-independent.TestImageCacheTTLExpiry/TestSubmoduleCacheTTLExpirybackdate through theStore's
PutEntryseam;TestInvalidateImageCacheasserts the cleared Store isempty;
TestImageCacheStoreDirIsNamedassertsimageCacheStore().Dir().R5 sweep + consumer liveness (executed)
The removed top-level API is
cache.Read/cache.Write/cache.Invalidate/cache.File. Swept the whole spec repo on the final tree, and checked the ONEout-of-tree consumer against its
origin/main:Exactly ONE live consumer exists (
plugin-substrate, onorigin/main). Itsmigration onto
cache.OpenNamed/Store.ReadTTL/Store.WriteValueis WRITTENand verified to build against this spec change (dev
replace), and lands as theimmediate-next consumer PR once this publishes — the pinned require can only
advance after the producer tags, so this is the org's producer-to-consumer order
(B6), not a deferral of in-scope work.
Rulebook compliance
/charly-internals:strict-policy,/charly-internals:go,/charly-internals:cutover-policy,/charly-build:migrate.earlier rounds surfaced (
Fill's revalidation claim, the unchecked testassertion, the over-broad package-doc scope) are fixed here.
(written + verified) and lands per producer-to-consumer order, named above
with its
origin/mainliveness proof.itself unified in
OpenNamed.Read/Write/Invalidate/FileAPI and both in-repoconsumers' private file-layout assumptions are deleted in the same change;
the sweep and consumer-liveness output is pasted above.
feat/cache-storeoff freshorigin/main; no force-push.components-drift, prune, Delete/HashHex/OpenNamed and TTL tests above.
PutEntrybackdating seam is the test path.dependency.
(gofmt/vet/test on the final tree) is the change-class gate.
schema/cache.cuedescribes theper-host
charly.ymlcache:section, which is untouched (the Store is theon-disk
~/.config/charly/cache/area).Change classification
gofmt+go vet+ freshgo test ./...on the finaltree (module gate — no disposable deploy target in this repo).
fully tested and validated.Attribution evidence — the runtime-reported model string (executed)
The footer names the harness, provider, and model string this authoring session
REPORTED at runtime — from the live opencode runtime log for this host, not a
config file:
So the runtime-reported triple is harness
opencode(1.18.31), providerollama-cloud, modeldeepseek-v4.1-flash— the exact string used across theorg's opencode-authored commits (
git logfooters on the org repos repeatopencode ollama-cloud/deepseek-v4.1-flash). Per the AI-attribution policy thestring is used VERBATIM; substituting a different model name would itself be the
defect.
Assisted-by: opencode ollama-cloud/deepseek-v4.1-flash (fully tested and validated)