Repository navigation
Description
Blocked on #908 (Cloudflare under Terraform), because an R2 bucket and its
API token are Cloudflare resources and this repo declares all infrastructure in
Terraform.
Why: the Actions cache backend is measurably too slow
#887/#893 moved sccache off S3 to kill $209/month of egress. That worked — the
egress is gone and is not coming back. But the Actions cache backend is 2.5x
slower, measured on main:
| wall | backend | |
|---|---|---|
3615cf18 |
9.8 min | S3 |
9583e470 |
25.1 min | ghac, first main run |
Two independent causes, both measured:
1. Per-hit read latency doubled. Average cache read hit 0.122 s on S3
against 0.242 s on ghac. At 500–1,100 hits per job that is ~1–2 min on the
critical-path job, and it is irreducible — it is just a slower store.
2. The write quota, which is the dominant cause. 9583e470 dropped 3,763
writes and landed 1,164, a ~24% success rate, giving hit rates across its
nine compile jobs of 1.37 / 6.32 / 21.77 / 26.74 / 30.34 / 32.04 / 36.32 /
39.74 / 48.25 % — mean ~27%. Cause is upstream and confirmed:
mozilla/sccache#2821 —
GHACache::build installs no RetryLayer, so GitHub's HTTP 429 is counted
rather than retried. The rate limit is per workflow run, shared across every
job in it, and 0.19.0 is affected.
#901 cannot fix this, and the ticket overstates its effect. Because the quota
is per run, one writer and twelve writers get the same ~1,100 objects. #901
makes those 1,100 a coherent set from one job instead of twelve overlapping
fragments — a real improvement in coverage, not a path back to a 10-minute gate.
Why R2 specifically
| cost/mo | read latency | per-run write quota | |
|---|---|---|---|
| S3 (before) | $209 | 0.122 s | none |
| ghac (now) | ~$5 | 0.242 s | ~1,100/run |
| R2 | ~$2 | S3-grade (S3 API) | none |
R2 is the only option that is both cheap and fast: zero egress fees, and it
is not GitHub's cache service so neither the 429 bug nor the per-run quota
applies. Priced at this footprint: ~4.8 GB storage at $0.015/GB-mo = ~$0.07,
plus ~4.6M Class B reads at $0.36/M = ~$1.66.
sccache reaches it through the S3 backend with SCCACHE_ENDPOINT, so the
workflow change is an endpoint and a credential rather than a new code path.
Cache poisoning — the open design question
The S3 setup had er-ci-sccache-read / er-ci-sccache-write precisely because a
PR able to write the cache is a path for a branch to plant object code a later
main build consumes, and poisoning outlives the credential that planted it.
R2 has no IAM condition keys, so that must be rebuilt:
- Two scoped R2 API tokens — read-only for PR jobs, read-write exposed only
tomain— mirroring both the S3 roles and the token split infra: bring the Cloudflare zone under Terraform (and give CI a scoped read-only token) #908 needs for the
zone. This is the expected answer. - Note the Actions backend currently provides this property for free via
branch scoping (verified on ci(rust): sccache back on the Actions cache backend, off S3 #893: all 1,137 entries landed on
refs/pull/893/merge, zero onrefs/heads/main). Moving to R2 gives that
up, which is the one way R2 is a step backwards and the reason this was not
the first choice.
Also closes, as a side effect
- ci: cache-prune will outgrow its 30m timeout now that sccache writes one entry per object again #902 — per-branch scopes drove entry count 73 → 1,223 in an hour and put
cache-pruneon course to outgrow its 30-minute timeout. R2 is one shared
content-addressed namespace, so the entry explosion goes away. - ci: concentrate the sccache GHA write quota on one writer (upstream 429 drops 45-90% of writes) #901 becomes moot.
- ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892 — unblocks deleting
sccache.tf, since the S3 bucket and both roles
go when nothing references them. Do not delete it before this lands; it is the
rollback.
Scope
- infra: bring the Cloudflare zone under Terraform (and give CI a scoped read-only token) #908 first: Cloudflare in Terraform with a working CI token story
- R2 bucket + lifecycle rule (14-day expiry, matching
sccache.tf) in
Terraform - Two scoped tokens; the write one reachable only from
main -
rust.yml:SCCACHE_BUCKET+SCCACHE_ENDPOINT+SCCACHE_REGION=auto,
droppingSCCACHE_GHA_ENABLED - Probe first, do not assume: sccache 0.19.0 against R2 is documented but
unverified here. Confirm on a branch before touching the gate. - Also move
shared/rust-gate.md(ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892) so one backend serves everything - Measure: wall time against the 9.8 min S3 baseline, and
Cache write errorsshould be ~0
Interim
Until this lands the gate runs at ~25 min. Reverting #893 restores ~9.8 min at
$209/month — sccache.tf, the bucket and both roles are deliberately still in
place, so git revert needs nothing re-provisioned. That is a cost-versus-CI-
throughput call for the owner.
Activity
infra(core): declare the R2 sccache bucket and its lifecycle rule
infra(core): declare the R2 sccache bucket and its lifecycle rule (#910…
fix(infra): the Cloudflare credential must reach the apply step, not …