Repository navigation
feat(build): reuse an unchanged build's ref instead of minting a new CalVer - #70
Conversation
…CalVer Every build of a box minted a fresh CalVer ref, even when the artifact was byte-identical to the previous build, so the refs churned on every invocation and the build summary never named the resolved base/builder refs (opencharly/charly#1292). The drive now reads the built archive's image ID (buildkitdrive.ImageID) and compares it with the newest local ref of the same repository. When the artifact IS that ref's artifact and the charly store holds it, the build reuses that ref (nothing to annotate, store or import); when the artifact changed it mints a fresh CalVer. The predicate is the artifact's content address, never the clock: a tag change with the same digest is a BuildKit cache hit, and re-pointing an existing tag at different bytes would be worse than churn. Scope: a caller tag (any non-CalVer tag, e.g. a bed/release/user tag), a push target (its ref is baked into the buildctl argv) and a mirrored build keep the resolve-time ref; a direct buildImage caller keeps the ref it passed. A child's Containerfile is rewritten with the refs the drive actually published, so its ARG BASE_IMAGE / builder FROM names a real artifact (with a token boundary so a tag that is a prefix of another is not corrupted). The build summary now prints the resolved base/builder refs and the ref decision: --- Building <box> (base <ref>; builders <refs>) --- --- <box> -> <ref> (reused|built; image <id>; previous <ref>) --- *Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`* *Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)*
Review — BLOCKHead SHA: Change class: code/config (Go, Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
…rent artifact A changed artifact rebuilt inside the same CalVer minute minted the SAME tag, so the second build silently re-pointed it at different bytes — the exact harm the reuse predicate exists to prevent, left unfixed on the mint path. mintAutoRef now returns the bare CalVer when the minute is free, a numeric suffix (-2, -3) when a DIFFERENT artifact owns it, the same ref when it already names this artifact, and a content suffix only when every numeric slot is taken. isAutoTag accepts the suffix so a bumped tag is still recognised as the drive's own. *Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`* *Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)*
|
STATUS New head 1. R10 — a disposable bed was run.
2. R1 — the same-minute collision is FIXED in-tree, not parked. 3. R12 — candidate C is now measured, not argued. Live, against the real store: the same artifact built as 4. A1 — every changed file is accounted for. RCA for the missed control (this round). Mechanism: my first body treated "the claim is true" as sufficient — the collision was accurately described as pre-existing and C was correctly reasoned about — so neither was measured, and an accurately-described defect was parked instead of fixed. Missed control: the pre-push audit asked "is each statement true?" rather than R1/R12's actual question, "is each candidate instrumented and each defect either fixed in-tree or filed?". Blast radius: an unfixed tag re-point on the mint path, and two candidates accepted on argument. Root fix is in this diff: the collision bump plus its tests, and the live store instrument pasted under Agent: |
Review — BLOCKHead SHA: Change class: code/config (Go, Security screen: PASS — no secrets/egress/eval, no guardrail weakening, no rulebook/validator edit, scope matches the stated ref-decision change. Prior round (comment 7218098549, Blocks
Verdict: BLOCK ollama-cloud/deepseek-v4.1-flash — action-review. |
|
STATUS Both blocks are body/issue fixes (no code change). 1. R1 / CONC(b) — the 2. R10 — the step accounting reconciles. The bed's summary lists 16 steps, and all 16 are now pasted in order (the previous paste omitted step 13, the second RCA for the missed control. Mechanism: I transcribed the bed's phase lines from the runner log instead of from Agent: |
The header comment and the buildImage note still said a changed artifact mints a fresh CalVer, which stopped being the whole truth when mintAutoRef began bumping the minute (-2, -3) on a collision. The comments now name the bump, so the file describes what the code does (R5: a stale description of replaced behaviour is a leftover, not documentation). *Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`* *Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)*
Review — PASSHead SHA: Security screen: PASS — no secrets/egress/eval, no guardrail/rulebook/validator edits, no new deps, scope matches the stated ref-decision change. Prior-round comments re-derived against current head:
Non-blocking observation (not a rulebook gap): the Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
Summary
Fixes the mechanism in opencharly/charly#1292 after reproducing it: every box build minted a fresh CalVer ref per invocation, so a repeated build of an unchanged tree moved the
FROM/ARG BASE_IMAGErefs and the build summary never named them.The corrected RCA (measured, recorded on the issue): a changed tag with an unchanged digest is a BuildKit cache HIT, so tag churn alone does not invalidate layers. What actually re-runs is the build itself, and the floating
pacman -Syu/releases/lateststeps then change the bytes. This PR addresses the ref half:buildkitdrive.ImageID) and compares it with the newest local ref of the same repository. Same artifact + present in the charly store → reuse that ref (nothing to annotate, store or import); changed artifact → mint a fresh CalVer. The predicate is the artifact's content address, never the clock.mintAutoRefreturns the bare CalVer when the minute is free, a numeric suffix (-2,-3) when a DIFFERENT artifact already owns it, the same ref when it already names this artifact, and a content suffix only when every numeric slot is taken.isAutoTagaccepts the suffix, so a bumped tag is still recognised as the drive's own. Without this, two changed builds inside one minute re-pointed one tag at different bytes — the exact harm the predicate exists to prevent (measured below).ARG BASE_IMAGE/ builderFROMnames a real artifact (token-bounded, so:probe-1cannot corrupt:probe-12).--- Building <box> (base <ref>; builders <refs>) ---then--- <box> -> <ref> (reused|built; image <id>; previous <ref>) ---.ref_reuse_test.gopins the decision table, the collision bump, the tag grammar and the substitution boundary.ref_reuse.go's header and thebuildImagenote said a changed artifact mints a fresh CalVer — true beforemintAutoRef, incomplete after it. Both now name the minute bump, so the file describes the code (R5).candy/plugin-build/buildkit_tail_test.gois an import-grouping fix only (no behaviour change): it restoresgofmton a filemainleft unsorted, found by the package gate.Scope: a caller tag (any non-CalVer tag — a bed tag like
check-tmux-pod-2026.331.1225, a release/user tag) names the artifact and is kept; a push target (its ref is in the buildctl argv) and a mirrored build keep the resolve-time ref; a directbuildImagecaller keeps the ref it passed.The 100 GB BuildKit GC budget (the other half of the cache story) is in opencharly/sdk#650; the
defaults.buildkitsurface is opencharly/spec#447 (merged) + the plugin-build daemon-config branch. This PR is independent of both.How tested
Unit coverage that fails without the change: the decision table (
TestChooseBuiltRef), the collision bump and its exhaustion (TestMintAutoRef), the tag grammar (TestIsAutoTag), and the token-bounded substitution (TestApplyRefSubstitutions,TestReplaceRefToken_DoesNotCorruptATagPrefix).Live, on the real daemon and engine. A minimal external-base probe (
testbase→testreuse) built twice back-to-back, both fully CACHED, with a charly binary built against this branch:No new tag on either repeat; the child's base ref was substituted to the reused one.
Disposable bed (
disposable: true), same branch binary and CalVer stamp.charly check run check-pod-overlayfromcharly/— all 16 steps fromsummary.yml, in order:summary.ymlreportsstatus: PASS, every stepok: true,len(steps) == 16. The three SKIPs belong to step 2's declaredcontext: [runtime]checks evaluated in box mode — the bed's documented mode split, not warnings. This is a fresh build AND acharly updaterebuild of the same images through the changed drive, at zero failures.Two more disposable beds were attempted; both failures are filed, not parked:
check-tmux-pod—[image-build]PASS 4m44.88s,[check-image]PASS 21.9s, then[check-live]FAIL: thetmux-roundtripcheck declares notimeout:and was killed at the ~2m never-hang ceiling. check-tmux-pod's tmux-roundtrip check has no timeout, so the ~2m never-hang ceiling kills it distro-arch#84. Two furthercharly box build check-tmux-boxruns against those artifacts reused every ref (arch,arch-builder,check-tmux-box), minting nothing.check-boxload-pod—[image-build]FAIL at the container-nesting candy's build-contextrun:(podman pull quay.io/libpod/alpine:latest→ exit 125 "no such file or directory", 0.159s): a BUILD-scope step depends on a working nested-podman runtime. build-context pre-pull runs podman unconditionally, so an image composing this candy cannot build when nested podman cannot initialise layer-container-nesting#21. It is filed because R1 requires a surfaced failure to be fixed or filed, even when no path from this diff reaches it.Spike
RCA claim: the per-build ref churn is real, but a tag change alone does not invalidate the cache; the artifact's content address is what must govern the ref.
Candidates, each with its instrument and pasted output:
check-tmux-boxbuilds above. Result:reusedon every repeat, no mint, the child's base rewritten. Works.probe-c-1, then underprobe-c-2, then the store's own index read back:Defects the spike found and this PR fixes:
LocalImageInfo.IDis bare hex whilebuildkitdrive.ImageIDreturnssha256:…; the first implementation compared them raw and never matched (fixed bysameDigest, pinned by a test).plugin-boxalways sends a computed CalVer inBuildRequest.Tag, so "an explicit--tag" was indistinguishable from the drive's auto tag. The decision now uses the TAG GRAMMAR (a bareYYYY.DDD.HHMM[-N]is the drive's own; every other tag is the caller's) andbuildImagetakes an explicit reuse policy so direct callers keep their ref.mintAutoRef).Winner: B. RCA verdict: confirmed — B reuses the ref on the live path, and the pre-change red is reproduced.
Rulebook compliance
build/generate/go/strict-policy/check/git-workflowloaded before the work.check-tmux-podlive-phase failure is a bed defect (notimeout:on the probe) filed as check-tmux-pod's tmux-roundtrip check has no timeout, so the ~2m never-hang ceiling kills it distro-arch#84; thecheck-boxload-podbuild failure is filed as build-context pre-pull runs podman unconditionally, so an image composing this candy cannot build when nested podman cannot initialise layer-container-nesting#21 (a build-scopepodman pullin the container-nesting candy).chooseBuiltRef), one minter (mintAutoRef), one substitution (replaceRefToken), one ref grammar (isAutoTag).charly version→2026.330.1332), whichcharly check runrequires.charly check run check-pod-overlayPASSED end to end (16 steps,status: PASS), including the image build, a genuinecharly updaterebuild, and a post-rebuild live check, on a binary built from this branch and CalVer-stamped. The other two beds attempted carry unrelated failures recorded above; thetmux-roundtriptimeout is filed as check-tmux-pod's tmux-roundtrip check has no timeout, so the ~2m never-hang ceiling kills it distro-arch#84.Change classification
A local build whose artifact is unchanged now keeps its existing ref instead of minting a new one; a changed artifact rebuilt inside one CalVer minute gets
-2/-3instead of overwriting; push targets, mirrored builds, caller-tagged builds and direct callers are unchanged. Breaking change + rollback: none — the ref policy is internal to the drive; rollback is a revert of this squash.Filed issues
check-tmux-pod'stmux-roundtripcheck declares notimeout:, so the ~2-minute never-hang ceiling kills it on a cold run (surfaced while proving this PR; the build phases pass).podman pullunconditionally, so an image composing it cannot build when nested podman cannot initialise (surfaced bycheck-boxload-pod).Agent:
jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5· OpenCode sessionses_de3fa473bffeFiBo62whHxDPE5Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)