Repository navigation
Conversation
Every buck2 daemon keeps its materialized outputs under buck-out/<isolation-dir>, so daemons with different isolation dirs, or different checkouts of the same repository, each download and store their own copy of every blob. Meta's build avoids this with a shared CASd that is not part of the open-source client, which writes each download straight into its destination. This adds an in-process equivalent to the gRPC client: a content-addressed directory, shared by every daemon configured with the same path, that blobs are downloaded into once and then cloned into whichever buck-out asks for them. On btrfs, XFS and APFS the clone is a reflink, so the data exists once on disk regardless of how many daemons use it; elsewhere it degrades to a copy that still saves the fetch. [buck2_re_client] cas_local_cache = $HOME/.cache/buck2/cas cas_local_cache_copy_policy = hybrid # or reflink, copy cas_local_cache_max_size_bytes = ... Design notes: - Blobs live at <root>/blobs/<hh>/<hash>-<size>, written to <root>/tmp and moved into place with an atomic rename, so concurrent daemons need no coordinating process. Sizes are verified before commit, so a short or truncated response can no longer be written silently. - Lookups happen before any upstream request is built, so hits are never requested from the remote, and a digest wanted at several paths is fetched once per request. - Files buck2 uploads are added to the cache too, but only when they can be reflinked; copying them would double the disk usage of every input on filesystems where the cache cannot share space anyway. - Eviction is LRU by mtime (hits touch the blob) and runs in the background once the configured cap is exceeded. Stale temporary files from dead processes are swept on startup. - Hit and miss counts are reported through the existing TLocalCacheStats plumbing, so they show up in the invocation record. - CopyPolicy now rejects unknown values instead of silently treating them as `copy`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
Replace the in-process per-daemon store from the previous commit with the architecture Meta uses: one machine-local CAS daemon owns the blob store, and every buck2 daemon on the host clones out of it. buck2-casd (remote_execution/oss/casd): - Serves the remote execution API's ContentAddressableStorage, ByteStream and Capabilities services on a loopback TCP port, including zstd, deflate and brotli compressed-blobs resources, since buck2 picks a compressor from the real backend's capabilities. - Passes misses, uploads and FindMissingBlobs through to an upstream CAS via the same gRPC client buck2 uses, so TLS, headers, retries and batching behave identically. Without --upstream it is a standalone CAS. - Stores every blob as a raw, read-only file at <dir>/blobs/<xx>/<hash>-<size>, written via temp file and atomic rename, and verifies size and hash before publishing, whether the bytes came from a client or from upstream. Raw files are what makes a whole-file reflink possible; bazel-remote and NativeLink both store blobs in a form buck2 cannot clone (a container header, or a file name with an internal generation counter), which is why this exists. - Is the single downloader (concurrent misses for one digest fetch once) and the single evictor (LRU by mtime under --max-size-bytes). buck2 client: - Config keys mirror Meta's: cas_shared_cache (the daemon's directory), cas_shared_cache_address (port or grpc URL; when set, CAS traffic goes to the daemon without TLS while engine and action cache keep their own addresses), cas_shared_cache_copy_policy (hybrid, reflink, copy) and cas_shared_cache_mode (local_without_sync or remote). - Buck2 only reads the directory. Blobs present there are cloned into buck-out; for the rest buck2 asks the daemon for the first byte, which makes it fetch and store the whole blob, then clones that too, so even the first daemon to need a blob gets a shared copy. Anything still absent is received over gRPC as before. - The channel pool gains a plaintext path for the daemon address, since TLS was previously a pool-wide setting. - Hits and misses flow through the existing TLocalCacheStats plumbing. Tests: store unit tests; end-to-end tests that run real daemons on loopback, drive them with the buck2 gRPC client, and cover standalone use, a proxy chaining to an origin, both directions over compressed ByteStream, concurrent misses, rejected uploads and eviction; and client tests for hit, warm-then-clone, gRPC fallback and empty files. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
…tion dir limits A daemon started without --upstream now also implements the remote execution API's ActionCache service, storing serialized action results under <dir>/ac/<xx>/<hash>-<size>. That makes it a complete cache backend for local builds (engine, action cache and CAS addresses all pointed at it), which is what an end-to-end check with a real buck2 daemon needed and what a purely local multi-checkout setup wants. With an upstream the action cache is refused with a pointer to action_cache_address, since the daemon only proxies CAS traffic. Verified with the buck2 binary built from this tree, two daemons (a standalone origin and a proxy in front of it) and a small project whose actions upload their outputs: a clean followed by a rebuild, and a build in a second checkout, both took action cache hits and materialized all 6.9 MB of outputs from the proxy's directory, with 696 bytes received over gRPC. Builds in other isolation dirs got no action cache hits at all, because the Command proto's output paths contain the isolation dir name and so the action digest differs per isolation dir; their identical output blob was still deduplicated in the store. The docs now say so. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
It was added only to get action cache hits in an environment without a remote executor, which is not the daemon's job: like Meta's CASd it proxies and shares CAS blobs, and the action cache belongs to the remote. The documentation of what does and does not carry across isolation directories stays. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
The daemon only ever serves this machine, so it now listens on a Unix socket, by default `buck2-casd.sock` inside its store directory, and the buck2 client dials that socket: the channel pool gains a Unix connector next to its TCP one, and `cas_shared_cache = /path` is the whole configuration. `cas_shared_cache_address` stays as Meta's CASdAddress type (`unix:///path` or a loopback port) only to move the daemon off its default socket; a port is the one option on Windows, which has no Unix sockets. Nothing can point buck2 at a daemon on another host. With the socket known, buck2 starts the daemon itself when nothing answers there (`cas_shared_cache_autostart`, default on). It runs the `buck2-casd` next to its own executable, or `cas_shared_cache_binary`, detached in its own process group with output in `buck2-casd.log`, and hands it the directory, the socket, the digest function from `[buck2] digest_algorithms`, `cas_shared_cache_max_size_bytes`, and the `cas_address`, TLS and instance name settings as its upstream. HTTP headers travel through the environment so literal secrets stay out of `ps`. A lock file in the directory makes one of several racing buck2 daemons do the starting while the others wait for the socket. The daemon writes `buck2-casd.pid` with its pid and address, and is never stopped by buck2 since other daemons and checkouts may be using it. Verified with the buck2 binary built from this tree and no daemon started by hand: the first build spawned buck2-casd on the socket with the upstream from buckconfig, its cache misses were fetched by the daemon and cloned from the directory with 892 bytes over gRPC, a clean rebuild and a second checkout were full directory hits against the same daemon pid, and the daemon survived `buck2 killall`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
…ts loss The daemon speaks the remote execution API, which is stable, so an older daemon under a newer buck2 is not a compatibility problem; what was missing was a way to stop and replace it and a way for running buck2 daemons to survive its disappearance. - `buck2 killall` now stops `buck2-casd` along with the buck2 daemons. The filtered forms (`--in-isolation-dir`, `--repo`) leave it alone, since it belongs to the machine, not to a repo. This is also how a new daemon binary is picked up after upgrading buck2. - The daemon removes its socket and pid files on SIGTERM and SIGINT, removing the socket first so that clients notice at once, and gives in-flight requests five seconds to finish; idle client connections do not hold it up. - A live buck2 client re-runs the start logic when the socket file is gone (a clean exit) and, at most every five seconds, when the daemon stops answering (SIGKILL, a crash), so builds keep working; at worst one request mid-flight fails. Since a download the directory can serve never touches the daemon, this only costs a stat per CAS call. - The client reaps the daemon it spawned if that dies, so a dead daemon no longer lingers as a zombie of the buck2 daemon that started it. Verified with the buck2 binary built from this tree: a build autostarts the daemon, `buck2 killall` reports and kills it, a build after SIGTERM starts a fresh one, and the crate test covers SIGTERM and SIGKILL under live clients with uploads succeeding through the replacement daemon. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
- `CopyPolicy::from_str` goes back to treating unknown values as `Copy`, which is what the internal `cas_shared_cache_copy_policy_v2` key has always relied on; the open-source `cas_shared_cache_copy_policy` key is parsed strictly through a separate `parse_strict`. - The autocargo-generated workspace manifest keeps its alphabetical order, and the daemon's manifest carries no field autocargo would not emit. - The autostart test is Unix-only (sockets and signals), and the end-to-end tests use loopback ports where there are no Unix sockets, so the crates build and test on Windows too. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 11, 2026
…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 Change-Id: I1a0f434f1180ca4d1d350594a99f9a6ddaa56b0a
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 11, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 11, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 11, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
…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 Change-Id: I1a0f434f1180ca4d1d350594a99f9a6ddaa56b0a (cherry picked from commit 2491333)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a (cherry picked from commit fe7b182)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3 (cherry picked from commit bdd0643)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506 (cherry picked from commit 28ea9f8)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a (cherry picked from commit fe7b182)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3 (cherry picked from commit bdd0643)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 15, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506 (cherry picked from commit 28ea9f8)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
…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 Change-Id: I1a0f434f1180ca4d1d350594a99f9a6ddaa56b0a (cherry picked from commit 2491333)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a (cherry picked from commit fe7b182)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3 (cherry picked from commit bdd0643)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506 (cherry picked from commit 28ea9f8)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
…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 Change-Id: I1a0f434f1180ca4d1d350594a99f9a6ddaa56b0a (cherry picked from commit 2491333)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a (cherry picked from commit fe7b182)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3 (cherry picked from commit bdd0643)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506 (cherry picked from commit 28ea9f8)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
…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 Change-Id: I1a0f434f1180ca4d1d350594a99f9a6ddaa56b0a (cherry picked from commit 2491333)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I32dd67250edadf6b9c6eb3dcc662318860d3bb7a (cherry picked from commit fe7b182)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: I9170bdd542f00bea98c584812376099c2b7b6ef3 (cherry picked from commit bdd0643)
jun-mercury
pushed a commit
to mercury/buck2
that referenced
this pull request
Oct 17, 2026
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 Change-Id: Ifb66e8c920f09d17e6ecefd61cb3496bb48f7506 (cherry picked from commit 28ea9f8)
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.
Problem
Every buck2 daemon keeps its outputs under
buck-out/<isolation-dir>, so daemons with different isolation dirs, or different checkouts of the same repository, each download and store their own copy of every blob. Meta avoids this with a shared CAS daemon (CASd) that the open-source client has no equivalent of: the OSS gRPC client writes every download straight into its destination.What this adds
The same architecture for open source: one machine-local CAS daemon owns the blob store, and every buck2 daemon on the host clones out of it. Configuration is one line:
buck2-casd(remote_execution/oss/casd, builds to abuck2-casdbinary)buck2-casd.sock), or on a loopback port; it never listens off the machine. Handles zstd, deflate and brotlicompressed-blobs, since buck2 picks a compressor from the real backend's capabilities.--upstreamit is a standalone CAS.<dir>/blobs/<xx>/<hash>-<size>, written via temp file and atomic rename, with size and hash verified before publishing. Raw files are what make a whole-file reflink possible; bazel-remote and NativeLink both store blobs in a form buck2 cannot clone (a container header, or a file name with an internal generation counter), which is why this daemon exists rather than reusing one of them.buck2-casd.pid; removes it and the socket on SIGTERM/SIGINT after a bounded drain.buck2 client
buck2-casdnext to its own executable (orcas_shared_cache_binary), detached in its own process group with output inbuck2-casd.log, given the directory, the socket, the digest function from[buck2] digest_algorithms,cas_shared_cache_max_size_bytes, and thecas_address, TLS and instance name settings as its upstream. HTTP headers go through the environment so secrets stay out ofps. A lock file makes one of several racing buck2 daemons do the starting while the others wait.cas_shared_cache_autostart = falsefor a service manager.buck2 killall, which now stops it along with the buck2 daemons (the filtered--in-isolation-dirand--repoforms leave it alone), or a reboot. The protocol between them is the remote execution API, so an older daemon keeps working under a newer buck2;buck2 killallis how a new daemon binary is picked up after an upgrade. A live buck2 daemon whose CAS daemon disappears (killed, crashed, directory removed) re-runs the start logic: at once when the socket file is gone, and at most every five seconds when the daemon stops answering, so builds keep working with at worst one request failing mid-flight. Buck2 reaps a daemon it spawned if that dies.buck-out(a reflink on btrfs, XFS and APFS, a copy elsewhere). For the rest buck2 asks the daemon for the first byte, which makes it fetch and store the whole blob, then clones that too, so even the first daemon to need a blob gets a shared copy. Anything still absent is received over gRPC as before.cas_shared_cache,cas_shared_cache_address(Meta'sCASdAddresstype:unix:///pathor a loopback port, only to move the daemon off its default socket; a port is the one option on Windows),cas_shared_cache_copy_policy(hybrid,reflink,copy; parsed strictly),cas_shared_cache_mode(local_without_sync,remote), pluscas_shared_cache_autostart,cas_shared_cache_binaryandcas_shared_cache_max_size_bytes.TLocalCacheStatsplumbing into the invocation record.Docs: a new section in
docs/users/remote_execution.mdand a note indocs/concepts/isolation_dir.md.Effect on Meta's build
Intended to be none.
#[cfg(fbcode_build)]code is untouched. The internalremote_executionclient is selected by the existing alias; the new daemon crate depends on the OSSre_grpccrate directly, like the OSS client itself, and comes with a BUCK file in the same style (oncall, third-party deps).buck2_re_configuration, which both builds share, only gains fields onBuck2OssReConfiguration(constructed solely byfrom_legacy_config) andCopy/PartialEq/Eqderives onCopyPolicy.CopyPolicy::from_strkeeps treating unknown values asCopy, which the internalcas_shared_cache_copy_policy_v2key relies on; the OSS key uses a separate strict parser.is_buck2_exeadditionally recognisesbuck2-casd, which does not exist internally.Cargo.tomlfiles are meant to match its output.cfg-gated, the autostart test is Unix-only, and the end-to-end tests use loopback ports where there are no Unix sockets.What does not change
An action's digest includes its output paths, and those contain the isolation dir, so two isolation dirs never get action cache hits from each other. That is pre-existing buck2 behaviour. What they share is content: any blob one of them uploads or fetches is stored once and cloned into each
buck-out. Full materialization from the daemon's directory happens across checkouts, afterbuck2 clean, across daemon restarts, and for remotely executed actions whose outputs already exist locally.Testing
cargo check -p buck2_executepasses.buck2binary built from this branch, no daemon started by hand, a standalone origin with an action cache as the remote, and a small project (a 27-byte and a 6.9 MB output; uploads enabled with[buck2] default_allow_cache_upload = true): the first build spawnedbuck2-casdon the socket with the upstream from buckconfig and had its misses fetched by the daemon and cloned from the directory with 869 bytes over gRPC; afterbuck2 clean, and in a second checkout, both actions were cache hits materialized entirely from the directory with 696 bytes over gRPC;buck2 killallreported and killed the daemon; a build after SIGTERM started a fresh one.Known limits
Uploads are forwarded synchronously rather than write-behind. GetTree, SplitBlob and SpliceBlob are unimplemented; buck2 does not call them. Windows has no Unix sockets, so it needs
cas_shared_cache_addressset to a port.History
dd7463cwas an in-process per-daemon store, replaced by the daemon design inbb1892b;5e9760d/1596c92added and removed a standalone action cache used for testing;9436425moved the daemon to a Unix socket and added autostart;6c33e9emadekillallstop it and live clients recover from its loss;4b337ffkeeps Meta's build unaffected. Squashing on merge is recommended.🤖 Generated with Claude Code
https://claude.ai/code/session_01Aco8NCns5VUrLHBfCjNDT3