From 9b7e9ddf66f19fabceeecb27b40ac91f57a588f4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 28 Oct 2026 00:35:21 +0000 Subject: [PATCH] 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. --- .cargo/config.toml | 6 ++++++ .github/actions/rust-ci-setup/action.yml | 13 +++++++++++++ docs/current/CI_ARCHITECTURE.md | 4 ++-- scripts/ci/test_workflow_policy.py | 21 +++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 5695366416..fb6e6003fc 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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" diff --git a/.github/actions/rust-ci-setup/action.yml b/.github/actions/rust-ci-setup/action.yml index a63495d906..5f1be153f3 100644 --- a/.github/actions/rust-ci-setup/action.yml +++ b/.github/actions/rust-ci-setup/action.yml @@ -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 + # 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 + 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 diff --git a/docs/current/CI_ARCHITECTURE.md b/docs/current/CI_ARCHITECTURE.md index 6a10bb35f9..77da4bcfd9 100644 --- a/docs/current/CI_ARCHITECTURE.md +++ b/docs/current/CI_ARCHITECTURE.md @@ -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/`). diff --git a/scripts/ci/test_workflow_policy.py b/scripts/ci/test_workflow_policy.py index 5fbf257f0a..15d14ad002 100644 --- a/scripts/ci/test_workflow_policy.py +++ b/scripts/ci/test_workflow_policy.py @@ -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) + 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)