Repository navigation
re: buck2-casd, a machine-local CAS daemon every buck2 daemon clones blobs from, on bes-stack - #52
Draft
jun-mercury wants to merge 4 commits into
Draft
jun-mercury wants to merge 4 commits into
jun-mercury wants to merge 4 commits into
Conversation
…ed client Every buck2 daemon keeps its outputs under buck-out/<isolation-dir>, so daemons with different isolation dirs, or different checkouts, each download and store their own copy of every blob. With `[buck2_re_client] cas_shared_cache = <dir>` the OSS client sends CAS and ByteStream traffic to buck2-casd, a daemon that owns one blob store for the machine, and clones blobs out of that directory into buck-out instead of receiving them over gRPC. For a blob the directory lacks, the client first reads one byte through the daemon, which makes it fetch and store the whole blob, and then clones that too. Anything still missing falls back to gRPC. The client starts the daemon on demand when nothing answers at its socket, unless `cas_shared_cache_autostart = false`. Ported from arianvp#2. bes-stack replaced upstream's pool.rs with sluongng's sharded client (70c6a39), so the integration is re-implemented there rather than cherry-picked: - The Unix socket connector and the plaintext override move from the pool into GrpcChannelConnector. bes-stack needs the override because its `tls` key wins over the address scheme (e8ba7b2). - bes-stack connects channels eagerly, so the daemon starts before the connectors dial. - Arian's per-call socket check and five-second probe are gone. A dead daemon now surfaces as a broken connection in the existing retry loop, and GRPCClients::reconnect starts a successor before redialing the CAS or ByteStream channel. The failing request is retried, not lost. - Warm-up reads use bes-stack's resource names, digest function segment included. - The auto-started daemon takes its digest function from the effective `digest_algorithms` bes-stack already passes in, not from a second parse of `[buck2] digest_algorithms`. - Batch uploads to the daemon go uncompressed. bes-stack picks a batch compressor from the engine's capabilities, and the daemon rejects compressed batch updates; its own upstream client compresses for the remote. Found in the live test against Namespace. - The client refuses `remote_cache_chunking` together with `cas_shared_cache`, because the daemon implements neither SplitBlob nor SpliceBlob. shared_cache.rs, casd_autostart.rs, the configuration keys and the download tests are Arian's as written, adjusted for bes-stack's `Option<bool>` `tls` and its test helpers. Assisted-by: Claude:claude-opus-5-5
The daemon serves the remote execution API's CAS, ByteStream and Capabilities services on a Unix socket in its directory, or on a loopback port, and never listens off the machine. It stores each blob once as a raw read-only file at <dir>/blobs/<xx>/<hash>-<size>. Raw files are what lets a buck2 daemon clone a blob whole, as a reflink where the filesystem supports one. Misses, uploads and FindMissingBlobs pass through to the upstream CAS via buck2's own OSS client. Concurrent misses for one digest fetch once, and eviction is LRU by mtime under an optional size cap. Ported from arianvp#2; the crate is Arian's. Three changes make it fit bes-stack. The upstream client leaves TLS to the address scheme unless `--upstream-tls` is given, matching bes-stack's `Option<bool>` `tls`. The upstream client gets the daemon's digest function, so it names blobs the way buck2 does. And ByteStream resource names may carry the REAPI 2.3 digest function segment (`blobs/blake3/<hash>/<size>`), which bes-stack sends for BLAKE3. The autostart test now expects the client's retry, not a timed probe, to replace a killed daemon. Assisted-by: Claude:claude-opus-5-5
buck2-casd outlives the buck2 daemons that start it, so without this it runs until reboot, and an upgraded buck2 keeps talking to the old binary. Recognising it in is_buck2_exe makes killall stop it. The filtered forms of killall, by isolation dir or repository, still leave it alone. A live client whose daemon disappears starts a new one on its next CAS request. From arianvp#2. Assisted-by: Claude:claude-opus-5-5
Documents the `cas_shared_cache` keys, the daemon's lifecycle, and the limit a reader would otherwise rediscover: action digests include the isolation dir, so two isolation dirs share blob content but never action cache hits. From arianvp#2. Assisted-by: Claude:claude-opus-5-5
This was referenced Sep 26, 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.
Arian's buck2-casd, arianvp#2, ported onto
bes-stack. Each buck2 daemon on a devbox keeps its outputs underbuck-out/<isolation-dir>, so every lab worktree and isolation dir downloads and stores its own copy of every blob. With[buck2_re_client] cas_shared_cache = <dir>, one machine-local daemon owns the blob store, and every buck2 daemon clones out of it.For the consumer. Set
cas_shared_cacheto a directory on the same filesystem asbuck-out. The first buck2 daemon that needs it startsbuck2-casd, the binary next tobuck2orcas_shared_cache_binary, on a Unix socket in that directory. It passes the daemon its owncas_address, TLS settings, instance name and digest function. CAS and ByteStream traffic then goes to the daemon, which fetches each blob from the remote once and keeps it as a raw file. buck2 clones those files intobuck-out. The engine and the action cache are still reached directly.buck2 killallnow stops the daemon too. Its filtered forms should leave it alone, because the daemon's command line has no--isolation-dir. That comes from reading the code, not from a run, since the unfiltered form would stop every session's daemons on this machine. A buck2 daemon whosebuck2-casddisappears starts a new one on its next CAS request.What was ported and what was rewritten. The daemon crate,
shared_cache.rs,casd_autostart.rs, the configuration keys, the docs and the tests are Arian's code. The four commits keep him as author. His PR's seven commits include an action cache that was added and then removed, so the net change is split by area instead of replayed. His client integration edits upstream'spool.rs.bes-stackhas no such file since70c6a3996dreplaced it with sluongng's sharded client, so the integration is re-implemented onGrpcChannelConnectorandGRPCClients:GrpcChannelConnector. The override is needed because onbes-stackthetlskey wins over the address scheme (e8ba7b2835), so a loopback daemon would otherwise be dialled over TLS.bes-stackconnects its channels eagerly, so the daemon starts before the connectors dial.GRPCClients::reconnectstarts a successor before it redials the CAS or ByteStream channel, and the request is retried rather than failed.bes-stackpicks a batch compressor from the engine's capabilities, and the daemon rejects compressed batch updates. The first live build hit exactly that. The daemon's own upstream client still compresses toward the remote; against Namespace it selected zstd.remote_cache_chunkingwithcas_shared_cacheis refused at connect time, because the daemon implements neither SplitBlob nor SpliceBlob.blobs/blake3/...) thatbes-stacksends for BLAKE3. The daemon's upstream client is also given the daemon's digest function.Base. This targets
bes-stack, not #51 (credential helper). The two touch the same files,client.rs,buck2_re_configurationanddocs/users/remote_execution.md, but in different places. Whichever lands second needs a textual rebase, not a redesign. One interaction to settle then: an auto-startedbuck2-casdgetshttp_headersbut notcredential_helper, so with a short-lived token its upstream connection would go stale while buck2's own connections renew.Evidence, 2026-09-26. These binaries were built with
cargo build --releasefrom this branch, not with buck2.cargo test:remote_execution110 passed,buck2_casd9 unit, 3 end-to-end and 1 autostart,buck2_re_configuration7,buck2_wrapper_common6. The autostart test starts the real binary from the client and replaces it after SIGTERM and after SIGKILL under a live client. Clippy reports nothing in the touched crates.Against Namespace RE, a scratch project with one remote action writes three incompressible 8 MB files. Two buck2 daemons,
--isolation-dir casdAandcasdB, shared onecas_shared_cache. A third daemon,casdCin a copy of the project without the key, is the control.bc62b92cc0a450d1b6ee7a59After casdB the store still held the same three 8 MB files: same inodes, same mtimes, and outputs with identical sha256 in both
buck-outtrees. So the 24 MB crossed the network once, for two daemons.A SIGKILLed
buck2-casdwith its socket file left behind was replaced by casdB's next build (build083ae77b), which succeeded.Not proven.
buck-outhas its own copy next to the store's. The network saving is proven; the disk saving needs btrfs or XFS and was not tested.buck2-casdsitting next tobuck2. Nothing packages it there yet, and lab'stools/buck2/pinis unchanged.Seen during the port, not changed here.
Posted by Claude Code on behalf of Jun Matsushita.