From 34ec6f17777cb48576143eaf42ee834094a4e246 Mon Sep 17 00:00:00 2001 From: DaniAkash Date: Thu, 27 Aug 2026 08:36:54 +0530 Subject: [PATCH 1/2] perf(rust): share cargo intermediates across checkouts Every checkout compiles its own copy of the dependency graph. Anyone keeping more than one clone or worktree open pays that in full each time, around 1.6G apiece. build-dir moves only the intermediate artifacts out of the checkout, and it supports path templating, so {cargo-cache-home} resolves to CARGO_HOME and one shared location covers every checkout on a machine. Nothing absolute or machine specific is committed. target-dir was the obvious alternative and does not work here: it has no templating, cargo expands neither ~ nor $HOME, so a committed value could only be relative to the checkout. That would limit sharing to sibling directories, and because it also moves the final artifacts it would break the three places the BrowserClaw release locates a built binary. Final artifacts still land in /target, so nothing that resolves a build output by path changes. Measured across two checkouts of the same branch: cold build 52.36s target 227M shared 1.6G second checkout 16.14s target 227M shared 2.1G A release build against a warm shared directory still produces target/release/browseros-claw-server-rs. rust-cache saves only workspace target dirs plus the registry and git caches, and never reads a build dir setting, so the shared directory is named to it explicitly. Without that, CI would recompile the dependency graph on every run. --- .cargo/config.toml | 11 +++++++++++ .github/workflows/test.yml | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..8025201ee --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,11 @@ +[build] +# Keep intermediate artifacts outside the checkout so every clone and worktree +# on a machine shares one copy instead of each rebuilding the dependency graph. +# {cargo-cache-home} expands to CARGO_HOME, so this is portable: no absolute +# path, no assumption about where the repo lives. Cargo does not expand ~ or +# $HOME, and target-dir does not support templating, so build-dir is the only +# form that gets this. +# +# Final artifacts still land in /target, so anything locating a built +# binary by path keeps working. +build-dir = "{cargo-cache-home}/build/browseros" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d216c9af..4c6029412 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -100,6 +100,11 @@ jobs: uses: Swatinem/rust-cache@v2 with: workspaces: packages/browseros-agent + # Intermediate artifacts live outside the checkout so worktrees can + # share them, and rust-cache only saves workspace target dirs plus the + # registry and git caches by default. Name the build dir explicitly or + # every run would recompile the dependency graph from scratch. + cache-directories: ~/.cargo/build/browseros - name: Install dependencies run: bun ci From 492bf0fa7c8e82ee5098a3c6cc2101df5544a031 Mon Sep 17 00:00:00 2001 From: DaniAkash Date: Thu, 27 Aug 2026 13:58:22 +0530 Subject: [PATCH 2/2] ci(rust): warm the rust cache on main and drop it fortnightly Three related gaps around the shared cargo build directory. The Rust cache was never warm for a new pull request. Tests run only on pull_request, so rust-cache saved under a PR branch's scope, and branches cannot read each other's caches. This is the same problem the Turbo warm run already solves, and Rust was simply never covered. It matters more now that the intermediates live in a cache-directories entry: without a warm run, every PR recompiles the dependency graph. Warming alone would not have worked. rust-cache builds its key from GITHUB_JOB unless shared-key is set, and the existing keys show it: v0-rust-test-Linux-x64-- A warm job under any other name would have written a cache nothing else could read. Both steps now pin the same shared-key, workspaces, cache-directories and toolchain, since the toolchain hashes into the key too. The new warm job mirrors what the Rust suites compile, test binaries and clippy's separate artifacts, and deliberately omits -D warnings because it exists to populate a cache rather than to gate on lints. Finally, rust-cache prunes only workspace target dirs and never extra cache-directories, so the shared build directory is cached wholesale and grows without bound. It is already the larger part of the problem: v0-rust 25 entries 6.97 GB all caches 262 entries 10.35 GB against a 10 GB allowance Being over the allowance means LRU eviction is already discarding other caches. Dropping the Rust entries on the 1st and 15th keeps that bounded, matched on the prefix so nothing else is touched, and the warm workflow is dispatched straight after so no branch waits for the next merge. --- .github/workflows/rust-cache-bust.yml | 69 ++++++++++++++++++++++++++ .github/workflows/test.yml | 3 ++ .github/workflows/turbo-cache-warm.yml | 45 +++++++++++++++-- 3 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/rust-cache-bust.yml diff --git a/.github/workflows/rust-cache-bust.yml b/.github/workflows/rust-cache-bust.yml new file mode 100644 index 000000000..2549b9e0a --- /dev/null +++ b/.github/workflows/rust-cache-bust.yml @@ -0,0 +1,69 @@ +name: Rust Cache Bust + +# The shared cargo build directory is cached as an extra `cache-directories` +# entry, and rust-cache prunes only workspace target dirs, never extra ones. So +# that entry is cached wholesale and accumulates artifacts for dependencies and +# profiles that no longer exist. Left alone it grows against the repository's +# 10GB Actions cache allowance and evicts entries that are still wanted. +# +# Dropping it on a schedule keeps that bounded. The next warm run rebuilds it +# from scratch, so the only cost is one cold Rust compile. +on: + schedule: + # 1st and 15th, so roughly fortnightly. Ahead of the Monday 06:00 warm run + # rather than alongside it, and the warm workflow is dispatched below in any + # case so a fresh cache does not wait for the next merge. + - cron: "0 5 1,15 * *" + workflow_dispatch: + +permissions: + actions: write + +concurrency: + group: rust-cache-bust + cancel-in-progress: false + +jobs: + bust: + name: Drop Rust caches + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Delete Rust caches + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + # rust-cache prefixes every key it writes with `prefix-key`, which is + # left at its default. Matching on that keeps Turbo and any other + # cache in this repository untouched. + ids="$(gh api --paginate "/repos/$REPO/actions/caches?per_page=100" \ + --jq '.actions_caches[] | select(.key | startswith("v0-rust")) | .id')" + + if [ -z "$ids" ]; then + echo "No Rust caches to drop." + echo "No Rust caches to drop." >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + + count=0 + while read -r id; do + [ -n "$id" ] || continue + gh api -X DELETE "/repos/$REPO/actions/caches/$id" + count=$((count + 1)) + done <<< "$ids" + + echo "Dropped $count Rust cache entries." + echo "Dropped $count Rust cache entries." >> "$GITHUB_STEP_SUMMARY" + + - name: Request a fresh warm run + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + set -euo pipefail + # Rebuild immediately rather than leaving every branch cold until the + # next merge or the Monday schedule. + gh workflow run turbo-cache-warm.yml --repo "$REPO" --ref main + echo "Dispatched Turbo Cache Warm on main." >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c6029412..6e76a8a84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -100,6 +100,9 @@ jobs: uses: Swatinem/rust-cache@v2 with: workspaces: packages/browseros-agent + # Without this the key embeds GITHUB_JOB, so the warm cache produced + # on main by a differently named job could never be restored here. + shared-key: browseros-agent # Intermediate artifacts live outside the checkout so worktrees can # share them, and rust-cache only saves workspace target dirs plus the # registry and git caches by default. Name the build dir explicitly or diff --git a/.github/workflows/turbo-cache-warm.yml b/.github/workflows/turbo-cache-warm.yml index 07b9b76d3..1686177d7 100644 --- a/.github/workflows/turbo-cache-warm.yml +++ b/.github/workflows/turbo-cache-warm.yml @@ -1,14 +1,16 @@ name: Turbo Cache Warm -# Populates the Turbo cache on `main` so PR branches inherit warm cache. -# GitHub Actions caches restore only from the same branch or the base/default -# branch, so without a run on `main` every PR would start cold. Neither the -# Tests nor Code Quality workflows run on `main`, so this is that run. +# Populates the Turbo and Rust caches on `main` so PR branches inherit warm +# cache. GitHub Actions caches restore only from the same branch or the +# base/default branch, so without a run on `main` every PR would start cold. +# Neither the Tests nor Code Quality workflows run on `main`, so this is that +# run. on: push: branches: [main] paths: - .github/workflows/turbo-cache-warm.yml + - .cargo/config.toml - packages/browseros-agent/** schedule: # Weekly full warm to backstop GitHub's 7-day unused-cache eviction for @@ -63,3 +65,38 @@ jobs: # Per-merge: warm only what this merge changed. bunx turbo run typecheck --affected fi + + warm-rust: + name: Warm Rust cache + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Setup Rust + # Pinned to match the Tests workflow. A different toolchain hashes into + # a different cache key, which would warm a cache nothing else reads. + uses: dtolnay/rust-toolchain@1.95.0 + with: + components: clippy,rustfmt + + - name: Cache Rust build + uses: Swatinem/rust-cache@v2 + with: + workspaces: packages/browseros-agent + # Must match the Tests workflow exactly. Without it the key embeds + # GITHUB_JOB and this cache would be unreadable there. + shared-key: browseros-agent + cache-directories: ~/.cargo/build/browseros + # Save even though nothing here is a pass/fail gate; warming is the + # entire point of the job. + save-if: "true" + + - name: Warm Rust cache + # Mirrors what the Rust suites compile: test binaries and clippy's + # separate artifacts. -D warnings is deliberately omitted, since this + # job exists to populate a cache, not to gate on lints. + run: | + cargo test --workspace --locked --no-run + cargo clippy --workspace --all-targets --locked