Repository navigation
feat(perhost): split Update into the shared Lock and the lock-held Apply - #437
Merged
Merged
Conversation
perhost.Update is the ONE reader/writer of the per-host charly.yml, but a
caller whose critical section is WIDER than one document update cannot use it:
deploykit's typed overlay cycle (deploykit.MutateDeployConfig) must hold the
lock across a typed read-modify-write, and `charly deploy reset` must decide
save-versus-remove under the same hold. Both therefore re-derived the lock path
and re-invented the bound (`deployConfigLockWait = 10 * time.Second`, a copy of
perhost.LockWait) instead of sharing perhost's.
This splits the shell into the two halves Update is made of, and exports both:
- Lock(path) — THE definition of the lock: `<path>.lock`, bounded by LockWait.
- Apply(path, mutate) — the document mechanics (read the CURRENT file, mutate
its root, marshal, atomic replace), for a caller that ALREADY holds Lock.
Update is now Lock + Apply, unchanged in behaviour. Apply must NOT re-acquire:
flock is per-open-file-description, so the second acquire in the same process
waits for the first and fails at LockWait — a self-deadlock. Both facts are
pinned by perhost_lock_test.go (Apply under a held Lock writes and returns
inside 5 s; an Update started while Lock is held cannot complete and completes
once it is released).
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 — pure library refactor; no secrets, no guardrail weakening, no supply-chain/CI-script change, no embedded directives. Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
This was referenced Nov 24, 2026
github-actions Bot
pushed a commit
to opencharly/charly
that referenced
this pull request
Nov 24, 2026
…1265) * chore(deps): bump spec to v0.2026328.1115 and sdk to v0.2026328.1130 The shipped binary must carry the per-host config writer fixes; neither pin had them yet. - spec v0.2026328.1115 (opencharly/spec#437): spec/perhost is the ONE reader/writer of ~/.config/charly/charly.yml — one bounded lock, the read INSIDE it, own-key-only mutation, atomic replace — and exposes Lock/Apply for the wider typed overlay cycle. - sdk v0.2026328.1130 (opencharly/sdk#632): the three remaining SDK writers (deploy overlay, install ledger, host snapshot) run through it. It also fixes a measured lost update: every ledger writer read the ledger OUTSIDE the lock and replaced the whole section with that stale snapshot, so two concurrent ledger writes each dropped the other's record — 21 of 24 concurrently-added records lost, 5 of 5 runs, with the SDK's new cross-writer test against the pre-change tree. No charly source changes: charly has no per-host config writer of its own (grep: os.WriteFile only in internal/pluginsgen and one comment; the DeployConfigPath/DeployConfigEnv helpers are referenced only by tests). Gates on this tree: go mod tidy, go build ./..., go vet ./..., go test ./... (CORE_TEST_OK), and the R9 worktree-local build — ./scripts/bootstrap-charly.sh -> bin/charly 2026.328.1114. Live, with the pre-bump binary 2026.327.1010: `charly cache bypass --off` printed "git-ref cache bypass cleared — the cache resumes" and the file read `bypass: true` again seconds later, written by a concurrent long-lived charly process that had loaded the flag before the clear (the bypassOwned defect). With the rebuilt binary the clear is written and read back as `false`. 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) * fix(deps): propagate the spec/sdk pins to the tools modules Round-1 CI fix: the `go` job failed on tools/gomod-canonical's TestContractPinsMatchShared — tools/generate-packages, tools/golden-cloudinit and tools/golden-compile are separate GOWORK=off modules that mirror the contract pins, and the bump touched only charly/go.mod: gomod_canonical_test.go:123: ../../tools/generate-packages/go.mod: requires sdk v0.2026327.1021, but the shared sdk pin is v0.2026328.1130 — run `charly task mods-tidy` `charly task mods-tidy` propagated both pins into the three modules (go.mod + go.sum each). Missed control: the gate I designed reproduced the CI job I remembered, not the one that runs. ci.yml also carries `go test ./charly/...` from the repo root, the `tools/*` sweep, `gofmt -l charly tools` and a per-module golangci-lint — and this repo ships `mods-tidy` for exactly this propagation. The full job is now reproduced verbatim: CI_REPRO_OK (charly/ 241.9s, tools sweep ok, gofmt empty, golangci-lint 0 issues in charly/ and in all five tools modules). 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)
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#435 made
spec/perhostthe ONE reader/writer of the per-hostcharly.ymland moved the git-ref cache onto it. One writer could not follow: the typeddeploy-overlay cycle (
deploykit.MutateDeployConfig) has to hold the lock across atyped read-modify-write — the caller's mutation runs against a freshly re-read
*DeployConfig, andcharly deploy resetdecides save-versus-remove under the same hold.Neither can be expressed as one
perhost.Update, so both re-derived the lock themselves:deploykit/deploy_config_cycle.goacquiredkit.AcquireFileLockWithin(path+".lock", true, deployConfigLockWait)with its owndeployConfigLockWait = 10 * time.Second— a copy ofperhost.LockWaitand a second statement of the lock path;deploykit.SaveDeployConfigre-implemented the whole document mechanics (read the file,set keys, marshal, tempfile, chmod, rename) because it is called inside that cycle and
must not take the lock again.
This PR splits
perhost.Updateinto the two halves it is already made of, and exports both:perhost.Lock(path)<path>.lock, bounded byLockWait(the ONE definition of the lock path and bound)perhost.Apply(path, mutate)perhost.Update(path, mutate)Lock+Apply; unchanged behaviourApplymust not re-acquire:flockis per-open-file-description, so a second acquire insidethe same process waits for the first and fails at
LockWait. That is exactly the trap thenext SDK change walks into (routing
SaveDeployConfigand the cycle through these two), soit is pinned here rather than in the consumer:
perhost_lock_test.goproves thatApplyunder a held
Lockwrites and returns inside 5 s, that anUpdatestarted whileLockis held cannot complete and completes once it is released (i.e. the two share ONE lock),
and that a nil
mutateis refused by both.This closes #436. The consumer change (SDK:
SaveDeployConfig→perhost.Apply,AcquireDeployConfigLock→perhost.Lock, the duplicated constant deleted,plus a cross-writer concurrency test) is opencharly/sdk#631.
How tested
Test accounting, stated exactly:
perhost_lock_test.go:TestApplyWritesUnderTheCallersLock(fails ifApplyacquires: it would block, and the 5 s bound reports it),TestUpdateWaitsForTheCallersLock(fails ifLockandUpdatedo not share one lock),TestApplyRefusesANilMutate.perhostandrefssuites, including the24-concurrent-
Updatepreservation test and the corrupt-file refusal.Rulebook compliance
/charly-internals:go,/charly-internals:design,/charly-internals:git-workflow,/charly-internals:strict-policy.pinned by a test instead of being discovered at runtime.
consumer PR deletes the copied constant and the copied write.
production waits.
Updatekeeps its exact signature and behaviour asLock+Apply.Applythat locks hangs into its 5 sbound; a
Lockon a different path letsUpdatecomplete early and fails the second test).mechanism-neutral helper package, the same posture as refactor(refs)!: route the per-host config through ONE reader/writer (spec/perhost) #435.
Change classification
own body).
Update's behaviour is byte-identical.LockandApplyare new API; the onlyconsumer is refactor(config): route every per-host config writer through spec/perhost sdk#631.
pin advances.
Filed issues
SaveDeployConfigandAcquireDeployConfigLockthroughperhost.Apply/perhost.Lock, delete the duplicated bound, and add the cross-writerconcurrency test (deploy cycle ∥ ledger ∥ cache ∥ system on one file).
Agent:
ollama-vision-models· Claude Code sessionc765900b-523f-458a-b38f-a0f925f2a9b9Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)