Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

cargo-lane

contrib/cargo-lane is the cargo counterpart of the git shim. It is a cargo wrapper for a machine where several coding agents build in parallel. It keeps cargo mutants and the bigger cargo test and clippy runs from piling onto one desktop, and sends each run to wherever it costs least: the local machine, a boat sandbox, or GitHub Actions. It is bash, not part of the drawbar binary, and is installed on its own.

Where each run goes

RunGoes toWhy
cargo build, check, doc, bench, install and friendslocal, in the sliceAn editor or agent is waiting on them, and their output is needed here.
cargo metadata, fmt, run and every other subcommandlocal, untouchedLight, or the program itself.
cargo test, nextest, clippy, the machine is quietlocal, in the sliceFastest when nothing else is building.
The same, from an agent session, while the machine is busyone boat sandboxMoves the load off the desktop for about a cent a run.
cargo mutants with up to mutants_local_max (40) mutantsthe local laneOne run at a time, in a cgroup with no swap.
cargo mutants with more, under mutants_remote_max_dollars ($0.50)boat, shardedA whole-crate drawbar run takes 17 minutes for about $0.11.
cargo mutants over the cap and over mutants_local_hard_max (200)refused, exit 75Grade it on GitHub Actions, which is free for public repositories.
Nightly whole-crate gradingGitHub Actionsmutants-nightly.yml, skipped when the commit is already graded.

“Busy” means any of:

  • at least offload_min_rustc (8) rustc processes;
  • less than offload_min_mem_avail_gib (6) GiB available;
  • a load average per CPU of the repository’s LOAD (default offload_min_load, 1.25);
  • the repository’s RUNS (default offload_min_scopes, 2) other cargo runs active in the slice.

offload_repos lists OWNER/REPO[:LOAD[:RUNS]], so each repository gets thresholds that match its suite:

Suite (full cargo test)Here, idleOn boat, from the golden snapshotEntry
Inspan, 1,949 tests125 s after a one-file change, 251 s cold155 s, $0.003OttoOps/inspan:0.5:1
drawbar, 276 tests12 s32 s, $0.0006OttoOps/drawbar:1.0:2

One local Inspan run pushes the load average to 24-30 on 16 CPUs, stalls on memory (PSI memory 64%), and uses about 12 GiB. A second one at the same time would not fit. So Inspan offloads as soon as one other cargo run is active or the load reaches half the CPUs. drawbar’s suite is light, and boat slows it down, so it offloads only once the load reaches the CPU count or two other cargo runs are active. Offload covers only the listed repositories, and only calls from an agent session (CLAUDECODE, T3CODE_THREAD_ID or CODEX_THREAD_ID set). A copy of a repository without .git, such as a reviewer’s export in /tmp, is matched by the repository URL in its root Cargo.toml (the workspace root, the same tree that is packed) and packed by its .gitignore, plus any ignored Cargo.lock. A copy with neither .git nor .gitignore runs locally. IDE-style calls pass straight through: --message-format, --no-run, --target-dir, --manifest-path, --list and --fix. A run that boat cannot start runs locally instead.

The slice

Every local run that builds goes into one systemd user slice, cargo-lane.slice, as its own scope (cargo-lane-<subcommand>-<pid>.scope). The slice caps all of them together:

  • MemoryHigh=40% of RAM: past this, the kernel reclaims and slows the builds in the slice instead of the rest of the machine.
  • MemoryMax=50%: past this, the OOM killer stops the largest process in the slice (a rustc or a runaway test), and that one cargo run fails. Nothing outside the slice is touched.
  • MemorySwapMax=0: builds never push the desktop into swap.
  • CPUWeight=50: when the CPUs are contended, the desktop and other services get twice the share of an agent build.
  • CPUQuota at 75% of the CPUs, in the drop-in install.sh writes (cargo-lane.slice.d/50-cargo-lane-cpu.conf): agent builds and tests together never take every core, so the desktop keeps a quarter of the machine however many agents build at once.

Four agents each starting a cold build of a large crate can no longer take WSL2 down: the worst case is a failed build. Change the limits with systemctl --user edit cargo-lane.slice. scope=off in the config, or CARGO_LANE_SYSTEMD=0, runs builds without a scope. When XDG_RUNTIME_DIR is unset, as in Codex shells, cargo-lane uses /run/user/$UID. Without a reachable user systemd there, builds run directly and decisions.jsonl records them as unscoped. Nested cargo calls, such as the ones cargo-mutants makes, stay in their parent’s scope.

The local mutants lane

Every local cargo mutants run takes an exclusive flock on ~/.local/state/cargo-lane/mutants.lock and runs inside its own scope inside the slice with MemoryMax=12G and MemorySwapMax=0, with CARGO_BUILD_JOBS=4 and --jobs lowered to 2. A second run does not queue: it exits 75 at once and names the run that holds the lane, so an agent can narrow its run or try later instead of stacking another build. Set mutants_lane_wait to a number of seconds to wait instead.

The cap is not hypothetical: one drawbar mutant allocates without bound, and every local run of the shard that holds it peaked at exactly the 12 GiB cap before the OOM killer stopped that mutant’s test, which cargo-mutants then counts as caught.

A finished run is cached for mutants_cache_hours (6) under a key built from the commit, the uncommitted diff, the untracked files and the arguments, so an agent that asks again for the same tree gets the same mutants.out back without a rebuild. CARGO_LANE_FORCE=1 skips the cache. Only runs that finished grading (exit 0, 2, 3 or 4, with an outcomes.json) are cached.

Boat

mutants-remote packs the worktree, uncommitted changes included, starts one sandbox per shard with --no-env, and merges the shards into mutants.out/ as if cargo-mutants had run locally. boat-cargo does the same for one cargo test or clippy and streams its output. Both:

  • pack only what git ls-files --cached --others --exclude-standard lists, leaving out .env*, *.pem, credentials*, nested repositories and mutants.out;
  • start from the saved snapshot golden-<repo> when it exists, which holds a built target/ for the default branch, and from rust-base otherwise;
  • wait for the sandbox to finish hydrating before they copy files in, since files restored from a snapshot carry whole-second mtimes until then and cargo misses rebuilds;
  • delete every sandbox they started, on success, failure or interrupt;
  • refuse to start a sandbox when fewer than min_plan_hours (40) of the plan’s included hours are left.

cargo-lane golden OWNER/REPO... rebuilds the golden snapshots. The installer adds a daily cargo-lane-golden.timer for the repositories in golden_repos; enable it with systemctl --user enable --now cargo-lane-golden.timer.

GitHub Actions

mutants-nightly.yml grades the whole crate in 8 shards on ubuntu-latest every night and on demand. When it finishes, it posts a mutants/full commit status on the commit. A boat run of the whole crate on a clean checkout of a pushed commit posts the same status. The nightly run checks for it first and skips a commit that is already graded, so one commit is never graded twice. To grade a pushed branch for free:

gh workflow run mutants-nightly.yml -R OttoOps/drawbar --ref my-branch -f force=true

Installing

contrib/cargo-lane/install.sh
cargo-lane status

The installer copies the scripts to ~/.local/opt/cargo-lane, links cargo, cargo-lane, mutants-remote and boat-cargo into ~/.local/bin, installs cargo-lane.slice and the golden timer in ~/.config/systemd/user, and writes ~/.config/cargo-lane/config from config.example if there is none. ~/.local/bin has to come before ~/.cargo/bin on PATH. It refuses to replace a file it did not install. install.sh --uninstall removes the links, the copy and the timer, and leaves the config and state.

The shim finds the real cargo further down PATH, skipping any copy of itself, or uses CARGO_LANE_REAL. CARGO_LANE=off passes every call straight through. Each routing decision is appended to ~/.local/state/cargo-lane/decisions.jsonl, and cargo-lane status shows the last ten with the current lane holder and load.

Configuration

~/.config/cargo-lane/config holds key=value lines. Unknown keys are ignored with a warning. See contrib/cargo-lane/config.example for every key and its default. mutants_seconds_per_mutant holds measured shard-seconds per mutant on boat large, per repository, and drives the cost estimate.

See ADR 0012.