Repository navigation
fix(refs): ClearCache clears the cache section, never the per-host deploy config - #434
Conversation
…ploy config `charly cache clear/refresh` deleted `~/.config/charly/charly.yml` — the per-host DEPLOY config — to clear a `cache:` section, taking every deploy, provides, ledger and system entry with it. The next resolution's `save()` (correctly a preserving yaml.Node read-modify-write) then rebuilt the file holding nothing but `cache:`. Measured on a real host, 2026-11-24: after a `charly cache refresh` the file went from ~94 KB with seven deploys to 50 KB of cache, while every deployed container kept running — the config was gone but the machines were not, the worst shape of this failure. The containers' systemd quadlets were the only surviving record. ClearCache now clears the section through the SAME writer save() uses (empty maps → the cache is rewritten empty, every other key preserved), and never removes the file. The stale comment claiming a removal is gone with it. Regression proof (R7): `TestClearCachePreservesTheDeployConfig` is RED without the fix — `the per-host config must still exist after a cache clear: … no such file or directory` — and green with it; `TestGitClientCacheSurface`'s old assertion that the file is removed is corrected to the real contract (file survives, cache empty). Full `./refs/` suite green. The observable `charly cache refresh` behaviour changes when a spec release carrying this is pinned by charly; the unit test is the gate here. Refs #433 (the cache's placement: move it under the cache root) Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9` Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Review — PASSHead SHA: Security screen: PASS — diff is a minimal, in-scope library fix; no secrets, no egress, no guardrail weakening, no instruction-injection content. Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Round-1 review fixes on #435. - Block 1 (CONC(a)/R5): `cacheLockPath()` lost its only caller when save() moved onto perhost.Update, and the `lock` import went with it. Deleted — `grep -rn cacheLockPath` returns nothing, and perhost.Update's `<path>.lock` is the ONE lock path for this file, which is what makes the body's "the cache's own copy of the mechanics is deleted here" true. - Block 2 (A1): the ClearCache preservation guard is PRE-EXISTING on main (it landed in #434); the body called it new. The body is corrected; no test accounting changes here. - Non-blocking note, fixed because this package becomes THE writer for three more sections (sdk#631): perhost.Set no longer APPENDS a second key when an intermediate path exists as a non-mapping node — it REPLACES that node with a mapping in place. A duplicate YAML key resolves differently per parser, so the latent path is worth closing now. TestSetReplacesANonMappingIntermediateInsteadOfDuplicatingTheKey pins it. Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9` Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
…(spec/perhost) (#435) * refactor(refs): route the per-host config through ONE reader/writer (spec/perhost) The per-host config (~/.config/charly/charly.yml) is a SHARED document: deploys, the git-ref cache, the ledger and the system info are written into it by different charly commands that can run concurrently. Four independent implementations of "take <file>.lock, read the yaml.Node, find-or-create my key, marshal, tempfile+rename" had grown, and the copies disagreed in ways that destroyed real data on 2026-11-24: one cleared a section by DELETING the whole file, and one wrote a stale in-memory value over a value another process had just changed. spec/perhost is that contract stated once — the cache writer's own approach, extracted: - ONE advisory lock, <file>.lock, bounded (10 s: a stuck holder fails fast, named); - the read happens INSIDE the lock (never a caller's snapshot); - the mutation touches ONLY the keys it owns (every other section survives); - the write is a tempfile in the same directory + rename (no torn reads), mode 0600; - a corrupt file is an ERROR and the mutation never runs — the bytes stay for recovery. refs (load, save, ClearCache) now runs through it; each caller supplies only its section logic. The two data-loss fixes of the previous commits become consequences of the shared writer rather than special cases. A defect this migration introduced and the suite caught: the helpers save() called took g.mu, but save() is documented to stay LOCK-FREE because LatestTag/DefaultBranch and the cache tests call it while holding g.mu — sync.Mutex is not reentrant, so TestGitClientCacheAndPersist hung for the package timeout. The helpers are lock-free now, and TestSaveIsCallableWhileHoldingMu pins the invariant by asserting that save() RETURNS. Tests: perhost — preservation of every other section, corrupt-file refusal (mutation never runs, bytes untouched), and 24 concurrent Update callers each keeping their own key; refs — the ClearCache preservation guard, the bypass lost-update guard, the mu invariant, and the existing suite. `go test ./refs/ ./perhost/` green (16.1 s / 1.1 s). The sdk's own three writers (kit system, kit ledger, deploykit's MutateDeployConfig) follow the same ORDER but each keeps its own copy of the mechanics; migrating them onto perhost is the next leg, after this release, tracked as opencharly/sdk#631. Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9` Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated) * refactor(refs): delete the dead cacheLockPath helper; harden perhost.Set Round-1 review fixes on #435. - Block 1 (CONC(a)/R5): `cacheLockPath()` lost its only caller when save() moved onto perhost.Update, and the `lock` import went with it. Deleted — `grep -rn cacheLockPath` returns nothing, and perhost.Update's `<path>.lock` is the ONE lock path for this file, which is what makes the body's "the cache's own copy of the mechanics is deleted here" true. - Block 2 (A1): the ClearCache preservation guard is PRE-EXISTING on main (it landed in #434); the body called it new. The body is corrected; no test accounting changes here. - Non-blocking note, fixed because this package becomes THE writer for three more sections (sdk#631): perhost.Set no longer APPENDS a second key when an intermediate path exists as a non-mapping node — it REPLACES that node with a mapping in place. A duplicate YAML key resolves differently per parser, so the latent path is worth closing now. TestSetReplacesANonMappingIntermediateInsteadOfDuplicatingTheKey pins it. Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9` Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated) * refactor(refs): one persistCache write for save() and ClearCache; harden the shared writer Round-2 review fixes on #435. - Block 1 (R2): save() and ClearCache() carried the IDENTICAL perhost.Update lambda while this PR's premise is de-duplication. Extracted `persistCache()`; both call it. warmUpSaveFn() moved INTO it, at the single place a write happens, so the seam counts WRITES (the coalescing test's contract) and ClearCache's write is now counted too — it was not when ClearCache carried its own copy. ClearCache stays un-gated by suppressSave, and says why: a clear is an operator action, never a coalesced prefetch write. - Note: perhost.Set now zeroes Style and Anchor on a node it replaces in place (a styled scalar would otherwise keep its style on the fresh mapping). - Note: SetBypass releases bypassOwned after the persisting write, so a long-lived client cannot re-assert a stale flag over a later operator clear. The missed-control RCA for the ROUND-1 findings is posted as this round's PR comment (the rulebook asks for it there): the orphaned cacheLockPath had no gate that can see an unused METHOD, and the duplicate-key path had no adversarial-input test. Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9` Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
Summary
charly cache clear/refreshdeleted the per-host deploy config(
~/.config/charly/charly.yml) to clear acache:section — taking every deploy, provides,ledger and system entry with it. The next resolution's
save()(correctly a preservingyaml.Node read-modify-write) then rebuilt the file holding nothing but
cache:.Measured on a real host on 2026-11-24: after a
charly cache refreshthe file went from ~94 KBwith seven deploys to 50 KB of cache, while every deployed container kept running — the config was
gone but the machines were not. Only the containers' systemd quadlets still described them.
Fix:
ClearCacheclears the section through the same writersave()uses (set the mapsempty, then
save()→ the cache is rewritten empty, every other key preserved) and never removesthe file. The stale comment claiming a removal goes with it.
How tested
R7 — the new test is red without the fix and green with it:
TestGitClientCacheSurface's old assertion that the file is REMOVED encoded the defect; it nowasserts the real contract (file survives, cache section empty). The observable
charly cache refreshbehaviour changes once a spec release carrying this is pinned by charly;the unit test is the gate here.
One reader/writer for the per-host config (R2)
The file is a SHARED document — deploys, the git-ref cache, the ledger and the system info are
written into it by different commands that can run concurrently. Four independent copies of "lock,
read the yaml.Node, set my key, marshal, tempfile+rename" had grown, and the copies have already
destroyed real data (this PR's first commit; the bypass race in its second).
spec/perhostis nowthat contract stated once, using the CACHE writer's own approach:
<file>.lock, bounded at 10 s (a stuck holder fails fast and is named);rename, mode 0600 (no torn reads);refs(load, save, ClearCache) runs through it now. A defect this migration introduced wascaught by the suite: the helpers
save()called tookg.mu, butsave()is documented to stayLOCK-FREE because
LatestTag/DefaultBranchand the cache tests call it while holdingg.mu—sync.Mutexis not reentrant, andTestGitClientCacheAndPersisthung for the whole packagetimeout (600 s). The helpers are lock-free, and
TestSaveIsCallableWhileHoldingMunow pins theinvariant by asserting that
save()RETURNS (a write-content test cannot see a deadlock).New tests, all green (
go test ./refs/ ./perhost/→ 16.1 s / 1.1 s):perhost: every other section preserved; a corrupt file refused with the bytes untouched;24 concurrent
Updatecallers each keeping their own key.refs:ClearCachepreservation; the bypass lost-update guard; theg.muinvariant.The sdk's three writers (kit system, kit ledger, deploykit's
MutateDeployConfig) follow the sameORDER but each keeps its own copy; migrating them onto
perhostis the next leg after thisrelease, filed as opencharly/sdk#631.
Rulebook compliance
/charly-internals:root-cause-analyzer,/charly-internals:strict-policy,/charly-internals:go,/charly-internals:xdg,/charly-internals:git-workflow.os.Remove(g.cacheFile)) before any edit; theincident and its trigger are recorded here; the placement defect (a cache in a config document)
is filed as fix(refs): the git-ref cache lives in the per-host deploy config; move it under the cache root (D-STORE-1) #433 rather than silently fixed by moving a file path.
save()'s one preserving writer instead of a second write path.corrected in the same change.
contract ("updates only the
cache:key, preserving every other key").Change classification
ClearCacheno longer destroys the deploy config; every other key is preserved.Behaviour of
charly cache refreshis otherwise unchanged.Filed issues
cache root (D-STORE-1) with a one-time migration.
deploykit) through
spec/perhost, with the cross-writer concurrency test.Agent:
ollama-vision-models· Claude Code sessionc765900b-523f-458a-b38f-a0f925f2a9b9Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)