Repository navigation
ci(rust): sccache on Cloudflare R2 — cheap AND fast - #920
Merged
Merged
Conversation
Third backend, and the first that is both. Measured on `main`: S3 (#350, 3615cf1) 9.8 min $209.32/mo egress ghac (#893, 9583e47) 25.1 min ~$5/mo R2 (this) TBD ~$2/mo S3 was fast and expensive — runners sit outside AWS, so every read was billed internet egress and no VPC endpoint can reach it. CUR 2.0 per-resource put `er-ci-sccache` / `DataTransfer-Out-Bytes` at $209.32 of a $211.62 November S3 total, against $0.02 of storage. The Actions backend was cheap and 2.5x slower, for two measured reasons. Per-hit read latency roughly doubled (`Average cache read hit` 0.122s -> 0.242s), and GitHub rate-limits cache writes PER WORKFLOW RUN shared across every job in it, while sccache's `GHACache::build` installs no `RetryLayer` and counts the resulting HTTP 429 instead of retrying (mozilla/sccache#2821, unfixed in the pinned 0.19.0). The first `main` run dropped 3,763 writes and landed 1,164 — 24% success, hit rates averaging ~27%. R2 has zero egress fees and is not GitHub's cache service, so neither the quota nor the retry bug applies. CREDENTIALS, and why there are two. R2 has no OIDC and no IAM condition keys, so the `er-ci-sccache-read`/`-write` role split cannot be reproduced directly — and it must be, because a PR able to write the cache is a path for a branch to plant object code a later `main` build consumes. The Actions backend gave that property away free via branch scoping (verified on #893: all 1,137 entries on `refs/pull/893/merge`, none on `main`), and giving it up is the one way R2 is a step backwards. So an Object-Read-only token in repository secrets, an Object-Read-&-Write token in the `sccache-write` environment (`protected_branches: true`), and each compile job selects between them by ref. THREE FACTS THAT MAKE THAT WORK, none of them documented, all measured on a throwaway probe workflow rather than assumed: 1. An environment-name expression evaluating to the empty string means "no environment" — the job runs, is not blocked, does not error. 2. An Environment secret a job cannot reach resolves to the empty string, which is falsy, so `||` selects the read credential. Probe output on a non-main branch: `write_len=0 read_len=32`. 3. No deployment record is created when the expression is empty, so PRs do not spam the Deployments tab. The read token was verified genuinely read-only: list succeeds, PutObject returns AccessDenied. A denied write is a counted miss in sccache rather than a failure — the same behaviour `sccache.tf` relied on for the S3 read role. The endpoint must be the DEFAULT one. Jurisdictions are separate NAMESPACES, not aliases: this bucket was created with none, so the `.us.` variant the dashboard offers answers `NoSuchBucket`. Measured both ways. `SCCACHE_REGION=auto` because R2 has no regions and the S3 client requires the field to be set. Leaves `sccache.tf`, the S3 bucket and both OIDC roles in place — they are the rollback, and #892 still references the read role. Closes #909 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Nov 17, 2026
This was referenced Nov 27, 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.
Closes #909
What
rust.yml's sccache moves to Cloudflare R2 over the S3 API, with a two-tokenread/write split selected by ref.
Why
Third backend, and the first that is both cheap and fast. Measured on
main:3615cf18)9583e470)S3 was fast and expensive. The Actions backend was cheap and 2.5× slower:
per-hit read latency doubled (0.122s → 0.242s) and GitHub rate-limits cache
writes per workflow run shared across every job, while sccache installs no
RetryLayerand counts the 429 instead of retrying(mozilla/sccache#2821) — 3,763
writes dropped, 1,164 landed, ~27% mean hit rate. R2 has zero egress and is not
GitHub's cache service, so neither applies.
Proof
actionlint0,workflow-shell-check0, and structural assertions against theparsed YAML:
The credential mechanism was measured, not assumed. The docs state none of
it, so I ran a throwaway probe workflow on a branch and deleted it:
Which establishes all three things this depends on: an empty environment-name
expression means no environment (job runs, not blocked, no error); an
unreachable Environment secret resolves to the empty string, so
||selects theread credential; and no deployment record is created, so PRs do not spam the
Deployments tab.
The read token is genuinely read-only, with a negative control:
The endpoint choice was measured both ways, because the dashboard offers a
.us.variant:Jurisdictions are separate namespaces, not aliases — this bucket has none.
This PR's own run is the experiment, and the number to read is the wall time
against the 9.8-min S3 baseline, plus
Cache write errorswhich should be ~0rather than the hundreds per job the Actions backend produced.
Risk & rollback
Risk: PR runs are read-only, so a cold
maincache means PRs get no sccachebenefit until
mainhas populated it once — the same ramp S3 had. Rollback isgit revert;sccache.tf, the S3 bucket and both OIDC roles are deliberatelystill in place and need nothing re-provisioned.
Post-merge ledger
Closed by: unclosed
mainis green with this change on it — the merge SHA, and the runthat proves it. A later head SHA with this commit as an ancestor counts;
a cancelled run with zero jobs does not:
imagesbuilt, or correctly never ran because nothing that goes intoan image changed:
deployconverged — proved by a line the running process emitted, notby the image digest and not by the workflow conclusion:
deploy,drift,kind's nightly leg) is green, or knowingly red for a reason that is notthis change:
Donethrough the automation rather than byhand, and the issue closed:
(a skill, a reference, memory) — or nothing new was learned:
Specific to this change
mainrun with awarm cache — the second one, since the first populates
main's objects.This is the number the whole three-backend exercise exists to produce:
Cache write errorsis ~0 on amainrun. Hundreds per job was theActions backend's signature; if R2 shows the same, the diagnosis in ci: move the sccache bucket to Cloudflare R2 (zero egress AND no per-run write quota) #909
was wrong and this needs reopening rather than tuning:
(denied, counted as misses) while
maindoes not, which is thepoisoning protection working rather than merely configured:
Actions backend: ci: concentrate the sccache GHA write quota on one writer (upstream 429 drops 45-90% of writes) #901 is its per-run write quota, ci: cache-prune will outgrow its 30m timeout now that sccache writes one entry per object again #902 its per-branch
entry explosion. Neither applies to one shared content-addressed bucket.
Verify rather than assume, then close:
DataTransfer-Out-Bytesflatlines in the CUR, and the Actions cacheusage drops back toward the free 10 GB once sccache stops writing there:
sccache.tfand both OIDC roles — blocked on ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892, whichstill references the read role:
deferred — #892Context — plan, discoveries, measurements, files
Discoveries
workflow-syntax reference says nothing about expressions in
environment, norabout empty names. A 30-second probe workflow settled all three; guessing
would have cost a 25-minute gate cycle per attempt.
ID = the token's ID, Secret = SHA-256 of the token value. Verified against the
management token before the real credentials existed, which is how the whole
S3 path was de-risked early.
dropdown changes which namespace you address, and a bucket created without one
simply does not exist at
.us..-fingh apisends strings, sodeployment_branch_policy.protected_branchesrejected
"true"; a JSON body via--input -is required.the PreToolUse guard, which matches command text rather than intent. Write
the message to a file and use
-F.Files
.github/workflows/rust.yml— backend env, plusenvironment:and credentialson all 7 compile jobs