Skip to content

feat(buildkitdrive): a 100 GB GC budget by default, and every daemon setting configurable - #653

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/buildkit-daemon-config-v2
Nov 27, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/buildkit-daemon-config-v2

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

charly box build of an unchanged tree re-executes its layers on this host. The cause is not the per-build tag (a changed tag with an unchanged digest is a cache HIT): it is BuildKit's own GC pruning the cache. buildkitd's compiled default policy keeps a 373 GB free-space target (--oci-worker-gc-keepstorage 10000,373000,100000 MB); this host has 247 GB free, so every GC pass prunes reclaimable cache toward the ~10 GB reserve floor. The next build then re-executes the evicted layers, and the floating pacman -Syu / releases/latest steps change the bytes, so the image digest (and the CalVer tag minted for it) moves.

Measured 2026-11-27 (buildkitd 0.35.1, 1.9 TB disk at 87% used):

$ buildkitd --help | grep oci-worker-gc-keepstorage
--oci-worker-gc-keepstorage string  (default "10000,373000,100000")  # Reserved 10GB, Free 373GB, Max 100GB

# captured per-step output of `box build arch.arch --tag gap-d` (buildctl wrapper in PATH):
#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) — selective cache loss, not the tag

$ buildctl du
Reclaimable: 6.64GB   Total: 7.93GB        # the cache floor, across builds

The change. DaemonOptions now carries the whole [worker.oci] daemon surface charly manages — process_mode, max_parallelism, snapshotter, no_process_sandbox, the GC budget (reservedSpace / maxUsedSpace / minFreeSpace), per-record [[worker.oci.gcpolicy]] entries, the registry mirror, and a raw extra TOML escape hatch — and DaemonConfig always writes an explicit 100 GB GC budget (reservedSpace = "100GB", maxUsedSpace = "100GB", minFreeSpace = "10GB"). Ensure reports, without failing the build, a running daemon whose GC policy predates the request; the value takes effect at the next daemon start.

This is the producer leg of the charly.yml surface (defaults.buildkit) implemented in opencharly/spec and consumed by opencharly/plugin-build.

How tested

This is the clean PR for the auto-closed #650 thread. The surviving finding there was a real defect in this change's own test: the legacy-key guard matched camel-case keepStorage, but buildkitd's legacy worker key is all-lowercase gckeepstorage, so the check could never fire. It is fixed here (case-insensitive, names the real key) and the red arm is pasted.

Contract-module change class (no deployable target in sdk): the repo's own module CI is the gate, run on this head.

$ GOWORK=off go build ./...              # exit 0
$ GOWORK=off go vet ./...                # exit 0
$ test -z "$(gofmt -l .)"                # exit 0
$ GOWORK=off go test ./...               # PASS (buildkitdrive, kit, deploykit, storekit, loaderkit, ...)
$ GOWORK=off go test ./buildkitdrive/ -run 'TestDaemonConfig|TestConfigGC|TestGCConfigMismatch|TestEnsure' -v
=== RUN   TestDaemonConfig_SetsOnlyTheMeasuredShape
--- PASS: TestDaemonConfig_SetsOnlyTheMeasuredShape (0.00s)
=== RUN   TestDaemonConfig_CarriesTheGCBudget
--- PASS: TestDaemonConfig_CarriesTheGCBudget (0.00s)
=== RUN   TestDaemonConfig_GCIsConfigurable
--- PASS: TestDaemonConfig_GCIsConfigurable (0.00s)
=== RUN   TestConfigGC_RoundTrips
--- PASS: TestConfigGC_RoundTrips (0.00s)
=== RUN   TestGCConfigMismatch
--- PASS: TestGCConfigMismatch (0.00s)
=== RUN   TestEnsureReportsTheRunningDaemonsGCPolicy
--- PASS: TestEnsureReportsTheRunningDaemonsGCPolicy (0.00s)
=== RUN   TestEnsureRewritesAStaleConfigWithoutParallelism
--- PASS: TestEnsureRewritesAStaleConfigWithoutParallelism (0.00s)
=== RUN   TestDaemonConfig_RendersEveryWorkerKnob
--- PASS: TestDaemonConfig_RendersEveryWorkerKnob (0.00s)
=== RUN   TestDaemonConfig_CarriesTheRegistryMirror
--- PASS: TestDaemonConfig_CarriesTheRegistryMirror (0.00s)
=== RUN   TestDaemonConfig_CarriesTheResolvedParallelism
--- PASS: TestDaemonConfig_CarriesTheResolvedParallelism (0.00s)
ok  	github.com/opencharly/sdk/buildkitdrive	0.004s

The new tests pin: the 100 GB default is rendered; every optional worker/GCPolicy knob (process_mode, max_parallelism, snapshotter, no_process_sandbox, gc, the three-space budget, gcpolicy incl. all/keep_duration/filters, registry_mirror, the raw extra block) renders when set AND is omitted at its zero value (TestDaemonConfig_RendersEveryWorkerKnob, which fails if any branch is dropped — verified by deleting the snapshotter branch: the rendered config must carry "snapshotter = \"overlayfs\""); a disabled GC renders no budget; the rendered policy reads back through ConfigGC for the running-daemon comparison; the legacy worker key gckeepstorage (all lowercase, mirroring --oci-worker-gc-keepstorage) and the 373 GB default value are not emitted — the guard is CASE-INSENSITIVE, and its red arm is pasted below; and BOTH new Ensure branches are exercised on Ensure itself (not only through the pure helpers):

  • No daemon listening — the always-write decision. TestEnsureRewritesAStaleConfigWithoutParallelism starts from the pre-GC max-parallelism = 4 file and asserts Ensure REPLACES it with the rendered config for an options value carrying no parallelism (the start seam captures the spawn and materialises the socket). It FAILS on the unmodified tree, where that branch skipped the write:
$ # old branch restored (write only when MaxParallelism > 0 or the file is absent)
$ GOWORK=off go test ./buildkitdrive/ -run TestEnsureRewritesAStaleConfigWithoutParallelism
--- FAIL: TestEnsureRewritesAStaleConfigWithoutParallelism (0.00s)
    buildkitdrive_test.go:439: the stale config was not replaced by the rendered one:
FAIL
  • A daemon already listening — the GC-mismatch report. TestEnsureReportsTheRunningDaemonsGCPolicy pre-creates the socket (so ready takes the listening branch), starts from a pre-GC config whose parallelism matches (so no restart is demanded), swaps the process stderr for a pipe, and asserts the report names the configured policy and the socket. It FAILS without the report:
$ # report block removed from the listening branch
$ GOWORK=off go test ./buildkitdrive/ -run TestEnsureReportsTheRunningDaemonsGCPolicy
--- FAIL: TestEnsureReportsTheRunningDaemonsGCPolicy (0.00s)
    buildkitdrive_test.go:441: the running-daemon report must name "reservedSpace=40GB":
FAIL

Red arm for the GC-default accuracy fix — the parser restored to "absent = disabled":

$ # ConfigGC: out := GCConfig{}  (WRONG)
$ GOWORK=off go test ./buildkitdrive/ -run 'TestGCConfigMismatch|TestEnsureReportsTheRunningDaemonsGCPolicy'
--- FAIL: TestGCConfigMismatch (0.00s)
    the report must name "the daemon's default GC policy":
    the report must name "373GB free target":
    an absent gc key must read as the daemon's ENABLED default (not explicit): {Enabled:false ...}
    an absent gc key must describe as the daemon's default policy: "gc disabled"
--- FAIL: TestEnsureReportsTheRunningDaemonsGCPolicy (0.00s)
FAIL

Red arm for the legacy key — the renderer made to emit the legacy key:

$ # paths.go injected: cfg += "  gckeepstorage = \"10GB\"\n"
$ GOWORK=off go test ./buildkitdrive/ -run TestDaemonConfig_CarriesTheGCBudget
--- FAIL: TestDaemonConfig_CarriesTheGCBudget (0.00s)
    buildkitdrive_test.go:292: the legacy `gckeepstorage` key (and the 373 GB default) must not be rendered:
          gckeepstorage = "10GB"
FAIL

Spike

RCA claim: the cache loss is BuildKit's GC pruning (default free-space target 373 GB > this host's 247 GB free), not the per-build tag.

Candidates spiked:

  • A. Leave GC unset (status quo). Instrument: buildkitd --help default + buildctl du + a captured per-step build. Result: fails — the cache floors at ~10 GB and the builder's large RUNs re-execute while a small one stays cached.
  • B. Explicit 100 GB GC budget + configurable daemon settings. Instrument: unit-level rendering (TestDaemonConfig_CarriesTheGCBudget) + ConfigGC round-trip. Result: works (rendered and read back); the live daemon-level effect is the consumer boundary's bed (the charly pin-bump PR), per the contract-module gate.
  • C. Set only minFreeSpace small, leave the rest to the default. Rejected by inspection, with the daemon's own defaults as the instrument:
    $ buildkitd --help | grep gc-keepstorage
       --oci-worker-gc-keepstorage string   Amount of storage GC keep locally, format "Reserved[,Free[,Maximum]]" (MB)
                                            (default: "10000,373000,100000")
    
    So the worker's three values are NOT undefined — they are Reserved 10 000 MB (10 GB), Free 373 000 MB (373 GB), Maximum 100 000 MB (100 GB), and the running daemon demonstrates the consequence on this host:
    $ buildctl --addr unix:///run/user/1000/charly/buildkitd.sock du
    Reclaimable:  9.38GB
    Total:        10.35GB
    $ df -h /home | tail -1
    /dev/mapper/root  1.9T  1.7T  170G  91% /home
    
    170 GB free, and the cache sits at ~10 GB: the reserve floor, not an undefined budget, is what retains it. C expresses one of the three values (the free-space target) and leaves the reserved floor and the ceiling inherited, so a policy that wants a different floor or ceiling cannot be authored — which is exactly what #1292 needs. The explicit three-key budget makes all three the operator's.

Winner: B. RCA verdict: confirmed — the default policy's free target is the pruning driver; the explicit budget removes it.

Rulebook compliance

  • R0 — build/generate/go/strict-policy/check/git-workflow loaded before the work.
  • R1 — the GC state the report names is now the daemon's REAL default (absent gc = enabled with keepstorage 10000,373000,100000), not "disabled"; the two report tests assert that wording and fail if the parser reverts. The anomaly was reproduced and measured before the change; the label-position hypothesis was tested and disproved (a LABEL value change, top vs end, leaves the COPY/RUN layers CACHED on 0.35.1 — labels are already emitted at the end of every generated Containerfile). The floating-input non-reproducibility is tracked separately on the base builder is rebuilt under a new CalVer tag on every build, so no layer is ever reused charly#1292.
  • R2 — one daemon-config renderer (DaemonConfig) and one write comparison (writeIfChanged); the GC comparison reuses the same rendered form. (This clean tree never carried the intermediate ConfigDiffers helper from the superseded thread, so there is nothing deleted here.)
  • R3 — no sleep/retry; the mismatch between a running daemon and a requested policy is reported, not worked around.
  • R7 — the new tests fail without the change (the default budget assertion did not exist; the old test asserted the opposite).
  • R8 — no live service is mocked; the daemon-level bed belongs to the consumer.
  • R9 — library module, no binary; module CI is the gate.
  • R10 — contract/library class: the module suite IS the gate; sdk ships no disposable: true entity, so no bed can exist. Every changed daemon.go path is reached by a test that fails without it: TestGCConfigMismatch (the pure report), TestEnsureReportsTheRunningDaemonsGCPolicy (the daemon-LISTENING branch, i.e. the fmt.Fprintf wiring) and TestEnsureRewritesAStaleConfigWithoutParallelism (the no-daemon always-write branch). The consumer boundary bed rides the charly pin-bump PR.
  • R11 — no DESIGN shape changes: this is a host-daemon config knob rendered by the build kit; the store roots still resolve through spec/storeroot (D-STORE-1).
  • R12 — the round above; candidate A measured red, B rendered and read back.

Change classification

The default GC budget changes behaviour: a buildkitd started by this drive keeps up to 100 GB of cache instead of pruning to ~10 GB, and an already-running daemon keeps its old policy until restarted (reported on stderr, never fatal). Breaking change + rollback: none for the module API beyond new optional fields on DaemonOptions; rollback is a revert of this squash, which restores the GC-unset renderer.

Filed issues

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

…setting configurable

buildkitd's compiled GC policy keeps a 373 GB free-space target and a 10 GB reserve floor; on a host with less free space the GC prunes reclaimable cache to that floor on every pass, so a repeated build of an unchanged tree re-executes its layers (opencharly/charly#1292). DaemonOptions now renders the full [worker.oci] surface (process-mode, max-parallelism, snapshotter, noProcessSandbox, the three-space GC budget, per-record gcpolicy entries, the registry mirror and a raw extra block), DaemonConfig defaults the budget to reservedSpace=100GB / maxUsedSpace=100GB / minFreeSpace=10GB, and Ensure writes the rendered config whenever it differs and reports a RUNNING daemon's GC mismatch on stderr (the policy is fixed at daemon start).

This is the clean PR for the auto-closed #650 thread: the surviving finding there was a real defect in this change's own test — the legacy-key guard matched camel-case 'keepStorage' while buildkitd's legacy key is all-lowercase 'gckeepstorage', so it could never fire. The guard is now case-insensitive and names the real key, with the red arm pasted in the PR body.

*Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`*

*Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)*
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 07ef1594bcc6414859a78476054d9908b3c1a7e4 (branch: feat/buildkit-daemon-config-v2)

Change class: code/config — sdk library kit (buildkitdrive); no deployable target, module suite is the gate. Comment thread: 0 comments, nothing to disposition.

Blocks

  1. R1 — the ConfigGC comment states the daemon's default GC is disabled, which the PR's own evidence refutes; the new mismatch report therefore mislabels the exact legacy daemon it targets.

    buildkitdrive/paths.go, ConfigGC doc comment:

    "an absent gc key reads as disabled (the daemon's own default when the key is missing is false for the worker's gc field)."

    and Describe() returning "gc disabled" when !Enabled.

    This is contradicted by three pieces of the PR's own pasted evidence, all of which show the missing-gc default is enabled:

    • The spike's buildctl --addr … du on the charly-started daemon (whose pre-GC config has no gc key) shows active pruning to Reclaimable 9.38GB / Total 10.35GB — GC ran by default.
    • Spike candidate A is "Leave GC unset (status quo)" and is reported to fail by flooring the cache — i.e. leaving gc unset keeps GC active.
    • buildkitd --help shows the live --oci-worker-gc-keepstorage default 10000,373000,100000 — a budget only meaningful if GC runs.

    Consequence: for a daemon that predates the budget (no gc key — the primary case Ensure is meant to warn about), GCConfigMismatch/Describe() emit "the running daemon was started with gc disabled", when in reality it is running the default enabled GC with the 373 GB free target — the very culprit. The operator is told the opposite of the truth, and the mismatch fires for the wrong stated reason.

    Both TestGCConfigMismatch and TestEnsureReportsTheRunningDaemonsGCPolicy assert the string "gc disabled", so the wrong label is baked into the gate.

    Fix: correct the ConfigGC comment (the worker's default GC is enabled); make the report name the actual state — e.g. "started with the daemon's default GC policy (373 GB free target)" — instead of "gc disabled"; and update the two tests' expected strings accordingly.

Note (non-blocking)

Verdict: BLOCK


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

View action run

… and the report says so

ConfigGC treated a missing gc key as disabled, so the mismatch report told the operator a pre-budget daemon was 'started with gc disabled' — the exact opposite of the truth: buildkitd's worker GC runs by default with keepstorage 10000,373000,100000 (10GB reserve, 373GB free target, 100GB ceiling), which is the policy that prunes a small host's cache to the floor. GCConfig now carries Explicit: absent means the daemon's default (enabled) and Describe() names that policy; an explicit gc=false still describes as disabled; an explicit budget describes its three spaces. wantedGC() marks the requested state explicit so the report renders the requested values. Red arm: restoring absent=disabled fails both report tests.

*Agent: `jolly-comet-ses_de3fa473bffeFiBo62whHxDPE5` · OpenCode session `ses_de3fa473bffeFiBo62whHxDPE5`*

*Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)*
@aitrawog

Copy link
Copy Markdown
Contributor Author

STATUS

New head 719b00d. The block was a real accuracy defect — thank you.

What was wrong. ConfigGC treated an absent gc key as DISABLED, so the mismatch report told the operator that a pre-budget daemon was "started with gc disabled" — the opposite of the truth. buildkitd's worker GC runs by DEFAULT with --oci-worker-gc-keepstorage 10000,373000,100000 (10 GB reserve / 373 GB free target / 100 GB ceiling), which is precisely the policy that prunes a small host's cache to the floor, and the PR's own buildctl du / --help evidence shows it running.

Fix.

  • GCConfig now carries Explicit. Absent gc ⇒ Enabled: true, Explicit: false (the daemon default); gc = false ⇒ disabled, explicit; a written budget ⇒ explicit with its three spaces.
  • Describe() names the actual state: an absent key renders "the daemon's default GC policy (--oci-worker-gc-keepstorage 10000,373000,100000: 10GB reserve, 373GB free target, 100GB ceiling)"; an explicit gc = false still renders "gc disabled"; an explicit budget renders its three spaces.
  • wantedGC() marks the requested state explicit, so the report's second half renders the REQUESTED values.
  • SameGC now requires an explicit budget, so an absent-gc daemon is correctly a mismatch against any requested budget.

Both report tests assert the corrected wording, plus a new arm: absent ⇒ enabled+not-explicit and describes as the default; explicit gc = false ⇒ "gc disabled". Red arm (parser restored to absent=disabled):

--- FAIL: TestGCConfigMismatch (0.00s)
    the report must name "the daemon's default GC policy":
    the report must name "373GB free target":
    an absent gc key must read as the daemon's ENABLED default (not explicit): {Enabled:false ...}
    an absent gc key must describe as the daemon's default policy: "gc disabled"
--- FAIL: TestEnsureReportsTheRunningDaemonsGCPolicy (0.00s)
FAIL

Non-blocking note — fixed too. The R2 line no longer claims a deletion: this clean tree never carried ConfigDiffers (it lived only in the superseded thread).

Gate on the head: go build ./..., go vet ./..., gofmt clean, go test ./... PASS.

RCA for the missed control. Mechanism: I took the daemon's TOML field default (gc absent ⇒ Go zero value false) as the daemon's RUNTIME default, and wrote both the comment and the report from that assumption — while my own spike output (a daemon with no gc key actively pruning to 10 GB, and --help printing the keepstorage default) refuted it. Missed control: a claim about an external program's default must be read off that program's own evidence, and the evidence I had already pasted was never re-read against the comment. Blast radius: the one diagnostic an operator would use to understand the cache problem said the opposite. Root fix in this diff: the parser's semantics, the wording, and tests that fail if the semantics revert.

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

@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 719b00d6958d35004258254857bd04e0912f3041 (branch: feat/buildkit-daemon-config-v2)

Security screen: PASS — no secrets, no egress, no guardrail weakening; Extra is an operator-facing escape hatch, not a gate loosening.
Checklist: All applicable rules PASS or NA. The one prior R1 defect is fixed in this head; the always-write and GC-report branches, the GC parser, and every renderer knob each have a test that fails on revert (red arms pasted).

Comment dispositions:

  • 7220919385 (@github-actions[bot], BLOCK): stale-superseded — the R1 finding (ConfigGC treating an absent gc key as disabled) was valid against 07ef159 but is resolved in the current head: ConfigGC now reads absent ⇒ Enabled:true, Explicit:false, Describe() emits "the daemon's default GC policy (…373GB free target…)", and both report tests assert the corrected wording. Not a surviving finding.
  • 7221028578 (@aitrawog, STATUS): verified-non-blocking — the fix it describes matches the current diff, and it carries the required R1 RCA of the missed control (an external program's default must be read off that program's own evidence), discharging the review-round-evidence obligation.

Non-blocking notes:

  • The live daemon-level GC effect is unproven in-repo; per the R10 contract-module exemption (sdk ships no disposable: true entity) this is explicitly deferred to the consumer bed. The changed Go paths did execute under the module suite.
  • TestDaemonConfig_RendersEveryWorkerKnob exercises Extra with a duplicate [worker.oci] table that the field's own doc says buildkitd rejects — harmless for a render-only assertion, but a misleading sample.
  • The Ensure "always-write" behaviour change is covered under How tested but not called out in the Summary/Change-classification paragraphs; worth tightening.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 27, 2026 14:40
@github-actions
github-actions Bot merged commit bd781bb into main Nov 27, 2026
8 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 27, 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