Repository navigation
fix(check): vm-stop false-success + word-keyed plugin-build cache race (#77, #76) - #114
Conversation
#77, #76) vm-lifecycle-correctness thematic batch — two non-blocking correctness fixes, one squash. #77 — `charly vm stop` backend-mismatch false-success (the stop sibling of #69's vm-destroy). Extract `vmHolder` (the authoritative "which backend ACTUALLY holds this domain" probe) shared with #69's `destroyVmDomain` (R3 — ONE shared abstraction, never a duplicate); `destroyVmDomain` is refactored to use it byte-equivalently. Add `stopVmDomain` (probe + stop + poll-for-shutoff verify — the same `pollUntil`/`StopGate` primitive `gracefulStopDomain` uses for destroy). Rewrite `charly vm stop` to use it; a nonexistent VM errors "no such VM" (mirroring #69 destroy) instead of false-success. The libvirt stop is an ASYNC ACPI poweroff, so the verify POLLS for the domain to leave `DomainRunning` (exactly what `vm list -a` reports as "running") rather than re-probing immediately (which false-positives mid-shutdown — confirmed live); only a guest still running after the grace errors, pointing at `charly vm stop --force`. The core `stopVM` (arbiter `holderStop`) is the same class in a separate code path — registered for the next vm-lifecycle cutover (cross-package kit unification of the duplicated stop/qemu/vmDir helpers). #76 — the out-of-tree plugin build cache (`~/.cache/charly/plugins/<name>`) was word-keyed shared-mutable state: two worktrees building the same plugin word raced the one `go build -o` output (the #75 shared-image-tag collision class). Scope the cache path by source dir (`pluginSourceTag`, a 16-hex digest of the absolute srcDir — always-rebuild, no cache-hit skip, so a dependency bump never serves a stale binary) + atomic publish (build to `bin.build` under the per-binary lock, then `os.Rename`) so a reader never sees a half-written binary. R10: `check-charly-vm` bed exit 0 / 7 steps ok (exercised `vmHolder` via the destroy teardown + #76 plugin builds with the new source-scoped cache paths — the `<tag>` suffix in every built plugin path is `pluginSourceTag`); live `charly vm stop` on a disposable SSH-ready `charly-vm` -> "Stopped VM" + verified `shut off` (rc=0); unit tests (`vm_stop_test.go`, `plugin_build_cache_test.go`) + golangci-lint 0 (charly / plugin-vm) + `task build:binary`. Assisted-by: Claude (fully tested and validated)
pr-validator — CHANGES REQUESTEDChange class: charly/sdk Go (runtime) Blocking finding (one)R17 — gofmt-dirty files the PR introduces. Both new test files are flagged by
CLAUDE.md R17 / the pr-validator spec: "a gofmt-dirty file the PR introduces FAILS" — no exception for cosmetic-only diffs. Fix: Everything else passed (independently re-verified)
Decision: FAIL — not merged. The single blocking finding is R17 gofmt-dirty (both new test files lack a trailing newline). Fix with Assisted-by: Claude (analysed on a live system) |
…tor R17) The fresh pr-validator's R17 gofmt gate flagged both new test files as missing a trailing newline. gofmt -w applied (AST-identical, no behavior change); the check-charly-vm R10 bed (ok:true, 349s) already covers the final code. Review-round fix on feat/vm-lifecycle-correctness. Assisted-by: Claude (fully tested and validated)
pr-validator — APPROVED ✅Change class: charly/sdk Go (vm-lifecycle + plugin build cache) A FRESH Checklist
R10 bed discrimination
Decision: PASS — finalizing the merge-time CalVer, merging Assisted-by: Claude (fully tested and validated) |
Assisted-by: Claude (documentation reviewed)
docs(vm): refresh the stale charly vm stop caveat (#77 docs leg) The correlated plugins-repo leg of opencharly/charly#114 (the vm-lifecycle-correctness batch). #77 (superproject) fixed charly vm stop's backend-mismatch false-success — authoritative vmHolder probe (shared with destroyVmDomain) + poll-for-shutoff verify — which made the VM skill's "Known live-tested caveats" entry for charly vm stop STALE (its workaround described the pre-#77 false-success). R1 makes the documentation divergence an incident and the sibling-set fix BLOCKING. Change: vm/skills/vm/SKILL.md — replace the stale "state-sync race under QEMU backend / Workaround: proceed to charly vm destroy" caveat with a present-tense description of the CURRENT behavior: charly vm stop tears the domain down from whichever backend ACTUALLY holds it (the shared vmHolder probe, regardless of configured vm.backend) and VERIFIES the domain is no longer RUNNING before reporting success; the verify POLLS for the domain to leave DomainRunning over the StopGate grace (async ACPI poweroff); a wedged guest hard-fails (never a silent "Stopped VM") with a pointer to charly vm stop --force (destroyDomain, the same force backstop charly vm destroy's gracefulStopDomain uses); a genuinely-absent VM errors "no such VM" (mirroring destroy). The skill states current behavior in present tense; history lives in this CHANGELOG. Tier: documentation reviewed — Documentation-only change class (a markdown skill edit, zero behavior change). Non-runtime standards: adversarial consistency review (the new text matches #77 live-proven behavior, 12/12 claims verified against the code on main), R5 grep self-test (the stale state-sync-race workaround claim is gone from the skill), cross-reference + markdown integrity. Assisted-by: Claude (documentation reviewed)
vm-lifecycle-correctness thematic batch — two non-blocking correctness fixes, one squash.
#77 —
charly vm stopbackend-mismatch false-success (the stop sibling of #69)charly vm stoptrusted the single resolved/default backend and switched on it: when the configuredvm.backendwasqemubut the live domain was libvirt, the qemu arm no-op'd (no qemu state dir for a libvirt domain) and printed "Stopped VM" + exit 0 while the libvirt domain kept running — the exact false-success class #69 fixed forcharly vm destroy. The VM skill documented it as a "Known live-tested caveat" with a "proceed tocharly vm destroy" workaround.Fix (R3 — extract/reuse ONE shared abstraction with #69, never a duplicate):
vmHolder(name)(candy/plugin-vm/vm.go) — the authoritative "which backend ACTUALLY holds this domain" probe, extracted from docs(sdd): CLAUDE.md defers the exception catalog to its sole owner #69's inlinedestroyVmDomainprobe. Libvirt probed FIRST (thedomain-stateop spawns the session daemon, so a libvirt domain is detected even when the configured backend is qemu); qemu state-dir fallback.destroyVmDomainrefactored to use it byte-equivalently.stopVmDomain(name, force)— the stop sibling, reusingvmHolder. Probes authoritatively, stops from whichever backend holds the domain, VERIFIES. A nonexistent VM (no libvirt domain, no qemu state) reportsstopped=false→ thecharly vm stopcommand hard-errors "no such VM" (mirroring docs(sdd): CLAUDE.md defers the exception catalog to its sole owner #69 destroy), so a typo never false-succeeds.pollUntil+StopGate, the same primitivegracefulStopDomainuses for destroy). The libvirtstopop (shutdownDomain) is an ASYNC ACPI poweroff — returns at once, guest powers off over theStopGategrace — so an immediate re-probe would false-positive on every graceful stop (domain stillrunningmid-shutdown; confirmed live). The poll waits for the domain to leaveDomainRunning(exactly whatvm list -areports as "running"); only a guest still running after the grace errors, pointing atcharly vm stop --force.force=trueis synchronous → poll returns at once.Scope boundary (R2 — non-blocking, registered for the next vm-lifecycle cutover): the SAME class lives in the CORE
stopVM(charly/vm_backend_lifecycle.go, 3-arg, the arbiter'sholderStop). Separate code path; the arbiter'swaitStoppedHostDETECTS the still-running holder (returns error) but the stop never happens, so GPU preemption of a backend-mismatched holder FAILS. Fixing it cleanly is a cross-package kit unification of the duplicated stop/qemu/vmDir helpers — a properly-sized separate cutover. Registered as the immediate-next vm-lifecycle batch.#76 — word-keyed plugin build cache races across worktrees (the #75 shared-tag class)
The out-of-tree plugin build cache (
~/.cache/charly/plugins/<name>,buildPluginBinary) was word-keyed shared-mutable state: two worktrees building the SAME plugin word from DIFFERENT source raced the onego build -o <bin>output (the #75 shared-image-tag collision class). The per-binary lock serialized writes, but after a build released the lock a second worktree's rebuild could overwritebinbefore the consumer'sLocalTransport.Connectexec'd it → truncated binary ("plugin did not connect" mid-fan-out).Fix (the #75 scoping principle applied to the filesystem cache):
bin = <safePluginBinName(name)>-<pluginSourceTag(srcDir)>, wherepluginSourceTagis a 16-hex digest of the ABSOLUTE srcDir. Same source reuses the path (lock serializes); different source (different worktree / remote@githubref) → distinct path. The tag is of srcDir, NOT content (go-build correctness depends on the full dep graph; a content hash would cache-hit a STALE binary after a dep bump; always-rebuild keeps it fresh).bin.build(under the per-binary lock) thenos.Renameontobin(atomic same-dir rename). A reader sees the OLD or NEW complete binary, never a half-written file. Temp removed on failure.Change class
charlyGo code (plugin-vm + core plugin_loader). Gate:go test ./...+golangci-lint run+task build:binary+charly check run <vm-bed>+ livecharly vm stop.R10 evidence (exploratory + fresh-rebuild)
Pre-flight:
go test ./...charly core ok (65s) + plugin-vm ok (2.2s);golangci-lint run0 issues (charly + plugin-vm);task build:binary→charly version=2026.195.0823(stamped, passes the #74 guard).R10 bed —
check-charly-vm(disposable VM lifecycle):Exit code 0 (real pass — steps have real durations, not a prereq-skip). Exercised #76 (built out-of-tree plugins with the NEW source-scoped cache paths — every
plugin-*-<16hex>suffix ispluginSourceTag:plugin-example-kind-e9e15ed84a32ba9b,plugin-cdp-b2ab30c115fa5edd,plugin-wl-...,plugin-dbus-...) and #77'svmHolder(the cleanup "Destroyed VM charly-check-charly-vm" randestroyVmDomain→vmHolder).Live
charly vm stopon a disposable, SSH-readycharly-vm(the #77 stopVmDomain gate):No false success: stop → "Stopped VM" (rc=0) → verified
shut off(not running) → destroy. (A guest stopped mid-cloud-init exceeds the StopGate cap — the wedge the "use--force" hint is for; not a false success.)Unit tests:
TestStopVmDomain_NotFound/TestStopVmDomain_QemuStateDir(mirrorvm_destroy_test.go);TestPluginSourceTag_DistinctSrcDirs/TestPluginSourceTag_SameSrcDirStable(mirror #75'sTestBedRunImageTag). All pass.Tier
fully tested and validated— all 10 standards (real artifact, disposable target, steady-state, declarative tests, binary matches source viatask build:binary, fresh-rebuild R10 via the bed + live stop, check coverage). Zero warnings.R0–R10 checklist
vmHolder) for docs(sdd): CLAUDE.md defers the exception catalog to its sole owner #69-destroy + docs(changelog): align 2026.193.1611 H1 with its filename #77-stop; fix(check): close the phase-resync goroutine leak + its data race #75 scoping principle for test(registry): add a provider-registry snapshot/restore seam for -count>1 isolation #76task build:binarystamped binary,charly versionmatchesFound + registered while landing (separate batches)
charly vm stopcaveat (plugins/vm/skills/vm/SKILL.md) now stale — fixed in the correlated plugins-repo leg (the immediate-next plugins-docs batch). Superprojectpluginsgitlink bump lands after that PR merges.stopVMbackend-mismatch (arbiterholderStop) — same docs(changelog): align 2026.193.1611 H1 with its filename #77 class, separate code path → next vm-lifecycle cutover (cross-package kit unification).candy/plugin-http/plugin-portplugin_test.go(fakeCCmissingResolveClusterContext) — pre-existingkit.CheckContextinterface change (K4 wave); K4/check-mock batch.HOLDING for the orchestrator to route a fresh
pr-validator. Do NOT self-merge.Assisted-by: Claude (fully tested and validated)