Skip to content

fix(vm)!: make #ResolvedVm.backend and .autostart optional, unbreaking every vm create - #342

Merged
github-actions[bot] merged 2 commits into
mainfrom
fix/vm-backend-autostart-defaults2
Nov 16, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
fix/vm-backend-autostart-defaults2

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes #ResolvedVm.backend and #ResolvedVm.autostart optional instead of !-required, which
unbreaks charly vm create for every VM in the org (#341).

charly: error: command "vm": applying vm defaults for "<entity>":
  applyCueDefaults vm: decode: autostart: cannot convert non-concrete value bool

Head 6d0b176, 3 files, 122 insertions(+), 4 deletions(−).

Mechanism — traced, not inferred

The SDK's kind table maps the vm kind to this def (sdk/loaderkit/cue_schema.go:
cueKindDefs["vm"] = "#ResolvedVm") and candy/plugin-vm/vm_host_seams.go routes every VM
operation through loaderkit.ApplyCueDefaults("vm", vm), which:

  1. marshals the resolved struct — Backend string and Autostart bool, both with omitempty, so an
    unset value is omitted from the marshaled YAML;
  2. unifies that YAML with #ResolvedVm;
  3. decodes back, with no .Default() call anywhere in the function.

With autostart!: bool / backend!: string, step 2 leaves those fields non-concrete whenever the struct
omitted their zero values, and step 3 fails. false is a zero value, so an entity that does not
autostart could never be encoded at all
.

Why not a default — measured, and it corrects my own earlier report

The obvious fix, autostart!: *false | true, does not work:

#ResolvedVm.autostart: cannot convert non-concrete value *false | true

Decode never resolves a default disjunction, so a required-with-default spelling fails identically.
I asserted the opposite on #341 earlier in this campaign; this PR and a comment on that
issue correct it.

Optional is both the fix and the shape this envelope already documents for itself — its own comment
says the resolved envelope carries "PLAIN post-default scalars", set by the producer when they are set:

ResolvedVm mirrors #Vm's fields — written out explicitly rather than embedding #Vm, since the resolved
envelope carries PLAIN post-default scalars, not #Vm's own enum/default machinery (firmware/backend/autostart
are plain string/bool here, never the *"bios"|... disjunction).

What this does not change: an authored backend:/autostart: still validates against the same closed
vocabulary, and the second test pins that every provider word is still accepted — no validation is traded
for the fix.

How tested

R7 — the new test fails on the pre-fix schema with the PRODUCTION error, and passes on the fixed one:

$ git stash push schema/vm.cue
$ GOWORK=off go test ./schema/ -run TestResolvedVmBackendAndAutostart
vm_defaults_test.go:52: decode #ResolvedVm without backend/autostart:
  #ResolvedVm.autostart: cannot convert non-concrete value bool
FAIL
$ git stash pop
$ GOWORK=off go test ./schema/ -run TestResolvedVm
--- PASS: TestResolvedVmBackendAndAutostartCarryDefaults (0.09s)
--- PASS: TestResolvedVmBackendAcceptsEveryProviderWord   (0.26s)

The fixture is compileShipped, the package's existing helper whose comment states it is "the SAME
contract the runtime's sharedCueSchema uses" — so the test exercises the shipped concatenation, not a
hand-built approximation of it. The entity is filled through the shipped value's own context, because
a cue.Value only interoperates with values from the context that built it.

The module's own gates, on this tree:

$ charly task cue-gen
  [pass] run   — generate the Go params in-process + schemagen the vocab lists      exit=0
  [pass] check — regen is reproducible — TestGenReproducible passes on the committed tree exit=0
$ GOWORK=off go build ./...        # ok
$ GOWORK=off go test ./...         # ok …/schema ok …/spec ok …/schemaconcat ok … (all green)
$ gofmt -l schema/ spec/           # empty

The generated diff is NOT comment-only, and my first revision of this body wrongly said it was. The
retag transform follows the constraint, so the JSON tags change too:

- Backend   string `yaml:"backend,omitempty"   json:"backend"`
+ Backend   string `yaml:"backend,omitempty"   json:"backend,omitempty"`
- Autostart bool   `yaml:"autostart,omitempty" json:"autostart"`
+ Autostart bool   `yaml:"autostart,omitempty" json:"autostart,omitempty"`

The Go types are unchanged (string, bool), so nothing recompiles differently — but the JSON wire
shape does: a consumer decoding JSON now sees the key ABSENT where it previously saw "" / false. That
is the correct counterpart to the optionality (YAML already carried omitempty) and it is called out in
the breaking-change answer below rather than left for a consumer to discover.

Coverage limit, stated rather than glossed: this lands the CONTRACT fix. The end-to-end proof — a real
charly vm create succeeding — needs this tag, then the sdk/charly require bump, then a rebuilt binary.
That is the producer-first sequence and it is not claimed here.

Rulebook compliance

  • R0 — /charly-internals:go (with references/schema-change-recipe.md),
    /charly-internals:vm-spec, plus this repo's own AGENTS.md. The recipe's step 1 ("edit CUE only, then
    regenerate — never hand-transcribe") and step 3 (charly task cue-gen, reproducibility-gated) are
    followed exactly.
  • R1 — every gate is green with zero warnings. The one anomaly this PR exists to fix was root-caused to
    a specific function and line before anything was changed, and the two candidate fixes were measured
    rather than argued: required-with-default was implemented first, observed to fail with a different
    non-concrete error, and discarded.
  • R2 — one source: the fields stay plain string/bool and the vocabulary stays in #VmBackend;
    nothing is duplicated and no second spelling of the word list is introduced.
  • R3 — no workaround: this fixes the constraint, not the decoder, and no consumer is patched around it.
  • R4 — no documented command changes.
  • R5 — nothing retired here; the earlier #Vm default machinery was already gone, which is how these
    fields lost their defaults, and this restores a workable contract without reviving it.
  • R6 — fresh session worktree off fresh origin/main (e433c4b); the submodule itself was never
    edited in place.
  • R7 — proven above, including the negative case.
  • R8 — no live service boundary in this change.
  • R9 — the binary that ran the codegen is the worktree-local build, not a shared install.
  • R10 — the change class here is a schema/contract change with no disposable: true target in this
    repo (its AGENTS.md: "this repo carries no per-repo candy gate; the merge gate is the org-wide
    charly/pr-validator"). The gate that owns it is charly task cue-gen + the module suite, both green on
    this tree. The live VM target is exercised in the consumer bump that follows.

Filed issues

Change classification

Schema (CUE) change plus one generated-file refresh and one new test.

Breaking change + rollback: it is !-marked because it relaxes a required field, and the effect reaches
the wire in two directions. In CUE, an envelope whose producer omitted the values now DECODES instead of
failing — that is the fix. In JSON, those keys are now omitted instead of emitted as ""/false, because
the retag transform put omitempty on the JSON tags to match; a JSON consumer that assumed the keys are
always present must treat absence as the zero value. Nothing else moves: both fields keep their names,
their types, their validation (the provider-word test above pins it), and their YAML spelling, so no Go
consumer recompiles differently. Rollback is a revert of this commit; the
two fields return to required and every charly vm create breaks again, which is the state this PR exists
to leave.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

…g every vm create

`charly vm create` fails for every VM in the org:

  charly: error: command "vm": applying vm defaults for "<entity>":
    applyCueDefaults vm: decode: autostart: cannot convert non-concrete value bool

MECHANISM, traced end to end rather than inferred. The SDK's kind table maps the vm
kind to THIS def (sdk/loaderkit/cue_schema.go: cueKindDefs["vm"] = "#ResolvedVm"), and
plugin-vm (candy/plugin-vm/vm_host_seams.go) routes every vm create through
loaderkit.ApplyCueDefaults("vm", vm), which:

  1. marshals the RESOLVED struct - whose Backend is `string` and Autostart is `bool`,
     both with `omitempty`, so an unset value is omitted from the marshaled YAML;
  2. unifies that YAML with #ResolvedVm;
  3. DECODES back, with no `.Default()` call anywhere.

With `autostart!: bool` / `backend!: string`, step 2 leaves those fields non-concrete
whenever the struct omitted their zero values, and step 3 fails on them. That is the
whole org-wide breakage: `false` is a zero value, so an entity that does NOT autostart
could never be encoded.

WHY NOT A DEFAULT - measured, and it corrects my own earlier report. The obvious fix,
`autostart!: *false | true`, does not work:

  #ResolvedVm.autostart: cannot convert non-concrete value *false | true

Decode never resolves a default disjunction, so a required-with-default spelling fails
identically. I asserted the opposite on #341 and am correcting it there.
Optional (`?:`) is both the fix and the shape this envelope already documents - its own
comment says the resolved envelope carries "PLAIN post-default scalars", set by the
producer when they are set.

WHAT THIS DOES NOT CHANGE: an authored `backend:`/`autostart:` still validates against
the same closed vocabulary; the second test below pins that every provider word is still
accepted, so this trades no validation for the fix.

R7 - the new test fails on the pre-fix schema with the PRODUCTION error:

  $ git stash push schema/vm.cue && go test ./schema/ -run TestResolvedVmBackendAndAutostart
  vm_defaults_test.go:52: decode #ResolvedVm without backend/autostart:
    #ResolvedVm.autostart: cannot convert non-concrete value bool
  FAIL

and passes with it. Reproducibility, build and the whole suite are green:

  $ charly task cue-gen            #[pass] run -- generate ... / [pass] check -- reproducible
  $ GOWORK=off go build ./...      # ok
  $ GOWORK=off go test ./...       # ok github.com/opencharly/spec/{schema,spec,schemaconcat,...}
  $ gofmt -l schema/ spec/         # empty

CONSUMER NOTE: this lands the CONTRACT fix. The runtime proof - a real `charly vm create`
succeeding - needs the spec tag, then the sdk/charly require bump, then a rebuilt binary;
it follows producer-first and is not claimed here.

Refs #341.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 6d0b1763e0551e2d7d6233f8494dec22a6d85a64 (branch: fix/vm-backend-autostart-defaults2)

Change class: schema (CUE) change + regenerated Go + one new test — code/config, not docs-only.

Blocks

  1. A1 / R1 — the body misstates the generated-file diff. spec/cue_types_gen.go is not "comment only". The diff changes the JSON struct tags:

    • Backend string — json:"backend" → json:"backend,omitempty"
    • Autostart bool — json:"autostart" → json:"autostart,omitempty"

    The body explicitly claims: "Generated output moved by comment only: the Go field types are unchanged", "the Go struct fields are byte-identical, so no consumer recompiles differently", and "Nothing breaks at the wire level … both fields keep their names, their types and their validation". That is contradicted by the diff: the JSON representation changes — an empty backend/autostart is now omitted from JSON rather than emitted as ""/false. The body also contradicts itself within the same sentence ("types are unchanged … both omitempty"). Fix: disclose the ,omitempty JSON-tag change and its wire-level implication for JSON consumers (or, if the generator should not have emitted it, fix the generator) and correct the "byte-identical / comment-only / nothing breaks at the wire level" classification accordingly.

  2. QUAL — lint-clean Go. schema/vm_defaults_test.go (if out.Autostart != false {) is a gosimple S1002 finding ("should omit comparison to bool constant"), caught by the default golangci-lint linter set the workflow runs where a config exists. Replace with if out.Autostart {.

Everything else — security screen (no secrets/egress/guardrail weakening/injection), SDD (CUE source and *_gen.go moved in the same commit), the R7 negative/positive test evidence, single-squash-commit cutover, and the AI Assisted-by: footer — checks out. No comments to disposition (0 comments). Note also the test is named …CarryDefaults but asserts zero values, not schema defaults; not blocking, but the name is misleading.

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

`if out.Autostart != false` is S1002; it is `if out.Autostart`. Caught by review,
since golangci-lint is not installed on this host - go vet and the test stay green.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 68f1716ccd106450af8ad62f13bd138423ab7673 (branch: fix/vm-backend-autostart-defaults2)

Security screen: PASS — schema/test change only; no secrets, egress, guardrail weakening, supply-chain edit, or injected directives.
Checklist: All applicable rules PASS or NA.

Comment disposition — 6929459267 (@github-actions[bot], head 6d0b176): stale-superseded. Both blocks are resolved against the current state: the body now explicitly discloses the json:",omitempty" tag change (spec/cue_types_gen.go) with its JSON wire implication and a dedicated breaking-change/rollback section; the gosimple S1002 finding is fixed — the test now reads if out.Autostart {, not != false.

Non-blocking notes (do not affect verdict): TestResolvedVmBackendAndAutostartCarryDefaults and its comment still say "schema's own defaults" though the fix is optionality (absent ⇒ Go zero value); and TestResolvedVmBackendAcceptsEveryProviderWord only iterates {libvirt, qemu}, so "every provider word" is asserted over just two words. Neither affects correctness of the fix or its coverage.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 16, 2026 21:15
@github-actions
github-actions Bot merged commit d5e485a into main Nov 16, 2026
4 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 16, 2026
github-actions Bot pushed a commit to opencharly/plugin-box that referenced this pull request Nov 16, 2026
…fields optional (#88)

Mechanical pin bump, and the first link of a two-repo chain. spec v0.2026320.2116 carries
opencharly/spec#342, which makes `#ResolvedVm.backend` and `#ResolvedVm.autostart` optional - the fix for
the org-wide failure of `charly vm create`:

  applyCueDefaults vm: decode: autostart: cannot convert non-concrete value bool

NO SOURCE CHANGE IS NEEDED HERE, and that is verified rather than assumed: with only the pin moved,
`go build ./...`, `go vet ./...` and `go test ./...` all pass. This module's code already compiles against
the new spec API; it was simply pinned behind it.

WHY THIS REPO AND NOT `charly` DIRECTLY. Bumping `charly` to the new spec without re-releasing this repo
fails at compile time:

  [email protected]/inspect_list.go:228:29: a.Name undefined

This module pinned by `charly` was built against the OLD spec, so the chain is
spec -> plugin-box -> charly. Measured: this is the ONLY plugin in charly's build graph that fails, so the
wave is two PRs, not an org-wide sweep.

R9: the binary under test was built from this worktree, not a shared install.
R10: this change class is a dependency pin in a plugin repo whose gate is its own module suite; there is no
`disposable: true` target in this repo, and the live proof (a real `charly vm create`) belongs to the
consumer commit that follows.

Refs opencharly/spec#341, opencharly/spec#342.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

Co-authored-by: aitrawog <[email protected]>
github-actions Bot pushed a commit to opencharly/charly that referenced this pull request Nov 17, 2026
…ate org-wide (#1180)

* chore(deps): bump spec/sdk/plugin-box to the releases that fix vm create org-wide

Consumes opencharly/spec#342, which makes `#ResolvedVm.backend` and `.autostart` optional, and
therefore fixes the failure that has blocked every `charly vm create`:

  charly: error: command "vm": applying vm defaults for "<entity>":
    applyCueDefaults vm: decode: autostart: cannot convert non-concrete value bool

MEASURED AFTER THE BUMP, on this tree's own binary (`2026.320.0227`, built by
scripts/bootstrap-charly.sh - R9):

  $ charly -C <distro-ubuntu> vm create ubuntu-debootstrap
  Generated SSH keypair in ~/.local/share/charly/vm/charly-ubuntu-debootstrap
  Created VM charly-ubuntu-debootstrap (libvirt session)

The probe VM was destroyed afterwards and `vm list` verified empty.

THE CHAIN, producer-first, with each link's evidence recorded on the way:

  spec        v0.2026319.1619 -> v0.2026320.2116   (PR #342, merged + tagged)
  plugin-box  v0.2026317.2259 -> v0.2026320.2124   (PR #88, merged + tagged)
  sdk         v0.2026319.1356 -> v0.2026320.1345

plugin-box had to go between them rather than being skipped: bumping straight to the new spec
failed to compile at the OLD plugin-box pin (`inspect_list.go:228: a.Name undefined`), and
enumerating charly's build graph showed it was the ONLY module that needed the intermediate
release - so this is a two-link chain, not an org-wide sweep.

The four lockstep `tools/*` modules are bumped to the same pins (the canonical-go.mod gate
asserts one shared pin) and each still builds. `charly/testdata/…/go.mod` is deliberately NOT
touched: it is a fixture that pins its own older version on purpose.

Gates on this tree:

  $ scripts/bootstrap-charly.sh        # built ./bin/charly (2026.320.0227)
  $ cd charly && go build ./...        # ok
  $ tools/{generate-packages,golden-cloudinit,golden-compile,gomod-canonical}: go build ./...   # ok
  $ vm create ubuntu-debootstrap       # Created VM charly-ubuntu-debootstrap (libvirt session)

THE VM BED, run against this binary (distro-ubuntu's check-ubuntu-debootstrap-vm, run
2026.320.2130) - it now gets through the VM lifecycle the decoder used to block:

  [vm-build] PASS   [vm-create] PASS (1.9s)   [wait-ready] PASS   [deploy-add] PASS (2m12)
  [bring-up-members] PASS   [check-live] FAIL   [cleanup] PASS   [cleanup-members] PASS

The single FAILURE is not this bump's: `tailscale-repo-suite-ubuntu-resolute` greps the guest's
/etc/apt/sources.list.d/tailscale.list for the `resolute` SUITE, and this binary still embeds the
`noble` vocabulary because the vocabulary change is #1177, not this commit.
That is the producer-first order made visible by the artifact: the sweep asserts the new suite,
the vocabulary that writes it has not landed, so the assertion fails while
`tailscale-package-installed` PASSES (the package came from the old suite).

So the ordering this commit enables is exactly:

  this bump  -> #1177 rebases onto it and its bed passes -> distro-ubuntu#65's bed passes

I am not claiming a green VM bed here: I am claiming the decoder is fixed, which the first five
steps show by getting through `vm-create` at all.

Refs opencharly/spec#341 (closed by #342).

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* test(spec): decode the RawBody view sub-shapes the spec's authored-def extraction left opaque

The pin bump alone does not compile the test suite, and the reviewer's CI found it before I did:

  candy_test_helpers_test.go:147: have Alias() []spec.CandyAlias
                                 want Alias() []spec.ResolvedCandyAlias

MEASURED, and the mechanism is a deliberate upstream design rather than a rename:

- spec v0.2026320.2116 moved the AUTHORED candy sub-shapes (#CandyAlias, #CandyVolume, ...) out
  of spec and into the plugin that owns the candy body, keeping only the WIRE (resolved) twins.
  The spec's own candy_reader.go states the split: "A reader decodes a body that has already been
  validated, so the resolved form is what it needs - the same split the vm unit landed
  (VmSpec = ResolvedVm)".
- so `CandyView`/`CandyModel`'s sub-shape fields are now `spec.RawBody` (= json.RawMessage), and a
  reader must DECODE them into the resolved types it returns.

Only the TEST helper implements spec.CandyReader in this repo (production builds untouched - `go
build ./...` passed before this commit), so the adaptation is confined to
candy_test_helpers_test.go: two small generic helpers plus the accessors the compiler names.

This is exactly the sibling of the defect this PR's pin fixes: the vm unit made the same
authored/resolved split, and that split is what opencharly/spec#341 was about.

Gates on this tree:

  $ go vet ./...        # clean
  $ go test ./...       # rc=0, zero failures (the CI failure was here)

A first attempt at this used a regex over the accessors and touched fields that were never
RawBody (Plan/PlanSteps among them) - reverted in full and redone one accessor per compiler error,
which is why the diff is now only the six the type-checker named.

Refs opencharly/spec#341, #1177.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* fix(test): count DECODED elements in the Has* predicates, not raw-JSON bytes

The RawBody migration left four predicates measuring byte length instead of element count, so a body
encoding an EMPTY list (the two-byte empty JSON array) reported as present:

  HasExtract() { return len(a.m.Extract) > 0 }   // a.m.Extract is now spec.RawBody
  HasData()    { return len(a.m.Data) > 0 }
  HasAliases() { return len(a.v.Aliases) > 0 }
  HasVolumes() { return len(a.v.Volumes) > 0 }

Measured from the spec's own structs, which are the authority on which fields moved: CandyModel's
RawBody fields are Service, Extract, Data, Volumes, Aliases, Hook, Artifact, and CandyView's are
Volumes and Aliases - so these four are exactly the predicates over a RawBody field. The other ten
Has* predicates read typed slices and are unchanged.

They now count the decoded slice:

  return len(decodeRawSlice[spec.CandyExtract](a.m.Extract)) > 0

This is a semantic bug, not a compile error: len(bytes) > 0 is true for the empty JSON array, so a
fixture with no aliases would have reported HasAliases() true and silently widened what a downstream
test believed. Caught by review, not by the compiler - the compiler cannot see it, which is exactly
why the four predicates needed reading rather than patching.

gates: go vet ./... clean; go test ./... rc=0, zero failures.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant