Repository navigation
feat(infra): terraform the sccache S3 bucket and its two CI roles (not applied) - #346
Merged
Merged
Conversation
…them sccache reports `Non-cacheable reasons: crate-type 147` — it cannot cache a final link, so the workspace's ~147 test binaries were compiled and linked uncached on every run of every CI job, each one statically linking bundled DuckDB. That is a floor no amount of cache work gets under, and it is the largest single cost in both long jobs. `autotests = false` plus one explicit `[[test]]` target per crate makes every file in `tests/` a module of `tests/main.rs` instead of a target of its own, for the three crates holding 76 of the 117 integration files: er-server 49, dedupe-core 20, er-match 7. **Files do not move.** That is the point of doing it with `autotests` rather than by relocating sources into a subdirectory: all 40 `include_str!` paths and the `CARGO_MANIFEST_DIR`-relative fixture helpers keep resolving, and git history stays attached to each file. ## Measured, same machine, back to back | | before | after | | |---|---|---|---| | test binaries linked (`cargo test --workspace`) | 147 | **75** | −49% | | er-server: compile lib + link its test targets | 52.6s | **13.4s** | 3.9× | | er-server suite wall | 259.5s | **30.6s** | 8.5× | | `check-e2e` test time | 346s | 210s | −39% | | `check-e2e` test time at CI's 4 threads | 346s | 256s | −26% | The suite win is the same overlap `cargo nextest` was meant to buy: cargo runs one test BINARY at a time, so these files ran strictly in series, and as modules of one binary they are threads in one process. Unlike nextest there is no process-per-test tax — nextest was measured 96s *slower* on the `test` job for exactly that reason (#344) — and unlike nextest this also removes 72 uncacheable links. One change, both costs. This is only safe because each Postgres test owns its own database (#344); before that, 49 concurrent threads on one shared schema is precisely the race `pg_serial.rs` exists to prevent. dedupe-core and er-match needed no equivalent work: their fixtures are read-only committed files, verified by grepping for writers. ## Consequences worth knowing `--test <file>` no longer resolves for these three crates; the target is `main` and the old file name is a name filter. Updated at all three call sites — rust.yml's extension-loading step and the 50k scale job, plus the ducklake-lakehouse skill. `er-cli --test lake_e2e` is untouched because er-cli is not consolidated. `pg_serial.rs` keeps doing its job unchanged: it scans `tests/` for `pg_*.rs` files, which are still there. Counts are identical to main: `make check` 586 passed, `check-e2e` 232 passed, zero skips. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Extends the same `autotests = false` pattern to the twelve other crates with more than one integration-test file: dedupe-cli, er-cli, er-compile, er-entity-gen, er-entity-lint, er-hash, er-ingest, er-reconcile, er-schema, er-standardize, er-std. Test binaries across the workspace go **147 -> 56**. ## One crate is deliberately left out, and it took a failure to find `er-entity-diff` is NOT consolidated. Its `pg_diff.rs` and `pg_reconcile.rs` both connect to the single database named by `ER_TEST_PG_DSN`, so as modules of one binary they ran concurrently against shared tables and Postgres returned `E40P01 deadlock detected` — one test waiting on AccessShareLock on the schema while the other held AccessExclusiveLock on a relation it was retyping. I had scanned every candidate crate for concurrency hazards before starting, but only for temp-file and working-directory collisions — not for a shared Postgres, because the database-per-test isolation (#344) lives in er-server's test support and I did not think to ask which *other* crate talks to that database. It is two links; the reason it stays separate, and what would have to happen first, is recorded in its Cargo.toml rather than left to be rediscovered. ## Measured | | main | after | |---|---|---| | test binaries linked | 147 | **56** | | `check-e2e` test time | 346s | **194s** (−44%) | CI on the previous commit (the big three only) already showed the effect on job wall-clock, against two independent controls with `fmt + clippy + docs` as the control variable: `test` 9.0m/10.2m -> 8.2m, `DuckLake e2e` 15.5m/17.4m -> 13.6m. Roughly −10% to −20% on both long jobs. Modest rather than dramatic, because what remains in both is dependency-tree compile, which only the cache can touch. `make check` 586 passed and `check-e2e` 232 passed, both unchanged from main, zero skips. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
NOT APPLIED, and rust.yml is deliberately untouched. Pointing the workflow at the bucket before `terraform apply` runs would make every compile job fail to assume a role that does not exist, so the sequence is: merge this, apply, then switch the workflow in its own change. ## Why sccache currently uses the GitHub Actions cache backend, which shares one 10 GB per-repository budget, LRU-evicted past it. That is why rust.yml carries a nightly `cache-prune` job — a cap on the thing doing most of the work. When the repository sat at the ceiling GitHub evicted its largest LRU victim, the rust-cache entry every compile job restores from, producing cold runs with no dependency change to explain them. Cold is roughly 3x: on DuckDB 2.0 the `DuckLake e2e` job measured 25m cold against 8m warm, `test` 15m against 6m. This is now the dominant remaining CI lever. After collapsing 147 test binaries to 56 (#345), what is left in both long jobs is dependency-tree compile, which only a cache can touch — consolidation got `test` to 8.2m and `DuckLake e2e` to 13.6m, and more test-structure work would be diminishing returns. ## The security decision in this change Two roles, not one, because **this repository is public**. A role that let any PR-triggered job write to the cache would be a path for a contributor-supplied branch to place compiled object code that a later `main` build consumes — cache poisoning straight into the build. So `er-ci-sccache-write` trusts only `ref:refs/heads/main`, exactly as the existing `er-ci-ecr-push` role restricts image pushes and as rust.yml's rust-cache config already restricts its single writer ("`lint` is the SINGLE WRITER of `shared-key: rust`, and only from `main`"). `er-ci-sccache-read` trusts any ref of this repository, so PRs read the cache `main` populated — which is where nearly all the value is, the dependency tree rather than the PR's own crates. Neither policy carries `s3:DeleteObject`; expiry is the lifecycle rule's job. Fork PRs get neither role: GitHub issues no `id-token` to a fork's `pull_request` run, so those have no cache. That is the safe failure and not a regression, since the Actions backend was equally unavailable to them. **One thing is unverified and the comment says so.** sccache is *expected* to treat a denied `PutObject` as a non-fatal cache-write miss and keep compiling. If it instead fails the build, the read-only role is unusable and the choice becomes one read+write role (accepting the poisoning surface) or no cache on PRs. Probe that on a single PR before deleting `cache-prune`. ## Notes The bucket is private, SSE-AES256, unversioned (every object is a content-addressed compilation result, so a second version is the same bytes), with a 14-day expiry that replaces the nightly prune and a 1-day abort-incomplete-multipart rule so a killed runner cannot leave billable uploads behind. The `github-oidc` module gains an `oidc_provider_arn` output: an account may hold only one OIDC provider per issuer URL and that module owns it, so these roles federate against the existing ARN rather than declaring a second provider (which would fail with EntityAlreadyExists). `terraform fmt -check -recursive` passes. I could not run `terraform validate` locally — my provider setup validates credentials at init and fails identically on unmodified `main`, so it is environmental — and infra.yml's credential-free `validate each env` job is the authority. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ing it The two-role split only works if sccache treats a denied cache write as a non-fatal miss. That was the one unverified precondition in this change, so I measured it rather than leaving it as a caveat: sccache 0.19.0 against a read-only cache directory, compiling a source change the cache could not satisfy, exits 0 and reports `Cache write errors 1`, `Cache errors 0`, `Compilation failures 0`. Kept one caveat honestly: the probe used the local-disk backend, not S3. The failure is handled at the same backend-agnostic `storage.put()` boundary, so this is strong evidence rather than proof that an S3 403 behaves the same way — hence the note to watch `Cache write errors` on the first PR run after the switch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`.claude/skills/aws-account-operations/references/footprint.md` is GENERATED from `infra/terraform/` — it counts resource types — so adding sccache.tf made it stale and both the `agent skills (lint + drift)` and `fmt + clippy + docs` jobs failed on it. My miss: on this branch I ran `terraform fmt` and leaned on infra.yml's validate, and never ran the repo-wide `make skills-check`. The terraform was fine; the generated doc derived from it was not. The inventory now reads aws_iam_role 9 -> 11, aws_iam_role_policy 6 -> 8, aws_s3_bucket 5 -> 6, plus the bucket's access-block/encryption/lifecycle entries. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Oct 28, 2026
athvin
added a commit
that referenced
this pull request
Oct 30, 2026
…PPLIED (#350) 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: bmoore813 <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
NOT APPLIED, and rust.yml is deliberately untouched. Pointing the workflow at
the bucket before
terraform applyruns would make every compile job fail toassume a role that does not exist, so the sequence is: merge this, apply, then
switch the workflow in its own change.
Why
sccache currently uses the GitHub Actions cache backend, which shares one 10 GB
per-repository budget, LRU-evicted past it. That is why rust.yml carries a
nightly
cache-prunejob — a cap on the thing doing most of the work. When therepository sat at the ceiling GitHub evicted its largest LRU victim, the
rust-cache entry every compile job restores from, producing cold runs with no
dependency change to explain them. Cold is roughly 3x: on DuckDB 2.0 the
DuckLake e2ejob measured 25m cold against 8m warm,test15m against 6m.This is now the dominant remaining CI lever. After collapsing 147 test binaries
to 56 (#345), what is left in both long jobs is dependency-tree compile, which
only a cache can touch — consolidation got
testto 8.2m andDuckLake e2eto13.6m, and more test-structure work would be diminishing returns.
The security decision in this change
Two roles, not one, because this repository is public. A role that let any
PR-triggered job write to the cache would be a path for a contributor-supplied
branch to place compiled object code that a later
mainbuild consumes — cachepoisoning straight into the build.
So
er-ci-sccache-writetrusts onlyref:refs/heads/main, exactly as theexisting
er-ci-ecr-pushrole restricts image pushes and as rust.yml'srust-cache config already restricts its single writer ("
lintis the SINGLEWRITER of
shared-key: rust, and only frommain").er-ci-sccache-readtrusts any ref of this repository, so PRs read the cache
mainpopulated —which is where nearly all the value is, the dependency tree rather than the PR's
own crates. Neither policy carries
s3:DeleteObject; expiry is the lifecyclerule's job.
Fork PRs get neither role: GitHub issues no
id-tokento a fork'spull_requestrun, so those have no cache. That is the safe failure and not aregression, since the Actions backend was equally unavailable to them.
The one precondition was measured, not assumed. The read-only half only
works if sccache treats a denied cache write as a non-fatal miss, so I tested
it: sccache 0.19.0 against a read-only cache directory, compiling a source
change the cache could not satisfy, exits 0 and reports
One caveat kept deliberately: that probe used the local-disk backend, not S3.
sccache handles the failure at the same backend-agnostic
storage.put()boundary, so it is strong evidence rather than proof that an S3 403 behaves
identically — watch
Cache write errorson the first PR run after the switch.Notes
The bucket is private, SSE-AES256, unversioned (every object is a
content-addressed compilation result, so a second version is the same bytes),
with a 14-day expiry that replaces the nightly prune and a 1-day
abort-incomplete-multipart rule so a killed runner cannot leave billable
uploads behind.
The
github-oidcmodule gains anoidc_provider_arnoutput: an account mayhold only one OIDC provider per issuer URL and that module owns it, so these
roles federate against the existing ARN rather than declaring a second provider
(which would fail with EntityAlreadyExists).
terraform fmt -check -recursivepasses. I could not runterraform validatelocally — my provider setup validates credentials at init and fails identically
on unmodified
main, so it is environmental — and infra.yml's credential-freevalidate each envjob is the authority.Co-Authored-By: Claude Opus 5 (1M context) [email protected]
🤖 Generated with Claude Code