Rudder
article 01 · filesystem isolation 2026-12-01 · 11 min read · linux overlayfs · userns · apfs

Zero-Copy Agent Isolation: How rudder-overlay Forks Warm Snapshots with Stacked OverlayFS, Private User Namespaces, and APFS Clones

Giving ten concurrent coding agents separate checkouts is easy until every launch copies 4 GB of node_modules, compiles 500 Rust crates from scratch, and walks 180,000 files on every VCS status check. Here is how Rudder turns workspace creation and snapshotting into metadata-only operations on both Linux and macOS.

source src/warm-snapshot.ts engine/src/jj_working_copy/mod.rs vcs-bridge/src/main.rs

Why plain worktrees break at 10 parallel agents

A single agent editing your main checkout inherits a warm compiler cache and installed packages, at the cost of locking you out of the tree while it works. Standard git worktree add or jj workspace add solves source collisions by materializing a fresh directory per agent, but each new directory starts completely cold:

  • Cold dependencies and build artifacts: Untracked trees like node_modules/, .venv/, and Cargo's target/ are absent. Every agent pays a 30-to-180 second bootstrap penalty plus gigabytes of duplicate blocks on disk.
  • Hardcoded build paths: Even if you copy a warm target/ directory into a new checkout, Cargo fingerprints, CMake caches, and DWARF paths embed the absolute path where the build originally ran, triggering cascading rebuilds anyway.
  • O(tree) VCS status scans: Jujutsu snapshots the working copy automatically before almost every command. On a cold or copied local tree without a valid Watchman clock, scanning hundreds of thousands of inodes adds visible latency to every agent step.

Rudder solves all three problems together by splitting workspace management into two halves: a single background warm snapshot builder that tracks trunk, and a zero-copy fork working copy (rudder-overlay on Linux, clonefile on macOS) that mounts or clones the latest ready build without copying file bytes.

Trunk-following .warm/<key> snapshots and MAX_LAYERS = 8 compaction

Inside .rudder-workspaces/<repo>/.warm/, one detached builder process per project holds builder.pid and polls currentBaseCommit every FOLLOW_POLL_MS = 1_000 (exiting cleanly after 30 minutes of idle trunk via FOLLOW_IDLE_MS). Each commit is keyed by its 12-character hex prefix (commit.slice(0, 12)) and progresses through atomic marker files: <key>.building (opened with wx exclusive create) to <key>.ready.tmp, renamed atomically onto <key>.ready so concurrent launches never read a half-written JSON descriptor.

When trunk advances, Rudder does not rebuild from scratch. It computes the file distance from every existing ready snapshot using git --git-dir <gitDir> diff-tree -r -z --no-renames --name-only and picks the nearest base. On Linux with rootless namespaces available, the refresh builds a thin OverlayFS delta layer directly on top of the previous snapshot stack:

  • Fixed build path: Regardless of which commit is building, the builder mounts the stack inside a private mount namespace at the canonical path .warm/build, applies only the changed source paths via a two-tree Git checkout, and runs install/build steps there (skipping package install altogether when lockfiles and manifests did not change).
  • Thin incremental upper: Compiler and bundler writes land in .warm/<key>/, while .warm/<key>.lowerdir records the colon-separated stack list, top layer first, exactly as Linux OverlayFS expects its lowerdir= mount option.
  • Compaction at MAX_LAYERS = 8: Deep OverlayFS stacks eventually degrade lookup() latency and approach kernel option-string limits. When a stack reaches MAX_LAYERS = 8, the next refresh mounts the read-only stack view and copies the merged projection into a fresh single-layer base directory, resetting stack depth to 1 without interrupting live agents still holding older layers.

If an agent launches when the nearest ready snapshot is within NEAR_SNAPSHOT_FILES = 500 changed files of the target revision, Rudder forks immediately and patches only the delta; if trunk jumped further than 500 files (for example after a major rebase), launches wait up to WAIT_FOR_BUILD_MS = 90_000 for the fresh base snapshot.

fig 01 · linux overlayfs warm stack + private namespace fork src/warm-snapshot.ts · engine/src/jj_working_copy/mod.rs
SHARED IMMUTABLE LOWER STACK .rudder-workspaces/<repo>/.warm/ .warm/a91f04c82e10/ (top layer) + a91f04c82e10.lowerdir · .ready .warm/7c3d91be04aa/ (layer n-1) incremental target/ + dist/ delta .warm/30b81e449f21/ (base layer 1) full checkout + node_modules + target MAX_LAYERS = 8 compaction 9th refresh flattens merged view -> depth 1 .warm/lower-links/<tree-id> content-keyed symlink to top layer HOST DISK (0 FILE BYTES) created by rudder-jj rudder-fork-add <ws>/.jj/working_copy/ upper/ (agent writes + 0/0 whiteouts) work/ (OverlayFS atomic rename dir) lower -> .warm/lower-links/<tree> overlay_state.json + overlay.lock type = "rudder-overlay" <ws>.fork/ (sibling state) enter (unshare -rm wrapper) alias -> .warm/build lower -> pinned snapshot dir bin/jj -> rudder-jj bind target jjmnt/ (bindback staging dir) AGENT PRIVATE NAMESPACE unshare -rm --propagation private Merged Overlay @ <ws> lowerdir=$L,upperdir=$W/upper userxattr · .jj bound back on top full warm tree visible immediately mount --rbind <ws> .warm/build Compiler paths from warm build resolve to this fork's own files Abstract sccache UDS \0rudder-sccache-<cksum> runs inside mountns, sees fork Upper-only jj snapshot O(changed files), 0 lower scans
On disk outside the namespace, an agent workspace contains only .jj/. Inside .fork/enter, Linux merges the stacked warm snapshot lowers with the fork's private upper/ directory, aliases .warm/build to the fork, and isolates sccache per mount namespace.

Inside .fork/enter: rootless unshare -rm, path aliasing, and sccache sockets

When Rudder creates a Linux fork via rudder-jj rudder-fork-add, the host directory at <workspace> contains only .jj/. Zero source files exist in the parent mount namespace. Alongside it, Rudder writes a sibling control directory <workspace>.fork/ containing lower, alias, bin/jj, and an executable enter wrapper. Whenever Rudder's native PTY host or task runner spawns a process whose working directory has a sibling .fork/enter, inFork() routes execution through this wrapper:

#!/bin/sh
# Generated in src/warm-snapshot.ts (ENTER_SCRIPT)
F="$(dirname "$(readlink -f "$0")")"; M="${F%.fork}"; U="$(id -u)"; G="$(id -g)"
exec unshare -rm --propagation private sh -ec '
F="$1"; M="$2"; U="$3"; G="$4"; shift 4
mount --bind "$M/.jj" "$F/jjmnt"
W="$F/jjmnt/working_copy"
L="$(readlink -f "$(cat "$W/lower")")"
if [ -f "$L.lowerdir" ]; then L="$(cat "$L.lowerdir")"; fi
mount -t overlay overlay -o "lowerdir=$L,upperdir=$W/upper,workdir=$W/work,userxattr" "$M"
[ -d "$M/.jj" ] || mkdir "$M/.jj"
mount --bind "$F/jjmnt" "$M/.jj"
A="$(cat "$F/alias" 2>/dev/null || true)"
if [ -n "$A" ] && [ -d "$A" ]; then mount --rbind "$M" "$A"; fi
J="$(readlink -f "$F/bin/jj")"
for d in $(printf %s "$PATH" | tr : " ") /usr/local/bin /usr/bin "$HOME/.local/bin"; do
  [ -f "$d/jj" ] && [ "$(readlink -f "$d/jj")" != "$J" ] && mount --bind "$J" "$d/jj" 2>/dev/null || true
done
cd "$M"
PATH="$F/bin:$PATH"; export PATH
SCCACHE_SERVER_UDS="\x00rudder-sccache-$(printf %s "$F" | cksum | cut -d" " -f1)"; export SCCACHE_SERVER_UDS
exec unshare -U --map-user="$U" --map-group="$G" -- "$@"' sh "$F" "$M" "$U" "$G" "$@"

Every line in ENTER_SCRIPT closes a real production failure mode we hit while running real compiler toolchains inside rootless namespaces:

  1. Two-stage .jj bind dance: Mounting OverlayFS onto $M hides the underlying $M/.jj directory that holds upper and work. Binding $M/.jj to $F/jjmnt first, mounting the overlay with userxattr (required for unprivileged OverlayFS in user namespaces), and then binding $F/jjmnt back onto $M/.jj keeps VCS metadata outside the overlay while exposing it where tools expect it.
  2. Builder path aliasing (mount --rbind "$M" "$A"): Because the warm builder compiled at .warm/build, generated files like Cargo dep-info, CMake Makefiles, or Next.js build manifests can point into .warm/build/.... Recursive-binding the fork onto .warm/build inside its private mount namespace makes hardcoded absolute paths resolve transparently to the agent's own copy-on-write files.
  3. Login-shell jj bind-over: Stock jj does not know how to load the rudder-overlay working copy type, and login shells spawned by coding harnesses frequently reset PATH. Bind-mounting rudder-jj over existing jj binaries on PATH inside the private mount namespace guarantees every subshell invokes the fork-aware binary.
  4. Per-namespace abstract sccache sockets: By default, sccache delegates compilation to a single machine-wide background daemon. That daemon runs in the host mount namespace, where <workspace> is an empty folder and .warm/build is unmounted, causing every Rust crate compile to fail with couldn't find file. Because network namespaces remain shared across forks, Rudder assigns each fork a deterministic Linux abstract Unix domain socket (\x00rudder-sccache-<cksum>) so an on-demand sccache server starts inside the fork's mount namespace while still sharing the underlying disk/remote object cache.
  5. Nested identity restoration: The outer unshare -rm maps UID 0 inside a user namespace so mount(2) succeeds without CAP_SYS_ADMIN on the host; the inner unshare -U --map-user="$U" --map-group="$G" restores the caller's real non-root UID and GID before running the agent harness, preventing tools like Claude Code, npm, or Cargo from thinking they are running as root.

Upper-only jj snapshots without tree scans

Fast workspace creation is only half the battle if jj status or jj diff still walks 200,000 lower-layer files. In engine/src/jj_working_copy/mod.rs, OverlayWorkingCopy implements Jujutsu's WorkingCopy trait directly against the private upper layer (.jj/working_copy/upper) and the recorded base MergedTree:

  • Regular files and symlinks in upper/ are hashed and inserted into a MergedTreeBuilder initialized from lower_tree, evaluated against .gitignore and .git/info/exclude rules.
  • Character devices with major/minor 0/0 are kernel OverlayFS whiteout nodes; OverlayWorkingCopy records MergedTreeValue::absent() at that path without touching the lower layer.
  • Directories carrying user.overlay.opaque = "y" (written by the kernel when a lower directory is unlinked and recreated under userxattr) clear all inherited lower entries beneath that prefix before adding the new upper children.

Because untouched lower directories are never opened or stat()ed, snapshotting a workspace with 3.8 GB of target/ and node_modules/ after an agent edits four TypeScript files reads only four inodes. Checking out a new tree in OverlayWorkingCopy::check_out is equally cheap: it links or materializes the target tree in lowers_root, updates overlay_state.json, and resets upper/ and work/.

invariant · kernel release gate

Rootless OverlayFS with userxattr depends on kernel support (Linux 5.11+, disabled on some restricted container hosts). Rudder probes an actual mount once per kernel release and caches os.release() in .warm/overlay-proven; if unavailable, workspace creation falls back cleanly to standard local checkouts rather than failing halfway through launch.

macOS parity: clonefile(2) and Watchman clock resets

macOS lacks OverlayFS and Linux mount namespaces, so rudder-jj rudder-clone-add (in vcs-bridge/src/main.rs) uses Apple's filesystem-level copy-on-write primitive instead: libc::clonefile(from, to, CLONE_NOFOLLOW) from <sys/clonefile.h>.

A single clonefile() syscall clones the entire warm snapshot directory tree on APFS in tens of milliseconds while sharing every underlying physical extent until modified. Crucially, clonefile() preserves exact mtime, file size, and permission bits across the entire tree, including .jj/working_copy/. Rudder then performs three surgical adjustments before publishing the workspace transaction:

  1. Rewrites destination/.jj/repo with the relative path back to the shared colocated .jj/repo store.
  2. Loads LocalWorkingCopy, renames the workspace in its locked state, and calls local.reset_watchman(). Clearing the inherited Watchman clock forces locked.finish() to rewrite the working-copy state file with a fresh timestamp while keeping every cloned file's recorded mtime/size stat cache valid, so the next jj status trusts the stat cache instead of rehashing gigabytes of source.
  3. Runs locked.check_out(&commit) before committing the repo transaction, writing only the handful of files that changed between the warm snapshot's commit and the target revision. If checkout or workspace registration fails, Rudder rolls back the unpublished workspace commit so no orphan workspace name leaks.

Isolation primitives side by side

operation plain jj / git worktree linux rudder-overlay macos rudder-clone-add
Fork disk bytes Full source copy; 0 build artifacts 0 file bytes (.jj/ metadata only) 0 data blocks (APFS CoW extents)
target/ & node_modules/ Cold (must reinstall & recompile) Warm via stacked .warm/<key> lowers Warm via APFS snapshot clone
jj status / snapshot cost O(tracked + untracked tree scan) O(.jj/working_copy/upper entries) O(stat cache delta after Watchman reset)
Compiler path stability Path changes per worktree mount --rbind aliases .warm/build Relocatable tool cache via toolCacheEnv
Snapshot GC safety Manual worktree pruning Reference-counted via layersInUse() Independent CoW extents once cloned

Reference-counted layer pruning

Because stacked snapshots share lower layers and long-running agents can outlive newer trunk builds, deleting an old snapshot directory naively would rip lower inodes out from under live OverlayFS mounts. pruneWarmSnapshots() computes the live transitive closure in layersInUse() before touching any directory:

  • It retains the newest KEEP_READY = 1 ready snapshot and expands every entry in its .lowerdir chain.
  • For every active <workspace>.fork directory, it retains both .fork/lower (the snapshot the agent's live mount namespace originally mounted) and .jj/working_copy/lower (in case check_out repointed the working copy).
  • It sweeps orphaned <key> and <key>.work directories left behind by interrupted builders (pruneUnfinishedBuilds, using chmod -R u+rwX first for read-only Go/Cargo module caches) and cleans unreferenced .warm/lower-links/ entries after a 5-minute grace window (UNUSED_LOWER_GRACE_MS).

OverlayFS and APFS clones give local and single-host Cloud workspaces near-instant warm starts. When workspaces span remote cas-backed images and explicit quota budgets, Rudder pairs this layer with a Rust virtual filesystem and content-addressed object store, covered in Article 02.

Spawn ten warm agent workspaces in milliseconds.

Run Claude Code, Codex, Gemini Antigravity, and OpenCode in parallel without copying node_modules or rebuilding cold Rust targets. Control every agent from your Mac or iPhone.

$ npm install -g @exla/rudder@latest