Repository navigation
ci: gate rust caches to main and share one per OS to fit the 10 GB cap - #3323
Conversation
The repo sat at 11.1 GB across 57 active caches against GitHub's 10 GB per-repo limit, so every workflow run evicted older caches LRU-style. ~57% of that was single-PR caches keyed to refs/pull/N/merge, which no other PR can ever restore — pure churn that evicted the reusable main caches. Four changes, mirroring PRQL's approach where it fits: - save-if gated to main on every rust-cache call. PRs restore main's cache via the restore-key fallback and never deposit their own. This alone drops the footprint under the cap. - A shared cache per OS for the test family. test-setup now sets shared-key, and `test` is the sole saver (new `save-cache` input, default true); affected-tests/collect-affected/release-target pass save-cache=false. The PR-only affected-tests job most needs this — it never runs on main, so a per-job key had no baseline and cold-built every PR. It now rides test's main cache. - Nightly/release jobs stop saving. Stable ones (feature-powerset, benchmarks, crate-build) restore the shared cache read-only; the nightly-toolchain ones (check-unused, minimal-versions) and the cross-target release-target just don't save — near-zero reuse against the cap. - cache-bin: false applied to the v0 jobs too (lint, feature-check, msrv, code-coverage), closing the latent rustup-proxy bug that test-setup already guarded against. lint/feature-check/code-coverage deliberately keep their own main-gated caches rather than joining the shared one: they build divergent artifacts (clippy-check, --no-default-features, coverage-instrumented) and we're no longer space-constrained after the above, so a right-sized own cache beats paying a 1.3 GB restore for partial reuse. Projected active cache: ~3-5 GB, all main-scoped. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The cache-gating change reads correctly to me. test (via test-setup, default save-cache: true) is the sole saver of the per-OS v1-rust/shared cache and only on main; every other site is save-if: false / save-cache: "false". The shared restorers (feature-powerset, benchmarks, crate-build) match prefix-key: v1-rust + shared-key: shared and run stable on ubuntu-24.04, so their key lines up with the test saver, while the nightly-toolchain jobs (check-unused-dependencies, minimal-versions) correctly omit shared-key. Top-level env (CARGO_TERM_COLOR, CARGO_INCREMENTAL, RUSTFLAGS) is identical between ci.yaml and nightly.yaml and no job-level CARGO*/RUST* env diverges, so the cross-workflow shared restore respects the env-hashing invariant in .github/CLAUDE.md. Not approving only because of the red below.
The three red checks are an unrelated infra flake, not this change. feature-powerset, benchmarks, and code-coverage all failed at the Install shells (zsh, fish) step — awalsh128/[email protected], which the diff doesn't touch. Identical signature on all three:
Validating action arguments (version='1', packages='')...
aborted
exit status 100Packages argument is empty.
The action's normalize step shells out to apt (exit status 100, the usual lock/transient apt error), comes back with an empty package list, and the empty_packages_behavior: error guard aborts. It's worth calling out because these are precisely the jobs this PR modified — but the cause is the apt-cache action, not the rust-cache gating. A rerun should clear them (most other jobs are still in progress, so --failed rerun would 403 until they finish).
awalsh128/cache-apt-pkgs-action's `v1.6.1` tag was force-moved onto a broken `v1.6.2` whose pre-cache step exits 3, failing every Linux job that installs zsh/fish — confirmed on main (code-coverage) and on this PR (feature-powerset, benchmarks, code-coverage all failed there in seconds). Two small packages install in a few seconds, so the apt cache the action provided isn't worth a flaky third-party dependency — and retiring it removes one more actions/cache consumer, in line with this branch's 10 GB-cap work. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
This commit replaces the flaky awalsh128/cache-apt-pkgs-action with a direct apt-get install zsh fish across ci.yaml, nightly.yaml, and the test-setup composite action — resolving the broken-tag failure my earlier review flagged as the sole reason for not approving. The replacement is correct (shell: bash is rightly added only in the composite action, where run: steps require it).
The one red check, pre-commit.ci - pr, is "error during mergeable check" — a pre-commit.ci-side transient where it bailed before computing the merge commit, not a hook failure on this diff. GitHub now reports the PR as MERGEABLE, so a re-trigger should clear it.
main's #3321 already fixed the awalsh128/cache-apt-pkgs-action v1.6.2 breakage by pinning back to v1.6.1 and adding a Dependabot ignore — the maintainer's chosen approach. This reverts the earlier apt-action removal on this branch so the PR stays scoped to the rust-cache churn work and doesn't diverge from that decision. (claude-setup's direct apt-get is pre-existing and untouched.) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…3846) `tend-setup`'s rust-cache step never restored anything: it looked up `prefix-key: hashFiles('Cargo.lock')` with no `shared-key`, and computed its environment hash before `Set build environment` ran, while the shared cache it could restore is published as `v1-rust`/`shared` with `CARGO_TERM_COLOR`/`CARGO_INCREMENTAL`/`RUSTFLAGS` already set. This points it at the shared keys and moves that env step above the cache step, so a tend job computes `v1-rust-shared-Linux-x64-6966df26-<lockfile hash>` — the exact key `test` writes from main. Verified by reproducing rust-cache's key arithmetic offline: the same hash function that yields today's missing `dc9f6f9f` from the tend job's environment yields the writer's `6966df26` from the post-fix one. One behavior change rides along: `RUSTDOCFLAGS=-Dwarnings` is dropped rather than worked around. It is the only var here no cache writer sets, so above the cache step it poisons the key and below it needs a second env step — and it is redundant either way, since both rustdoc gates set it inline in `.config/wt.toml` (`doctest`, `doc`), which is what ci.yaml's `fast-checks` already relies on; that workflow sets no `RUSTDOCFLAGS` of its own. <details><summary>The key arithmetic, and how it was verified</summary> ## What was wrong The shared cache is written by the jobs that call `test-setup` without `save-cache: false` — `test` and `fast-checks` in ci.yaml, `full-tests` in nightly.yaml — which publish the Linux entry as `v1-rust-shared-Linux-x64-6966df26-709538b9` (1034 MB, [run 32157064498](https://github.com/max-sixty/worktrunk/actions/runs/32157064498)). The nightly tend job ([32106850263](https://github.com/max-sixty/worktrunk/actions/runs/32106850263)) computed `dac153ac…d7975-nightly-Linux-x64-dc9f6f9f-709538b9` and printed `No cache found.` Three independent mismatches: 1. **prefix** — `hashFiles('Cargo.lock')` vs `v1-rust`. 2. **shared-key** — absent, so rust-cache substitutes the job name (`nightly`, `handle`, `review`, …) where the writer has `shared`. 3. **env hash** — `dc9f6f9f` vs `6966df26`. Both jobs list the same two toolchains and the same lockfile hash (`709538b9`); the difference is entirely which `CARGO*`/`RUST*` vars were exported by the time the cache step ran. The writer's are `CARGO_INCREMENTAL`, `CARGO_TERM_COLOR`, `RUSTFLAGS`; the tend job's was `CARGO_INCREMENTAL` alone, because `Set build environment` sat at the *end* of the composite. ## Verification rust-cache builds that hash in [`src/config.ts`](https://github.com/Swatinem/rust-cache/blob/v2/src/config.ts): sha1 over each installed toolchain's `<release> <host> <commit-hash>`, then each matching `KEY=VALUE` in sorted key order, truncated to 8 hex chars. Replaying it against the environments both jobs logged reproduces both observed hashes exactly, which is what makes the third prediction trustworthy: ```python import hashlib rust = ["1.96.0 x86_64-unknown-linux-gnu ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96", "1.97.1 x86_64-unknown-linux-gnu 8bab26f4f68e0e26f0bb7960be334d5b520ea452"] def env_hash(pairs): h = hashlib.sha1() for r in rust: h.update(r.encode()) for k, v in sorted(pairs): h.update(f"{k}={v}".encode()) return h.hexdigest()[:8] INCR = ("CARGO_INCREMENTAL", "0") COLOR = ("CARGO_TERM_COLOR", "always") FLAGS = ("RUSTFLAGS", "-C debuginfo=0") DOC = ("RUSTDOCFLAGS", "-Dwarnings") env_hash([INCR]) # dc9f6f9f — tend today, matches the logged miss env_hash([INCR, COLOR, FLAGS]) # 6966df26 — the writer, and this PR env_hash([INCR, COLOR, DOC, FLAGS]) # 2c91e6ea — RUSTDOCFLAGS kept above the step ``` The third line is why `RUSTDOCFLAGS` had to be dealt with rather than left alongside the other three: it sorts between `CARGO_TERM_COLOR` and `RUSTFLAGS`, and no writer sets it, so including it produces a key nothing has written — the same silent miss, differently caused. `cache-bin` is the fourth field that had to move, and it is not part of the key string: it decides the *paths* list, and `actions/cache` derives an entry's version from those paths — so the old `cache-bin: true` (six paths, including `~/.cargo/bin`) would have missed the writer's three-path entry even with a correct key. One incidental detail, since it explains an odd line in the logs: `CARGO_INCREMENTAL` shows up in the tend job's considered set even before anything exported it, because rust-cache's own `restore.ts` calls `core.exportVariable("CARGO_INCREMENTAL", 0)` first. It is equal on both sides either way; the composite exports it regardless, to keep the three in step with ci.yaml's `env:` block for the builds that follow. There is no live check before merge, and that's worth being explicit about: every tend workflow runs this composite against the **base** tree — tend-review is `pull_request_target`, and the scheduled workflows check out `main` — so this PR's own tend runs still load main's version and log the old `dac153ac…-review-Linux-x64-dc9f6f9f` key and `No cache found.` The first tend run after this merges is the confirmation; a wrong answer shows up as a `No cache found.` line in that job's Cache Configuration group. ## Cost A restore moves ~1 GB and takes ~35 s, against ~13 s previously spent computing a key nothing had written. Compiling sessions win that back many times over (the nightly session ran 5 `cargo test` invocations plus clippy and fmt; a Zola-migration session ran 17, with one `--lib --bins` + integration block occupying 15.6 min of its 68). No workflow pays it on an idle tick. `tend-notifications` polls every ~15 min, but its `actions/checkout` and `tend-setup` steps carry the same `steps.check.outputs.count != '0' || github.event_name == 'workflow_dispatch'` condition as the agent step, so a poll that finds nothing to process skips the composite entirely. Every run that restores the cache is a run that boots a session — which is where the compiles are — so the per-workflow carve-out an earlier revision of this description offered isn't needed. ## History The key had been untouched since the action was created in #1273 (2026-03-05). #3323 (2026-06-29) introduced the `v1-rust`/`shared` scheme and moved every other consumer onto it — nightly.yaml's two restore-only blocks and benchmarks.yaml read identically today — but didn't reach this file. Observed as a miss on three consecutive daily sweeps (2026-08-16/17/18), recorded in #3691. The composite was renamed `claude-setup` → `tend-setup` by #3849 while this PR was open; main is merged in here, so the change lands on the new path. </details> --------- Co-authored-by: worktrunk-bot <[email protected]>
What
The Actions cache sat at 11.1 GB across 57 caches against GitHub's hard 10 GB per-repo cap, so every run was evicting older caches LRU-style — constant churn. ~57% of that was single-PR caches (
refs/pull/N/merge) that no other PR can ever restore, depositing budget that evicted the reusablemaincaches.Changes
save-ifgated tomainon every rust-cache call. PRs restoremain's cache via the restore-key fallback and never deposit their own. This alone drops the footprint under the cap.test-setupnow setsshared-key, withtestas the sole saver (newsave-cacheinput, defaulttrue);affected-tests/collect-affected/release-targetpasssave-cache: "false". The PR-onlyaffected-testsjob needed this most — it never runs onmain, so a per-job key had no baseline and cold-built every PR; it now ridestest'smaincache.feature-powerset,benchmarks,crate-build) restore the shared cache read-only; the nightly-toolchain ones (check-unused,minimal-versions) and the cross-targetrelease-targetjust don't save — near-zero reuse against the cap.cache-bin: falseapplied to the v0 jobs too (lint,feature-check,msrv,code-coverage), closing the latent rustup-proxy bug thattest-setupalready guarded against.Deliberate non-changes
lint/feature-check/code-coveragekeep their ownmain-gated caches rather than joining the shared one. They build divergent artifacts (clippy-check,--no-default-features, coverage-instrumented), and we're no longer space-constrained after the above — a right-sized own cache beats a 1.3 GB restore for partial reuse.Cargo.lock-hash-in-prefix-key: rust-cache already keys on the lockfile, andsave-if: mainalready prevents the PR-junk accumulation that trick fights (one mechanism per guarantee).awalsh128/cache-apt-pkgs-actionstays pinned atv1.6.1(per fix(ci): pin cache-apt-pkgs-action back to v1.6.1 #3321, merged into this branch) — not replaced. OnlySwatinem/rust-cacheconfig changes here.Projected active cache: ~3–5 GB, all
main-scoped. Nowtbehavior change, so no changelog entry.