Skip to content

fix(add_candy): fail loudly when a pinned ref cannot be honoured, instead of running another version's plan - #113

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/addcandy-version-guard
Oct 14, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/addcandy-version-guard

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

rp.CandyModels is keyed by candy identity (BareRef: no @, no :version), which is right
for the graph — include:/require: edges are bare refs and the dep walk is literally
layers[BareCandyRef(ref)] — but it cannot distinguish two coordinates of one repo. When two
scopes in the same project pin the same repo at different tags, the loader FETCHES both
(sdk/loaderkit/refs_collect.go's per-(repo, tag) fetch set, scan_orchestrate.go's
materials[repoVer{repo,ver}]) and then PickCandyVersion keeps one winner per identity — the
losers are dropped at exactly that point. So candyAddSteps' bare lookup returns the arbiter's
winner whatever the deploy pinned.

This change is the MISSED CONTROL, not the fix. The scan already stamps the winning source git
tag onto the model (ws.Model.Version = winner.GitTag), which makes the collision detectable: an
authored ref that names a version and receives a model stamped with a different one is an
unresolvable input, not a plan to run. It now fails loudly (infra exit) naming the ref, the wanted
version, the model's version and the issue, instead of silently asserting a version the deploy never
named. The guard is narrow by construction:

  • a version-less ref keeps the identity lookup — there is no pin to honour;
  • an unstamped model (Version == "") is not gated — that is the documented local-shadow case
    (a local candy of the same name wins, as INFO, and carries no git tag);
  • a local bare-name ref has no version at all.

It does NOT unblock opencharly/distro-arch#52 — and it says so. The pin still cannot be
honoured here; with this guard in the tree #52's child phase fails LOUDLY (naming both versions)
rather than quietly asserting the wrong one. A guard that pretended to unblock would be the fake fix.
Honouring the pin needs the per-coordinate models carried on the resolved-project envelope: a
#ResolvedProject field (spec/schema/resolvedproject.cue, CUE-sourced → cue-gen) plus the
loader's exit — which is the seam method ScanCandyFromLocal (spec/spec/loader_seam.go:362)
with 7 call sites across charly, plugin-build ×4 legs, plugin-loader and the vendored charly
mirrors
. That is filed as the next row in opencharly/plugin-check#112, never half-landed.

The cheap green is refused in writing on #112: making the whole project agree on ONE coordinate
for that repo (a layer-agent-forwarding tag + three box bumps) would turn #52 green while the
bare-keyed lookup kept silently ignoring pins — the next pin bump anywhere would re-open the class
with the same silence.

How tested

Change class: compiled-in plugin Go code (plugin-check's own AGENTS.md: the plugin is baked
via github.com/opencharly/plugin-check/candy/plugin-check in charly/go.mod, and the R10 witness
is the disposable check-local bed in opencharly/charly). That bed is a consumer artefact
(it composes this plugin through a pin), so its run rides the consumer change — the same
producer→consumer order as every other leg of this campaign. What I can prove on this head, I pasted
below: the module gates, the unit test with its negative control, and a LIVE A/B of the changed path
on the measured bed's own deployment.

Module gates on this head (7ce151e, 3 files, +120/−14):

$ cd .worktrees/dsh-opencharly/plugin-check-guard && git rev-parse HEAD ; git rev-parse HEAD^{tree}
7ce151ead051a2a122ed131e423aa98bd5784124
5f5b930c11536d57800c49c94fbf32716862caf5
$ cd candy/plugin-check && go build ./... ; echo rc=$?
rc=0
$ go test ./... ; echo rc=$?
ok  	github.com/opencharly/plugin-check/candy/plugin-check	20.476s
?   	github.com/opencharly/plugin-check/candy/plugin-check/cmd/serve	[no test files]
rc=0
$ gofmt -l .    # empty = clean

The negative control (R7: a test that cannot fail is invalid). With the guard's condition
disabled in place and everything else identical:

$ go test -run 'TestCandyAddSteps' -count=1 ./...   # guard disabled
--- FAIL: TestCandyAddStepsRejectsAPinTheModelCannotHonour (0.00s)
    cmd_helpers_addcandy_test.go:91: a pinned ref the resolution cannot honour must FAIL LOUDLY, not
    resolve to another version's plan; got 1 step(s) and no error
FAIL
$ go test -run 'TestCandyAddSteps' -count=1 .        # guard restored
ok  	github.com/opencharly/plugin-check/candy/plugin-check	0.012s

The LIVE A/B — the changed path executed on the measured bed's deployment. Same command, same
venue, same tree; the ONLY difference is which plugin-check ran:

$ cd .worktrees/dsh-opencharly/distro-arch    # head d925bfb6cf7ea294102fdcd1d3db0a55c8074d9b
$ /tmp/charly-guard-build/charly-guard check live check-arch-vm.arch-host      # THIS plugin
charly: error: command "check": add_candy "@github.com/opencharly/layer-direnv:v2026.287.2155"
  names version "v2026.287.2155" but the resolved model for
  "github.com/opencharly/layer-direnv" is version "v2026.272.0057": a bare-keyed lookup cannot
  honour a pin when the same repo is pinned at two coordinates in one project, and this resolution
  carries the arbiter's winner, not the pinned version. Running it would assert a version this
  deploy never named (opencharly/plugin-check#112). Honour the pin (or drop the version and pin the
  project consistently) and retry
rc=1

$ CHARLY_PLUGIN_DIR=/home/atrawog/charly-plugins/plugin-check-guard <lane-beds driver 2026.287.1934> \
    check live check-arch-vm.arch-host                                          # the STOCK plugin
  ... the unchanged plan, none of the guarded step:
9 steps: 6 passed, 3 failed, 0 skipped
command "check": 3 check(s) failed
rc=2
# and NO plugin-check "served from" line: the baked plugin ran, not my binary.

Two things that A/B establishes beyond the guard working:

  1. The mechanism is now MEASURED, not inferred. The guard's own message reports the winner's
    identity — v2026.272.0057, the transitive coordinate reached through
    layer-agent-forwarding:v2026.274.0608 (composed by three boxes in that manifest) — against the
    bed's pinned v2026.287.2155. That is the collision, named by the engine itself.
  2. CHARLY_PLUGIN_DIR is INERT for a BAKED plugin, and that is why the live proof needed a
    rebuilt host: the loader never consults a plugin directory for a plugin linked into
    charly/go.mod. Measured twice (no served from line, identical plan), independently reproduced
    by lane-beds.

Provenance of the guarded host binary, stated exactly because the instrument matters:
/tmp/charly-guard-build/charly-guard, built from the umbrella's charly/ tree (the submodule at
its gitlink) with a scratch go.work in /tmp that uses the charly module plus this
worktree's candy/plugin-check module — the same shape -dev-plugin's generated go.work.dev has.
charly version → 2026.286.2307. No repo file was written: the workspace and the binary live
under /tmp. The scratch workspace also carries one replace — the plugin-build pin movement
below — which is what made the assembled build compile at all.

Pin-skew evidence, added to opencharly/plugin-cache#10: the first assembled build attempt
failed on EXACTLY the mechanism that issue measures —
[email protected] no longer compiles against loaderkit's NamespaceAncestors seam once
MVS raises sdk (this plugin module requires the storekit tag). The scratch replace to
v0.2026286.1121 (the pin movement #10 names) compiles. That is an existing issue's evidence, not
a new finding, and the real fix belongs in charly/go.mod (charly#910's row).

Rulebook compliance

Rule / check Answer
T1–T4 (security screen) No secrets, no egress, no dependency, no guardrail weakened; a guard that fails closed (infra exit) — not security machinery, so no maintainer sign-off applies.
A1 The four required sections are present, every path in the diff is accounted for, ## Filed issues follows, and the attribution footer is the LAST line.
A2 Change class and gate named above (compiled-in plugin → the check-local bed, consumer-side; module gates + live A/B pasted).
A3 Tier analysed on a live system — a live invocation of the changed path produced retained output (the A/B), and the class's assembled bed is the consumer's.
R0 /charly-internals:git-workflow and /charly-internals:strict-policy loaded before any git/PR action; this repo's AGENTS.md read.
R1 The anomaly that surfaced mid-proof (the instrument silently doing nothing) is RCA'd in the round comment, and the missed control — assuming CHARLY_PLUGIN_DIR overrides a baked plugin — is now recorded rather than hidden. The class and the next row are filed (## Filed issues).
R2 One home for the rule: the guard lives beside the lookup it protects, and reuses the stamp the loader already writes instead of re-deriving a coordinate.
R3 No sleep, retry, fallback or ad-hoc infrastructure command; the guard fails closed with one named error.
R4 No product defect is routed around: the unresolvable pin is surfaced as a named failure instead of being papered over by a plan that pretends to be the pinned one.
R5 Claim-keyed sweep, RUN and pasted in the block below: the stale clause "Remote (@github) candies are skipped, matching the original" — which contradicted the code it sat above — is deleted, not reworded beside itself.
R6 git status --short clean before and after the single commit; no amend after push planned, no force-push, no bypass, no direct push to main; no repo outside this worktree was written (the host build lives in /tmp).
R7 The new test FAILS without the change (guard disabled → got 1 step(s) and no error) and the changed path executed LIVE (the A/B).
R8 Live, never mocked: the guard was exercised against a real deployment over real SSH; the control is the same command with the stock plugin.
R9 The host binary was rebuilt from source with a CalVer stamp and its provenance is stated (2026.286.2307), including the scratch workspace that composed this plugin; no new runtime dependency.
R10 Class gate named above; the assembled check-local bed is the consumer's, and this PR states that it has not run on this head.
HC One commit, one cutover, nothing deferred inside its scope (the next row is a different cutover with its own sizing).
PIL — ADE The changed code is the plan GATHER, not a plan; the plugin's own plan: and grader contract are untouched, and the guard exists to stop a plan being assembled from the wrong version.
PIL — RDD The highest-risk assumption (that the collision is the mechanism) was proven live before the push — and the proof upgraded it from elimination to direct measurement: the engine names the winner.
PIL — SDD N/A — no spec/schema/*.cue, wire shape or generated type is touched here (the schema field belongs to the next row).
CONC N/A for concurrency; CONC(d)'s paste requirement is met by the A/B and the sweep above.
ARCH The guard stays in the consumer that reads the envelope (plugin-check); the version-carrying change belongs to the contract/loader rows, as stated.
DISP The live run is read-only against a disposable: true bed's deployment; nothing was destroyed, rebuilt, or mutated (with the guard the plan never executes).
QUAL gofmt -l empty, go build ./... clean, go test ./... green (pasted).
COORD STATUS on opencharly/plugin-check#112 (the class), lane-beds told the outcome of the probe on their venue, and plugin-check was checked for contention before branching (no open PRs; three stale worktrees on other files, none touched).

R5 sweep, executed on this head (the claim is worth its pasted lines):

$ cd .worktrees/dsh-opencharly/plugin-check-guard
$ git grep -n 'Remote (@github) candies are skipped' origin/main -- candy/plugin-check ; echo exit=$?
origin/main:candy/plugin-check/cmd_helpers.go:86:// collectAddCandySteps. Remote (@github) candies are skipped, matching the original: they carry
exit=0
$ grep -rn 'candies are skipped' candy/plugin-check ; echo exit=$?
exit=1
$ grep -rn 'skipped, matching the original' candy/plugin-check ; echo exit=$?
exit=1

Read precisely: the clause survived on the base at cmd_helpers.go:86 while the code below it had
already been changed to LOOK UP remote refs — a comment asserting the opposite of its function — and
on this head both greps return exit=1 (no match). The replacement states the map-key rule the code
actually implements.

Change classification

plugin-check Go source: candy/plugin-check/cmd_helpers.go (the guard + the returned error),
candy/plugin-check/live_gather.go (propagation), candy/plugin-check/cmd_helpers_addcandy_test.go
(the collision test + the two boundary cases). Zero schema, zero pin, zero plan text. Tier on this
push: analysed on a live system.

Filed issues

  • opencharly/plugin-check#112 — the class this change guards: a pin that changes the fetched
    artifact and not the plan is a lookup that ignores the version.
    The comment on it carries the
    design answer (the bare key is deliberate at its layer; the losers are dropped at
    PickCandyVersion), the 7-call-site measurement for the real fix, the live proof, and the refused
    cheap-green route.
  • opencharly/plugin-box#45 — the validator arm that should have refused the inert
    context: [deploy]-on-a-check:-step combination (the sibling class from #111).
  • opencharly/plugin-cache#10 — evidence added, not filed: the assembled build fails on exactly
    the plugin-build pin skew its body measures, and the v0.2026286.1121 pin movement it names is
    what compiles.

Agent: dsh-opencharly
Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

…tead of running another version's plan

`rp.CandyModels` is keyed by candy IDENTITY (`BareRef`: no `@`, no `:version`), which is right for
the graph — `include:`/`require:` edges are bare refs and the dep walk is literally
`layers[BareCandyRef(ref)]` — but it cannot distinguish two coordinates of ONE repo. When two
scopes in the same project pin the same repo at different tags, the loader FETCHES both
(`sdk/loaderkit/refs_collect.go`'s per-`(repo, tag)` fetch set, `scan_orchestrate.go`'s
`materials[repoVer{repo,ver}]`) and then `PickCandyVersion` keeps ONE winner per identity — the
losers are dropped at that exact point. So `candyAddSteps`' bare lookup returns the arbiter's
winner whatever the deploy pinned, and a bed's child plan is another version's plan.

MEASURED (#112): `distro-arch`'s bed pins
`layer-direnv:v2026.287.2155` while `layer-agent-forwarding:v2026.274.0608` transitively pins
`layer-direnv:v2026.272.0057` (three boxes in the same manifest). The fetched artifact carried the
pinned manifest (`grep -c context` = 12, `id: direnv-hook-wired-at-venue`), yet the child
`check live` ran the OLD plan — `9 steps: 6 passed, 3 failed, 0 skipped`, none of the new steps —
before and after the pin move, and with `charly cache bypass` on (so the cache is refuted as the
cause).

This change is the MISSED CONTROL, not the fix. The stamp the scan already writes
(`ws.Model.Version = winner.GitTag`) makes the collision DETECTABLE: an authored ref that names a
version and receives a model stamped with a different one is an unresolvable input, so it now
fails loudly (infra exit) naming the ref, the wanted version, the model's version and the issue,
instead of silently running the wrong plan. Narrow by design:
- a version-less ref keeps the identity lookup (no pin to honour);
- an UNSTAMPED model is not gated — that is the documented local-shadow case
  (sdk/loaderkit gives a local candy of the same name precedence, as INFO, and a local candy has
  no git tag);
- a local bare-name ref has no version.

It does NOT unblock `opencharly/distro-arch#52`: the pin still cannot be honoured here. That needs
the per-coordinate models carried on the resolved-project envelope (spec schema + `cue-gen` → the
loader's exit → this lookup), which is a spec-level change because the scan's exit is the
`ScanCandyFromLocal` seam method with 7 call sites across charly, plugin-build ×4 legs,
plugin-loader and the vendored mirrors — filed as the next row rather than half-landed.

Test: `TestCandyAddStepsRejectsAPinTheModelCannotHonour` (with the guard disabled it reports
"got 1 step(s) and no error" — the negative control) plus
`TestCandyAddStepsToleratesAnUnpinnedRefAndAnUnstampedModel` for the two boundaries; `go build`,
`go test ./...` and `gofmt -l` clean.

Agent: dsh-opencharly
Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 7ce151ead051a2a122ed131e423aa98bd5784124 (branch: fix/addcandy-version-guard)

Security screen: PASS — the diff adds a fail-closed guard (no secrets, egress, dependency, or weakened gate); T4 not triggered.
Checklist: All applicable rules PASS or NA. Comment intake: 0 comments on the thread, nothing to disposition.
Non-blocking note (rulebook observation): the class's declared R10 witness bed (check-local) is consumer-side and structurally unrunnable for an unmerged producer commit; the author substitutes a fresh-rebuild live A/B (guard firing on the real collision, stock plugin unchanged) plus a negative-control unit test. This is coherent and honestly disclosed, but the rulebook does not state a producer-repo exception in so many words — a candidate gap worth stating explicitly in the class's AGENTS.md.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 14, 2026 22:20
@github-actions
github-actions Bot merged commit ed1077f into main Oct 14, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 14, 2026
github-actions Bot pushed a commit that referenced this pull request Nov 13, 2026
…st, so the child phase asserts the PINNED coordinate (#147)

* fix(check): a deploy's add_candy refs ride the resolved-project request, so the child phase asserts the PINNED coordinate

The child `check live` phase composed its plan from `rp.CandyModels[deploykit.BareRef(ref)]`
— an identity-keyed lookup — in a resolution that never MATERIALIZED the coordinate the
deploy pinned: the envelope's candy scan is reachability-scoped over the project's IMAGE
closure, and a deploy's `add_candy:` refs sit outside it (candy/plugin-build's own cache-key
comment states the consequence: ExtraCandyRefs "is the ONLY way a host-side plugin candy that
no image closure reaches enters rp.Candies at all"). So the phase read whatever OTHER
coordinate of that repo the closure reached — an older tag transitively required by a composed
layer — and, since #113, refused naming the mismatch. A bed's pin could be read, fetched and
still not change what the phase asserted (#112).

The fix is at the request, where the mechanism lives: the live and feature-live arms now pass
the deploy's own `add_candy:` refs (scoped with spec.ScopedExtraCandyRefs/spec.BoxScope, the
same construction the host's deployNodePluginContext uses, and over the same plugin-side
merged-tree resolver) as `ResolvedProjectRequest.ExtraCandyRefs`, so the pinned coordinate
becomes a CANDIDATE, the arbiter resolves it, and `candyAddSteps` reads the pinned model.

Evidence: the new in-repo R10 bed `check-addcandy-pin-honoured` (a disposable kind:local bed
driving the child phase of testdata/addcandy-pin-fixture, which pins layer-direnv at the newer
of two coordinates that project references) PASSES on this tree and FAILS on the previous
binary; unit tests pin the request field and the collection rule, both mutation-proven.

Agent: fix-112
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

* fix(check): name the bed that actually witnesses #112, and state the collector duplication

Round-1 review found the new unit test's header naming two beds that this diff never
creates (`check-addcandy-pin-advanced` / `-stale`): draft names, replaced by
`check-addcandy-pin-honoured` before the beds were authored and never re-read. The header
now names the real witness and describes what it actually does — the fixture pins
layer-direnv at the NEWER of the two coordinates the project references, so the phase must
compose the PINNED plan rather than refuse on the other one; it does not "advance a pin".

No behaviour change: comments only, in the file the finding named.

Agent: fix-112
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

* refactor(check): consume spec's ScopedAddCandyRefs, so this diff carries no duplicate traversal

Round-2 review was right that a stated duplication is not a cured one: `scopedAddCandyRefs`
re-implemented the host's ref-collection half in NEW code this change introduced, which R2
marks blocking regardless of which repo the other copies live in.

`opencharly/spec#310` now owns that traversal - spec.DeployNode.ScopedAddCandyRefs(scope),
beside the member-tree accessors it walks and the scope constructors it tags with - so this
package deletes its copy and calls the shared one. The plugin's own two facts stay here: WHICH
node the deploy name denotes (over the plugin-side merged tree, with the host's node-lookup
contract) and which composition scope the refs take (spec.BoxScope(name)).

The spec pin advances to the tag spec#310 minted, v0.2026317.1828. That tag also carries
opencharly/spec#308 (the #1131 connect-seam wire field), which is additive and changes nothing
this package consumes; the bump is go.mod + two go.sum lines and `go mod tidy` is clean.

Behaviour is unchanged, and that is measured, not assumed: the deleted local collector and the
shared method were dumped over the same node (a node with two add_candy refs, an in-substrate
member carrying a third, and a deploy-level sibling carrying a fourth that must NOT appear) and
the two dumps are byte-identical; the witness bed and both directions of the fixture A/B are
re-run on this head.

Agent: fix-112
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

---------

Co-authored-by: charly <[email protected]>
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