Repository navigation
fix(vm): cloud-init unit-layout split + idempotent qemu vm start - #268
Conversation
Two root-caused VM-bootstrap defects, both surfaced by the
check-debian-debootstrap-vm bed.
1. The Debian/Ubuntu debootstrap bootloader install_template enabled the
legacy `cloud-init` unit unconditionally. cloud-init 24.3 (upstream PR
#5489) split it: `cloud-init.service` became `cloud-init-network.service`
plus a new `cloud-init-main.service` daemon. Debian 13 ships 25.1.4, where
the legacy name is gone, so every debootstrap build emitted "Failed to
enable unit: Unit cloud-init.service does not exist" — swallowed by the
step's `|| true`, so the bed passed while the template's comment described
a layout the distro had not shipped in two releases (R1: a warning is not a
pass). Ubuntu 24.04 ships 24.1.3, BELOW the split, where the legacy unit is
real and the enable is load-bearing — so neither name can simply replace
the other. The loop now tests for each unit file before enabling it and
covers both layouts. Applied to charly/charly.yml AND the faithful copy in
candy/plugin-vm/build_defaults.yml (R3).
2. `charly vm start` was not idempotent on the QEMU backend: starting an
already-running VM re-executed the stored command and the second QEMU
failed to lock the pidfile ("cannot create PID file: Resource temporarily
unavailable", exit 1). This broke the `update` step of every QEMU-backed
bed, since `vm create` already starts the domain and the rebuild path's
ensure-running guard therefore always hit a live VM. `vm start` now returns
a clean no-op when the recorded process is alive, matching the libvirt
backend's already_running semantic. The liveness probe is extracted as
`qemuAlive` and shared with `vm list`'s state scan (R3): pidfile read →
Signal(0) → /proc/<pid>/cmdline contains "qemu-system", the last check
closing the reused-PID false positive.
R10: check-debian-debootstrap-vm (disposable: true) PASS, 9/9 steps, exit 0,
zero warnings, run-calver 2026.226.0950, binary 2026.226.0947. Coverage fails
without the change: the `update` step failed at 3.982s on the unfixed vm start
(run 2026.226.0940) and passes at 4m30.239s here, and the vm-build log shows
zero "Failed to enable" occurrences with cloud-init-main/cloud-init-network
enabled.
Assisted-by: Claude Code Anthropic Claude Opus 5 (fully tested and validated)
Claude-Session: https://claude.ai/code/session_01EcRjMUc6bAdoq8aEr84V9Y
pr-validator — CHANGES REQUESTED ❌Validated at head Change class: code/config (build vocabulary + Checklist
Placement / per-item trace (item 15). No staged What I re-derived independently (all of it, not the author's word)Go gates — re-run by me, R9 — binary equals source. R10 bed evidence — cross-checked on disk, not taken from the body. Coverage-fails-without-the-change — verified, and the cloud-init half needed evidence the PR body never pointed at. The qemu witness is real: All six pre-fix debian runs carry the failure and enable R2 batching judgment — I agree with the author, on my own reasoning. The qemu defect is not a second cutover riding along: it surfaced inside this cutover's own R10 ( Provenance of the qemu port — faithful and complete. Both hunks are byte-identical to
Blocking findingsF1 — the gate ran too few beds:
|
…134) feat(vmshared): add QemuAlive, one hardened QEMU liveness predicate Adds `vmshared.QemuAlive` — one hardened QEMU liveness predicate — and routes the package's existing `KillQemuByPID` through the same shared resolution step (`qemuProcFromStateDir`). The predicate reads `<stateDir>/qemu.pid`, `Signal(0)`, then matches `-pidfile <stateDir>/qemu.pid` as adjacent NUL-separated `/proc/<pid>/cmdline` argv fields, whole-field — so a live process is confirmed to be the qemu started for THAT state dir, rejecting both a recycled PID and a different VM's qemu on a reused PID. The consumer (opencharly/charly#268) deletes three divergent hand-rolled copies (two bare `Signal(0)` probes on main, plus the in-flight `vm start` guard), which is the R3 unification this producer enables. Placement is `sdk/vmshared` on the sdk-kit criterion: consumers in more than one module, and the module already owns both couplings (`VmStateRoot` resolves the state dir, `RenderQemuArgv` emits the argv). The `-pidfile` match rests on a documented CALLER invariant: `RenderQemuArgv` appends `-pidfile` conditionally (`if paths.PidFile != ""`), and every production launch sets it to `<vmStateDir>/qemu.pid` — observed in production during the live invocation, not assumed. Tested: whole-module gates green (gofmt, go build, go vet, go test 10 packages, golangci-lint 0 issues); coverage mutation-verified against the weaker predicates this replaces; invoked live against a real charly-managed qemu VM in both directions (running → true, after `charly vm stop` → false, with the stale pidfile still on disk). Fresh-rebuild R10 belongs to the consumer PR (charly#268). Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
sdk#134 landed QemuAlive in sdk/vmshared (v0.2026226.1201). Adopt it at all three call sites and delete the local copies: - candy/plugin-vm/vm.go: the idempotent already-running guard in `vm start` and `vm list`'s state scan now call vmshared.QemuAlive. - candy/plugin-vm/vm_qemu.go: the local qemuAlive (a bare Signal(0) + "qemu-system" substring) is deleted. - candy/plugin-preempt/holder_dispatch.go: the holder probe — the arbiter deciding whether a preemptible GPU-holder VM may be preempted — was a bare Signal(0) probe that reports a recycled PID as a live holder. It now calls vmshared.QemuAlive, which additionally matches `-pidfile <stateDir>/qemu.pid` as adjacent NUL-separated argv fields. Pin bumps required by the adoption: sdk → v0.2026226.1201 (050b0af), spec → 4cff4d0 (v2026.225.2111, the sdk's packaging-contract requirement), and the plugin go.mod/go.sum bumps (go 1.26.4, spec v0.2026225.1800). Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
The sdk pin bump (v0.2026226.1201) requires go 1.26.4; the workspace go.work and the charly module's go directive must match or `go build ./charly` fails workspace load. Same change the sdk-adopt cutover makes. Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Resolve the qemuAlive overlap: keep the F2 vmshared.QemuAlive (sdk 050b0af), delete charly#267's local qemuAlive + its unused imports. sdk submodule stays at 050b0af (v0.2026226.1201, sdk#134). go.work.sum reconciled via go work sync.
pr-validator — CHANGES REQUESTED ❌Re-validated at head Change class: code/config (build vocabulary + Checklist
Placement / per-item trace (item 15). No staged The four prior findings — each independently re-verified
What I re-derived independentlyGo gates — re-run by me ( R9 — binary equals source. R10 bed evidence — cross-checked on disk, not taken from the body. Both summaries verified above. Warning sweep: debian run dir → 0 Coverage-fails-without-the-change — verified. The qemu witness is real: CHANGELOG format. Filename Blocking findingF5 — R5 stale-reference + R1 claim-keyed divergence in
|
…he vm skill The F2 adoption deleted the local qemuAlive identifier, but the vm skill's description still named it and described the refuted substring mechanism (Signal(0) -> /proc/<pid>/cmdline contains qemu-system). Update the description to name vmshared.QemuAlive and describe the -pidfile <stateDir>/qemu.pid ownership match (adjacent NUL-separated argv fields), which closes the reused-PID false-positive and the recycled-onto-another-VM case the substring check accepted. R5 sweep: qemuAlive now survives only in CHANGELOG history. Assisted-by: Claude Code <deepseek-v4-flash:0731-cloud> (documentation reviewed)
pr-validator — APPROVED ✅Re-validated at head Change class: code/config (build vocabulary + Checklist
Placement / per-item trace (item 15). No staged F5 — the prior blocking finding — independently re-verified as RESOLVEDThe F5 fix commit
F1–F4 — each independently re-verified as still RESOLVED
What I re-derived independentlyGo gates — re-run by me ( R9 — binary equals source. R10 bed evidence — cross-checked on disk, not taken from the body. Both summaries verified above. Warning sweep: debian run dir → 0 Coverage-fails-without-the-change — verified. The qemu witness is real: CHANGELOG format. Filename Comments considered:
Cross-PR interactions considered:
DecisionThe prior blocking finding F5 is genuinely resolved — the description now names Assisted-by: Claude Code deepseek-v4-flash:0731-cloud (analysed on a live system) |
Assisted-by: Claude Code <deepseek-v4-flash:0731-cloud> (analysed on a live system)
pr-validator — merged
Assisted-by: Claude Code deepseek-v4-flash:0731-cloud (analysed on a live system) |
distro-cachyos landed a272233 (drop the last Android references, #268) after the previous bump, so the umbrella's derived edge for it is blocked-by this gitlink. The other four box/* pins are already current. Staged by charly task sync; pin-current reports the repo's own pins at their intents. Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
Summary of changes
Two root-caused defects in the VM bootstrap path, both surfaced by the
check-debian-debootstrap-vmbed, both fixed here. They batch as one cutover because they are the same theme (VM bootstrap correctness) and one bed run proves both.1. cloud-init unit-layout split (
charly/charly.yml+candy/plugin-vm/build_defaults.yml)The Debian/Ubuntu debootstrap bootloader
install_templateenabled a fixed unit list naming the legacycloud-initservice unconditionally.cloud-init 24.3 (upstream PR #5489, "Single Process Optimization") split that unit:
cloud-init.servicewas renamed tocloud-init-network.service, and a newcloud-init-main.servicedaemon was added, with the four stage services becoming shims that connect to it over/run/cloud-init/share/*.sock.Failed to enable unit: Unit cloud-init.service does not exist. The step's|| trueswallowed it, so the bed passed while the template's own comment asserted a layout the distro had not shipped in two releases. R1: a warning is not a pass, and a doc-vs-reality divergence is an incident.So neither name can simply replace the other. The enable loop now tests for each unit file (in both
/usr/lib/systemd/systemand/lib/systemd/system) before enabling it, covering both layouts, and the comment states the version pivot instead of asserting one layout. On Ubuntu the enable is a no-op in practice (the postinst already creates the wants symlink), but the loop keeps the legacy name regardless — relying on a package's postinst is an undeclared dependency, and the existence guard makes carrying it free.Applied to both copies of the build vocabulary —
charly/charly.yml(embedded) andcandy/plugin-vm/build_defaults.yml(the faithful copy) — per R3.2.
charly vm startwas not idempotent on the QEMU backend (candy/plugin-vm/vm.go)Starting a VM whose QEMU process was already running re-executed the stored command; the second QEMU then failed to lock the pidfile:
This broke the
updatestep of every QEMU-backed bed:vm createalready starts the domain, so the rebuild path's ensure-running guard hit an already-live VM every time.vm startnow returns a clean no-op when the recorded process is alive, matching the libvirt backend'salready_runningsemantic.3. One QEMU liveness predicate, in
sdk/vmshared(QemuAlive, R3) — the F2 adoptionThe liveness probe existed in THREE places: inline in
vm start, inline invm list's state scan, and — unhardened — incandy/plugin-preempt's holder probe, the arbiter that decides whether a preemptible GPU-holder VM is running. All three now call onevmshared.QemuAlive; the two inline copies are deleted. The predicate belongs insdk/vmsharedbecause it has consumers in more than one module and the module already owns this class (VmStateRoot,RenderQemuArgv).It also asserts more than the earlier copy did. A bare
Signal(0)probe reports a recycled PID as "running", and a/proc/<pid>/cmdlinesubstring match onqemu-systemnarrows that only to "some qemu" — a PID reused by a DIFFERENT VM's qemu still passes, sovm startwould no-op on a stopped VM and the arbiter would refuse to preempt a departed holder.QemuAlivematches-pidfile <stateDir>/qemu.pidas adjacent NUL-separated argv fields, so a live process is confirmed to be the qemu started for THAT state dir. That match rests on a CALLER invariant, not a renderer guarantee:RenderQemuArgvappends-pidfileconditionally (if paths.PidFile != ""), and what makes the argv reliable is that every production launch setsPidFileto<vmStateDir>/qemu.pid. Table-tested in the sdk (qemu_liveness_test.go), including the recycled-onto-another-VM case that the substring check accepted.Pin bumps required by the adoption: sdk →
v0.2026226.1201(050b0af, the merged sdk#134), spec →4cff4d0(v2026.225.2111, the sdk's packaging-contract requirement), the plugingo.mod/go.sumbumps (go 1.26.4, specv0.2026225.1800), and the workspace go-version bump (go.work +charly/go.mod→ 1.26.4).Diffstat vs
29c5140e(the merged charly#267): 70 files, 245 insertions / 272 deletions. The bulk is the sdk-pin go.sum reconciliation across the plugin candies (the F2 adoption bumps sdk to050b0af, so every plugin's go.sum must match the new sdk deps); the authored change is 10 files —charly/charly.yml,candy/plugin-vm/build_defaults.yml,candy/plugin-vm/vm.go,candy/plugin-vm/vm_qemu.go,candy/plugin-preempt/holder_dispatch.go,charly/go.mod,charly/go.sum,sdk,spec,CHANGELOG/2026.226.0953.md.Change class
code/config (build vocabulary +
candy/plugin-vm+candy/plugin-preemptGo + sdk/spec pin bumps)Landing order — charly#267 landed, branch updated
charly#267 (the sdk-adopt cutover) has landed (
29c5140e, taggedv2026.226.1608). This branch was updated onto it:git merge origin/mainresolved the qemu-file overlap — charly#267 carried a localqemuAlivethat this PR's F2 deletes — by keeping the F2vmshared.QemuAlive(sdk050b0af, v0.2026226.1201) and deleting the local copy + its unused imports (bytes,strconv,strings,syscall). The sdk submodule stays at050b0af;go.work.sumwas reconciled viago work sync. The tree builds and the full workspace test suite is green.How R10-tested — exact gate, commands, and pasted output
Fresh R10 on the FINAL tree (with the F2 adoption), run after the charly#267 merge and the branch update.
charly check run check-debian-debootstrap-vmandcharly check run check-ubuntu-debootstrap-vm(bothdisposable: true), which automate build → deploy → check-live → update → check-live-rebuild → cleanup. Theupdatestep is the one that exercises the qemu idempotency fix.task build:binary→charly version=2026.226.1629. Both fixes verified embedded (strings bin/charly | grep -c 'cloud-init-main cloud-init-network'→ 2;grep -c 'is already running'→ 2;grep -c 'qemu.pid'→ 1, thevmshared.QemuAlivepredicate).warningmatches across every log. The ubuntu run dir has exactly 3warningmatches —update-rc.d: warning: start and stop actions are no longer supported(vm-build.log:1348) anduseradd warning: libvirt-qemu's uid 64055 is greater than SYS_UID_MAX 999(deploy-add.log:2655, update.log:2662) — all three from the distro's own package postinsts, identical to the pre-F2 run2026.226.1022(same lines), so they are pre-existing distro noise, not from the changed path. The changed path (the cloud-init unit enable + the qemuvm startguard) emits zero warnings in both beds.Debian bed (run from
box/debian, the submodule that owns the bed):Ubuntu bed (run from
box/ubuntu):Coverage that fails without the change
Both halves have a witness in the same bed, and both were observed failing on the unfixed tree:
2026.226.0940(same bed, same tree, WITHOUT thevm startfix) failed at[update] FAIL after 3.982swith the pidfile-lock error above. With the fix:[update] PASSafter a full rebuild. The step goes from a 4-second hard failure to a full multi-minute rebuild.vm-build.loghas zero occurrences ofFailed to enable(grep -c→ 0), withcloud-init-main/cloud-init-networkenabled (lines 1297-1298, 1373-1374). Before the fix the same log carriedFailed to enable unit: Unit cloud-init.service does not exist. The ubuntu run'svm-build.log(cloud-init 24.1.3, below the split) has zeroFailed to enableAND the legacycloud-init.serviceIS enabled (line 1377) — the load-bearing enable the existence guard preserves.Go gates (final tree)
gofmt -lempty ·go vet ./...clean (charly module, workspace resolution) · per-modulego test -count=1 ./...green across every go.work module (charly, sdk, spec, all 60 candy/plugin-*) ·golangci-lint run ./...→ 0 issues on the charly module + the two changed plugin modules (candy/plugin-vm,candy/plugin-preempt). One environment caveat: the spec module'sproctemp-sweep tests fail whenTMPDIRis overridden (the sandbox /tmp-quota workaround) because the sweep scans a hardcoded/tmpwhileos.TempDir()followsTMPDIR; withTMPDIRunset they pass — a pre-existing environment artifact, not a regression.Attribution tier
analysed on a live system— the changed runtime paths (the qemuvm startguard + the cloud-init unit enable) ran live on two disposable beds with retained output (above), including the previously-failingupdatestep. The complete fresh-rebuild R10 for the whole nFPM cutover (the Phase 3 check beds) has not passed yet — that is the nFPM cutover's own gate, not this PR's.Harness rulebook compliance — state HOW each is satisfied
/charly-vm:vm,/charly-vm:debian-debootstrap-vm,/charly-distros:debian,/charly-check:check,/charly-internals:root-cause-analyzer,/charly-internals:git-workflow.warningmatches in the ubuntu run dir are 3 pre-existing distro postinst messages, identical to the pre-F2 run (see "How R10-tested"). The swallowedFailed to enablewarning is precisely what R1 forbids treating as a pass.sdk/vmshared(QemuAlive), shared byvm start,vm list, and the preempt arbiter — the three local copies are deleted.qemu/virshcommands; the beds ran viacharly check run.vm list, the localqemuAliveincandy/plugin-vm/vm_qemu.go, and the bareSignal(0)probe incandy/plugin-preempt/holder_dispatch.goare all REMOVED, not left beside the shared predicate. No transitional path.go testalone was not treated as the gate.task build:binary(2026.226.1629) and invoked through this worktree'sbin/; both fixes verified present in the built artifact. No new runtime OS deps.check-debian-debootstrap-vm+check-ubuntu-debootstrap-vm(bothdisposable: true), fresh rebuild, zero warnings, with the failing-without-the-change witnesses above.check:steps are unchanged and still pass. SDD N/A — no.cueedits, no generated files.candy/plugin-vm+candy/plugin-preempt(the plugins that ownvm start/vm list/the preempt arbiter); no corecharly/*.gotouched, no new imports, no alias.check-debian-debootstrap-vmisdisposable: true(box/debian/charly.yml:39); the destroy+rebuild was authorized by that flag, not inferred.CHANGELOG/2026.226.0953.md(placeholder CalVer, finalized by the validator at merge).Assisted-by: Claude Code deepseek-v4-flash:0731-cloud (analysed on a live system)