Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
ci: make the Rust cache hit (CUA-2139) (#5822)
Francesco Bonaccifcd1ca0c1070
diff --git a/.github/actions/rust-cache/action.yml b/.github/actions/rust-cache/action.ymlindex 3ad352c849..221c447e52 100644--- a/.github/actions/rust-cache/action.yml+++ b/.github/actions/rust-cache/action.yml@@ -3,16 +3,21 @@ description: >-Drop-in replacement for Swatinem/rust-cache in Cua workflows.rust-cache stores a whole target directory per job (1-3 GB each) and always- drops the workspace crates, so every job rebuilt them and the 10 GB Actions- cache budget was evicted within minutes. This action routes rustc through- sccache instead. sccache is content addressed: a fresh checkout still reuses- every unchanged crate, in every workflow and job. The cache directory is one- size-capped entry per OS and workspace family, restored by every run and- saved by main (pull requests restore main's entry; they save their own only- when the pr-save input is "true"). sccache runs from a local directory, not its GitHub- backend: that backend writes thousands of small objects and GitHub- rate-limits most of them (measured: 70% of writes failed), which left the- cache empty. When sccache cannot start, cargo simply compiles.+ drops the workspace crates, so every job rebuilt them and the Actions cache+ budget was evicted within minutes. This action routes rustc through sccache+ instead. sccache is content addressed: a fresh checkout still reuses every+ unchanged crate, in every workflow and job. The cache directory is one+ size-capped entry per OS and family, restored by every run and saved by main+ at most once per family per UTC day (pull requests restore main's entry and+ never save, unless the pr-save input is "true"). sccache runs from a local+ directory, not its GitHub backend: that backend writes thousands of small+ objects and GitHub rate-limits most of them (measured: 70% of writes+ failed), which left the cache empty. When sccache cannot start, cargo simply+ compiles.++ The sccache summary (hit rate, hits, misses, cache size against its cap) is+ printed at the end of every job by the "Post Run mozilla-actions/sccache-action"+ step and appears as a "sccache stats" annotation on the run.Do not use this action in release builds that must be reproducible fromscratch; those keep their own explicit cache settings.@@ -29,6 +34,8 @@ inputs:Cache family; defaults to the first workspace. Jobs that compiledifferent unit kinds (clippy `check` units versus builds and tests) usedifferent families so the entry a run saves holds what its siblings need.+ Jobs of the same shape (same profile, features and target) share one+ family on purpose: that is what lets one main run warm many jobs.default: ""save-if:description: "Set to 'false' to restore only."@@ -39,12 +46,17 @@ inputs:pr-save:description: >-"true" lets Linux pull request runs save their own cache entry. Off by- default: with the repository's 10 GB Actions cache limit every PR entry- evicts main's. Flip this default once the limit is raised.+ default: a PR entry is readable only by that PR, and every one of them+ (1 to 4 GB each) counts against the repository's Actions cache budget and+ evicts main's entries.default: "false"size:- description: "Cap of the sccache directory."- default: "2G"+ description: >-+ Cap of the sccache directory (sccache evicts its least recently used+ objects beyond it). A family smaller than the cap saves only what it+ holds. 4G fits the whole dependency tree of the largest families, which a+ 2G cap truncated on every run.+ default: "4G"runs:using: composite@@ -67,52 +79,86 @@ runs:fam="${first:-root}"fifam="$(printf '%s' "$fam" | tr -c 'A-Za-z0-9\n' '-' | cut -c1-60)"- # main saves on every OS. Pull requests restore main's cache and save- # only when the pr-save input is "true" (set it- # once the Actions cache limit is large enough for one entry per- # push), and then only on Linux.+ # Who saves. main saves on every OS (pushes, schedules and manual+ # runs). A manual run on another branch saves too, into that branch's+ # own scope: it is how a change to a workflow's cache is measured+ # before it merges (run it twice and read the second run). Pull+ # requests restore main's cache and save only when the pr-save input+ # is "true", and then only on Linux.save=falseif [ "$REF" = refs/heads/main ]; then save=true+ elif [ "$EVENT" = workflow_dispatch ]; then save=trueelif [ "$PR_SAVE" = true ] && [ "$RUNNER_OS" = Linux ]; then save=true; fi[ "$SAVE_IF" = false ] && save=falsedir="$RUNNER_TEMP/sccache"- echo "family=$fam" >> "$GITHUB_OUTPUT"- echo "save=$save" >> "$GITHUB_OUTPUT"- echo "dir=$dir" >> "$GITHUB_OUTPUT"- echo "prefix=sccache-v1-$RUNNER_OS-$RUNNER_ARCH-$fam-" >> "$GITHUB_OUTPUT"+ # The prefix ends in "_", which the family never contains (it is+ # reduced to letters, digits and "-"). With a "-" the family libs-cua+ # was a prefix of libs-cua-build-fixtures, libs-cua-lint and the rest,+ # and a run restored a sibling's entry instead of its own.+ prefix="sccache-v2-$RUNNER_OS-$RUNNER_ARCH-${fam}_"+ # One key per family per UTC day. A key with the commit sha was new on+ # every push, so every main push saved a full copy of every family and+ # the 50 GB budget turned over several times an hour. With the day in+ # the key the first main run of the day saves, later runs that day see+ # an exact hit and skip the save, and everything else restores the+ # newest entry through the prefix.+ bucket="$(date -u +%Y%m%d)"+ {+ echo "family=$fam"+ echo "save=$save"+ echo "dir=$dir"+ echo "prefix=$prefix"+ echo "key=$prefix$bucket"+ } >> "$GITHUB_OUTPUT"+ echo "sccache plan: family=$fam key=$prefix$bucket save=$save"- name: Install sccacheuses: mozilla-actions/sccache-action@fd02668681acd5f960e1372061bee5e3e987195c # v0.0.11- name: Restore the sccache directory+ id: restoreif: steps.plan.outputs.save != 'true'uses: actions/cache/restore@v4with:path: ${{ steps.plan.outputs.dir }}- key: ${{ steps.plan.outputs.prefix }}${{ github.sha }}+ key: ${{ steps.plan.outputs.key }}restore-keys: ${{ steps.plan.outputs.prefix }}- name: Restore and later save the sccache directory+ id: restore-saveif: steps.plan.outputs.save == 'true'uses: actions/cache@v4with:path: ${{ steps.plan.outputs.dir }}- key: ${{ steps.plan.outputs.prefix }}${{ github.sha }}+ key: ${{ steps.plan.outputs.key }}restore-keys: ${{ steps.plan.outputs.prefix }}- name: Route rustc through sccacheshell: bashenv:DIR: ${{ steps.plan.outputs.dir }}SIZE: ${{ inputs.size }}+ FAMILY: ${{ steps.plan.outputs.family }}+ SAVE: ${{ steps.plan.outputs.save }}+ EXACT: ${{ steps.restore.outputs.cache-hit || steps.restore-save.outputs.cache-hit }}+ MATCHED: ${{ steps.restore.outputs.cache-matched-key }}run: |mkdir -p "$DIR"- export SCCACHE_DIR="$DIR" SCCACHE_CACHE_SIZE="$SIZE"+ files="$(find "$DIR" -type f | wc -l | tr -d '[:space:]')"+ # Never let the server idle out: the end-of-job statistics come from+ # it, and a job that compiles early and then runs tests for more than+ # the default 10 minutes would report a fresh server's zeros.+ export SCCACHE_DIR="$DIR" SCCACHE_CACHE_SIZE="$SIZE" SCCACHE_IDLE_TIMEOUT=0if sccache --start-server >/dev/null 2>&1; then{echo "SCCACHE_DIR=$DIR"echo "SCCACHE_CACHE_SIZE=$SIZE"+ echo "SCCACHE_IDLE_TIMEOUT=0"echo "RUSTC_WRAPPER=sccache"# Incremental artifacts cannot be cached and bloat the target dir.echo "CARGO_INCREMENTAL=0"} >> "$GITHUB_ENV"- echo "sccache enabled, dir $DIR ($(du -sh "$DIR" | cut -f1) restored)"+ if [ "$files" = 0 ]; then how="miss, starting cold"+ elif [ "$EXACT" = true ]; then how="exact hit"+ elif [ -n "$MATCHED" ]; then how="prefix hit on $MATCHED"+ else how="prefix hit"; fi+ echo "sccache enabled: family $FAMILY, cap $SIZE, restored $(du -sh "$DIR" | cut -f1) in $files files ($how), this run saves: $SAVE"elseecho "::warning::sccache did not start; compiling without it"fidiff --git a/.github/workflows/README.md b/.github/workflows/README.mdindex 0ba46e866b..ca51a23066 100644--- a/.github/workflows/README.md+++ b/.github/workflows/README.md@@ -44,24 +44,49 @@ check to the required list without a gate job that always runs.All Rust CI jobs use `.github/actions/rust-cache`, which routes `rustc` throughsccache with a local cache directory persisted by `actions/cache` (one-size-capped entry per OS and workspace). Why not `Swatinem/rust-cache`: it-stored a whole `target/` per job (1-3 GB each), always dropped the workspace-crates, and filled the repository's 10 GB cache budget, so entries were evicted-within minutes and most jobs compiled cold. sccache is keyed by the content of-each compile unit, so an unchanged crate is reused in any job of any workflow.+size-capped entry per OS, architecture and family). Why not `Swatinem/rust-cache`:+it stored a whole `target/` per job (1-3 GB each), always dropped the workspace+crates, and filled the repository's Actions cache budget, so entries were+evicted within minutes and most jobs compiled cold. sccache is keyed by the+content of each compile unit, so an unchanged crate is reused in any job of any+workflow.-* main saves the cache on every OS (one entry per OS and family; clippy, test+* The family is the `shared-key` input, or the first workspace. Clippy, testand build jobs of the same workspace use separate families because they- compile different units).-* PRs restore main's cache and do not save. After raising the repository's- Actions cache limit, flip the `pr-save` default in the action and- Linux PR runs also save, so a PR's next push builds on its previous one.+ compile different units; jobs of the same shape share one on purpose, so one+ main run warms all of them. The `key` input is ignored.+* The cache key is `sccache-v2-<OS>-<arch>-<family>_<UTC date>`. The `_` cannot+ occur in a family, so a family is never a prefix of another (`libs-cua` used+ to restore `libs-cua-build-fixtures`' entry). Bump `v2` to start every+ family clean.+* main saves, on every OS, at most once per family per UTC day: the first main+ run of the day saves, later runs that day hit the same key and skip the+ save, and everything else restores the newest entry of the family. A key+ with the commit sha would save a full copy per push and turn the budget over+ several times an hour.+* PRs restore main's cache and do not save (a PR entry is readable only by that+ PR, 1 to 4 GB each, and evicts main's). `pr-save: "true"` lets Linux PR runs+ save too; use it only after raising the repository's cache limit.+* A manual run (`workflow_dispatch`) on any branch saves into that branch's own+ scope. To measure a change to a job's cache before it merges, dispatch the+ workflow twice on the branch and compare the second run.+* The cap (`size`, default 4G) bounds the directory; sccache evicts its least+ recently used objects beyond it. Raise it per job only when the end-of-job+ statistics show "Cache size" equal to "Max cache size".+* Every job ends with sccache's statistics (the "Post Run+ mozilla-actions/sccache-action" step, and a "sccache stats" annotation on the+ run). "Cache hits rate (Rust)" is the number to watch; the "Route rustc+ through sccache" step at the start says how the directory was restored.* Workflows that build the SDK have a `push: main` trigger (same paths) so mainkeeps the cache warm. Their concurrency only cancels superseded pull request- runs, never main runs (a cancelled run saves nothing).+ runs, never main runs (a cancelled run saves nothing). A workflow that runs+ only on pull requests never seeds its own family; put it on a family that+ main already keeps warm, or add a `push: main` trigger with the same paths.* CI uses a cheaper release profile (opt-level 1, no LTO, no debug info) forsmoke tests; release builds in `cd-*.yml` keep the shipped profile.* When sccache cannot start, cargo compiles normally.+* sccache hashes the rustc version into every object key, so a toolchain bump+ simply misses until main re-seeds, and the cap ages the old objects out.## Known flaky tests and quarantinediff --git a/.github/workflows/ci-openkoalabot-example-tauri.yml b/.github/workflows/ci-openkoalabot-example-tauri.ymlindex 1e3111c7cf..1b490abb4a 100644--- a/.github/workflows/ci-openkoalabot-example-tauri.yml+++ b/.github/workflows/ci-openkoalabot-example-tauri.yml@@ -77,15 +77,12 @@ jobs:libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev \libx11-dev libxkbcommon-dev libwayland-dev libxcb1-dev libx11-xcb-dev \libxkbcommon-x11-dev libxrandr-dev libxi-dev libudev-dev- - name: Cache cargo- uses: actions/cache@v4+ # sccache keeps compiled crates, not the whole target directory (4 to+ # 7 GB per entry, one per pull request). Main saves; pull requests restore.+ - uses: ./.github/actions/rust-cachewith:- path: |- ~/.cargo/registry- ~/.cargo/git- examples/openkoalabot-example-tauri/src-tauri/target- key: openkoalabot-example-tauri-${{ hashFiles('examples/openkoalabot-example-tauri/src-tauri/Cargo.lock') }}- restore-keys: openkoalabot-example-tauri-+ workspaces: "examples/openkoalabot-example-tauri/src-tauri -> target"+ shared-key: openkoalabot-example-tauri- name: cargo check (core + Tauri shell)working-directory: examples/openkoalabot-example-tauri/src-taurirun: cargo check --locked --workspace --all-targetsdiff --git a/.github/workflows/e2b-bindings.yml b/.github/workflows/e2b-bindings.ymlindex 75321c439f..c2eb9b6c71 100644--- a/.github/workflows/e2b-bindings.yml+++ b/.github/workflows/e2b-bindings.yml@@ -8,7 +8,8 @@# label, pushes to main and the nightly schedule. This workflow adds the# missing piece: the Swift suite (swift/scripts/test.sh, against the release# dylib and the loopback test fixtures) on ordinary PRs for the binding paths.-# It reuses the same cache key as ci-cua-sdk.yml's swift job.+# It uses the same Rust cache family (libs-cua on macOS) as ci-cua-sdk.yml's+# swift job, which main's pushes and the nightly keep warm.name: e2b-bindingson:@@ -54,10 +55,9 @@ jobs:- name: Install protocuses: ./.github/actions/setup-protoc- uses: dtolnay/[email protected]- - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2+ - uses: ./.github/actions/rust-cachewith:workspaces: libs/cua- key: cua-sdk-swift- name: Release dylib, test fixtures, Swift suiterun: |cargo build --locked --release -p cua-sdkdiff --git a/.github/workflows/e2b-core-nightly.yml b/.github/workflows/e2b-core-nightly.ymlindex 8f863932d3..eacaa11807 100644--- a/.github/workflows/e2b-core-nightly.yml+++ b/.github/workflows/e2b-core-nightly.yml@@ -67,10 +67,9 @@ jobs:- name: Install protocuses: ./.github/actions/setup-protoc- uses: dtolnay/rust-toolchain@stable- - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2+ - uses: ./.github/actions/rust-cachewith:workspaces: "libs/cua-spacesd -> target"- key: e2b-core-nightly- name: Install Linux build dependencies and the privileged-test toolsworking-directory: .run: |@@ -115,10 +114,12 @@ jobs:- name: Install protocuses: ./.github/actions/setup-protoc- uses: dtolnay/[email protected]- - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2+ # The reference disk below is built inside Docker, where sccache does+ # not reach; this covers the host's cua-vmm test build.+ - uses: ./.github/actions/rust-cachewith:workspaces: libs/cua- key: e2b-core-nightly-vmm+ shared-key: libs-cua-vmm- name: QEMU, firmware and image toolingrun: |sudo apt-get update -qqdiff --git a/.github/workflows/perf-cua-channel.yml b/.github/workflows/perf-cua-channel.ymlindex 9e7acd12cb..0879af6bb0 100644--- a/.github/workflows/perf-cua-channel.yml+++ b/.github/workflows/perf-cua-channel.yml@@ -52,12 +52,12 @@ jobs:- name: Install protocuses: ./.github/actions/setup-protoc- uses: dtolnay/[email protected]- - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2+ - uses: ./.github/actions/rust-cachewith:workspaces: |libs/cualibs/cua-spacesd- key: perf-cua-channel+ shared-key: perf-cua-channel- name: Check script self-testrun: python3 libs/cua/bench/channel/check.py --self-test- name: QEMU and KVM