Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ci: sccache read-only on pull requests
Pull requests read the Actions cache. Main pushes and schedules write.
CARGO_INCREMENTAL=0 was already set. The Linux CPU pin is a cargo
config target table beside the Windows stack flags. The shared setup
does not set RUSTFLAGS, because Cargo 1.89 replaces every rustflags
entry when that variable is set.
  • Loading branch information
cursoragent committed Oct 28, 2026
commit 9b7e9ddf66f19fabceeecb27b40ac91f57a588f4
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ rustflags = ["-C", "link-args=/STACK:16777216"]
[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-args=-Wl,--stack,16777216"]

# Same baseline the replay hash pins on x86_64. A separate target table so
# this flag is not applied by replacing the Windows stack rustflags.
# aarch64 stays on the compiler default (target-cpu=native is forbidden).
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=x86-64"]

# Convenience aliases for the editor
[alias]
editor = "run --bin aw_editor --profile release-fast"
Expand Down
13 changes: 13 additions & 0 deletions .github/actions/rust-ci-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ runs:
echo "CARGO_INCREMENTAL=0" >> "$GITHUB_ENV"
echo "SCCACHE_CACHE_SIZE=10G" >> "$GITHUB_ENV"
echo "SCCACHE_IDLE_TIMEOUT=0" >> "$GITHUB_ENV"
# sccache 0.19 writes through the Actions cache. A pull request that

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment treats sccache 0.19 as the implementation. The install step calls mozilla-actions/sccache-action@v0.0.9 with no version input, and that action installs the latest release when the input is empty. Latest on 2026-10-28 is v0.19.0 (published 2026-10-24), so SCCACHE_GHA_RW_MODE works today. In that tag, an unrecognized mode warns and config_from_env uses unwrap_or(ReadWrite). A later release that renames or drops the variable turns pull requests back into writers, and test_sccache_pull_requests_are_read_only still passes because it only searches this file for the string. Pass version: "0.19.0".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment treats sccache 0.19 as what the job runs. The install step above is still mozilla-actions/sccache-action@v0.0.9 with no version input. setup.ts uses an empty input as getLatestRelease().tag_name and interpolates that string into both the download URL and the asset name. Latest on 2026-10-28 is v0.19.0 (published 2026-10-24). I requested the musl asset: .../download/v0.19.0/sccache-v0.19.0-x86_64-unknown-linux-musl.tar.gz returned 302, and the same path with 0.19.0 returned 404. The pin is version: "v0.19.0", not 0.19.0.

In that tag, cache_mode_from_env_var("SCCACHE_GHA_RW_MODE").unwrap_or(ReadWrite) (config.rs) turns any other string into a writer. A later release that renames or drops the variable puts pull requests back on the write path, and test_sccache_pull_requests_are_read_only still passes because it only searches this file for the echo.

ReadOnlyStorage::put does not drop the write quietly. It returns Cannot write to read-only storage without calling the backend, and server.rs counts that as a cache write error without failing the compile. Pull-request sccache --show-stats will show one write error per miss. That counter is local. It is not the Actions rate limit the comment above is describing. RemoteStorage::check still skips the .sccache_check write when the mode is already read-only, and gets still forward.

# also writes hits the service rate limit (cache write errors) and
# evicts the shared cache. Main pushes and schedules populate it.
# CARGO_INCREMENTAL=0 is already required; sccache still refuses bins,
# cdylibs, and proc-macros.
if [ "${{ github.ref }}" = "refs/heads/main" ] && [ "${{ github.event_name }}" != "pull_request" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actions expands ${{ github.ref }} and ${{ github.event_name }} before bash parses this script. github.event_name is a fixed token. github.ref is not: a branch name may contain ", ;, and $(). Today's callers do not hand that ref to a fork. pull_request uses refs/pull/N/merge, and ci.yml pushes only main and develop. Quote the runner variables, which are not reparsed:

if [ "$GITHUB_REF" = "refs/heads/main" ] && [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then

The write arm is also wider than the comment above it. Every event other than pull_request writes when the ref is refs/heads/main, including workflow_dispatch. There is no pull_request_target workflow in the tree. A later one that calls this action would write, because that event's github.ref is the base branch and its name is not pull_request. An allowlist of push and schedule matches the comment. Keep workflow_dispatch on that list only if a manual main run should keep populating the cache.

echo "SCCACHE_GHA_RW_MODE=READ_WRITE" >> "$GITHUB_ENV"
else
echo "SCCACHE_GHA_RW_MODE=READ_ONLY" >> "$GITHUB_ENV"
fi
# Do not set RUSTFLAGS here. Cargo 1.89 replaces every rustflags
# entry in .cargo/config.toml when that variable is set. The Linux
# CPU pin lives in that file next to the Windows stack flags.

- name: Cache cargo registry (one key per OS, save on main only)
uses: Swatinem/rust-cache@v2
Expand Down
4 changes: 2 additions & 2 deletions docs/current/CI_ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ When the same tests also run under nextest (an affected crate on a pull request,

- pinned toolchain (default 1.89.0) via `dtolnay/rust-toolchain`
- Linux build dependencies, including `libudev-dev` and `libasound2-dev` (this is what Editor CI was missing on PR #212)
- `sccache` with `SCCACHE_GHA_ENABLED=true` and `RUSTC_WRAPPER=sccache`
- `sccache` 0.19.0 with `SCCACHE_GHA_ENABLED=true` and `RUSTC_WRAPPER=sccache`. `CARGO_INCREMENTAL=0` is set in this action and in `ci.yml`. Pull requests and non-main refs set `SCCACHE_GHA_RW_MODE=READ_ONLY`. Pushes and schedules on `refs/heads/main` set `READ_WRITE`. The action does not set `RUSTFLAGS`: Cargo 1.89 replaces every `rustflags` entry in `.cargo/config.toml` when that variable is set. The Linux CPU pin is `[target.x86_64-unknown-linux-gnu] rustflags = ["-C", "target-cpu=x86-64"]`, beside the Windows 16 MiB stack flags. aarch64 keeps the default baseline. sccache 0.19 does not cache `bin`, `cdylib`, or `proc-macro` crate types.
- Swatinem `rust-cache` v2 with `shared-key: ${{ runner.os }}-astraweave`, `cache-targets: false`, `save-if` only on `refs/heads/main`

Registry and git caches are shared across jobs and workflows on the same OS. Compilation artifacts stay in sccache, so the two caches do not both wrap `target/`. Pull requests restore the cache and do not save it.
Registry and git caches are shared across jobs and workflows on the same OS. Compilation artifacts stay in sccache, so the two caches do not both wrap `target/`. Pull requests restore both caches and do not save them. Job `121303738868` (run `40235303264`) recorded rust hit rate 11.01%, 263 cache write errors, and 826 non-cacheable calls (621 `crate-type`, 113 `bin`, 66 `proc-macro`) while `effective_cache_mode` was `ReadWrite`. Gate samples from the same window were 24.34% and 38.52% overall.

Sanitizer, Miri, and mutation workflows keep their own `actions/cache` keys. They use nightly or sanitizer instrumentation; sharing stable sccache objects with them is the failure mode the sanitizer workflow already documented (stale nightly ABI in `target/`).

Expand Down
21 changes: 21 additions & 0 deletions scripts/ci/test_workflow_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,27 @@ def test_aravath_supply_chain_uses_prebuilt_tools(self) -> None:
self.assertIn("9bd3e599314f50810c9d98b8b68a617ff9d3cc20873968d90b29d121f6b226ff", script)
self.assertIn('"$tool" cyclonedx --version', script)

def test_sccache_pull_requests_are_read_only(self) -> None:
action = (ROOT / ".github" / "actions" / "rust-ci-setup" / "action.yml").read_text(encoding="utf-8")
self.assertIn("CARGO_INCREMENTAL=0", action)
self.assertIn("SCCACHE_GHA_RW_MODE=READ_ONLY", action)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertIn checks stay green if the if / else arms are swapped, if READ_ONLY exists only in a comment, or if both echoes run unconditionally. GITHUB_ENV keeps the last assignment, so an unconditional pair that ends on READ_WRITE would write from every pull request and this test would still pass.

Lock one substring that contains the refs/heads/main condition and the READ_WRITE echo, and another that contains the else and the READ_ONLY echo. The same test never opens integration-tests.yml, toolchain-management.yml, dependency-management.yml, or benchmark_alert.yml. Those workflows still enable the GHA backend with no mode variable. They are not on pull_request, so they do not break this pull-request claim; they do keep writing on main pushes and schedules.

self.assertIn("SCCACHE_GHA_RW_MODE=READ_WRITE", action)
self.assertIn("refs/heads/main", action)
# RUSTFLAGS replaces every rustflags entry. The pin is in cargo config.
self.assertNotIn("RUSTFLAGS=", action)
config = (ROOT / ".cargo" / "config.toml").read_text(encoding="utf-8")
self.assertIn("[target.x86_64-unknown-linux-gnu]", config)
self.assertIn('"-C", "target-cpu=x86-64"', config)
self.assertIn("[target.x86_64-pc-windows-msvc]", config)
self.assertIn("link-args=/STACK:16777216", config)
self.assertIn("[target.x86_64-pc-windows-gnu]", config)
self.assertIn("link-args=-Wl,--stack,16777216", config)
replay = (WORKFLOWS / "determinism-replay.yml").read_text(encoding="utf-8")
self.assertIn('echo "RUSTFLAGS=-C target-cpu=x86-64" >> "$GITHUB_ENV"', replay)
self.assertIn("target-cpu=native is forbidden", replay)
aravath = (WORKFLOWS / "aravath-determinism.yml").read_text(encoding="utf-8")
self.assertIn("-C target-feature=-fma", aravath)

def test_allocation_measurement_is_a_real_gate_off_prs(self) -> None:
text = (WORKFLOWS / "allocation-measurement.yml").read_text(encoding="utf-8")
self.assertIn("schedule:", text)
Expand Down
Loading