Skip to content

ci(rust): sccache back on the Actions cache backend, off S3 - #893

Merged
athvin merged 1 commit into
mainfrom
ci/sccache-back-to-gha
Nov 8, 2026
Merged

athvin merged 1 commit into
mainfrom
ci/sccache-back-to-gha

Conversation

@athvin

@athvin athvin commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Closes #887

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

rust.yml's sccache moves from the S3 backend back to the Actions cache
backend. Seven id-token: write grants and seven configure-aws-credentials
role 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
$? reads tail's status, which is how this repo has read a false green
before). scripts/ci/workflow-shell-check.sh → exit 0. Structural assertions
against the parsed YAML:

rust.yml parses; 17 jobs
env SCCACHE_GHA_ENABLED = true
env has SCCACHE_BUCKET  = False
jobs using sccache: 7
of those, still granting id-token: none
jobs still assuming an AWS role: none

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: on in the runner env). If it does not, every
compile job runs cold and the Build cost (sccache stats, target size) step
shows a collapsed hit rate and non-zero Cache read errors — bounded and
revertible, 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/settings
404s; 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 and sccache.tf
are untouched by this PR precisely so the revert needs nothing re-provisioned.

Post-merge ledger

Closed by: unclosed

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not:
  • images built, or correctly never ran because nothing that goes into
    an image changed:
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion:
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change:
  • the board card reached Done through the automation rather than by
    hand, and the issue closed:
  • follow-ups are open for everything deferred here — numbers: ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned:

Specific to this change

  • The hit rate on a main run is 95%+. This is the whole premise. Read
    Build cost (sccache stats, target size) on a main run after the cache
    has been populated once, and record the number. A collapsed rate with
    Cache read errors > 0 means the v2 cache service is the problem and this
    should be reverted, not tuned:
  • Peak cache usage settles under 20 GB. Billing is on peak hourly usage
    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/usage
  • A billing spending limit is set. The eviction limit is not a spend
    guard. Without this, growth in the cache is growth in the bill with
    nothing to stop it:
  • S3 DataTransfer-Out-Bytes actually goes to zero for
    er-ci-sccache, confirmed from the CUR rather than assumed — the agentic
    workflows (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. Its
    sccache budget was dormant through the S3 era and is live again at a value
    no run has exercised. Read its enumeration output:
  • sccache.tf and 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, which
    still references the read role:
    deferred — #892
Context — plan, discoveries, measurements, files

Plan

  1. Attribute the bill per resource (CUR 2.0, not Cost Explorer — it cannot group by resource here)
  2. Price the alternatives: GHA cache, R2, CloudFront, git, Git LFS
  3. Single-writer cache guards (ci(frontend): one writer per shared cache key, and only from main #889) to make room
  4. Owner: Pro + eviction limit 20 GB
  5. Flip rust.yml
  6. Measure hit rate and peak usage, then delete sccache.tf (ci: move the two agentic workflows' sccache off S3 too (needs the gh-aw that compiled the tree) #892 first)

Discoveries

  • The 10 GB ceiling is purchasable, and that post-dates perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED #350. My first
    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.
  • R2 was the cheaper option on paper and still lost. ~$2/month against
    ~$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 would
    have needed redesigning. $2.70/month does not buy a vendor integration plus a
    security redesign.
  • Git and Git LFS are not options. The repo is 36 MB against a 4.78 GB
    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
    billed at $5/50 GB — **
    $240/month, more than the S3 bill it would replace.**
  • gh aw compile would have silently downgraded four workflows. The local
    CLI is v1.0.1; the committed lock files pin
    github/gh-aw-actions/setup@4607d462 # v1.2.0, and recompiling rolled it back
    to 221ba4f4 # v1.0.1. gh extension upgrade gh-aw reports v1.0.1 as
    current. 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.
  • The coverage job was never part of the problem. Its ~1.6 GB looked like
    the same pattern as the duplicate pnpm-store entries but it is
    schedule/dispatch-only, so no PR can write it.
  • The read-only-role explanation for cold merge-bus batches was wrong. A
    novel tree is cold because nothing has compiled it, whoever holds the
    credential. Comment corrected rather than carried over.

Measurements

$ duckdb -c "SELECT line_item_resource_id, line_item_usage_type,
    sum(line_item_usage_amount), sum(line_item_unblended_cost)
    FROM 'nov-cur.parquet' WHERE line_item_product_code='AmazonS3' ..."
er-ci-sccache  DataTransfer-Out-Bytes   2425.7 GB   $209.32
er-ci-sccache  Requests-Tier2          4598006      $1.84
er-ci-sccache  TimedStorage-ByteHrs       0.9 GB-mo  $0.02
er-audit-archive Requests-Tier1          7404        $0.04   <- next largest, anywhere

$ # ~8.7 sccache jobs per rust run, sampling 25 runs from 2026-11-07
217 sccache job-runs / 25 runs = 8.68;  396.3 GB / 922 jobs = 0.43 GB/job
106 runs x 8.7 x 0.43 GB = 396 GB = $35.67   (matches the CUR daily figure)

$ # one job's stats, run 42506286161 `scale golden (50k)`
Compile requests 546 / hits 495 / misses 1 / hit rate 99.80%
  of those hits: 322 C/C++ (bundled DuckDB), 158 Rust, 15 Assembler
rust/target 2.8G

$ gh api /repos/athvin/entity-resolution-engine/actions/cache/usage
10,387,544,948 bytes / 75 entries      # clamped: 73 -> 75 entries, +437 bytes

Files

  • .github/workflows/rust.yml — env block, 7 permission blocks, 7 role steps,
    7 orphaned comments, the cache-prune budget, 2 header claims and the
    test-shard timeout rationale

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]>
@athvin

athvin commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

First-run evidence (run 42510475808) — the experiment this PR exists to run

All 18 compile jobs ran and succeeded. Cache location: ghac, so the backend
is genuinely active and not silently falling back.

Four things proven

1. The v2 Actions cache service works with sccache 0.19.0. Cache read errors: 0 in every job — the risk this PR was opened to test.

2. The 20 GB eviction limit is live. This is the probe I said was
impossible: the limit is not exposed via REST or GraphQL, so it could only be
confirmed by watching usage pass the old clamp. It did —
10,387,544,948 → 11,864,269,537 bytes, 75 → 1,221 entries. A 10 GB ceiling
could not have held that.

3. Branch scoping behaves exactly as the security argument claimed. All
1,137 sccache entries are on refs/pull/893/merge and zero on
refs/heads/main (paginated count — the unpaginated first page says 87, which
is the truncation trap this repo has been bitten by before). A PR's compiled
object code is quarantined from main by the platform, with no IAM condition to
misconfigure. That is the two-role S3 split, demonstrated rather than cited.

4. Cold is not slow here, and my prediction was wrong. I said to expect a
~40-minute cold build brushing test-shard's 45-minute timeout. Actual: 15
minutes total wall, slowest job 14.9 min.

14.9  DuckLake e2e server (pg m-z)      13.0  test shard (rest)
14.7  DuckLake e2e shard (3/4)          12.7  DuckLake e2e server (rest)
14.7  DuckLake e2e shard (1/4)          12.3  entities
13.3  DuckLake e2e server (pg a-l)      11.8  DuckLake e2e shard (2/4)

Why: the 12 parallel compile jobs populate the cache for each other mid-run, so
hit rate climbs within a single run — fmt + clippy + docs (early) 13.11%,
test shard (rest) (later) 62.13%. Same-network reads also beat S3's
Average cache read hit 0.095 s over the internet.

One open question, and it is not benign

Writes partially fail: Cache write errors 445 in test shard (rest), 316 in
fmt + clippy + docs.
Cache read errors is 0, and 1,137 entries did land,
so this is not a broken credential. sccache logs no error text, so the counters
are the only signal.

The shape is suspicious rather than obviously harmless:

job misses write errors
test shard (rest) 445 445 — every miss failed to store
fmt + clippy + docs 742 316 — about 43%

Equality in the first row means that job stored nothing it compiled. A plausible
reading is throttling or key contention under 12-way concurrent writers, all
compiling the same dependency tree — but I have not proven the cause, and the
alternative readings differ in consequence.
If it is contention on duplicate
keys it is harmless (the object is in the cache either way). If it is throttling
or a per-run write ceiling, then on main — where all 12 jobs write — the
shared cache may never fully populate, and the hit rate this change is justified
by would not materialise.

This is the thing to read on the first main runs, and it is why the ledger
asks for a 95%+ hit rate rather than treating green as done. If write errors
persist once the cache is warm, the mitigation is fewer concurrent writers —
a single designated writer job, the pattern #889 just applied to the frontend
caches — not a revert.

@athvin
athvin merged commit 8f4059d into main Nov 8, 2026
43 checks passed
@athvin

athvin commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Merged — and one dynamic the first run exposed that was not in the plan

Merged as 8f4059de; prerequisite #889 as 3615cf18. Both verified present on
origin/main.

8f4059de's own rust/frontend runs were cancelled, and that is not this
diff.
#875 merged on top within minutes, and GitHub keeps only one pending
run per concurrency group (cancel-in-progress is false for push here), so a
third push cancels the middle one. Green is being established from 350cd213,
which has 8f4059de as an ancestor — the documented way out, not a re-run.

The budget dynamic that replaces the egress bill

S3 was one shared content-addressed namespace: 4.78 GB total, every job both
reading and writing it, so a PR benefited from every other PR's compilations.

The Actions backend is scoped per branch — the property that gives us the
cache-poisoning protection for free. The cost of that property is that each PR
gets its own copy. Measured: this PR's scope is 1,137 entries / ~1.48 GB,
and 309 distinct PR branches ran rust.yml in the last 7 days:

309 branches x ~1.48 GB = ~457 GB of demand against a 20 GB limit

So LRU eviction will be continuous rather than exceptional, and that is expected
rather than alarming — but it changes what to watch:

  • main's scope should survive. Every PR run restores from the default
    branch, so main's entries are the hottest things in the cache and LRU
    protects them. They are also the valuable ones: the dependency tree, not a
    PR's own crates.
  • PR scopes will thrash, and most of what a PR writes will be evicted before
    anything reads it. Wasted work, but free — unlike S3, writes are not metered.
  • What is genuinely lost versus S3 is cross-PR sharing. A PR now gets
    main's dependency objects plus its own run's, never a sibling PR's.
  • cache-prune's sccache budget, raised to 12288 MiB in this PR and live again
    for the first time since perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED #350, is the thing bounding this nightly. It has
    never been exercised at that value.

If the warm hit rate on main does not reach 95%, budget pressure evicting
main's entries is the first hypothesis to test, ahead of the write-error
question in the previous comment.
The lever then is making PR runs
restore-only so they stop competing for the budget — the shape the S3 read role
enforced through IAM — which would trade away the within-run climb (13% → 62%
observed here) for a main scope nothing contends with.

athvin pushed a commit that referenced this pull request Nov 8, 2026
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]>
athvin added a commit that referenced this pull request Nov 8, 2026
…) (#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]>
athvin added a commit that referenced this pull request Nov 8, 2026
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]>
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.

ci: move sccache off S3 to the Actions cache backend ($209/mo egress -> ~$5)

2 participants