Repository navigation
ci(rust): sccache back on the Actions cache backend, off S3 - #893
Conversation
S3 egress from the sccache bucket was the largest line item in the AWS account. By CUR 2.0 per-resource attribution, November MTD: `er-ci-sccache` / `DataTransfer-Out-Bytes` was $209.32 of a $211.62 S3 total — 2,425.7 GB — while storage was $0.02 and the next-largest S3 line anywhere in the account was $0.05. GitHub-hosted runners sit outside AWS, so every cache read is billed internet egress at ~$0.09/GB and no VPC endpoint can reach it. The denominator is compile jobs, not runs: ~8.7 sccache jobs per `rust` run (measured across 25 runs on 2026-11-07), each pulling ~0.43 GB at a 99.8% hit rate, nearly all of it dependency objects a sibling job in the same run had already fetched. What makes this a revert rather than a regression: the 10 GB per-repository ceiling that drove #350 to S3 became PURCHASABLE on 2025-11-20, at $0.07/GB-month above the included 10 GB. Eviction was the entire problem with this backend — `cache-prune`'s own comment records run 39783867347 at 96.65%/97.54% hit rate with the whole workflow in 8m03 ON THIS BACKEND — and the ceiling is the part money fixes. The repository's eviction limit is now 20 GB, and the account is on Pro, which that setting requires. ~$4.70/month replaces $209. Cache poisoning is handled better than before, not worse. The two S3 roles existed because a PR able to write the cache is a path for a branch to plant object code a later `main` build consumes. GitHub enforces the same separation natively: a run cannot restore caches created for child or sibling branches, so a PR-branch entry is unreadable from `main` while PRs still read what `main` populated. Seven `id-token: write` grants and seven role assumptions are gone with it. `cache-prune`'s sccache budget goes LIVE again and is raised 5120 -> 12288 MiB. It spent the S3 era vestigial, kept precisely so this rollback would not silently uncap it — which is the one reason that note existed. Does NOT touch the two agentic workflows that import `shared/rust-gate.md`. They still point at S3, which costs nothing because they are disabled, and my `gh aw` is v1.0.1 while the committed lock files carry a v1.2.0 action pin — so recompiling here would silently downgrade `gh-aw-actions/setup` across four workflows. Follow-up ticket instead. Closes #887 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
First-run evidence (run 42510475808) — the experiment this PR exists to runAll 18 compile jobs ran and succeeded. Four things proven1. The v2 Actions cache service works with sccache 0.19.0. 2. The 20 GB eviction limit is live. This is the probe I said was 3. Branch scoping behaves exactly as the security argument claimed. All 4. Cold is not slow here, and my prediction was wrong. I said to expect a Why: the 12 parallel compile jobs populate the cache for each other mid-run, so One open question, and it is not benignWrites partially fail: The shape is suspicious rather than obviously harmless:
Equality in the first row means that job stored nothing it compiled. A plausible This is the thing to read on the first |
Merged — and one dynamic the first run exposed that was not in the planMerged as
The budget dynamic that replaces the egress billS3 was one shared content-addressed namespace: 4.78 GB total, every job both The Actions backend is scoped per branch — the property that gives us the So LRU eviction will be continuous rather than exceptional, and that is expected
If the warm hit rate on |
First half of #909. Creates the bucket; does NOT repoint `rust.yml`, which waits until the bucket exists and the two scoped credentials are in GitHub secrets — splitting them avoids the race where `rust.yml` on `main` runs against a bucket whose apply has not finished. WHY R2, after two backends that each failed differently. S3 (#350) was fast and expensive: runners sit outside AWS, so every read is 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 cache backend (#893) was cheap and slow: per-hit read latency roughly doubled (0.122s -> 0.242s), and GitHub rate-limits cache writes PER WORKFLOW RUN shared across every job, while sccache's `GHACache::build` installs no `RetryLayer` and counts the resulting 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, ~27% mean hit rate, 25.1 minutes against 9.8 on S3. R2 is the only option that is both: zero egress, and not GitHub's cache service so neither the 429 bug nor the per-run quota applies. ~$2/month. Stated plainly because it is the one regression: the Actions backend gave cache-poisoning protection free via branch scoping — verified on #893, all 1,137 entries on `refs/pull/893/merge`, none on `main`. R2 has no OIDC and no IAM condition keys, so that is rebuilt from two scoped tokens and a `main`-only environment in the follow-up. Opt-in gated on `var.cloudflare_account_id` (null by default), the `ses.tf` pattern and its reason: without a token the provider cannot authenticate and the WHOLE `core` plan fails, leaving every resource that does plan cleanly unchecked. The `count`s should come out when #908 gives CI a scoped read-only token — the gate is worth more here than for SES, because this bucket is on the critical path of every compile job. Two provider caveats recorded in the file rather than left to be rediscovered, both reported by the first real plan rather than guessed: the lifecycle resource cannot be destroyed by Terraform and does not support `import`, and `max_age` is in SECONDS here where the S3 rule took days. `.terraform.lock.hcl` carries linux_amd64 AND darwin_arm64 hashes for the new provider. A lockfile written only on darwin fails CI's init on linux, and `envs/dev` and `envs/prod` already track multiple platforms. Closes #910 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…) (#912) * infra(core): declare the R2 sccache bucket and its lifecycle rule First half of #909. Creates the bucket; does NOT repoint `rust.yml`, which waits until the bucket exists and the two scoped credentials are in GitHub secrets — splitting them avoids the race where `rust.yml` on `main` runs against a bucket whose apply has not finished. WHY R2, after two backends that each failed differently. S3 (#350) was fast and expensive: runners sit outside AWS, so every read is 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 cache backend (#893) was cheap and slow: per-hit read latency roughly doubled (0.122s -> 0.242s), and GitHub rate-limits cache writes PER WORKFLOW RUN shared across every job, while sccache's `GHACache::build` installs no `RetryLayer` and counts the resulting 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, ~27% mean hit rate, 25.1 minutes against 9.8 on S3. R2 is the only option that is both: zero egress, and not GitHub's cache service so neither the 429 bug nor the per-run quota applies. ~$2/month. Stated plainly because it is the one regression: the Actions backend gave cache-poisoning protection free via branch scoping — verified on #893, all 1,137 entries on `refs/pull/893/merge`, none on `main`. R2 has no OIDC and no IAM condition keys, so that is rebuilt from two scoped tokens and a `main`-only environment in the follow-up. Opt-in gated on `var.cloudflare_account_id` (null by default), the `ses.tf` pattern and its reason: without a token the provider cannot authenticate and the WHOLE `core` plan fails, leaving every resource that does plan cleanly unchecked. The `count`s should come out when #908 gives CI a scoped read-only token — the gate is worth more here than for SES, because this bucket is on the critical path of every compile job. Two provider caveats recorded in the file rather than left to be rediscovered, both reported by the first real plan rather than guessed: the lifecycle resource cannot be destroyed by Terraform and does not support `import`, and `max_age` is in SECONDS here where the S3 rule took days. `.terraform.lock.hcl` carries linux_amd64 AND darwin_arm64 hashes for the new provider. A lockfile written only on darwin fails CI's init on linux, and `envs/dev` and `envs/prod` already track multiple platforms. Closes #910 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * infra(ci): give the core apply leg the Cloudflare credential and account id Without these the apply job plans `envs/core` with no Cloudflare auth and `var.cloudflare_account_id` null, so r2.tf stays `count = 0` and the bucket is never created. The apply job re-plans to a file inside itself (`scripts/ci/tf-apply-plan.sh`) rather than consuming the plan tier's artifact, so these reach the plan that actually lands — and the destroy guard still reads it before anything is applied. `CLOUDFLARE_API_TOKEN` is an **Environment** secret on `infra-apply-core`, which is `protected_branches: true`. A pull request therefore cannot read it even by editing this workflow. That is the property replacing the `er-ci-sccache-read`/`-write` role split S3 had, and it is the pattern `agent-fleet.md` already prescribes for the secrets added after #439 gave up the zero-secret invariant: environment-scoped to `main` rather than repository-wide. The account id is NOT a secret and is deliberately in the tree: it appears in every dashboard URL and the S3-API endpoint is derived from it, exactly as `rust.yml` carries the AWS account id inside `SCCACHE_BUCKET`. Set unconditionally rather than per-matrix-leg, which is the subtle part. Only `envs/core` declares the variable and Terraform silently ignores a `TF_VAR_` for an undeclared one — unlike `-var`, which errors. A `matrix.key == 'core' && … || ''` expression would be actively wrong: it yields the empty STRING on the other legs, and `"" != null`, so `local.r2_enabled` would flip true with no account id to use. Known gap, bounded and recorded on the pull request: the PR plan tier has no Cloudflare token, so R2 changes are not previewed on a pull request even though the apply leg creates them. That is the §14.2 tradeoff `envs/dev/ses.tf` already makes, and #908 is what closes it by giving CI a scoped read-only token. Closes #910 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Closes #887
What
rust.yml's sccache moves from the S3 backend back to the Actions cachebackend. Seven
id-token: writegrants and sevenconfigure-aws-credentialsrole assumptions go with it.
cache-prune's sccache budget goes live again,raised 5120 → 12288 MiB.
Why
S3 egress was the largest line item in the AWS account. CUR 2.0 per-resource,
November MTD:
er-ci-sccache/DataTransfer-Out-Bytes= $209.32 of a$211.62 S3 total (2,425.7 GB). Storage was $0.02; the next-largest S3 line
anywhere in the account is $0.05. Runners are outside AWS, so every read is
billed internet egress and no VPC endpoint reaches it.
The 10 GB ceiling that sent #350 to S3 became purchasable on 2025-11-20
($0.07/GB-month above the included 10). The account is on Pro and the
repository's eviction limit is set to 20 GB, so ~$4.70/month replaces
$209.
Proof
actionlint .github/workflows/rust.yml→ exit 0 (run without a pipe; a piped$?readstail's status, which is how this repo has read a false greenbefore).
scripts/ci/workflow-shell-check.sh→ exit 0. Structural assertionsagainst the parsed YAML:
Every edit was scripted with an asserted match count rather than a blind regex —
and that caught a real error: I had said "8 role steps" in planning; the
assertion failed at 7, which is the true number.
This PR's own run is the experiment. The claim that needs CI, not reasoning,
is that sccache 0.19.0's GHA backend works against the v2 Actions cache service
(
ACTIONS_CACHE_SERVICE_V2: onin the runner env). If it does not, everycompile job runs cold and the
Build cost (sccache stats, target size)stepshows a collapsed hit rate and non-zero
Cache read errors— bounded andrevertible, and the only way to find out. Read that step before merging.
Risk & rollback
Risk: if the eviction limit were not actually at 20 GB, sccache's ~4.8 GB lands
in a full budget and evicts the entries that make CI fast — cold is ~3× and
test-shard's 45-minute timeout starts failing jobs rather than slowing them.The limit is set, but it is not readable via REST or GraphQL (
/actions/cache/settings404s; the repo object has no cache keys), so it is confirmed by the owner and by
cache usage growing past the old 10.39 GB clamp — not by a probe.
Rollback:
git revert <merge-sha>. The bucket, both OIDC roles andsccache.tfare untouched by this PR precisely so the revert needs 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 is 95%+. This is the whole premise. ReadBuild cost (sccache stats, target size)on amainrun after the cachehas been populated once, and record the number. A collapsed rate with
Cache read errors > 0means the v2 cache service is the problem and thisshould be reverted, not tuned:
and GitHub explicitly warns the eviction limit "should not be used for
controlling costs" — eviction lags, so peak can exceed it. Record the
figure; if it sits near 20 GB, either raise the limit deliberately or
lower
cache-prune's 12288 MiB budget:gh api /repos/{owner}/{repo}/actions/cache/usageguard. Without this, growth in the cache is growth in the bill with
nothing to stop it:
DataTransfer-Out-Bytesactually goes to zero forer-ci-sccache, confirmed from the CUR rather than assumed — the agenticworkflows (ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892) still hold the read role, so a small residual is
expected and anything larger means a consumer was missed:
cache-prune's next nightly run deleted nothing it should not. Itssccache budget was dormant through the S3 era and is live again at a value
no run has exercised. Read its enumeration output:
sccache.tfand both OIDC roles deleted — 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
Plan
Attribute the bill per resource (CUR 2.0, not Cost Explorer — it cannot group by resource here)Price the alternatives: GHA cache, R2, CloudFront, git, Git LFSSingle-writer cache guards (ci(frontend): one writer per shared cache key, and only from main #889) to make roomOwner: Pro + eviction limit 20 GBFliprust.ymlsccache.tf(ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892 first)Discoveries
answer on this said rolling back to the GHA backend was unavailable and cited
the full budget as a hard blocker. Wrong conclusion from a right measurement:
the ceiling is the purchasable part. Announced 2025-11-20, after perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED #350 shipped.
~$4.70, but it has no equivalent of GitHub's branch scoping, so the
cache-poisoning protection that
sccache.tf's two-role split provides wouldhave needed redesigning. $2.70/month does not buy a vendor integration plus a
security redesign.
cache that git keeps every version of; sccache has no git backend; and
checkout would move
11× more bytes than sccache fetches. The LFS variant is$240/month, more than the S3 bill it would replace.**billed at $5/50 GB — **
gh aw compilewould have silently downgraded four workflows. The localCLI is v1.0.1; the committed lock files pin
github/gh-aw-actions/setup@4607d462 # v1.2.0, and recompiling rolled it backto
221ba4f4 # v1.0.1.gh extension upgrade gh-awreports v1.0.1 ascurrent. Reverted and split to ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892. Nothing in CI recompiles and compares the
lock files, so this drift is not gated.
coveragejob was never part of the problem. Its ~1.6 GB looked likethe same pattern as the duplicate
pnpm-storeentries but it isschedule/dispatch-only, so no PR can write it.novel tree is cold because nothing has compiled it, whoever holds the
credential. Comment corrected rather than carried over.
Measurements
Files
.github/workflows/rust.yml— env block, 7 permission blocks, 7 role steps,7 orphaned comments, the
cache-prunebudget, 2 header claims and thetest-shardtimeout rationale