Skip to content

build(cargo): slice 3 — shared CARGO_TARGET_DIR for airc worktrees - #1531

Merged
joelteply merged 1 commit into
canaryfrom
80ef9cd1/cargo-shared-target
Jun 6, 2026
Merged

joelteply merged 1 commit into
canaryfrom
80ef9cd1/cargo-shared-target

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Slice 3 of the build-time efficiency series (card 424deb5e). Collapses N per-worktree target/ dirs into ONE shared ~/.airc/cargo-target, mirroring the opt-in pattern from slices 1 (sccache) and 2 (linker selection).

Why

Per [[local-worktree-is-temp-dir]] — worktrees are L1 cache, not durable state. Each airc worktree currently carries its own 5-10 GB target/ dir. With ~10 active worktrees the dev-artifact sprawl reaches 50-100 GB.

Direct observation today (2026-06-05): a hung Docker daemon pinned cargo test, target/ accumulation across worktrees maxed the disk, the bash tool's output buffer couldn't write, and the metal_monitor #163 fix was blocked mid-build until manual cleanup.

Shared CARGO_TARGET_DIR is the structural fix — single biggest disk lever in the build-time efficiency series.

What ships

src/workers/.cargo/config.toml slice 3

Opt-in block (commented like slices 1+2) documenting the shared-target pattern, trade-offs, and composition with prior slices. Notes cargo issue #14149 (config doesn't expand ~ or env vars) as the reason absolute paths are required.

scripts/airc-shared-target-opt-in.sh

Operator helper:

  1. Creates ~/.airc/cargo-target/
  2. Appends export CARGO_TARGET_DIR=... to the user's shell init (auto-detects zsh/bash/sh, idempotent)
  3. Reports current per-worktree target/ sprawl with sizes for reclaim

Modes: interactive (default) + --no-prompt for CI.

Trade-offs (documented up front per no-fallbacks doctrine)

  • Sequential builds only: cargo's target lock serializes concurrent cargo build across worktrees. Invisible for one-PR-at-a-time flow.
  • Branch-switch rebuilds: when Cargo.lock differs between branches, affected crates rebuild. Cargo incremental + sccache (slice 1) absorb the rest.
  • Opt-in by design: single-target-dir is a tradeoff, not a universal win. Devs with one-worktree flows lose nothing; devs juggling many gain the most.

Composition with slices 1+2

  • Slice 1 (sccache): per-worktree target/ + shared rustc cache
  • Slice 2 (lld/mold linker): cuts link time from 30-60s to 2-5s
  • Slice 3 (this PR): collapses N target/ into ONE — stacks with slices 1+2

What this PR does NOT do

  • Does NOT delete existing per-worktree target/ — script reports them with sizes; reclaim is operator-driven
  • Does NOT auto-set CARGO_TARGET_DIR from airc work claim — cross-repo airc-side work, tracked as follow-up
  • Does NOT extend airc work cleanup --force to wipe target/ on Closed/Merged — also airc-side follow-up

Test plan

  • Script runs cleanly in --no-prompt mode and reports current sprawl (verified 33 GB in fa25de80 worktree before this commit)
  • Script idempotent: re-runs detect the existing export line and skip
  • Cargo config slice 3 block is entirely commented — no build behavior change without operator opt-in
  • Operator opt-in flow (after merge): run script → open new shell → cargo build from any airc worktree → verify build lands in shared tree

Doctrine

  • [[local-worktree-is-temp-dir]] — the architectural frame
  • [[every-error-is-an-opportunity-to-battle-harden]] — today's disk-full incident drove the slice
  • [[organization-purity-as-we-migrate]] — mirrors existing slice 1+2 pattern
  • [[no-fallbacks-ever]] — opt-in shape; no silent "tries shared target, falls back" behavior

card: 80ef9cd1-5bb9-4777-a174-ced9926c8484

Extends card 424deb5e (build-time accelerators) with slice 3:
collapse N per-worktree target/ dirs into ONE shared
`~/.airc/cargo-target`. Mirrors the opt-in pattern from slices 1
(sccache) and 2 (linker selection): config block is checked-in
guidance, an opt-in script does the per-machine setup.

## Why

Per [[local-worktree-is-temp-dir]] — worktrees are L1 cache, not
durable state. Each airc worktree currently carries its own
5-10 GB target/ dir. With ~10 active worktrees the dev-artifact
sprawl reaches 50-100 GB and saturates the disk.

Direct observation today (2026-06-05): a hung Docker daemon
pinned `cargo test`, target/ accumulation across worktrees
maxed the disk, the bash tool's output buffer couldn't write,
and the metal_monitor #163 fix was blocked mid-build until Joel
manually cleaned worktree target/ dirs.

Shared CARGO_TARGET_DIR is the structural fix: one shared tree
instead of N copies. Single biggest disk lever in the
build-time efficiency series.

## What this commit ships

### `src/workers/.cargo/config.toml` slice 3

Opt-in block (commented like slices 1+2) documenting:
- The shared-target pattern + how to enable it
- Trade-offs: sequential cargo builds (target lock), branch-
  switch rebuilds when Cargo.lock differs
- Composition with slices 1+2 (all three stack)
- Why the absolute path is necessary (cargo config doesn't
  expand `~` or env vars in [env] values — cargo issue #14149)

### `scripts/airc-shared-target-opt-in.sh`

Operator helper that:
1. Creates `~/.airc/cargo-target/` if missing
2. Appends `export CARGO_TARGET_DIR=...` to the user's shell
   init (auto-detects zsh/bash/sh)
3. Reports current per-worktree target/ sprawl with sizes so
   the operator knows how much reclaim is available

Modes:
- Interactive (default): asks before modifying the shell rc
- `--no-prompt`: CI / scripted opt-in (still safe; idempotent
  detection skips if already present)

### Memory update

`[[local-worktree-is-temp-dir]]` gets a footer pointing at
slice 3 + the opt-in script as the canonical lever, plus the
airc-side automation follow-up.

## Trade-offs documented up front (no fallbacks doctrine)

- **Sequential builds only**: cargo's target lock serializes
  concurrent `cargo build` calls across worktrees. Invisible
  for the typical one-PR-at-a-time flow.
- **Branch-switch rebuilds**: when Cargo.lock differs between
  branches, the affected crates rebuild on switch. Cargo
  handles incrementally; sccache (slice 1) absorbs the rest.
- **Opt-in by design**: single-target-dir is a tradeoff, not
  a universal win. Devs with one-worktree flows lose nothing
  by leaving it off; devs juggling many airc worktrees gain
  the most.

## Composition with the build-time series

- **Slice 1** (sccache): per-worktree target/ + shared rustc
  cache. Useful even without slice 3.
- **Slice 2** (lld/mold linker): cuts link time from
  30-60s to 2-5s. Useful at any target-dir configuration.
- **Slice 3** (this commit): collapses N target/ into ONE.
  Stacks with slices 1+2 — sccache + fast linker + shared
  target = minimum-friction multi-worktree flow.

## What this commit does NOT do

- Does NOT delete existing per-worktree target/ dirs — the
  script reports them with sizes; reclaim is operator-driven.
- Does NOT auto-set CARGO_TARGET_DIR from `airc work claim` —
  that's cross-repo airc-side work, tracked separately.
- Does NOT extend `airc work cleanup --force` to wipe target/
  on Closed/Merged — also airc-side follow-up.

## Doctrine

- `[[local-worktree-is-temp-dir]]` — the architectural frame
- `[[every-error-is-an-opportunity-to-battle-harden]]` — the
  disk-full incident today drove this slice
- `[[organization-purity-as-we-migrate]]` — mirrors the
  existing slice 1+2 pattern (config + opt-in script + memory)
- `[[no-fallbacks-ever]]` — opt-in shape (commented config,
  operator-driven script); no silent "tries shared target,
  falls back to per-worktree" behavior

card: 80ef9cd1-5bb9-4777-a174-ced9926c8484

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@joelteply
joelteply merged commit 6157c8a into canary Jun 6, 2026
3 checks passed
@joelteply
joelteply deleted the 80ef9cd1/cargo-shared-target branch June 6, 2026 01:01
joelteply added a commit that referenced this pull request Oct 4, 2026
…ay's airc-lib fixes (#4735)

Kimi on the 5090 kept hitting "settled work is not claimable" on her own card
with her daemon already at #1532: the claim gate is airc-lib, compiled into
this core at the pinned rev, and 7499136 predates every airc fix of
2026-10-04. A daemon update cannot deliver an airc-lib fix to personas; only
this pin can.

Adopts #1528 (right-sized payloads), #1529 (per-channel ring byte bound;
channel_count and ring_bytes_total in status), #1530 (verbs are never room
names), #1531 (the owner resumes her own card after her lease lapses), #1532
(ownership durable, the lease is presence, from 2026-10-04T16:00Z), #1533
(test) and #1534 (work claim/update/link --room).

continuum-core lib + bins + tests type-check clean against it (mac-cpu-only
features), 0 errors. Lockfile changes outside airc are only windows-sys /
windows-core versions inside airc crates' dependency lists (#1480).

Card 86c5eb48.


Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant