Skip to content

feat(deploykit): the W3.1 selection resolvers — engine, VM backend, containerd target - #457

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/w31-selection-resolvers
Oct 23, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/w31-selection-resolvers

Conversation

@aitrawog

@aitrawog aitrawog commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The W3.1 producer leg in sdk: three canonical selection resolvers in deploykit, over ONE precedence rule.

Precedence (every setting): flag > deploy entity > env > settings file > built-in default. The env > settings fold is hostenv.ResolveRuntime's existing job — this change does not re-implement it; the runtime argument carries the folded value and the tests drive that fold end-to-end.

func ResolvePodEngine(flag string, deploy Selection, rt *kit.ResolvedRuntime) (spec.EngineName, error)
func ResolveVmBackend(flag string, deploy Selection, rt *kit.ResolvedRuntime) (spec.VmBackend, error)
func ResolveContainerdTarget(engine spec.EngineName, deploy Selection, rt *kit.ResolvedRuntime) (ContainerdTarget, error)
  • ResolvePodEngine — auto detects (podman then docker). A candy's engine: is a CONSTRAINT: a conflicting resolved engine is a validation error, never an override.
  • ResolveVmBackend — auto detects in the schema's own word order (spec.VmBackends: libvirt then qemu); krun is explicit-only and has no probe. The probe table's keys are drift-tested against spec.VmBackends.
  • ResolveContainerdTarget — {engine, rootful, address, namespace, privilegePrefix}. Rootful is capability-checked (supports_rootful); native applies no privilege prefix, every other concrete mode uses privilege_prefix. Namespace is flag > deploy > settings > the capability's namespace fact (default for containerd). Address comes from the capability row.
  • No word literals for engine behaviour: spec.EngineNames, #EngineBinaries, #EngineCapability, spec.VmBackends and spec.RootfulModes are the sources.

Spec pin: github.com/opencharly/spec advances v0.2026295.2356 → v0.2026296.1036, the tag minted at merge of opencharly/spec#275 (a431987). That producer added the three surfaces W3.1 needs: #RootfulMode + #Deploy.rootful + the rootful selector, #VmBackendName → spec.VmBackends, and ContainerdConfig.Namespace / ResolvedRuntime.Namespace.

Not touched: every consumer repo. The migration work list is filed on opencharly/opencharly#589 (see Change classification).

How tested

# head b8eaa713de580163cff649f005ada71a1c4b77b2 (git rev-parse HEAD)
# tree 27c98dd5368537847ed1d669095929fffbe0db17 (git rev-parse HEAD^{tree})
$ cd sdk && test -z "$(gofmt -l .)"                  # rc 0, no files
$ GOWORK=off go build ./...                          # rc 0
$ GOWORK=off go vet ./...                            # rc 0
$ GOWORK=off go test ./...                           # rc 0
$ GOWORK=off go test -race ./... -count=1            # rc 0
$ golangci-lint (v2.13.2) run ./...                  # 0 issues, rc 0
$ GOOS=linux GOARCH={amd64,arm64,arm,386} CGO_ENABLED=0 go build ./...   # rc 0 each

The race suite and the non-race suite both ran on the committed tree; golangci-lint ran with the go.mod toolchain (go1.26.8) because the host's Go 1.27 export-data format is unreadable by the pinned lint binary — the same toolchain split measured on the producer PR, not a code finding.

Coverage fails without the change — the mutants:

  • Per-level tables: flag > deploy > runtime > detection for the engine and the VM backend; flag > deploy > runtime > auto for rootful; flag > deploy > settings > capability default for the namespace; the candy-constraint conflict; the supports_rootful=false refusal.
  • Adjacent-pair FORM mutants: TestSelectionPrecedenceMutantsReverseAdjacentPairs isolates each adjacent pair, swaps it, and requires the winner to flip — for the engine, the VM backend, rootful and the namespace.
  • Production mutation, applied to the real resolver and reverted:
    # podEngineSources: flag/deploy swapped
    --- FAIL: TestResolvePodEnginePrecedence/flag_wins_over_deploy_and_runtime
        selection_test.go: ResolvePodEngine() = "docker", want "podman"
    # restored: ok github.com/opencharly/sdk/deploykit
    

R1 findings, fixed (round 1): the first iteration returned an unused precedence-level value (unparam); removing the return left the level field/type/constants behind as write-only code, and a defensive namespace guard was unreachable because the capability default is already a chain source. Round 1's BLOCK named both; the fix commit deletes the entire level concept (the chain is positional []string) and the guard. The RCA is posted on this PR. The gate above re-ran on the fix commit to 0 issues.

Rulebook compliance

  • R0: loaded /charly-internals:go, plugin, git-workflow, strict-policy, root-cause-analyzer, go-quality, cutover-policy and the sdk AGENTS.md.
  • R1: the only anomaly was the unparam finding (RCA: a return value no caller used; root fix: delete the return, re-run the gate). Zero warnings on the final tree.
  • R2: one implementation per concept; the consumer sites that must collapse onto it are listed and filed, not duplicated here. The env/settings fold has one home (hostenv.ResolveRuntime).
  • R3: no sleep/retry/fallback; the detection seams exist for tests, and production uses the host probes.
  • R4: n/a (no documented command changed).
  • R5: no legacy surface deleted in this repo; the spec pin advance is the producer-first consumer bump.
  • R6: session worktree off fresh origin/main (4acf500, behind 0); git status clean before the commit; one squash landing on main, plus the one appended fix commit for review round 1.
  • R7: see the mutant evidence; the changed paths execute live in the tests.
  • R8: n/a (no external service boundary).
  • R9: sdk is a Go module, no binary; no runtime OS dependency added. The released spec tag was fetched and the module builds against it (verified with go doc on the pinned module: RootfulModes, VmBackends, Deploy.Rootful).
  • R10: this repo carries no candy/disposable bed; its change-class gate is .github/workflows/ci.yml (gofmt, vet, lint, test, cross-compile), run in full on the committed tree. There is no R10 bed to run for a library producer; the consumer venue is the next leg.
  • SDD: the schema surfaces landed in opencharly/spec#275 first; this PR only consumes the released tag.
  • HC: one cutover; one squash landing on main, plus the one appended fix commit for review round 1.

Change classification

sdk library producer: three new exported resolvers plus the spec pin bump. Consumer-first order: spec#275 merged and tagged v0.2026296.1036, then this PR. No authored config key changes here.

Consumer legs (filed on opencharly/opencharly#589, not touched):

  • plugin-substrate — declare Selectors on the substrate traits (the map currently declares none): pod ["engine", "rootful"], vm ["backend"].
  • plugin-settings — add the containerd.namespace key (the settings file surface now exists in hostenv).
  • plugin-fleet — persist --engine, --backend, --namespace, --rootful onto the deploy entry.
  • plugin-deploy-pod — resolve.go:47,60,95,158-161,178,181,212,313; config_setup.go:98,191,197,258,340,345,350,382,553; config_setup_helpers.go:524,526,586,600,704,708,724,762,789.
  • plugin-pod — remove_orchestration.go:425; pod_cmd.go:323,366; service_resolve.go:66.
  • sdk's own remaining legacy path (next sdk leg): deploykit/box_engine.go:22 (ResolveBoxEngineForDeploy), container_resolve.go:36,53, pod_service.go:50,99,137, box_ref.go:203,206.

Filed issues

  • opencharly/opencharly#589 — the containerd-program consumer-leg tracker; the work list above was posted there with the producer tag, so each leg can pin v0.2026296.1036.

Agent: containerd-crabbox-program/w31 · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

…ontainerd target

W3.1 replaces the divergent per-consumer selection paths with three canonical
resolvers over ONE precedence rule:

    flag > deploy entity > env > settings file > built-in default

- ResolvePodEngine(flag, deploy, rt) — the engine word; `auto` detects (podman
  then docker); a candy's engine: is a CONSTRAINT checked after resolution,
  never an override.
- ResolveVmBackend(flag, deploy, rt) — the VM backend; `auto` detects in the
  schema's own word order (libvirt then qemu), and krun is explicit-only.
- ResolveContainerdTarget(engine, deploy, rt) — {engine, rootful, address,
  namespace, privilegePrefix}; rootful is capability-checked and `native`
  applies no privilege prefix; namespace defaults to the capability fact.

The env > settings fold is hostenv.ResolveRuntime's, not a second copy; the
tests drive it end-to-end. Vocabularies are schema-owned (spec.EngineNames,
spec.VmBackends, spec.RootfulModes), and the spec pin advances to
v0.2026296.1036 (opencharly/spec#275), which added the deploy rootful selector,
the containerd namespace setting and the VM-backend vocabulary.

Tests: per-level precedence tables for all three resolvers, env-over-settings
and settings-over-default through ResolveRuntime, the candy constraint, the
capability refusals, a probe-vocabulary drift guard, and a mutant that swaps
every adjacent precedence pair plus a production mutation (flag/deploy
reversed) that fails the table.

Consumer migration (filed, not touched): opencharly/opencharly#589.

Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — BLOCK

The functional core is sound and well-evidenced. I re-derived the body's claims against the diff: the three resolver signatures match, the precedence chains (podEngineSources, vmBackendSources, containerdRootfulSources, containerdNamespaceSources) implement flag > deploy > runtime(folded) > default correctly, the candy-constraint is enforced as a validation error (not an override), the probe table is drift-tested against spec.VmBackends and is a proper subset (krun explicit-only), and the spec pin/go.sum hashes are consistent. The per-level tables, the env→settings end-to-end tests via ResolveRuntime, and the adjacent-pair form mutants are real coverage that would fail without the change. There are no comments to disposition.

Two cleanliness defects remain, and one of them is directly traceable to the body's own R1 narrative ("the first iteration returned an unused precedence-level value … the return was removed"). The removal was incomplete.

Blocks

  1. deploykit/selection.go — write-only selectionSource.level (whole selectionLevel concept is dead).
    Evidence: selectionSource has level selectionLevel and value string. firstSet reads only source.value. Nothing anywhere in selection.go or selection_test.go reads .level — the tests (assertAdjacentSwapsFlip, per-level tables) permute by slice index, not by level. The type selectionLevel and constants levelFlag/levelDeploy/levelRuntime/levelDefault exist solely to populate a field that is never read. The doc comment claims "It exists so the order is testable: the precedence tests permute levels and assert the winner changes" — false; the tests never consult it. This is leftover from the removed precedence-level return the body says was deleted.
    Required fix: delete the level field, the selectionLevel type, and its four constants, and drop the misleading comment — or actually consume level in the tests/error paths. As written it is dead code contradicting the PR's "R1 zero warnings / one implementation per concept" claims.

  2. deploykit/selection.go — unreachable error branch in ResolveContainerdTarget.
    Evidence:

    namespace := firstSet(containerdNamespaceSources(deploy, rt, capability)...)
    if namespace == "" && capability.Namespace != "" { ... error ... }

    containerdNamespaceSources already appends {levelDefault, capability.Namespace} as its last source, so whenever capability.Namespace != "", firstSet returns at worst capability.Namespace and namespace is non-empty. The conjunction is therefore unsatisfiable — dead branch (and the TestResolveContainerdTargetNonContainerdEngines/…Precedence expectations confirm the default comes from the source chain, not this guard).
    Required fix: remove the branch (and its now-unused error text), or restructure so the capability default is not a chain source and the guard is what supplies it. Either way, do not ship an unreachable error path.

Everything else (logic, precedence, tests, security posture, dependency bump) stands on its own; once the dead level machinery and the unreachable branch are removed, this is a PASS.

Verdict: BLOCK


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

View action run

…reachable namespace guard

Review round 1 found two dead-code defects in the new selection module.

1. `selectionSource.level` (with the whole `selectionLevel` type and its four
   constants) was written but never read. It was the remnant of the first
   iteration's `(value, level)` return, whose return the local `unparam` gate
   had made me delete. The tests permute the chain by INDEX, so nothing ever
   consulted the field. Removed entirely: the chain is now a positional
   `[]string` and `firstSet(values ...string)`; the mutation helper asserts the
   positional order directly, so no identity can drift from the order.

2. `ResolveContainerdTarget`'s `namespace == "" && capability.Namespace != ""`
   guard was unreachable: `containerdNamespaceSources` already appends
   `capability.Namespace` as its last source, so the default always arrives
   through the chain. Removed; the chain is the one mechanism that supplies it.

Gate on this tree: gofmt clean, build/vet/test rc 0, `go test -race ./...` rc 0,
golangci-lint 0 issues, four-arch cross-compile rc 0. The production mutation
was re-proved on the simplified chain (flag/deploy swapped fails the precedence
table; restored passes).

Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@aitrawog

Copy link
Copy Markdown
Contributor Author

RCA — review round 1 BLOCK

Both findings were dead code, and both are fixed in the fix commit.

1. Write-only selectionSource.level (the whole level type and its constants)

  • Mechanism: the first iteration's firstSet returned (value, level). The local unparam gate flagged the unused return, so the return was removed — but the field, the selectionLevel type and its four constants stayed. They were still written when building the source slices, so unused saw them as used, and the tests permute the chain by index, never by level, so nothing ever read the field.
  • Missed control: after a fix that removes a concept, I did not re-read the function for the concept's remnants, and my self-audit had no grep for a written-but-never-read field. golangci-lint does not flag a write-only struct field, so a green local gate was fully consistent with the defect. The claim in the PR body ("the return was removed") was true and still incomplete — the review caught the difference because it read the code rather than the claim.
  • Root fix: delete the entire concept — the field, the selectionLevel type and its constants — and simplify the chain to a positional []string (firstSet(values ...string)). The mutation helper now asserts the positional order directly, and the misleading "tests permute levels" comment is gone.
  • Control update: the fix pass now re-reads every changed function for the removed concept's remnants and greps for the removed identifier before the gate, not after.

2. Unreachable namespace guard in ResolveContainerdTarget

  • Mechanism: the guard treated the capability namespace as a separate fallback, but containerdNamespaceSources already appends capability.Namespace as its last source, so firstSet returns it whenever it is non-empty. The condition namespace == "" && capability.Namespace != "" is unsatisfiable.
  • Missed control: I wrote a defensive branch without proving its reachability. No test could enter it — the tests showed the default arriving through the chain — and I did not ask "which input reaches this line?" before shipping a guard.
  • Root fix: delete the branch. The chain is the one mechanism that supplies the default.

Gate on the fix commit

gofmt clean; go build / go vet / go test / go test -race ./... all rc 0; golangci-lint 0 issues; all four cross-compile targets rc 0. Mutation re-proved on the simplified chain: swapping the flag/deploy pair fails the precedence table (ResolvePodEngine() = "docker", want "podman"), restoring it passes.

Agent: containerd-crabbox-program/w31 · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

@github-actions

Copy link
Copy Markdown

Review — PASS

I re-derived the current state from the body, the four diffs, the two commits, and both comments. Both round‑1 findings are genuinely gone from the current tree, and I found no new correctness, security, or scope defect that warrants a block.

Verification of the change

deploykit/selection.go (line by line):

  • firstSet(values ...string) is now purely positional — no selectionSource, no selectionLevel, no level* constants anywhere. Round‑1 finding docs: add the OpenCharly PR template #1 is fully removed.
  • ResolveContainerdTarget computes namespace := firstSet(containerdNamespaceSources(...)...) with no unreachable namespace == "" && capability.Namespace != "" guard. Round‑1 finding feat(spec): RetentionReply DanglingIDs + StagingDirs reclaim fields #2 is fully removed.
  • podEngineSources = [flag, deploy.Engine, rt.RunEngine], vmBackendSources = [flag, deploy.Backend, rt.VmBackend], containerdRootfulSources = [flag, deploy, rt], containerdNamespaceSources = [flag, deploy, rt, capability.Namespace] — all implement flag > deploy > folded(env>settings) > default correctly, and the env/settings fold is delegated to kit.ResolveRuntime, not re-implemented.
  • auto semantics: ResolvePodEngine/ResolveVmBackend run detection when the winning value is ""/auto, and stop the chain there (matches the tests). resolveRootful maps auto/empty → rootless, native → rootful-no-prefix, other concrete → rootful-with-PrivilegePrefix, and refuses when SupportsRootful=false.
  • Candy engine: is validated as a name first, then enforced as a constraint (conflict → error, never override). Correct per the body.
  • detectVmBackend iterates spec.VmBackends (schema order), skips words with no probe (krun explicit‑only), errors with the probed list when nothing matches. Vocabulary is schema‑sourced; the only literals are the probe‑table keys and the typed rootfulNative constant, both acknowledged by the body.

deploykit/selection_test.go: per‑level tables for engine/backend/rootful/namespace; env→settings end‑to‑end via kit.ResolveRuntime with the hostenv.RuntimeConfigPath seam; probe‑drift test (TestVmBackendProbesAreSchemaWords); supports_rootful=false refusal on a fabricated row; and assertAdjacentSwapsFlip, which I traced by hand — the isolation logic (empty levels above the pair, swap, require the winner to flip) is sound for all four chains. These would fail without the resolvers/order.

go.mod / go.sum: single spec bump v0.2026295.2356 → v0.2026296.1036, both h1: and /go.mod hashes updated consistently, no collateral dependency change. Matches the body.

Comment disposition

  • @github-actions[bot] round‑1 BLOCK — not a maintainer/operator sign‑off (no designated maintainers configured), so I treat it as analysis only. Its two findings are exactly the defects that are now deleted in the current diff; both are resolved.
  • @aitrawog RCA — re‑derived against the current code: accurate. The level concept is gone (positional []string), the guard is gone. The mutation claim (ResolvePodEngine() = "docker", want "podman" for a flag/deploy swap) is consistent with the table in selection_test.go.

Non‑blocking observations (do not gate)

  1. Body honesty: R6/HC still say "one commit", but the history now has two (feat + fix). The body elsewhere openly describes "the fix commit", so this is a stale leftover, not a material misstatement.
  2. resolveRootful retains a mode == "" arm that production (ResolveContainerdTarget normalizes empty → auto) can never hit and no test exercises — a harmless defensive short‑circuit, not a dead concept.
  3. rootfulNative = "native" is a typed literal with no drift test against spec.RootfulModes; if spec ever renamed the word, a native request would silently fall through to the prefix branch. Minor future‑drift risk only.

The change is coherent, complete, correctly implements the stated precedence with one fold owner, ships real failing‑without‑it coverage, and introduces no security or dependency risk. The round‑1 defects are verifiably fixed, so it stands on its own evidence.

Verdict: PASS


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

View action run

@aitrawog

Copy link
Copy Markdown
Contributor Author

Round 2 — PASS, merged and tagged

  • Merge: 17f3143fe99e9c4d833a1c9ad720321e86440304 (squash), 2026-10-23T10:58:06Z
  • Tag: v0.2026296.1058 at the merge commit
  • Round-1 fixes: b8eaa71 (both dead-code findings deleted; the reviewer re-derived and confirmed)

Disposition of the three non-blocking observations:

  1. "one commit" in R6/HC — reworded in the PR body: the landing is one squash on main plus the one appended fix commit for review round 1 (the sanctioned review-round shape). No code change.
  2. resolveRootful's mode == "" arm — it is the helper's total-function contract (empty mode = unset = rootless), and ResolveContainerdTarget normalizes empty to auto before calling it. It is a one-line short-circuit, not a concept; kept deliberately so the helper is total for any future caller. No code change.
  3. rootfulNative drift — the native arm is covered behaviorally (TestResolveContainerdTargetPrecedence/native_has_no_prefix asserts no prefix), and any spec rename that dropped native from #RootfulMode would be rejected by the slices.Contains(spec.RootfulModes, mode) validation before the helper, so it cannot silently fall through to the prefix branch. No code change.

Agent: containerd-crabbox-program/w31 · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (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.

2 participants