Skip to content

the base builder is rebuilt under a new CalVer tag on every build, so no layer is ever reused #1292

Done

Description

@aitrawog

Category

category:delivery

Type

type:fix

Remedy / files the remedy will touch

the build's base-builder resolution — reuse a pinned/existing builder tag when its content is unchanged instead of minting a new CalVer tag per invocation

Cited design decision or org-rulebook rule (or none)

AGENTS.md R3, R7

Classification

Non-blocking — genuinely separable; left unclaimed for a later session to pick up.

Evidence (verified: commands with output, file:line, measurements)

$ podman images --format '{{.Repository}}:{{.Tag}} {{.CreatedAt}}' | grep arch-builder | sort -k2 | tail -4
ghcr.io/opencharly/arch-builder:2026.330.2011  2026-11-26 20:14:15 UTC
ghcr.io/opencharly/arch-builder:2026.330.2035  2026-11-26 20:37:42 UTC
ghcr.io/opencharly/arch-builder:2026.330.2137  2026-11-26 21:39:27 UTC
ghcr.io/opencharly/arch-builder:2026.330.2152  2026-11-26 21:53:03 UTC

# the openwebui Containerfile's base changed between two identical builds:
build A (contentstaging-2135): FROM ghcr.io/opencharly/arch-builder:2026.330.2035
build B (contentstaging-2135-b, same tree, same candy content): FROM …:2026.330.2152
wall: A 869 s, B 758 s — no layer reuse despite the content-addressed candy staging

Mechanism

Each charly box build that composes the arch-builder produced a NEW arch-builder image tag (four within 100 minutes), and the generated Containerfile's FROM resolves the newest store tag. Two builds of the SAME tree and the SAME candy content therefore used different base images (2035 then 2152), so every downstream layer was invalidated: 869 s and 758 s wall, with no reuse — even after the candy staging dir became content-addressed (verified: .build/_candy/openwebui.3dcd95a9ec44e5eb in both).

Missed control

Nothing asserts that the resolved base image ref is stable across builds of unchanged inputs, and the build summary does not show the base ref it resolved, so the churn is invisible in the logs.

Blast radius

Every image build that composes a builder (all CDI images): the builder stage and everything above it re-execute on every build, which is the dominant cost the pixi cache cannot offset.

Root fix

Resolve the builder to an existing tag whose content matches the current builder inputs (content-addressed or input-hash keyed), or record and reuse the resolved base ref; surface the resolved base ref in the build summary so churn is visible.

Spike (its result, or none with the reason)

Control: the same candy staging dir (content hash unchanged) produced two builds with different FROM refs and no layer reuse — the variable is the base ref, not the candy ref.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

Activity

  1. added
    category:delivery
    type:fix
    on Nov 26, 2026
  2. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    CLAIM

    Taking this. I reproduced the mechanism on this host and the issue's stated cause is only partly right: the per-invocation CalVer is real, but a changed tag alone does NOT invalidate BuildKit's cache (controlled child build with the same bound digest → same manifest, CACHED), and two same-tree builds with a warm cache produced identical image IDs. A cold rebuild of the same tree DID change both digests (arch 3d4f50→0cfb2d, arch-builder 6ec0a3→83f8a7), because the base/builder layers run pacman -Syu and fetch yay via releases/latest.

    Implementing the agreed option B: always rebuild, and reuse the existing ref only when the freshly built artifact's digest is unchanged (compare the archive's image ID via buildkitdrive.ImageID with the newest local ref for that repo), plus surface the resolved base/builder ref and the reuse/mint decision in the build output. The floating-upstream non-reproducibility is a separate finding I will file RCA-complete. Working in plugin-build first (self-contained), then the charly pin bump + R10 bed.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  3. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    STATUS — verified RCA (supersedes the issue's stated mechanism)

    I reproduced the churn and measured what actually invalidates the cache. The per-invocation CalVer is real, but a changed tag alone does NOT invalidate BuildKit; the layer loss comes from cache eviction + floating upstream inputs.

    Verified on this host (binary 2026.330.1332, buildkitd 0.35.1)

    1. Tag churn is real. Two box generate openwebui runs, same tree, 1 minute apart:

    run1 ARG BASE_IMAGE=ghcr.io/opencharly/arch:2026.331.0806  FROM arch-builder:2026.331.0806
    run2 ARG BASE_IMAGE=ghcr.io/opencharly/arch:2026.331.0807  FROM arch-builder:2026.331.0807
    

    diff of the two Containerfiles: only the tag suffix (arch, cachyos, intermediate, arch-builder). --tag probe-1292 gives arch:probe-1292 + arch-builder:<clock> (borrowed node keeps a clock tag).

    2. A changed tag with an unchanged digest does NOT invalidate. Controlled buildctl with the drive's own binding shape (--oci-layout ... --opt context:<ref>=oci-layout://...@<digest>): two children differing only in the ARG BASE_IMAGE tag text, bound to the same digest -> same manifest, second run #6 CACHED. A warm-cache rebuild of arch twice (tags 0809/0812) gave identical image IDs (3d4f502d / 6ec0a323).

    3. A real consumer DOES rebuild, because its parents' digests change. Tiny pixi-composing box, two builds (Containerfile diff = the two tag lines only):

    arch        7b1b4c35601c -> e43c1eaffe2c
    arch-builder f64685ad1cad -> 64b686fb70c9
    cachyos     c910025df26b -> b375f3c6e2f4
    testpixi    2616665a72cf -> 9958aaf72c95   (layers 0-4 identical, 5-8 changed)
    

    Both builds ~5m; the pixi stage re-ran.

    4. What actually re-runs (captured per-step output, which the drive currently discards; #1202). With a buildctl wrapper in PATH for box build arch.arch --tag gap-d:

    #7  [stage-0] RUN pacman -Syu ... curl ca-certificates   CACHED
    #9  [builder] RUN pacman -Syu ... nodejs npm            DONE (re-ran)
    #16 [builder] RUN pacman -Syu ... base-devel git        DONE / base-devel downloading+installing
    

    Same parent digest (arch config 53f3ea52f802; store payload sha256:3292800...). The builder's large RUN layers re-executed while the small arch RUN stayed cached - selective cache loss, not the tag. The evicted layers then re-run the floating inputs (below) and produce different bytes, which mints a new digest and a new tag.

    5. The cache is pruned by BuildKit's own GC default. buildkitd 0.35.1 started with no gc flags and a rendered config with no gc section (sdk/buildkitdrive/paths.go deliberately leaves GC unset: 'GC is ... UNPROVEN, so it is not invented'). The effective default is:

    --oci-worker-gc-keepstorage 10000,373000,100000   (MB: Reserved 10GB, Free 373GB, Max 100GB)
    

    This host has 247 GB free (1.9T at 87%). BuildKit's GC tries to keep the 373 GB free target, so it prunes reclaimable cache toward the 10 GB Reserved floor. Observed: buildctl du floors at ~8-10 GB across builds; the hit/miss pattern is 'builds within the window hit, a build after the GC gap misses'. (The GC event itself is not in the default log level; the cache floor + the selective re-execution above are the direct observations.)

    6. Labels are already at the END, and their position is not the trigger. Generated files:

    arch.arch          first LABEL line 38 ; last RUN/COPY line 34
    arch.arch-builder  first LABEL line 115; last RUN/COPY line 111
    cachyos            first LABEL line 61 ; last RUN/COPY line 57
    

    Controlled test on buildkitd 0.35.1 (real arch base, real store binding): a LABEL whose value changed, placed top vs end, left the COPY/RUN layers CACHED in both positions. So label position does not re-run layers. (A label change does change the image config digest, so a CHILD that builds FROM it sees a new base digest - that is content change, not label placement.) The only tag-bearing top-of-file tokens are ARG BASE_IMAGE=<ref> and the builder FROM <ref>:<tag>, and those resolve to a digest (point 2).

    7. The floating inputs guarantee a re-execution changes the artifact. Generated Containerfiles: pacman -Syu (arch bootstrap; builder layers for nodejs/toolchain/base-devel - the embedded pac template is charly/charly/charly.yml:606), task_linux_${ARCH}.tar.gz from .../releases/latest (arch bootstrap), yay from api.github.com/.../releases/latest (layer-yay; sdk/kit/builder_resolve.go:48 also sudo pacman -Syu + yay -S).

    Corrected mechanism

    1. BuildKit GC prunes the cache (default free target 373 GB > 247 GB free) -> big builder layers evicted.
    2. The next build re-executes them; the floating -Syu/latest steps change the bytes.
    3. A changed parent digest invalidates every downstream layer.
    4. The per-invocation tag mints a new ref for the changed digest (the issue's headline - a consequence, not the cause).

    Fix directions (in order of measured impact)

    1. BuildKit GC policy: explicit keep policy (100 GB default) + all buildkit settings configurable from charly.yml (requested by @atrawog). Removes the eviction that makes every cold build re-run.
    2. Tag reuse when the digest is unchanged (option B): stops the ref churn and keeps the resolved ref stable for the summary, without hiding a real content change.
    3. Pin the floating inputs (-Syu -> snapshot/pin; latest -> version) so a cold rebuild is reproducible - separate finding.

    Note on buildctl vs the Go BuildKit client

    The drive shells out to buildctl by design (sdk/buildkitdrive): the buildkitd daemon is a separate rootless process charly manages, the CLI is a stable versioned boundary, and importing moby/buildkit/client would put the BuildKit/containerd dependency surface into sdk and every plugin binary. The daemon's GC is a daemon config concern, so the Go client would not change point 5. The CLI's captured output is currently discarded on success (#1202) - that is the real cost, and the per-step capture above is the evidence it should be surfaced.

    Next: the GC default + charly.yml configurability, then the tag reuse, with the R10 bed on a disposable target.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  4. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    STATUS — GC/config implementation opened; the cache trigger is confirmed

    Implementation of the measured fix is in flight (producer-first):

    • feat(buildkitdrive): a 100 GB GC budget by default, every daemon setting configurable sdk#650 — sdk/buildkitdrive: an explicit 100 GB GC budget by default (reservedSpace=100GB, maxUsedSpace=100GB, minFreeSpace=10GB) plus the full [worker.oci] daemon surface on DaemonOptions (process mode, max-parallelism, snapshotter, noProcessSandbox, gcpolicy entries, registry mirror, raw extra TOML). Module CI green (build/vet/gofmt/full test). The rendered config was validated against a throwaway buildkitd 0.35.1: the daemon started and answered debug workers, so the new GC keys parse.
    • feat(schema): add defaults.buildkit, the buildkitd daemon settings spec#447 — #Buildkit (defaults.buildkit) + #BuildResolveReply.buildkit, generated with the in-process schemagen; TestGenReproducible green.
    • opencharly/plugin-build — feat/buildkit-daemon-config (local commit f478cb2): resolve carries defaults.buildkit into the reply, the drive maps it onto DaemonOptions with the stage-parallelism/env fallbacks. Unit tests green; its PR opens after the sdk/spec tags (producer-first).

    A running buildkitd keeps the policy it started with; Ensure now reports the mismatch on stderr and never fails the build, so applying the budget is a daemon restart (and it is written for the next start).

    Filed: #1300 — the charly workspace cannot build against spec main because spec#446 removed the Android/apk types while charly's go.mod still pins the pre-removal plugin/spec releases. This blocks the charly pin-bump + R10 bed leg of this wave; the producer PRs are unaffected.

    Still owed: the plugin-build PR (after the tags), the charly pin bump + the bed (two builds with a daemon restart and a gap, asserting the cache persists), and the tag-reuse (option B) leg.

    Label position — tested, and it is not the trigger

    The generated Containerfiles already emit every LABEL at the END (arch: first LABEL line 38 vs last RUN/COPY 34; arch-builder 115 vs 111; cachyos 61 vs 57). A controlled test on buildkitd 0.35.1 with the real arch base and the real store binding — change a LABEL value with the LABEL at the TOP vs the END — left the COPY/RUN layers CACHED in both positions. The only tag-bearing top-of-file tokens are ARG BASE_IMAGE and the builder FROM <ref>:<tag>, and a changed tag bound to the same digest was CACHED too. The invalidation comes from the cache eviction (default GC free target 373 GB > 247 GB free) + the floating -Syu/latest steps, as measured above.

    buildctl vs the Go BuildKit client

    It is a deliberate thin-contract choice (sdk/buildkitdrive): the buildkitd daemon is a separate rootless process charly manages, the CLI is a versioned boundary, and importing moby/buildkit/client would pull the BuildKit/containerd dependency surface into sdk and every plugin binary. The daemon GC is a daemon-config concern, so the Go client would not have changed the pruning. The real cost of the CLI shape is that the per-step output is captured and discarded on success (#1202) — the captured CACHED/DONE lines above are exactly what that hides.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  5. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    STATUS — three producer PRs open; option B proven live

    Live proof of B (charly binary built against the branch; minimal external-base probe, two back-to-back builds, both fully CACHED):

    --- testbase  -> ghcr.io/opencharly/testbase:2026.331.1207  (reused; image sha256:4a96c580...) ---
    --- testreuse -> ghcr.io/opencharly/testreuse:2026.331.1207 (reused; image sha256:92110491...) ---
    

    No new tag on the second build; the child's base ref was substituted to the reused one. Two defects were found by that spike and fixed: LocalImageInfo.ID is bare hex vs ImageID's sha256: prefix, and plugin-box always sends a computed CalVer so an explicit --tag is only distinguishable by the tag grammar.

    Still owed: the plugin-build daemon-config PR (local commit f478cb2) opens after sdk#650 + spec#447 merge/tag; then the charly pin bump + the R10 bed (two builds with a daemon restart and a gap), which #1300 currently blocks for a workspace build against spec main.

    A watcher is armed over the three PRs.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  6. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    WAITING

    The remaining legs of this wave are blocked on two producer PRs, which are the blocking side:

    What waits on them here: the opencharly/plugin-build daemon-config PR (local commit f478cb2, which maps defaults.buildkit onto buildkitdrive.DaemonOptions) opens once both merge and tag, because it consumes their shapes; then the opencharly/charly pin bump + the R10 bed (two builds across a daemon restart with a gap, asserting the cache and refs persist).

    NOT blocked, and already open: opencharly/plugin-build#70 — the ref-reuse change (option B) is independent of both producer PRs and is being reviewed on its own thread.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  7. aitrawog commented on Nov 27, 2026

    @aitrawog
    ContributorAuthor

    STATUS

    STATUS — wave state after the first merges, and one real defect the validator caught.

    Merged and tagged

    Auto-closed, continued cleanly

    Filed, not fixed

    Not repinned — charly still pins plugin-build v0.2026328.1, sdk v0.2026328.1805, spec v0.2026329.803; no pin-bump PR exists, so no shipped binary has any of this. Remaining order: #653 merges+tags → plugin-build daemon-config PR (branch rebased onto the merged #70 main, local) → one coherent charly pin advance (including #1300's plugin pins) → consumer bed (two builds across a daemon restart).

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5
    Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

  8. aitrawog commented on Nov 28, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED — the wave landed, producer-first, and the consumer pins it.

    Producer legs merged and tagged

    repo PR tag what it fixed
    opencharly/plugin-build #70 candy/plugin-build/v0.2026331.1306 ref reuse: always build, reuse the newest same-repo auto-ref when the artifact digest matches AND the store holds it; mint only otherwise (minute bump -2/-3)
    opencharly/sdk #653 v0.2026331.1440 100 GB GC default (reservedSpace/maxUsedSpace 100 GB, minFreeSpace 10 GB), full [worker.oci]/gcpolicy surface, GCConfigMismatch seam
    opencharly/spec #447 / #448 v0.2026331.1221 / v0.2026331.1553 #Buildkit + defaults.buildkit typed in #NodeDoc; mergeBoxConfig carries it through the walk→materialize merge
    opencharly/plugin-build #71 v0.2026331.1456 defaults.buildkit reaches DaemonOptions; daemon-config render test

    Consumer — #1307 merged (7f89ab36), and main carries the result (verified today):

    charly/go.mod      github.com/opencharly/sdk v0.2026331.2334      (≥ 1440)
                       github.com/opencharly/spec v0.2026331.1553
                       plugin-build/candy/plugin-build v0.2026331.1456
                       plugin-substrate/candy/plugin-substrate v0.2026331.1555
    # grep -n 'DefaultGCReservedSpace' [email protected]/buildkitdrive/paths.go
    176:	DefaultGCReservedSpace = "100GB"
    

    Measured behaviour, not just pins

    • Ref reuse (the defect this issue names): two consecutive builds of the same tree reused the same ref instead of minting a new CalVer each time; the pre-change arm minted a different sha256 digest per invocation (2289e7b3… then 4a96c580…).
    • Cache survives a daemon restart: the store reported Total 1.19GB after the restart and the next build hit it.
    • defaults.buildkit reaches the daemon: a project authoring max_parallelism: 2, reserved_space: 50GB, max_used_space: 60GB, min_free_space: 7GB produced exactly those lines in buildkitd.toml (before the loader fix: 4 and 100/100/10).
    • GC default is 100 GB on a fresh daemon, and a running daemon keeps its own policy (reported, not fatal).

    Filed from the wave, still open by design

    Every other finding the wave surfaced is closed: #1300, #1306, #1308, #1309 (this session), distro-arch#84/#75, sdk#655.

    Agent: jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5 · OpenCode session ses_de3fa473bffeFiBo62whHxDPE5

    Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:deliverytype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions