Skip to content

Remote cache: the gRPC interface of the Remote Execution API (#19) - #79

Open
ambroise-leclerc wants to merge 4 commits into
18-uploadsfrom
19-grpc
Open

ambroise-leclerc wants to merge 4 commits into
18-uploadsfrom
19-grpc

Conversation

@ambroise-leclerc

Copy link
Copy Markdown
Owner

Summary

cppmcache can now use servers that offer only the gRPC interface of the Remote Execution API, such as BuildBuddy and Buildbarn. Last part of epic #38, stacked on #78.

  • URLs: grpc://host[:port][/instance] and grpcs://…. The path is the instance name. grpcs is TLS with ALPN h2, with the same Web PKI authentication and credentials as https (Remote cache: TLS and authentication #17); the credentials go in the authorization metadata.
  • Implementation choice (the open question of Remote cache: speak the gRPC interface of the Remote Execution API #19): gRPC written in this project over HTTP/2, rather than the official gRPC and protobuf libraries. TLS was already provided by stdnet (Remote cache: TLS and authentication #17), and protobuf encoding was already here (Proto.cppm). The libraries would have added a very heavy dependency next to import std;, and every project importing cppmcache with CPM would have had to build it.
    • Grpc.cppm: an HTTP/2 client limited to what cache calls need: one connection, one call at a time, prior knowledge or ALPN. It advertises the largest windows, honours the server's windows and frame size, refuses push, and ends a call on GOAWAY or RST_STREAM.
    • Hpack.cppm: HPACK. The encoder writes literal fields only, with authorization marked never-indexed. The decoder covers the whole format: dynamic table, size updates, Huffman. The Huffman and static tables are generated from the text of RFC 7541 and checked there: 257 codes, each matching its bit pattern, forming a complete prefix code.
  • Calls: ActionCache.GetActionResult and UpdateActionResult; FindMissingBlobs; BatchReadBlobs and BatchUpdateBlobs for blobs up to 3 MiB per batch; ByteStream.Read and Write above that, in chunks of 1 MiB. Consecutive operations of one kind share a call.
  • Manifest keys: a manifest key names no action and gets a nominal digest size of 1. bazel-remote refuses a size of 0 for a hash other than the empty blob's (Invalid zero-length SHA256 hash).
  • Blobs are not compressed over gRPC yet. The compressed-blobs/zstd resources would be the next step.

Closes #19

Verification

  • GCC 16.1: configure, build and ctest: 109/109 passed
  • Clang 21 with libc++: configure, build and ctest: 109/109 passed; clang-tidy clean on the files touched
  • MSVC: CI only
  • clang-format --dry-run -Werror on the files touched
  • tools/check_attribution.py
  • Other, against the pinned bazel-remote image on this machine:
    • tests/integration/Remote.cmake with CPPMCACHE_REMOTE=grpc://…:9092: passed, including a new step with a 5 MB output that goes through ByteStream both ways;
    • the same with grpcs://, the test root, Basic authentication (htpasswd), an untrusted root, wrong credentials (gRPC status 16) and a password read from a file: passed;
    • unit scenarios: every example of RFC 7541, Appendix C (with and without Huffman, evictions in a 256-byte table), malformed blocks, gRPC framing and URLs.

Two defects found that way and fixed before this PR: FindMissingBlobsResponse.missing_blob_digests is field 2, not 1 (no blob was uploaded, so bazel-remote, which checks an ActionResult's dependencies, answered NOT FOUND); and the size-0 digest above.

Not verified: servers other than bazel-remote (BuildBuddy, Buildbarn); Windows and macOS (CI does not run bazel-remote there); a server that sends a header block in several CONTINUATION frames.

Effect on cache keys

None.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 00:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still has unresolved moderate issues affecting performance (per-frame heap allocations), protocol correctness (invalid HTTP/2 WINDOW_UPDATE handling), and functional interoperability (gRPC has() sending size_bytes = 0), indicating it isn’t ready for approval.

3 open issues
What changed in this PR

Adds support for Remote Execution API remote caches via the gRPC interface (grpc:// / grpcs://) by implementing an in-repo gRPC-over-HTTP/2 client and HPACK, wiring it into remote cache operations, and extending tests/docs.

Changes:

  • Add grpc:// and grpcs:// URL support (including instance path) and route remote cache operations through REv2 gRPC services.
  • Introduce minimal HTTP/2 + HPACK + gRPC plumbing in-tree (Grpc.cppm, Hpack.cppm) to avoid external gRPC/protobuf dependencies.
  • Expand unit/integration coverage and CI to exercise gRPC paths (framing, HPACK examples/malformed blocks, URL parsing, and ByteStream for larger blobs).
File Description
tests/​spec/​HttpSpec.cpp Updates HTTP-related spec expectations to account for grpc:// and grpcs:// schemes in URL parsing/diagnostics.
tests/​spec/​HpackSpec.cpp Adds HPACK unit tests covering RFC 7541 Appendix C examples and malformed header-block scenarios.
tests/​spec/​GrpcSpec.cpp Introduces gRPC-focused unit tests for message framing and grpc(s):// URL parsing behavior.
tests/​integration/​Remote.cmake Extends remote integration testing to exercise gRPC mode, including a large-blob round trip through ByteStream.
tests/​CMakeLists.txt Registers the new gRPC and HPACK spec tests in the test build configuration.
src/​cppmcache/​RemoteTransportDisabled.cpp Updates the disabled transport stub to match the transport API changes (including the ALPN parameter).
src/​cppmcache/​RemoteTransport.hpp Extends the remote transport interface to accept an ALPN protocol name when opening connections.
src/​cppmcache/​RemoteTransport.cpp Implements/plumbs ALPN selection for TLS connections through the updated transport open API.
src/​cppmcache/​Remote.cppm Adds the gRPC-backed remote cache execution path implementing REv2 ActionCache/CAS/ByteStream calls with batching and call reuse.
src/​cppmcache/​Http.cppm Extends URL parsing/printing and related diagnostics to recognize grpc:// and grpcs:// remote cache URLs.
src/​cppmcache/​Hpack.cppm Implements HPACK encoding (literal fields) and full decoding (dynamic table, size updates, and Huffman) needed for HTTP/2 headers.
src/​cppmcache/​Grpc.cppm Implements a minimal gRPC client over HTTP/2 tailored for remote cache calls, including framing, settings, and flow control handling.
src/​cppmcache/​Cache.cppm Adjusts cache logic to propagate digest sizing requirements needed by the gRPC/REv2 code path (including manifest key handling).
README.md Documents how to use grpc(s):// remote cache URLs and the high-level behavior of gRPC mode.
docs/​usage.md Adds user-facing guidance for configuring and using the remote cache over gRPC, including notable behavior and limits.
CMakeLists.txt Wires the new module sources (HPACK/gRPC) into the build configuration.
.github/​workflows/​ci.yml Updates CI to run integration coverage against bazel-remote’s gRPC endpoints (plain and TLS) alongside existing checks.

Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

Comment thread src/cppmcache/Grpc.cppm Resolved
Comment thread src/cppmcache/Grpc.cppm Resolved
Comment thread src/cppmcache/Remote.cppm Resolved
@ambroise-leclerc
ambroise-leclerc force-pushed the 19-grpc branch 3 times, most recently from 892eb8b to 1fcc1a5 Compare December 1, 2026 02:22
- grpc:// and grpcs:// URLs, the path being the instance name. grpcs is TLS
  with ALPN h2 and the same authentication and credentials as https.
- An HTTP/2 client written here (Grpc.cppm): prior knowledge or ALPN, the
  largest windows advertised, the server's windows and frame size honoured,
  no push, GOAWAY and RST_STREAM ending the call. HPACK (Hpack.cppm): literal
  fields when encoding, the whole format with Huffman coding when decoding.
- The operations of the remote cache become ActionCache.GetActionResult and
  UpdateActionResult, FindMissingBlobs, BatchReadBlobs and BatchUpdateBlobs
  below 3 MiB, ByteStream.Read and Write above. A manifest key gets a nominal
  digest size of 1: servers refuse 0 for a hash other than the empty blob's.
- Tests: the examples of RFC 7541, Appendix C; gRPC framing and URLs; a 5 MB
  output in the remote integration test; CI runs that test against
  bazel-remote's gRPC port, plain and with TLS and Basic authentication.
- A call on a connection kept from an earlier one is made again once on a new
  connection when it fails: the server may have closed an idle connection.
- The receive windows start at their largest and are widened again once half
  of either is used, so that a long connection or a large download does not
  stall.
A server whose limit on the size of a batch is below 3 MiB answers
INVALID_ARGUMENT or RESOURCE_EXHAUSTED: the blobs of that batch then go one by
one through ByteStream, which has no such limit, instead of failing.
… a size (#19)

- The 64 KiB buffer of readFrame() is allocated once per channel.
- A WINDOW_UPDATE of zero, or one that takes a window beyond 2^31 - 1, ends the
  connection as a protocol error (RFC 9113, section 6.9).
- RemoteCache::has() takes the size of the digest, which gRPC needs.
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.

2 participants