Repository navigation
fix(buildkitdrive): never rewrite a live daemon's record on a slow or cancelled probe - #685
Merged
Merged
Conversation
… cancelled probe
Ensure treated ANY failed readiness probe as "no daemon": a probe that
missed its 500 ms deadline on a busy host, or a caller whose context was
already done. It then rewrote the shared buildkitd.toml with the caller's
options and tried to start a second daemon. DaemonOptions{} (EmitVmBox)
renders no max-parallelism key, so the record said 0 while the daemon ran
at 4, and every later build failed with a false "configured with
max-parallelism=0 but 4 was requested" mismatch until a manual kill.
- A done context ends Ensure without touching the record or starting a
daemon.
- Liveness is decided by the daemon's own one-instance lock on the state
root (buildkitd.lock): a live daemon that did not answer in time is waited
for and attached to, never rewritten and never doubled.
- A drive-level ensure.lock (spec/lock) serializes probe, write, start and
ready across processes, closing the start race in which concurrent
callers each spawned a daemon and the record was the last writer's.
Four regression tests fail on the previous tree and pass here.
Closes #684
Claude-Session: https://claude.ai/code/session_01Tvdn3t2LD2HiQqQM8sxByy
Agent: openclaw-cdi · Claude Code session 7011c83d-8b59-4309-bde8-b5d3bb83fd75
Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)
This was referenced Dec 2, 2026
Review — PASSHead SHA: Security screen: PASS — no secrets, no egress, no weakened guardrails, no supply-chain change (no Non-blocking notes (do not affect the verdict):
Verdict: PASS ollama-cloud/deepseek-v4.1-flash — action-review. |
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
buildkitdrive.Ensuretreated any failed readiness probe as "no daemon is listening". Two things make that probe fail:buildctl debug workersmisses the 500 ms budget (readinessInterval*5);In either case it rewrote the shared
buildkitd.tomlof a live daemon with the caller's options, then tried to start a second daemon on the same root.deploykit.EmitVmBoxpassesDaemonOptions{}, which renders nomax-parallelismkey. So the record read 0 while the daemon kept running at 4. From then on every build on the host failed with a false mismatch, until someone killed the daemon by hand:This is the state the shared daemon on the operator's host was in on 2026-12-02: the record was rewritten at 16:16:36 local, the daemon log was untouched, and the daemon had been alive since 2026-12-01 23:09. It also very likely explains #665's measured "idle daemon at 0".
The fix, in
Ensure:buildkitd.lock), not from probe latency. A live daemon that did not answer in time is waited for and attached to. Its record is never rewritten, and a second daemon is never started on its root.ensure.lock(spec/lock) serializes probe → decide → write → start → ready across processes. Concurrent callers on an empty root no longer each spawn a daemon and leave the last writer's record.attach()andwaitReady()are extracted. Both the "listening" and the "live but slow" paths use the same compare and wait, so neither is a copy.Closes #684.
Files
buildkitdrive/daemon.goEnsure: ensure lock, done-ctx early return,daemonOwnsRootliveness, extractedattach()/waitReady()buildkitdrive/paths.goEnsureLockName = "ensure.lock", documented besideLockNamebuildkitdrive/ensure_live_test.goHow tested
golangci-lint runs under
GOTOOLCHAIN=go1.26.8, go.mod's floor, because the host's Go 1.27 cannot typecheck under the v2.13.2 binary (opencharly/opencharly#1400).The tests fail without the change. The new tests ran against
origin/main'sdaemon.goandpaths.go, with only theEnsureLockNameconstant added so the package compiles:The changed path, run live on a real rootless daemon (
rootlesskit+buildkitd), with a 30-line program that callsbuildkitdrive.Ensure. The daemon is private (CHARLY_CACHE_HOME/CHARLY_RUNTIME_DIRrelocated), so the shared host daemon was not touched.Before, with sdk
v0.2026334.1628(the version charly 2026.335.1816 embeds):After, with this head (
go mod edit -replaceonto the worktree,built-against-f54f752):Spike
The RCA's candidate fixes, each judged against the two reproduced signatures:
(a) Liveness from the daemon's lock, no write on a done ctx, plus an ensure lock. This is the winner. The liveness signal was spiked first, on the private daemon:
It then cleared both signatures live (the "After" block above) and passed all four regression tests.
(b) A longer probe deadline. Rejected. Any finite deadline can be exceeded on a loaded host, so the conflation of "slow" with "absent" remains. Signature 2 (a done ctx) is unaffected by any deadline. This is the C5 band-aid shape.
(c) Compare the request against the running daemon's own
--configfile (found through the lock holder's cmdline). Not chosen for this change. It would makeattachtruthful after a poisoning, but the record would still be rewritten and duplicate daemons still spawned: it treats the symptom of the race, not the race. Proposed on #1390 byvol-cdi; it remains open for discussion on buildkitdrive.Ensure overwrites a LIVE daemon's record on a slow or cancelled probe — every later build then fails with a false 'max-parallelism=0' mismatch #684.Rulebook compliance
Plan conformance
Winning candidate: (a).
spec/lock.AcquireFileLock(non-blocking) onbuildkitd.lock;ensure.lockvia the same primitivesdk, never a private copy (D-SDK-1, D-CODE-3)." The lock is the sharedspec/lockprimitive (whichkit/filelock.gore-exports), andwaitReadyis the one readiness wait, now shared by both paths.ensure.lockheld only for the ensure sequence, released on return or process deathflockis released by the kernel when the holder exits.Ensuremade safe for concurrent callers through a host-resource lockEnsurecalls now start one daemon and never rewrite a live one's record (TestEnsureConcurrentCallersStartOneDaemon). The sentence's second half, "Locking is core's alone (D-DEP-4)", is the DEPLOYMENT lock, which this does not take. A per-uid host resource guarded through the sharedspec/lockprimitive is an existing row of that mechanism, used on the same path:plugin-build/candy/plugin-build/buildkit.go:143kit.AcquireImageBuildLock,plugin-vm/candy/plugin-vm/vm_build.go:102,sdk/deploykit/data.go:172.AGENTS.md.Ensureagainst a live daemon with a slow probe or a done ctx. Zero warnings in this change's gates. Two incidental findings are pre-existing: the local lint toolchain mismatch (already local golangci-lint v2.13.2 cannot typecheck under the host Go 1.27 toolchain (export data v5 > v4); CI pins go.mod's 1.26.8 opencharly#1400), and the zero-opinion START case below (buildkitdrive: an idle daemon with a different max-parallelism blocks every build until manually killed #665).### Spike.attach/waitReadygive one compare and one wait, both reused. The lock is the sharedspec/lockprimitive, not a new one.Ensure's probe behaviour.built-against-f54f752).origin/main(f607fda33801c46c00ddfcecc0de5f0d66dd7a71), one commit, no force-push, no hook bypass.Change classification
go vet ./...,go test ./...,-raceon the Ensure tests, the cross-compile matrix, and golangci-lint v2.13.2, all on the committed head.fully tested and validated.claude-opus-5-5(Anthropic Claude Opus 5.5).Ensure's signature and its success results are unchanged. A live-but-slow daemon is now attached to (it used to be raced), and a done ctx now returnsctx.Err(), where it used to succeed or fail opaquely. Roll back by reverting this squash commit.Filed issues
max-parallelism, so a later build that requests a value mismatches) stays there and is deliberately not changed here.https://claude.ai/code/session_01Tvdn3t2LD2HiQqQM8sxByy
Agent:
openclaw-cdi· Claude Code session7011c83d-8b59-4309-bde8-b5d3bb83fd75Assisted-by: Claude Code Anthropic Claude Opus 5.5 (fully tested and validated)