Skip to content

fix(container): refuse a stale short-name election in the build-scope verdict resolver - #29

Merged
atrawog merged 8 commits into
mainfrom
feat/check-box-target-image
Aug 15, 2026
Merged

atrawog merged 8 commits into
mainfrom
feat/check-box-target-image

Conversation

@atrawog

@atrawog atrawog commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Round 5 — a regression THIS chain introduced, and the gate that missed it

Unifying the resolver's two recency orderings into one moreRecent comparator
made the staleness guard a tautology, and it shipped green. With both the
election's sort and the newest-build scan using the same total order, cands[0]
IS the maximum the scan returns — so NewestBuildRef == Ref always and
RefuseIfStale had nothing to compare. The guard could never fire.

Why the suite stayed green is the more useful part. Every refusal test used
the two-family label split, where the newest-build scan walks the WIDER union and
can still differ. None covered a single-family stale election — the exact
scenario the guard's own doc comment names: "an image built from a
differently-versioned source tree outranks a newer build"
. A whole class was
untested, so a dead guard passed.

The two orderings must differ in their PRIMARY key; the difference IS the
mechanism.

  • electionOrder — primary labelCalVer. Which artifact does this NAME mean.
    A short name refers to a box's content, not to whatever was compiled last.
  • buildOrder — primary created, deliberately blind to the content label.
    Which of these was BUILT most recently.
  • orderTail — the shared deterministic last resort. Arbitrary is fine;
    DISAGREEING is not, and two disagreeing last resorts were the genuine
    duplication (they refused a pair in which neither was newer).

R3 applies to the tail. It does not apply to two answers that are supposed to be
able to contradict each other — deduplicating those deletes the contradiction the
guard detects.

Coverage: TestResolveBuiltImageRef_SingleFamilyStaleElectionRefuses, written
before the fix and failing against the unified comparator:

--- FAIL: TestResolveBuiltImageRef_SingleFamilyStaleElectionRefuses
    ResolveBuiltImageRef(web) = "ghcr.io/opencharly/web:2026.227.0830", nil — want a REFUSAL

Each ordering level is now independently mutation-gated, one distinct test per
level — so a future unification cannot pass silently again:

mutation                                          gate that catches it
election loses its created key                    BedTaggedElectsNewest, BedTaggedFreshBuildIsNotRefused
buildOrder shares the election (the regression)    SingleFamilyStaleElectionRefuses
orderTail flips ref direction                      TiedKeysDoNotRefuse

All 14 resolver tests pass at the fix; live on real storage the guard resolves
and both verdict verbs name their artifact again.

Second validation round — four findings, all fixed

1. The gate did not engage either — third bed-by-coincidence in this cutover.
At the earlier 526s run, storage held exactly ONE image named check-agent-box,
so the election had a single candidate and the four box labels calls could not
discriminate. Green because there was nothing to decide. The gate of record is
now run 2026.227.1403 on the final tree
(PASS, 13 steps, 366s), and the
candidate set is recorded with it because a PASS line alone cannot show whether
an election happened:

1eb138cf  2026-08-15 14:05:37  check-agent-box:check-agent-pod-2026.227.1403
7c33f745  2026-08-15 13:43:01  check-agent-box:check-agent-pod-2026.227.1341

Both carry the SAME content label (2026.226.1600), so the election resolved
through the creation-time tiebreak — the exact code path under test — and the
guarded agent-capability-labels step passed against it.

Findings 2-4 detail is in opencharly/charly#278; the spec half carries the
Created comment correction and the tiebreak alignment.

⚠️ CORRECTION — the first version of this fix was blocked, and rightly

A validator proved the guard blind to bed tags: check box docs-site-app
certified an image ~17 hours old, green, exit 0 — the very defect this PR
exists to remove, sailing past the new guard. Reproduced independently with my
own binary before designing the fix.

Root cause, deeper than the symptom and not new. ExtractCalVerTag is not
total over the tags charly mints: charly box build --tag REPLACES the CalVer
tag, so every bed build carries check-<bed>-<calver>, which is not three
decimal dot-parts and reads as EMPTY. With the content label tied across one
source tree and the tag key empty for every candidate, the election fell to a
lexicographic last resort and elected the OLDEST build — while the guard's own
"newest build" probe returned "" and treated that as "nothing to worry about".

This had already been root-caused, and routed around rather than fixed.
candy/plugin-check/live_image.go:14-22 names the mechanism verbatim, from
2026-08-05, including "the OLDEST local build of the box won". That fix made
the LIVE path ask the running container which image it is — an authoritative
source a build-scope verdict does not have — so the resolver kept the flaw and
this guard was built on top of it.

The fix keys build recency on the image's CREATION TIME. It is the only key
total over arbitrary --tag values, it agrees with the tag CalVer wherever that
key worked, it does not tie, and it costs nothing: it rides the same
images --format json rows Size already comes from. The content label stays
the election's PRIMARY key; creation time replaces the tag as the tiebreak, with
the tag kept as a tertiary for builds sharing a second under parallel load.

Two properties only expressible once the ordering is real:

  • SameArtifact — many tags on ONE image id are one artifact, so there is
    nothing older or newer to arbitrate and the guard stays silent instead of
    refusing a box against itself. This also removes the false-refusal face the
    validator found.
  • OrderKnown — when any candidate reports no creation time the guard
    REFUSES with an explicit "could not establish which build is newest" rather
    than passing. Permissive-on-unknown is the same class as the silent-pick
    defect this cutover removes, so it is not kept as a convenience.

A second finding, reported twice independently, is fixed here too: a verdict
verb printed NO artifact identity when it bailed. check box returned before its
Image: line whenever the image carried no baked plan, so exactly the artifacts
where provenance matters most produced no ref and exited 0 — while the mitigation
this cutover told operators to use was "read the Image: line". Both
build-scope verbs now print it FIRST, on every path.

The gate moved to the bed that can actually fail. check-marketplace passed
by naming coincidence (marketplace-app had no CalVer-tagged sibling, so the
guard never engaged). box/arch's check-agent-pod runs the guarded verb with a
BARE short name four times against a box it builds under a bed tag — the exact
shape at issue. PASS, 13 steps, 526s, which also settles the open scope
question: the resolver fix is sufficient, box/arch needs no change, the batch
stays five repos.

### the validator's live reproduction, on the fix
$ charly check box docs-site-app
Image: ghcr.io/opencharly/docs-site-app:check-docs-2026.227.1227   ← the newest build

### provenance on the no-plan path
$ charly check box fedora-nonfree:2026.227.1139
Image: ghcr.io/opencharly/fedora-nonfree:2026.227.1139
No plan steps defined for this image.

### the three new gates, failing on the BLOCKED body
--- FAIL: TestResolveBuiltImageRef_BedTaggedElectsNewest
    resolve = "…:check-docs-2026.226.1543", want "…:check-docs-2026.227.1227"
--- FAIL: TestResolveBuiltImageRef_BedTaggedFreshBuildIsNotRefused
    resolve = "…check-agent-box:2026.216.1908", want "…:check-agent-pod-2026.227.1300"
--- FAIL: TestResolveBuiltImageRef_RefusesWhenOrderUnknown
    no refusal when the ordering could not be established

Everything below this line was written for the first version; the evidence it
cites still holds, but read the ordering description above as authoritative.
main was merged in (never rebased) to clear a submodule-pointer conflict.

Summary of changes

charly check box <box> could certify an image that was not the one you built, report every step green, and give no sign. This is the resolver half of the fix; the emitter half is opencharly/sdk, the call sites are opencharly/charly.

Measured 2026-08-15 (day 227): a check: step was added to a candy, the box rebuilt as ghcr.io/opencharly/fedora-nonfree:2026.227.0835 / :0836, and charly check box fedora-nonfree printed Image: ghcr.io/opencharly/fedora-nonfree:2026.216.1908 with 5 passed, 0 failed — the OLD baked plan, the new step absent entirely. Two shapes in ResolveLocalImageRef reach that outcome, both traced against the real image store rather than reasoned about:

  1. candidates split into a LABEL family (ai.opencharly.box == <short>) and a NAME family (trailing repo segment matches); the label family is taken WHOLE and the name family discarded (cands := labelCands; if len(cands)==0 { cands = nameCands }). A build whose label disagrees with its own repo name lands in the name family and is dropped regardless of how much newer it is.
  2. the election's PRIMARY key is the content-derived ai.opencharly.version label with the per-build tag only a tiebreak, so an image built from a differently-versioned source tree (a sibling worktree, a pulled release) outranks a newer build regardless of when either was produced.

Concrete edits, all in container/local_image_coneb.go + spec/image_errors.go:

  • LocalImageResolution — the full answer: the elected Ref, the NewestBuildRef (highest build-tag CalVer across BOTH candidate families), and Pinned.
  • ResolveLocalImage — the single body doing the candidate gather, the ordering, and the ambiguity error. ResolveLocalImageRef becomes a thin wrapper returning .Ref (R3 — one gather, one ordering).
  • ResolveBuiltImageRef — resolves, then REFUSES when the elected image is not the newest local BUILD, wrapping spec.ErrStaleLocalImage and naming both refs plus the runnable pinned re-invocation.
  • LocalImageResolution.RefuseIfStale + newestBuildRef helper.
  • spec.ErrStaleLocalImage — new sentinel next to ErrImageNotLocal.
  • container/local_image_coneb_test.go — five tests over a fixture reproducing the measured storage byte-for-byte.

The election itself is UNCHANGED. Every consumption path (deploy, charly vm build, builder bootstrap, kube preresolve) keeps the lenient ResolveLocalImageRef; only the verbs that pronounce a verdict on an artifact opt into the guard. Changing the primary key globally would change what charly update and the deploy paths resolve to — far broader than this defect justifies, and with its own wrong case (a colleague's build from older sources winning). A stale check that errors is recoverable; one that PASSes is not.

Change class

cross-repo — charly-or-sdk Go.

Landing order (producer → consumer): spec (this PR) → sdk → plugins → docs → charly.

  • opencharly/spec — this PR (the resolver + the sentinel).
  • opencharly/sdk — deploykit emits the box's LEAF name into ai.opencharly.box; kit re-exports the new resolver surface.
  • opencharly/plugins, opencharly/docs — regenerated skill + site page.
  • opencharly/charly — the three call sites, the check skill source, the gitlink bumps.

How R10-tested — exact gate, commands, and pasted output

  • The gate for this change class: the resolver is reached by a build-scope check verb, so the gate is charly check run <bed> on a bed that exercises the changed path, plus per-module go test / golangci-lint. The bed is check-marketplace, chosen deliberately: its plan runs charly box labels marketplace-app host-side with a BARE short name, so it is the bed that could actually REGRESS from this guard — not the most convenient green one. Picking the bed that can fail is the point.
  • Eval beds run: check-marketplace | pod | ok | 13 steps | 370s — run calver .check/check-marketplace/2026.227.1148/, binary charly version = 2026.227.1116 (the one binary every step below ran on). Single-bed gate: this change is a resolver used identically by every bed's PINNED check step, and check-marketplace is the only bed whose plan reaches it UNPINNED. Not a concurrency-class change (see below), so no roster batch.
  • Fresh rebuild: R9 satisfied — the binary was rebuilt from this source with task build:binary and ./bin/charly version reports 2026.227.1116; no .go file under the changed packages is newer than bin/charly. The bed's own update (97s) + check-live-rebuild (37s) legs are the fresh-rebuild gate and both passed, at ZERO warnings.
  • Did the CHANGED code path execute live? Yes, including the NEW ERROR BRANCH. RefuseIfStale fired live on real podman storage, and the success path ran in the bed. One caveat, stated plainly: in opencharly/charly one of the three call sites (box feature run) could not execute because that verb is unreachable for a separate pre-existing reason — that caps the tier at analysed on a live system. Nothing in THIS repo's diff is unexecuted.
  • Concurrency: N/A — this changes a read-only probe of local image storage (podman images + label decode). It takes no lock, mutates no shared state, and touches neither the loader walk, the deploy ledger, the resource arbiter, nor any build lock.
### The refusal, live on real storage — produced with charly commands only
### (the same box built from two project roots whose rpmfusion versions differ:
###  the multi-worktree shape, no fixtures, no hand-tagging)

$ ./bin/charly check box fedora-nonfree
charly: error: command "check": short name resolves to a stale local image:
"fedora-nonfree" resolves to ghcr.io/opencharly/fedora-nonfree:2026.227.1139,
but ghcr.io/opencharly/fedora-nonfree:2026.227.1145 is a newer local build of the
same box. A build-scope verdict on the older artifact would certify the wrong
image, so charly refuses to choose for you. Re-run naming the artifact you mean —
`fedora-nonfree:2026.227.1145` for the newest build, or any full ref
exit=1

### The same refusal from the second verdict verb
$ ./bin/charly box labels fedora-nonfree
charly: error: command "labels": short name resolves to a stale local image: ... (identical)

### The pinned escape hatch — RefuseIfStale returns nil, the plan runs
$ ./bin/charly check box fedora-nonfree:2026.227.1145
Image: ghcr.io/opencharly/fedora-nonfree:2026.227.1145
  SKIP  run execute the neighboring command  ...  skipped — verify-only mode (mutating step)
  PASS  check the RPM Fusion free repo definition file is present on disk  ...  ok
  PASS  check the rpmfusion-free-release package is recorded in the rpm database  ...  installed
  PASS  check the RPM Fusion nonfree repo definition file is present on disk  ...  ok
  PASS  check the rpmfusion-nonfree-release package is recorded in the rpm database  ...  installed
  PASS  check the free repo file declares the rpmfusion-free repository section header  ...  ok
6 steps: 5 passed, 0 failed, 1 skipped
exit=0

### R10 bed — .check/check-marketplace/2026.227.1148/summary.yml (every step ok: true)
image-build 52s | check-image 20s | deploy-add 27s | config 19s | start 17s
bring-up-members 0s | check-live 51s | feature-run 17s | update 97s
check-live-rebuild 37s | feature-run-rebuild 16s | cleanup 16s | cleanup-members 0s
total_seconds: 370   ok: true          -> PASS (steps=13), zero warnings

### The bed step that exercises this resolver UNPINNED (check-live.log:23);
### its command is `${CHARLY_BIN} box labels marketplace-app`, in_container: false
PASS  check the marketplace-app image carries the composed ripgrep skill in its
      ai.opencharly.skill label (R8 — skills are readable from the image, no fetch)
      [marketplace-skill-label]  exit=0
  ... and again identically in check-live-rebuild.log after the fresh update.

### R10 coverage that FAILS without this change — guard call removed from
### ResolveBuiltImageRef, nothing else touched:
=== RUN   TestResolveLocalImageRefShortTaggedPinsExactBuild
--- PASS
=== RUN   TestResolveLocalImageRef_NeverReturnsSiblingDeployAlias
--- PASS
=== RUN   TestResolveBuiltImageRef_RefusesStaleElection
    local_image_coneb_test.go:287: ResolveBuiltImageRef(fedora-nonfree) = "ghcr.io/opencharly/fedora-nonfree:2026.216.1908", nil — want a refusal: ghcr.io/opencharly/fedora-nonfree:2026.227.0836 is a newer local build
--- FAIL: TestResolveBuiltImageRef_RefusesStaleElection (0.00s)
=== RUN   TestResolveLocalImageRef_LenientFormStillElects
--- PASS
=== RUN   TestResolveBuiltImageRef_PinnedInputPassesThrough
--- PASS
=== RUN   TestResolveBuiltImageRef_ConsistentLabelsElectNewestBuild
--- PASS
=== RUN   TestResolveBuiltImageRef_SiblingAliasIsNotANewerBuild
--- PASS
FAIL	github.com/opencharly/spec/container	0.003s

### The tests DISCRIMINATE: exactly one moves, and it fails with the incident's
### literal ref (:2026.216.1908) — the same ref the original repro printed.
### === HEADS-UP FOR THE VALIDATOR: spec/proc fails in a TMPDIR-exported shell ===
### Running the spec suite in a session whose TMPDIR is exported produces:
$ go test ./...
--- FAIL: TestSweepStaleTemps_UnheldCreatorIsSwept (0.01s)
    temphold_test.go:87: the pre-fix creator shape survived the sweep — this control is no longer reproducing the deletion the fix prevents, so the held-temp test above proves nothing
--- FAIL: TestSweepStaleTemps_ReleasedTempIsSwept (0.01s)
    temphold_test.go:106: SweepStaleTemps() left a RELEASED stale temp behind (stat err = <nil>) — the leak the sweep exists to prevent
FAIL	github.com/opencharly/spec/proc	0.298s

### These are NOT this change — nothing in this diff touches spec/proc. Root cause,
### RCA'd rather than dismissed: proc/cleanup.go:181 globs a HARDCODED "/tmp/" while
### the creators use proc.MkdirTempHeld("", ...) (sdk/deploykit/localpkg.go:198,252),
### which honours $TMPDIR — so on a TMPDIR-set host the sweep never sees the temps it
### exists to reap. The tests are honest; the sweep is the R4 environment-specific
### defect. That is separable finding C, reported with an assigned owner.
### Proof it is environmental and not the diff — the SAME tree, TMPDIR unset:
$ env -u TMPDIR go test ./...
ok  climodel · container · exec · exitcode · hostenv · internal/wiregen · ops
ok  phase · proc · refs · spec · transport          (12/12 packages, proc INCLUDED)
### Also verified against the UNMODIFIED tree (git stash): identical two failures,
### so it predates this branch.

### File restored via `git checkout --` immediately; tree is clean.

$ go test -count=1 ./container/
ok  	github.com/opencharly/spec/container	0.004s

$ golangci-lint run ./container/...
0 issues.
exit=0

Attribution tier

analysed on a live system.

Every changed path in THIS repo executed live, including the new error branch, and the R10 bed passed with its fresh-rebuild leg. The tier is nevertheless not fully tested and validated, because the cutover spans repos and one of its three call sites in opencharly/charly (box feature run) could not be exercised: that verb is unreachable on a clean baseline (it routes to the top-level charly feature grammar) and its hidden engine leaf check __feature-box is not reachable either — verified, not assumed. The table requires changed paths executed live; one did not, so the whole cutover claims the lower tier.

Stated so the validator is not misled in the other direction: the lower tier's own wording ("the complete fresh-rebuild R10 did not pass") understates this case — the R10 bed DID pass. The downgrade rests purely on that one unexecuted call site.

Trailer: Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system).

Harness rulebook compliance — state HOW each is satisfied

  • R0 skills: loaded before any source was read — /charly-check:check (the verb surface + the R10-gate-by-change-class matrix that selected the bed), /charly-internals:go, /charly-internals:plugin, /charly-internals:git-workflow, /charly-internals:strict-policy, /charly-build:build (the CalVer-only tagging contract this resolver implements).
  • R1 RCA + zero warnings: the reported symptom was root-caused to TWO independent mechanisms before a line was written, each confirmed with podman image inspect against the live store (the label values fedora.fedora-nonfree vs fedora-nonfree, and the label-vs-tag CalVer split across :2026.227.0945 / :2026.227.0942) — not inferred from reading. Further anomalies surfaced mid-work and were each RCA'd before being classified, none dismissed as flake or environmental (see R2). Bed output has zero warnings (grep -rin warn .check/check-marketplace/2026.227.1148/*.log → empty).
  • R2 no out-of-scope: FOUR separable defects surfaced and NONE is parked. A fourth — candy/plugin-clean's retention sort sharing this cutover's ordering blind spot — was found late and FOLDED INTO this cutover rather than named as separable, because it is the only surface here that DESTROYS an artifact rather than producing a false answer, and it consumes the same struct on the same root cause. The other three are RCA'd to file:line, named in the superproject CHANGELOG/<CalVer>.md "Separable findings" section, and reported to the orchestrator, which has assigned owners: (1) an imported box bakes NO ai.opencharly.description (CollectDescriptions → cfg.BoxConfig/WalkBaseChain, flat map lookups with no namespace descent) — opened as its OWN cutover; (2) charly box feature run unreachable; (3) spec/proc.SweepStaleTemps globs a hardcoded /tmp/ while its creators honour $TMPDIR — both joined the check-verb-correctness batch. Finding 1 was deliberately NOT widened into: its fix is making the deploykit collector family namespace-aware, an architectural change outside check-verb correctness.
  • R3 no duplication: the whole point of the shape. ResolveLocalImageRef and ResolveBuiltImageRef are both thin wrappers over ONE ResolveLocalImage body — one candidate gather, one ordering, one ambiguity error. No second copy of the resolution logic, and the guard is at the resolver rather than repeated at each of the three call sites. This also retires a per-caller workaround: the R10 bed sequence already pinned <image>:<run-tag> for exactly this reason (candy/plugin-check/bed_run.go's runTaggedImageRef, with a comment saying so) — the same problem, second surface, so the fix belongs here.
  • R4 no workaround: no sleep, retry, magic number, or env shim. The staleness question is answered from data already gathered (the candidate set), not by probing again. Every image-store observation in this PR came from charly verbs (box build, box list tags, box labels, check box) except the read-only podman image inspect diagnostics used during RCA, which observe rather than operate.
  • R5 hard cutover + grep: nothing was removed or renamed, so there is no deleted identifier to sweep — ResolveLocalImageRef intentionally survives as the lenient form for every consumption path, and its doc comment now says so explicitly rather than leaving the split implicit. No transitional or dual-mode path exists in the final code: the guard is either called or not, per call site.
  • R6 git safety: git status checked before every destructive action. The one stash used (an RCA baseline check) was git stash push + pop with the tree verified clean on both sides. The temporary fix-reverts used to produce the failing-test proof were restored with git checkout -- <file> and the tree re-verified 0 dirty in all five repos.
  • R7 runtime gate: satisfied — charly check run check-marketplace end to end (build → check box → deploy → check live → fresh update → check-live-rebuild → teardown), not just go test. Output pasted above.
  • R8 artifact invariants: N/A for this repo's diff (no generation change here). The companion sdk PR carries the label assertion, read back post-build with charly box labels.
  • R9 binary == source + deps: binary rebuilt via task build:binary, charly version = 2026.227.1116, and find <changed pkgs> -name '*.go' -newer bin/charly is empty. No new runtime OS dependency, so pkg/arch/PKGBUILD is untouched.
  • R10 disposable + coverage: check-marketplace is disposable: true (pod: with disposable: true, lifecycle: dev); no non-disposable target was touched. Fresh rebuild via the bed's own update leg, zero warnings. Coverage that fails without the change is pasted above and DISCRIMINATES — exactly one of seven tests moves when the guard is removed.
  • RDD / ADE / SDD: RDD — the two root causes are the high-risk claims here, and both were proven against the live image store before any edit; the refusal was then proven live on real storage rather than argued from the unit test. ADE — N/A for this repo (no candy in the diff); the superproject PR's candy edit keeps its description: + plan: and charly box validate exits 0. SDD — N/A, no .cue edit; the new sentinel is a plain Go error var alongside the existing ErrImageNotLocal, not a schema-shaped type.
  • Hard cutover: ONE atomic commit in this repo. No TODO, no phase 2, no deferred half. The cross-repo split is by REPO, not by phase — every repo's half lands in the same batch, in the producer→consumer order above.
  • Kernel/plugin boundary law: N/A — no kernel change. This is the spec/container fabric slice, a kind-blind host primitive (container-CLI probes + ref-shape predicates). No concrete-kind schema, kind-word switch, or per-kind map is introduced; charly/ import purity is untouched (this repo is github.com/opencharly/spec, which charly/ is explicitly permitted to import).
  • Disposable-only autonomy: the only destroy/rebuild was the check-marketplace bed, declared disposable: true. The live refusal experiment created image TAGS only (via charly box build) and destroyed nothing.
  • Clean architecture + Go gates: gofmt -l . empty; golangci-lint run ./... → 0 issues, exit 0; go vet clean; go test ./... green. One honest note: spec/proc fails two tests in a session whose TMPDIR is exported, and passes under env -u TMPDIR — that is separable finding 3 (the sweep hardcodes /tmp/), unrelated to this diff and reported for its own cutover.
  • CHANGELOG: CHANGELOG/2026.227.1157.md staged — placeholder CalVer, the pr-validator finalizes it at merge.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

… verdict resolver

`charly check box <box>` could certify an image that was not the one you built,
report every step green, and give no sign. Measured 2026-08-15: a fresh build
tagged :2026.227.0836 while `check box fedora-nonfree` ran :2026.216.1908 and
reported 5 passed, 0 failed against the OLD baked plan.

Two shapes reach that outcome, both live on a multi-worktree host:

- the label family (`ai.opencharly.box == <short>`) is taken WHOLE and the name
  family discarded, so a build whose label disagrees with its own repo name is
  invisible to a resolve of that name (the emitter half is fixed in sdk);
- the election's PRIMARY key is the content-derived `ai.opencharly.version`
  label with the build tag only as a tiebreak, so an image built from a
  differently-versioned source tree outranks a newer build outright.

ResolveLocalImage returns the full answer (elected Ref + NewestBuildRef across
BOTH families + Pinned); ResolveLocalImageRef and the new ResolveBuiltImageRef
are thin wrappers over that one body (R3). ResolveBuiltImageRef refuses when the
election is not the newest local BUILD, wrapping the new spec.ErrStaleLocalImage
and naming both refs plus the pinned re-invocation.

The election itself is unchanged: every consumption path (deploy, vm build,
builder bootstrap) keeps it. Changing its primary key would change what `charly
update` and the deploy paths resolve to — broader than this defect justifies,
and with its own wrong case. A stale check that errors is recoverable; one that
PASSes is not.

Escapes (pre-existing): a full ref, or the `<box>:<calver>` pin — which is why
the R10 bed sequence, which pins `<image>:<run-tag>`, never reaches the guard.

Coverage: five tests over a fixture reproducing the measured storage; the gate
fails on the pre-fix body (returns :2026.216.1908, nil error).

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
@atrawog

atrawog commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

charly/pr-validator: CHANGES REQUESTED — #29

Fresh independent evaluation, head 2655e05b93475c33dc8845cbbe13b70688e15e46. I re-derived every claim
rather than reading the PR body for them; the reproductions below are my own.

This repo is where the blocking defect lives, so it is also where the fix belongs. Nothing in the
five-repo batch merges until it is corrected.

Blocking defect — newestBuildRef is not total over the tags charly actually mints

The guard defines "the newest local BUILD" as the candidate with the highest CalVer-parsable build tag
(spec/container/local_image_coneb.go:373 newestBuildRef → ExtractCalVerTag, which returns "" for any
tag that is not three decimal dot-parts).

But charly box build <box> --tag <anything> replaces the CalVer tag rather than adding to it
(sdk/buildkit/config_resolve.go:311 resolveTag: Tag == "auto" → calver, otherwise the authored/--tag
value wins). Every bed build therefore produces exactly one tag, check-<bed>-<YYYY.DDD.HHMM>, which
ExtractCalVerTag reports as empty — a fact this repo already documents at
candy/plugin-check/live_image.go:14-18 ("ExtractCalVerTag reports as EMPTY for a bed tag").

So the staleness comparison is blind to a large and ordinary class of local builds. Two consequences, both
reproduced.

(1) Blind spot — the certification this cutover exists to prevent still happens, silently

Live, on this host, with this PR's binary (./bin/charly version = 2026.227.1116), two local builds of
docs-site-app exist and the unpinned verdict verb certifies the older one, green:

$ ./bin/charly box list tags | grep docs-site-app
docs-site-app	ghcr.io/opencharly/docs-site-app:check-docs-2026.227.0846	2026.215.1207
docs-site-app	ghcr.io/opencharly/docs-site-app:check-docs-2026.226.1543	2026.215.1207

$ ./bin/charly check box docs-site-app
Image: ghcr.io/opencharly/docs-site-app:check-docs-2026.226.1543
21 steps: 17 passed, 0 failed, 4 skipped
exit=0

:2026.226.1543 is ~17 hours older than :2026.227.0846. Both carry non-CalVer bed tags, so
newestBuildRef returns "", RefuseIfStale short-circuits on its r.NewestBuildRef == "" arm, and the
election falls through to its lexicographic last resort (cands[i].ref < cands[j].ref), which picks the
older string. This is the identical failure shape as the incident in the PR body — a green verdict against
an artifact that is not the newest local build, with no sign — and it is not caught by the new guard.

That also makes the prose shipped in opencharly/plugins#173 / opencharly/docs#55 /
candy/charly-check/charly.yml untrue as written: "the verb REFUSES when that election is not the
newest local BUILD of that box"
. It does not, for any box whose builds carry --tag values.

(2) False refusal, with remediation advice pointing AT the stale artifact

The mirror case: when the fresh build carries a bed tag and an older plain-CalVer build is also present,
the election correctly picks the fresh one, newestBuildRef names the old one (it is the only CalVer-tagged
candidate), and RefuseIfStale fires — refusing a correct election and telling the operator to re-run
against the stale image. Probe over the unmodified PR tree (spec/container, fixture only):

CONTENT-NEWER: lenient elects "ghcr.io/opencharly/check-agent-box:check-agent-box-2026.227.1148"
 | guarded -> ref="" err=short name resolves to a stale local image: "check-agent-box" resolves to
 ghcr.io/opencharly/check-agent-box:check-agent-box-2026.227.1148, but
 ghcr.io/opencharly/check-agent-box:2026.216.1908 is a newer local build of the same box. ...
 Re-run naming the artifact you mean — `check-agent-box:2026.216.1908` for the newest build, or any full ref

:2026.216.1908 is the older image. The refusal message instructs the operator to certify exactly the
artifact the guard exists to keep them away from.

Why this is not hypothetical — a second unpinned bed surface was missed

The PR states: "check-marketplace is the only bed whose plan reaches it UNPINNED." That is not correct.
box/arch/charly.yml (bed check-agent-pod, disposable: true) runs the guarded verb with a bare short
name
four times in one in_container: false step, id agent-capability-labels:

${CHARLY_BIN} box labels check-agent-box --format agent_provide | grep -q '"provider":"pi"'
${CHARLY_BIN} box labels check-agent-box --format agent_provide | grep -q '"provider":"tmux"'
${CHARLY_BIN} box labels check-agent-box --format terminal_profiles | grep -q '"claude-code"'
${CHARLY_BIN} box labels check-agent-box --format terminal_profiles | grep -q '"pi"'

That bed builds check-agent-box under a bed tag, i.e. shape (2) above. It was not run, and box/arch is
not among the five repos in this batch.

check-marketplace passed only because marketplace-app happens to have no CalVer-tagged sibling on the
bed host — its other local refs are ghcr.io/opencharly/check-marketplace:<CalVer> deploy aliases, which
shortNameMatchesRef filters out of the marketplace-app candidate set, leaving NewestBuildRef == "". The
bed passed by naming coincidence, not by a property the guard guarantees. The bed choice was the right
instinct; the run does not carry the weight the PR assigns it.

The guard does fire correctly where it can — the breakage is real too

For completeness, on the same host the intended behaviour is also live and is a genuine, broad behaviour
change on two very common commands:

$ ./bin/charly box labels arch
charly: error: command "labels": short name resolves to a stale local image: "arch" resolves to
ghcr.io/opencharly/arch:2026.206.0718, but ghcr.io/opencharly/arch:2026.226.0556 is a newer local build ...
exit=1

$ ./bin/charly box labels cachyos
charly: error: ... "cachyos" resolves to ghcr.io/opencharly/cachyos:2026.198.1538, but
ghcr.io/opencharly/cachyos:2026.226.0823 is a newer local build ...
exit=1

I judge that breakage acceptable and adequately disclosed — erroring with both refs and a runnable
re-invocation strictly beats answering wrong in silence, and the disclosure is in the PR body, the commit
message, all four CHANGELOGs, the help: text of all three verbs, and the skill/docs page. It is the
correctness of the comparison, not the decision to refuse, that blocks.

Root cause, one sentence

"Newest build" is derived from a CalVer-only tag parse, while --tag (and therefore every bed build) mints
tags that parse to nothing — so the ordering the guard rests on is partial where it must be total.
ParseLocalImagesJSON already reads Size off the same podman images --format json rows that carry
Created, so a build-recency signal that is total over every local image is one field away; whatever shape
the fix takes, the coverage must include a fixture whose candidates carry non-CalVer --tag builds, since
that is the case every current test omits.

Rulings on the questions the brief asked me to judge

  • Both root causes are real. Verified independently, not accepted. The label/ref disagreement is at
    sdk/deploykit/render_prep.go:110 and the resolver keys its label family on that equality at
    spec/container/local_image_coneb.go:260; the content-version-primary ordering is at lines 329-339 with
    the build tag only a tiebreak. Both hold.
  • Coverage discriminates. Re-derived in scratch worktrees, not read from the PR body. spec: removing the
    RefuseIfStale call moves exactly one test, TestResolveBuiltImageRef_RefusesStaleElection, failing with
    the incident's literal ref — ResolveBuiltImageRef(fedora-nonfree) = "ghcr.io/opencharly/fedora-nonfree:2026.216.1908", nil
    — while the other six resolver tests pass. sdk: reverting spec.LeafName(boxName) → boxName moves
    exactly one test, TestBuildBakedMetadata_BoxLabelIsLeafName (ai.opencharly.box = "fedora.fedora-nonfree").
    Both claims are true as stated. The coverage's gap is the --tag case above, not its discrimination.
  • The scoping seam is right. "Verbs that pronounce a verdict on a built artifact" is a real category, and
    it is the one where a wrong answer is undetectable — a consumption path that resolves an older image
    produces a deployment that fails its own live checks, whereas a verdict verb produces a proof that is
    indistinguishable from a true one. Refusing across consumption paths would break charly update on every
    multi-worktree host for no correctness gain. Including box labels is correct and I would have flagged
    its absence
    : the rulebook names charly box labels as the R8 artifact check, so reporting an older
    image's labels is the same false-proof class, and leaving it lenient would have been the R3 miss. I found
    no fourth verb in the category — check live reads the running container's ref
    (candy/plugin-check/live_image.go), box inspect reads charly.yml, and shell/vm build/builder
    bootstrap/kube preresolve are all consumption.
  • The rejected alternatives are correctly rejected. Making the newest build win globally would change what
    deploy, charly vm build and the pod path resolve to, and the label-CalVer-primary ordering is load-bearing
    — the comment at lines 265-277 records a prior cross-deployment image-crossing defect that this ordering
    plus the shortNameMatchesRef filter fixed. A --tag flag would be a second spelling of the already-existing
    <box>:<calver> pin (R3). The third option the spec CHANGELOG also addresses — silently re-electing the
    newest build in the verdict verbs — is rightly rejected: a verb whose answer becomes a proof must not guess.
  • Beds genuinely pin. candy/plugin-check/bed_session.go:348 sets imageTag := bedRunImageTag(bed, calver)
    unconditionally and non-empty, and bed_run.go:391,412 pass it through runTaggedImageRef, so the bed's own
    check-image step is always <image>:<run-tag> → requestedTag != "" → Pinned → the guard returns early.
    Confirmed. What is not protected is a bed's own plan: steps that shell out to a verdict verb unpinned —
    check-marketplace and check-agent-pod both do.
  • The tier is right, and the framing is fair, not self-serving. I verified the unreachability rather than
    accepting it: ./bin/charly box feature run fedora-nonfree → unknown feature subcommand "run";
    ./bin/charly check __feature-box fedora-nonfree → usage, exit=80; and charly check feature run routes
    to the deploy-scope mode (container charly-fedora-nonfree is not running), never to Mode:"feature-box".
    The third call site genuinely cannot execute. Claiming analysed on a live system rather than
    fully tested and validated is the correct read of the table, and the note that the lower tier's parenthetical
    understates the case is a transparency remark that claims nothing — it does not reach for the higher rung.
    Had this cutover been otherwise clean, I would have accepted the tier as stated.

What I verified green (so re-work does not re-litigate it)

  • spec: go test ./... green in every package except the two spec/proc SweepStaleTemps tests, which fail
    only with TMPDIR exported and pass under env -u TMPDIR — the separable defect, not this cutover's.
    golangci-lint run ./container/... ./spec/... → 0 issues.
  • sdk: go test ./deploykit/... ./kit/... green under the workspace; golangci-lint run ./deploykit/... ./kit/...
    → 0 issues.
  • charly: go test ./... green (120s, import-purity assertion included), candy/plugin-check and
    candy/plugin-box green.
  • The check-marketplace run artifacts under .check/check-marketplace/2026.227.1148/ exist and match the
    pasted summary; the marketplace-skill-label step is PASS in both check-live.log:23 and
    check-live-rebuild.log:22, as claimed.
  • The added prose is byte-identical across candy/charly-check/charly.yml, the plugins skill reference, and the
    docs page — the generated chain is consistent.
  • All five commits carry a correctly-formed Assisted-by: trailer and a CHANGELOG/2026.227.1157.md placeholder.

… blind to bed tags

The first version of this guard was blind on exactly the builds it most needed
to see, and a validator proved it live: `check box docs-site-app` certified an
image ~17 hours old, green, exit 0.

Root cause, and it is not new. `ExtractCalVerTag` is not total over the tags
charly mints: `charly box build --tag` REPLACES the CalVer tag, so every bed
build carries `check-<bed>-<calver>`, which is not three decimal dot-parts and
reports as EMPTY. With the content label tied across one source tree and the tag
key empty for every candidate, the election fell through to a lexicographic last
resort and picked the OLDEST build. That was already root-caused on 2026-08-05
for the LIVE path (candy/plugin-check/live_image.go names the mechanism verbatim,
including "the OLDEST local build of the box won") — that fix routed AROUND this
resolver by asking the container, so the flaw survived here, and the guard was
built on top of it.

Three shapes, one key:

- blind: all candidates bed-tagged → no tag CalVer anywhere → oldest elected, and
  newestBuildRef returned "" which the guard read as "nothing to worry about";
- misdirecting: a fresh bed-tagged build beside an older plain-CalVer one → the
  old image elected (an empty tag sorts last) and, depending on label versions,
  either silently certified or named as the "newest build" the operator should
  re-run against — a guard pointing at the artifact it exists to avoid;
- unknowable: permissive-on-unknown, which is the same class as the original
  silent-pick defect.

The fix keys build recency on the image's CREATION TIME (LocalImageInfo.Created,
read from the `images --format json` rows Size already comes from — no extra
process, no extra call). It is the only key total over arbitrary --tag values,
agrees with the tag CalVer wherever that worked, and does not tie. The content
label stays the election's primary key; creation time replaces the tag as the
tiebreak, with the tag retained as a tertiary for sub-second parallel builds.

Two properties creation time makes possible:

- SameArtifact: many tags on ONE image id are one artifact — nothing older or
  newer to arbitrate, so the guard stays silent instead of refusing a box
  against itself;
- OrderKnown: when any candidate reports no creation time the guard REFUSES with
  an explicit "could not establish which build is newest" rather than passing.

Coverage: eight tests over fixtures reproducing the measured host, including all
three shapes above. The three new gates fail on the blocked body — the bed-tag
election returns the 08-14 ref, the mirror case returns the stale plain-CalVer
ref, and the unknown-order case does not refuse at all.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
The CHANGELOG entry described the first fix's tag-keyed ordering, which a
validator blocked as blind to bed tags. Updated to describe what the branch
actually ships — creation-time ordering, the SameArtifact exemption, and
refuse-on-unknown — plus the six new coverage gates.

Assisted-by: Claude Code Anthropic Claude Opus 5 (documentation reviewed)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
…rrect a false comment

Two validator findings.

The election's final tiebreak is ascending ref; newestBuild's was descending.
They diverge only when two DISTINCT images tie on every recency key — same label
version, same creation second, no CalVer tag — but there they name different
refs, and RefuseIfStale compares refs rather than keys, so the guard refused a
pair in which neither is newer than the other. Distinct builds do share a
creation second under parallel load, so it was reachable, not theoretical.
newestBuild now uses the election's ascending last resort; gated by
TestResolveBuiltImageRef_TiedKeysDoNotRefuse, which fails with the descending
form (it refuses, naming one twin "a newer local build").

The comment "podman and docker both emit it" — the sentence justifying
refuse-on-unknown — was false. Measured: podman 427/427 rows, docker 0/3
(`docker images --format json` emits CreatedAt/CreatedSince). Docker's path is
degenerate well upstream of recency: JSON-LINES rather than the JSON ARRAY this
parser unmarshals, and no Names/RepoTags/Labels either. So refusing on unknown is
the correct behaviour there rather than an accident. The sibling claim in the same
function ("docker uses RepoTags" — that is the INSPECT shape) is corrected too:
an authoritative comment that does not match the system is the shape this cutover
exists to remove.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
…nd newestBuild

The two sides each defined their own last resort — the election ascending by ref,
newestBuild descending — so for two DISTINCT images tying on every recency key
they named different refs, and RefuseIfStale compares refs rather than keys: the
guard refused a pair in which neither was newer. Aligning the two definitions
would have fixed today's divergence while leaving two definitions of one order
that can re-diverge. moreRecent is now THE definition, used by both (R3).

The arbitrary last resort is fine precisely because it is shared: whatever it
picks, both callers agree, so an all-keys tie can never read as 'one of these is
newer'.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
…ade the guard a tautology

Unifying electionOrder and buildOrder into a single moreRecent was a regression,
and it shipped GREEN. Sharing the comparator made cands[0] identically the
maximum the newest-build scan returns, so NewestBuildRef == Ref always and
RefuseIfStale had nothing to compare: the staleness guard could never fire.

Every refusal test survived it because they all use the two-family label split,
where the newest-build scan walks the WIDER union and can still differ. No test
covered a SINGLE-family stale election — the exact scenario the guard's own doc
comment names — so the suite was green on a dead guard.

The two orderings must differ in their PRIMARY key, because the difference IS the
mechanism:

- electionOrder, primary labelCalVer — which artifact does this NAME mean;
- buildOrder, primary created, blind to the content label — which was BUILT most
  recently;
- orderTail, the shared deterministic last resort. Arbitrary is fine;
  DISAGREEING is not, and that was the genuine duplication (two last resorts that
  disagreed refused a pair in which neither was newer).

R3 applies to the tail. It does not apply to two answers that are supposed to be
able to contradict each other; deduplicating those deletes the contradiction the
guard exists to detect.

Coverage: TestResolveBuiltImageRef_SingleFamilyStaleElectionRefuses fails against
the unified comparator and passes here. Each ordering level is now independently
mutation-gated — dropping the election's created key fails the bed-tag tests,
sharing the comparator fails the single-family test, flipping the tail's ref
direction fails the tied-keys test.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
Renames the placeholder CHANGELOG stamp to the CalVer generated at merge and
rewrites its H1 to match. Documentation only — no code, schema, or test changes;
the validated tree is byte-identical to 91c7d20 apart from this rename.

Assisted-by: Claude Code Anthropic Claude Opus 5 (documentation reviewed)
Claude-Session: https://claude.ai/code/session_01Rt9KMZF6v3x1iL24M74dN2
@atrawog
atrawog merged commit bbb3c6a into main Aug 15, 2026
@aitrawog
aitrawog deleted the feat/check-box-target-image branch September 25, 2026 19:09
charly-auto-merge Bot added a commit that referenced this pull request Sep 25, 2026
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