An agent fleet needs boundaries

Task ownership, Git worktrees, resource leases, and recovery records for a fleet of coding agents.


Two coding agents sharing a checkout can undo each other’s work without touching the same line of code. One switches branches while the other stages a fix. Add more workers and the first problem is ownership: who owns the task, which resources can they change, and what survives when a run dies?

An agent can repeat a tool call, stop after writing half a change, or act on an old checkout. That calls for familiar asynchronous-worker controls: bounded concurrency, durable task identity, conditional state transitions, and explicit ownership of shared resources.

Three task checkouts isolate files and indexes but share repository state, ports, sessions, databases, and caches. A durable lease records owner, expiry, and generation.

Each task gets a separate checkout. Resources outside it need their own owner. The handoff identifies an exact commit, so another worker can resume without guessing.

Open full size Scroll horizontally to read the diagram on a small screen.

Why not one big agent

The single-agent design fails the way a single overloaded engineer fails. Context. One agent holding the whole problem spends most of its budget re-reading state it already saw, and the output sags as the conversation grows. Repeated reads, forgotten constraints, and changes that drift from the original task are the warning signs. The model didn’t get dumber. The signal it needs is buried under everything it’s already done.

Splitting a task changes its coordination and context costs. A narrow agent with a sharp brief and a small window is cheaper and easier to reason about than one generalist trying to be everything. You pay for that in coordination. Explicit task contracts, durable checkpoints, and retrieval of the small amount of state the next step needs can reduce those costs. Isolation makes those contracts easier to enforce; it does not make an agent immune to context loss.

Isolation is the whole game

Consider two agents sharing a working directory. One stages a fix while the other switches branches. A watcher then stashes the combined working tree. The index and checkout now contain transitions owned by three independent actors, with no reliable association between a task and its files.

The ownership rule is simple: one task, one worktree, one branch, one pull request. Every agent that touches the repo gets its own checkout. When a run dies, its partial work sits on its own branch instead of poisoning everyone else’s.

# Run this script with a short task slug as its first argument.
set -eu
slug=${1:?usage: start-task short-task-slug}
case "$slug" in
  *[!a-z0-9-]*|'') echo "use lowercase letters, digits, and hyphens" >&2; exit 2 ;;
esac
repo=$(git rev-parse --show-toplevel)
parent=$(mktemp -d "${TMPDIR:-/tmp}/agent-task.XXXXXXXX")
worktree="$parent/checkout"
branch="task/$slug-$(basename "$parent")"
git -C "$repo" fetch origin master
git -C "$repo" worktree add -b "$branch" "$worktree" origin/master
cd "$worktree"
git status --short --branch

The explicit -b matters: passing only origin/master creates a detached checkout. The temporary parent keeps the new worktree outside the source checkout, and set -eu stops a failed fetch from quietly becoming a task based on stale state. Keep the directory until its changes have reached the outcome branch and PR; remove it with Git’s worktree commands after checking for uncommitted work.

Worktrees give each task its own HEAD, index, and files. They still share repository objects and refs. A process can use git -C to edit another checkout, and deleting a shared branch still affects other users of the repository. Worktrees also do not isolate ports, databases, browser sessions, generated files outside the tree, or dependency caches. Those resources need separate names or explicit ownership.

A watcher that rebases or stashes must be stopped or configured to respect a task lease before editing begins. A marker file has no built-in meaning to Git; it helps only when the actual watcher checks it. The marker is only as useful as the watcher’s enforcement.

Choose a concurrency budget

Adding a worker has to save time. Every cold spawn re-pays a fixed setup cost: loading the brief, warming the cache, establishing the worktree. Fan out for trivial work and you spend more on overhead than you save on wall clock.

Start with the scheduling arithmetic. With N independent tasks taking t seconds each and at most P workers, serial work takes roughly N × t. Parallel work takes setup time + ceil(N / P) × t + integration time. Parallel execution pays when that second quantity is smaller. Unequal tasks make the slowest lane important; shared rate limits and memory can reduce P below the number of available processes.

The missing term in most optimistic estimates is integration. Two agents can finish quickly and still produce incompatible interfaces. Give the shared contract one owner, keep implementation lanes disjoint, and reserve time to reconcile the result. A task that needs the previous task’s output belongs in the dependency chain.

Elapsed completion time and integration rework tell you whether the split helped. A count of active workers does not.

The same ownership model can support review and repair loops. A finding becomes a durable task, one worker owns the fix, and the resulting PR carries its exact revision and review evidence. Human approval remains a separate transition from producing a ready change.

A checkpoint that survives a dead worker

A useful task record names its base commit, branch, intended outcome, changed files, remaining decisions, and the checks actually run. A commit is useful recovery state, but an unpushed commit still lives on one machine. Push the outcome branch before handing off and put incomplete validation in the PR description.

A lease needs an owner and expiry. If a worker stops responding, inspect its process and Git state before assigning a replacement. Starting another worker against the same mutable checkout turns recovery into a race. Reclaiming a lane means preserving its diff, establishing one new owner, and making the old worker unable to publish later.

Review must follow the current commit. A green check on yesterday’s head says nothing about the patch added this morning. The review unit is one outcome with a known base and a specific head SHA, plus evidence that describes that exact revision.