Skip to content

perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED - #350

Merged
athvin merged 1 commit into
mainfrom
bm/ci-sccache-s3-switch
Oct 30, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/ci-sccache-s3-switch

Conversation

@athvin

@athvin athvin commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Companion to #346. This breaks every compile job until
terraform apply has created the bucket and roles
— six jobs would fail to
assume er-ci-sccache-{write,read}. Opened as a draft so the sequence stays
apply-then-merge.

What changes

SCCACHE_GHA_ENABLED out, SCCACHE_BUCKET/SCCACHE_REGION in, and each of the
six compile jobs (lint, entities, test, ducklake-e2e, bench-compile,
scale-tests) gains id-token: write plus one configure-aws-credentials step.
The role is chosen by ref:

github.ref == 'refs/heads/main' && ...sccache-write || ...sccache-read

Pushes on main write; everything else reads. The repository is public, so a PR
able to write the cache would be a path for a contributor branch to plant object
code a later main build consumes. PRs still get the dependency tree, which is
nearly all the value. #346's sccache.tf carries the full reasoning and the
measurement showing a denied write is a counted miss rather than a build
failure.

Verified mechanically rather than by eye: every job with the OIDC step also has
id-token: write, and no job has one without the other — a mismatch there fails
at role assumption, which is a confusing way to find out.

cache-prune STAYS, against the plan

I had this slated for deletion, on the grounds that S3 removes the budget the
prune exists to defend. The job's own measurement says otherwise:

sccache        4682 entries  3341.1 MiB
buildkit-blob   ~70 entries  ~5000 MiB   <- four entries at 763.8 MiB
v1-rust-rust       2 entries   364.1 MiB each

sccache was never the only unbounded producer. images.yml's
type=gha,mode=max buildkit layer cache held half the 10 GB budget and was
evicting the rust-cache entry every compile job restores from — the exact
failure the prune was built to stop. rust-cache still lives on the Actions
backend, so deleting the prune would have handed the budget back to buildkit and
reintroduced cold runs by a different route.

Its sccache budget line is now vestigial (that producer writes to S3 and will
always measure zero) and is kept only so a rollback to the GHA backend does not
silently uncap it. Both rationales in the file are rewritten to say which reason
is live.

After applying

Watch Cache write errors in the first PR run: non-zero and harmless is the
expected shape. Zero together with a collapsed hit rate would mean the
read-only denial lands somewhere other than where it was measured.

Co-Authored-By: Claude Opus 5 (1M context) [email protected]

🤖 Generated with Claude Code

…PPLIED

Companion to #346. **This breaks every compile job until
`terraform apply` has created the bucket and roles** — six jobs would fail to
assume `er-ci-sccache-{write,read}`. Opened as a draft so the sequence stays
apply-then-merge.

## What changes

`SCCACHE_GHA_ENABLED` out, `SCCACHE_BUCKET`/`SCCACHE_REGION` in, and each of the
six compile jobs (lint, entities, test, ducklake-e2e, bench-compile,
scale-tests) gains `id-token: write` plus one `configure-aws-credentials` step.
The role is chosen by ref:

    github.ref == 'refs/heads/main' && ...sccache-write || ...sccache-read

Pushes on main write; everything else reads. The repository is public, so a PR
able to write the cache would be a path for a contributor branch to plant object
code a later main build consumes. PRs still get the dependency tree, which is
nearly all the value. #346's `sccache.tf` carries the full reasoning and the
measurement showing a denied write is a counted miss rather than a build
failure.

Verified mechanically rather than by eye: every job with the OIDC step also has
`id-token: write`, and no job has one without the other — a mismatch there fails
at role assumption, which is a confusing way to find out.

## `cache-prune` STAYS, against the plan

I had this slated for deletion, on the grounds that S3 removes the budget the
prune exists to defend. The job's own measurement says otherwise:

    sccache        4682 entries  3341.1 MiB
    buildkit-blob   ~70 entries  ~5000 MiB   <- four entries at 763.8 MiB
    v1-rust-rust       2 entries   364.1 MiB each

sccache was never the only unbounded producer. `images.yml`'s
`type=gha,mode=max` buildkit layer cache held *half* the 10 GB budget and was
evicting the rust-cache entry every compile job restores from — the exact
failure the prune was built to stop. rust-cache still lives on the Actions
backend, so deleting the prune would have handed the budget back to buildkit and
reintroduced cold runs by a different route.

Its sccache budget line is now vestigial (that producer writes to S3 and will
always measure zero) and is kept only so a rollback to the GHA backend does not
silently uncap it. Both rationales in the file are rewritten to say which reason
is live.

## After applying

Watch `Cache write errors` in the first PR run: non-zero and harmless is the
expected shape. Zero *together with* a collapsed hit rate would mean the
read-only denial lands somewhere other than where it was measured.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin marked this pull request as ready for review October 30, 2026 00:14
@athvin
athvin merged commit 3246a40 into main Oct 30, 2026
24 of 28 checks passed
@athvin
athvin deleted the bm/ci-sccache-s3-switch branch October 30, 2026 00:14
athvin added a commit that referenced this pull request Oct 30, 2026
…ref (#356)

The first unattended apply failed all three envs in under three minutes:

    ##[error]Could not assume role with OIDC:
    Not authorized to perform sts:AssumeRoleWithWebIdentity

The role exists — I created it in the bootstrap apply. The cause is the OIDC
`sub` claim. A job that references a GitHub Environment gets
`…:environment:<name>` instead of `…:ref:refs/heads/main`, and each apply job
sets `environment: infra-apply-<env>`. So a ref-pinned `StringEquals` could
never match it.

The diagnosis is a clean contrast rather than a guess: `plan` and `apply` use
the same provider, the same repo and the same branch, and differ only in that
`plan` sets no environment. `plan` succeeded; `apply` could not assume.

Now trusting the three environment subjects explicitly.

## This is not weaker than the ref condition

Each `infra-apply-*` environment carries
`deployment_branch_policy.protected_branches = true`, so only a protected
branch — `main` — can deploy to it, and GitHub enforces that before minting the
token. The main-only property moves from the claim to the environment; it does
not disappear. Listing the three names rather than globbing `:environment:*`
keeps a future environment from silently inheriting apply rights.

## The other two roles are correct as they stand — checked, not assumed

`er-ci-deploy-dev` and the sccache pair are used by jobs that set no
environment, so their ref-based subjects are right. Verified rather than
reasoned: `images.yml`'s `deploy-dev` has no `environment:` key, and sccache's
write role demonstrably works — the first `main` run after #350 reported

    Cache hits rate   100.00 %
    Cache write errors     0

which also closes out the read/write split: PRs get write errors and succeed,
`main` writes cleanly.

## One more human apply, and it is the last one

This changes the apply role's own trust policy, so it cannot be applied by the
role it fixes. `envs/core` needs one more human apply; after that CI owns every
apply including this file's future changes.

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 Oct 31, 2026
…he Rust gate on terraform-only PRs (#358)

* fix(infra): let the plan role read bootstrap state, not just envs/

Prerequisite for the next PR, which adds `bootstrap/state-backend` to the
terraform plan matrix. The plan role's state-read policy allows only
`envs/*.tfstate`, so that matrix leg would fail on the PR that introduces
it — the policy only goes live once CI applies it on merge. Same ordering
trap as #350, so this lands first, on its own.

`bootstrap/state-backend` will be planned and never applied from CI: it
owns the bucket its own backend lives in, so applying it there is the
circular case, but a plan still catches drift in the bucket's
configuration. `bootstrap/organization` stays out of the plan tier
entirely — its one required variable is a root account email deliberately
kept out of a public repository, and supplying it would introduce the
first repository secret into a pipeline whose stated property is that it
has none.

Enumerated rather than widening to `/*`: the point of the statement is
that the role reads Terraform state and nothing else in the bucket.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* perf(ci): stop running the Rust gate on terraform-only PRs

This PR changes one Terraform file and still ran `test`, `entities`,
`cargo-deny`, `fmt + clippy + docs` and the 14-minute DuckLake e2e.

`rust.yml`'s detect is a DENYLIST — it counts changed paths *not* under
`.claude/`, so every tree except that one counts as code. `frontend.yml`
and `infra.yml` use allowlists, which is why terraform already skips the
frontend gate; `images.yml` runs on `push` only and never sees a PR. So
`rust.yml` was the only one paying for this.

`infra/terraform/**` joins the denylist. Verified it is safe rather than
assumed: no crate or manifest under `rust/` references `infra/` (the two
mentions are prose in comments) and no `make check` target touches it.

The one real coupling is worth recording, because it looks like a hole and
is not: `scripts/skills-check.sh` derives generated skill references FROM
`infra/terraform/**` — `resource "aws_*"` counts, IAM users, Pod Identity
associations, pinned provider versions — so a terraform-only PR can make a
reference stale. That is caught by the `skills` job, which runs the same
drift check and is deliberately not gated on `detect`. That job existing
separately is exactly what makes this skip safe.

The skip stops at those two trees. `docs/**` still runs the gate, because
`entities` verifies docs/erd.md staleness. `infra/k8s/**` still runs it
too — this change is scoped to Terraform.

Simulated over nine PR shapes before pushing: terraform-only, multi-file
terraform, .claude-only and terraform+.claude all skip; terraform+rust,
terraform+docs, helm, a workflow edit and rust-only all still run.

Note this PR cannot demonstrate its own skip: adding `rust.yml` to it
means it is no longer terraform-only, so the gate correctly runs here one
last time. Its `detect` log now prints the changed paths it decided on,
so the next terraform-only PR can be read directly.

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 2, 2026
…e-name gate (#388)

The 30m job was 2m16s of build (sccache S3, 100% hits) and ~22m of test
binaries running one after the other — er-cli's lake suite 888s, then
er-server's 419s (run 41461727505). Now: `lake-e2e` runs er-cli alone as two
nextest hash partitions (no postgres service — er-cli's tests never touch pg),
`ducklake-e2e` keeps dedupe-cli + er-server + er-entity-diff + the extensions
step, and `ducklake-gate` carries the old job's exact name so the required
context "DuckLake + extensions e2e" kept reporting and branch protection never
changed. Expected wall: ~30m -> ~15m for ~+10 runner-minutes.

nextest, though the `test` job measured it out: that tax is process-per-test on
thousands of tiny tests; this suite is 44 tests averaging ~21s (recorded A/B on
the combined job: 15.5m cargo vs 15.2m nextest), and hash partitioning
auto-assigns new tests to a shard, so the filter-list failure mode (a new test
in no leg) cannot happen. The pg suite stays on plain `cargo test` — its tests
coordinate around the shared service database in-process.

Also retires three pieces of prose the sccache-S3 move left stale: rust.yml's
header still said "GHA backend", sccache.tf still said "NOT APPLIED YET"
(applied 2026-10-28/29, live since #350), and build-cost.md/SKILL.md still
carried S3 as the next step. The new build-cost.md section records the split's
before-numbers; per-leg after-numbers get appended once the first runs land.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
athvin added a commit that referenced this pull request Nov 6, 2026
…ng them exposed (#708)

* fix(skills): the new-stack rule was imprecise, and an eval demanded the wrong answer

Doing the follow-ups from #685 started by checking the premise of one, and the
premise was wrong.

The plan role's state grant is two PREFIX wildcards — `envs/*.tfstate` and
`bootstrap/*.tfstate` (envs/core/ci-terraform.tf:112-118). So a new stack under
either prefix needs no IAM change at all. The rule read "A new stack needs the
plan role's state read first, in its own PR", which is true only for a stack
introducing a NEW prefix. That is what #358 actually did: it added
`bootstrap/*.tfstate` so `bootstrap/state-backend` could join the plan matrix.
#350 is cited alongside it as the same apply-before-merge ordering trap, but on
sccache roles rather than state, so it no longer reads as evidence for this rule.

Eval 7, which #685 added, was worse: it made that claim a MUST and used
`envs/staging` as its example, so a session answering correctly — no grant
needed, the wildcard covers it — would have been scored as failing. It now
tests the precise rule, with a must-not for the imprecise one.

What a new stack does need is the part the rule never mentioned, and it is the
quieter failure: the `validate` tier's `for d in …` loop and the `plan` job's
`matrix.include` are both hand-written enumerations. A stack in neither is
never checked and nothing turns red. The next commit derives that gap.

make skills-check: ok.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* feat(skills): derive infra coverage, because the gap is what nobody maintains

the follow-up that stops them coming back. This is it — but not the one that
was proposed, and the difference is the point.

The proposal was a NodePool inventory plus a stack list. Checked against the
tree, half of that is worthless: `make cluster-objects` runs
`kubectl apply -f infra/k8s/nodepools/`, which is non-recursive, so the deployed
set is the top level and `measure/` is excluded by the layout itself. A set
difference there is empty by construction.

What is NOT covered is the stack enumerations. `infra.yml` lists stacks three
separate times — the `validate` shell loop, `plan`'s `matrix.include` and
`apply`'s — and nothing cross-checks them against the tree. A stack missing from
one is never checked and no job goes red. Same shape for `infra/k8s`: the skill
carried a hand-written manifest table that had already gone stale (it omitted
`priorityclasses/`, added later).

So `infra-coverage` derives three tables, each a set difference:

- stacks in the tree (by `backend.tf`) against all three tiers, flagging any
  stack no tier reaches
- every `infra/k8s` path against the sites referencing it — which surfaced that
  `secrets/` and `network-policy-controller.yaml` are referenced by NOTHING in
  the tree, so they are hand-applied or not applied at all. Nobody would guess
  that from the old table
- the NodePool manifests against the non-recursive apply, which derives the
  `measure/` exclusion that #685 had to state by hand

Verified by running it, not by reading it: `bash -n` passed while the generator
was fatally broken. Under `set -o pipefail` the no-match `grep` that IS the gap
case exits 1 and killed the entire regen, twice — once for the search and again
for the filter stage — with an empty generated block as the only symptom. Both
stages are now explicitly tolerant, and the committed output exercises both
(three rows resolve to "nothing in the tree"). That trap is now recorded in
docs/agent-skills.md for the next generator author.

make skills-check: ok, 14 generated files.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(skills): a spliced file missing from generated_files was never drift-checked

Found by mutation-testing the previous commit rather than trusting it: added a
fake `envs/staging` stack so the committed coverage block went stale, ran
`skills-check check`, and it reported "generated references are current" and
exited 0.

Adding a generator takes TWO edits that nothing tied together — the `splice`
call in `run_regen`, and an entry in `generated_files`, which is the list
`run_drift_check` iterates. `infra-coverage` had the first and not the second,
so the file regenerated locally and was never compared against HEAD. A stale
committed block would have sailed through CI, which is the one failure mode this
gate exists to prevent.

Nothing hinted at it. The "regenerated N generated files" line prints
`${#generated_files[@]}` — the array length, not what was actually spliced — so
the count was identical whether or not the new file was registered.

Two changes: the missing entry, and a guard so the pairing cannot be forgotten
again. `splice` already knows its target, so it now asserts membership and fails
with the reason rather than leaving the file silently unguarded.

Verified by mutation, all three ways:
- stale committed block  -> exit 1, names the file and prints the diff
- clean tree             -> exit 0
- splice with no array entry -> exit 1, "spliced but missing from
  generated_files, so the drift check would never see it"

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs(skills): the manifest table omitted a directory and miscounted another

The consistency sweep over what the merge left behind. Both defects are the
class the new generated coverage table exists to end, which is why they were
worth finding rather than just fixing.

- `infra/k8s/priorityclasses/` was missing from the non-chart manifest table.
  It exists, holds the task PriorityClass, and is applied by the same target as
  the node pools and again by the kind probe.
- "the namespace and the **three** upstream chart value files" was already
  wrong: there are four value files plus `openobserve.yaml` beside
  `namespace.yaml`. The count is gone, not corrected.
- The closing claim that these are "applied directly" was doing less work than
  it sounds. `secrets/` and `network-policy-controller.yaml` are referenced by
  no target, script or workflow anywhere in the tree, so they are applied by
  hand or not at all — stated now, because a reader assumes the opposite.
- The table is marked purpose-only, deferring the inventory to the generated
  table. It names `coverage.md` in prose rather than linking it, since a
  reference must not link a sibling.
- `make nodepools` is now `make cluster-objects`, with the old name kept
  callable. The bullet also names the mechanism that matters: the apply is
  non-recursive, which is the entire reason `measure/` stays out of the cluster.

Checked and found still accurate, so left alone: `docs/infrastructure.md` §5.1
is titled "Karpenter disruption settings", and every skill this one routes to
exists.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(skills): the generator piped a writer into grep -q, which CI forbids by test

CI caught this; `make skills-check` could not. The membership tests in
`gen_infra_coverage` were spelled as a `printf` piped into a quiet exact-match
grep — the form `scripts/ci/skills-check-test.sh` exists to forbid in this
file, because a quiet grep closes the pipe at its first match, SIGPIPEs the
writer under `pipefail`, and can report a FOUND match as missing. Three lines,
one per tier, each a latent false "—" in the coverage table.

Replaced with `in_list`, a pure-bash `[[ ]]` membership test: no subprocess, no
pipe, nothing to race. The needle is quoted inside the pattern so a stack path
matches literally rather than as a glob.

Two things worth recording, because both cost a round trip:

- The gate I verified was not the gate CI runs. `make skills-check` runs
  `skills-check.sh all`; the meta-test is a SEPARATE workflow step
  (`rust.yml:388`) that the Makefile target does not invoke. Running the local
  target to green says nothing about it.
- That test is TEXTUAL, so the first fix failed it again on the explanatory
  comment, which quoted the bad form as an example. The comment now describes
  the shape instead of spelling it, and says why.

Verified: skills-check-test 5 passed / 0 failed, `skills-check check` exit 0
with regen a no-op, and the regenerated table is byte-identical to the
committed one — so `in_list` agrees with what the piped form produced.

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
)

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: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants