← All posts

Running Many Coding Agents at Once: What Broke

I run coding agents in parallel, each in its own git worktree. The worst failures were not in the agents' code. They happened at the edges: which commit an agent started from, which repository it landed in, which files a merge could replace, how a run reported its result, and what the batch did to the machine and to my other sessions. One of them deleted about 40 GB of ignored model outputs from a Kaggle project. There was no backup.

Below are thirteen incidents, grouped by layer. Each has what happened, why, and the check I now use. Most of the mechanisms, and the checks for them, run in a small lab in temporary repositories. My earlier posts cover one agent: the harness, CLAUDE.md and skills. This one covers many agents on one machine.

In short

  • I ran batches of five agents, one worktree and one task each, on a private product codebase. One run reached 100 agents in 20 batches over two days, 22 to 23 November 2026. Five at a time kept the shared machine responsive.
  • Start: worktree agents began from the remote's main branch, not my unpushed local main, and landed in the wrong repository when the shell's last directory was elsewhere. Pin the commit in the brief.
  • Touch: a symlink an agent committed replaced a real ignored directory, and git deleted the ignored files in it. Ignore /data, not data/.
  • Verify: a backgrounded run reported exit code 0 with a FAILED line in its log. Read the log, and run the suites of the importing packages.
  • Machine and human loop: temp files filled a disk, a test re-initialised the real repository, and an amend hit another session's commit.

The setup

Each agent got a worktree, a brief with one task, and its own branch. I merged the branches myself. A worktree is a second working directory on the same repository. The git documentation says it shares everything except per-worktree files such as HEAD and the index. That sharing makes worktrees cheap. It also causes several of the failures below.

One main checkout holding the ignored data directory, one shared dot git directory, three worktrees each with their own HEAD and index, and a per-worktree directory under dot git worktrees One repository, many working directories main checkout ignored data/ lives here .git, shared by all objects, refs, config worktree 1 own HEAD and index worktree 2 own HEAD and index worktree 3 own HEAD and index .git/worktrees/<name> one directory per worktree A worktree starts without the ignored data/ of the main checkout. Linking it in is what went wrong. The push exported .git/worktrees/<name>; in the lab that form flips core.bare.
Figure 1. The main checkout, the shared .git, and the worktrees. Ignored files live only in the main checkout.
A five step chain: brief, worktree, agent, checks, merge. The checks box is highlighted. A note below lists what to confirm before the next batch One batch: five agents, one worktree each, and a check at every hand-off Brief pins the local main commit Worktree one per agent, one task each Agent first step: check the commit Checks by you, not the agent Merge then remove that worktree Before the next batch: free disk, current directory, task lists with no overlap, a handoff note in the repository. Five at a time kept a shared machine responsive.
Figure 2. One batch. Every arrow is a hand-off where something below went wrong.

A brief has a fixed shape. It pins a commit, starts with a command that proves the repository, then gives the task, the paths the agent may change, the tests it may run and what to report:

Pinned commit: <sha>
First step (stop and report if it fails; do nothing else):
  git cat-file -e <sha>^{commit} && git reset -q --hard <sha> && test -z "$(git status --short)"
Task: <one task>
You may change: src/pkg/, tests/pkg/
Do not: create symlinks, touch other worktrees, message other agents, amend or push.
Tests you may run: pytest tests/pkg > run.log; echo exit $? >> run.log
Report: the branch name, the files changed, and the tail of the test log with its exit status.

The lab tests this first step. In the right repository it resets to the pinned commit. In another repository it fails and changes nothing.

Five rows for the five layers, with dots at the dates of twelve incidents between 23 October and 23 November 2026, and a marker for the 100 agent run on 22 to 23 November Twelve dated incidents, 23 October to 23 November 2026, by layer Where it starts stale base wrong repo wrong repo again What it may touch second copy 21 worktrees symlink How you know importers exit code The machine editor, 167 worktrees disk GIT_DIR The human loop amend 23 Oct 1 Nov 8 Nov 15 Nov 23 Nov run of 100 agents in 20 batches, 22 to 23 Nov Not plotted: two agents given one task on the same night (no date recorded).
Figure 3. The incidents on a calendar. The thirteenth, two agents on one task, has no recorded date.

Layer 1: where an agent starts

The base was 290 commits behind

What happened. On 23 October 2026 I spawned ten agents. Three started from a base 290 commits behind my local main, which I had not pushed. One finished its task on the old code and had to rebase.

Why. The worktrees started from the remote's main branch, not my local one. git worktree add takes the commit-ish it is given, and nobody gave it mine.

Two rows of commits. Local main has five commits that the remote does not. An agent branched from the remote's main lacks them. An agent that resets to the pinned commit has them A worktree branched from the remote's main starts behind the unpushed local main local main origin/main 5 commits only on this machine (lab) agent stale: lacks the 5 commits; rebase later, or finish on old code agent pinned: reset to the sha in the brief, then work Merge-base check before merging: git merge-base --is-ancestor <sha> <branch> fails for the first, passes for the second.
Figure 4. Base drift. In the lab the unpushed main is five commits ahead. In my run it was 290.

The check. Put the local main's commit in the brief, and reset to it as the first step. Before merging, ask git whether the branch contains it:

git merge-base --is-ancestor <sha> <branch> || echo "stale base"

In the lab, a worktree added from origin/main is five commits behind the local main. After the reset it is zero behind.

Agents landed in the wrong repository

What happened. On 28 October 2026 three agents landed in the wrong repository's worktrees, and one failed outright. On 8 November the same thing happened with five agents. They stopped only because their first step, a reset to a commit that did not exist in that repository, failed.

Why. Worktrees are created from the repository the shell is in, and my last cd was in another project.

The check. Check pwd before spawning. Make the first step of every brief prove the repository, and stop if it fails. The pinned commit doubles as an identity check. In the lab, git cat-file -e <sha>^{commit} succeeds in the right repository and fails in another.

Layer 2: what an agent may touch

A symlink that erased 40 GB

What happened. I told agents to symlink the main checkout's data folder into their worktree. They committed the link. On 10 November 2026 a merge replaced the real ignored directories with the link, and git deleted every ignored file inside them: about 40 GB of model outputs in a Kaggle project. I had no backup.

Why. The .gitignore held data/. The gitignore documentation says that if there is a separator at the end of the pattern, it will only match directories. A symlink is not a directory, so it was not ignored and git add data staged it. When a merge needs the path to be a link, git replaces what is there. Ignored files are not protected.

Two columns. With the pattern data slash the link is staged, committed and the merge replaces the directory, leaving 0 of 2 ignored files. With the pattern slash data git refuses to stage the link, leaving 2 of 2 files Why a link named data was committed, and what the merge did to the real directory pattern data/ matches directories only agent runs: git add data link is not ignored committed: merge replaces the directory ignored files: 0 of 2 left (lab) pattern /data matches files and directories agent runs: git add data link is ignored git refuses to stage it ignored files: 2 of 2 left (lab) Git may overwrite ignored files when a merge needs their path, so a directory of untracked outputs is not protected by .gitignore.
Figure 5. The same agent step under two patterns, as measured in the lab.

In the lab the real directory holds two ignored files. With data/ the link is staged, the merge succeeds, and zero files remain. With /data git refuses to stage the path and both files survive.

The check. Three checks, because one was not enough. Ignore the path with a leading slash and no trailing one:

/data

Before merging, list the symlinks a branch adds. Each one shows git mode 120000:

git diff --raw --no-renames main...agent | awk '$2 == "120000"'

And back up large ignored artefacts, because git will not. Better still, tell agents not to link anything, and give them the data path in the brief.

A message that started a second copy

What happened. On 28 October 2026 I messaged an agent whose workflow was still running. The message did not reach it. A second copy resumed from the transcript in the same worktree, and the two overwrote each other's edits.

Why. A running workflow does not take messages. A message to it starts a resumed copy instead.

The check. Stop the workflow first, or wait. A worktree has one writer.

Two agents, one task

What happened. Two agents took the same task the same night.

Why. The task sat on two lists.

The check. Keep task lists disjoint.

Cleaning up other sessions' worktrees

What happened. On 9 November 2026 a cleanup request in one session removed 21 worktrees that belonged to other sessions.

Why. All worktrees hang off one repository, so a listing shows every session's, finished or not.

The check. A session removes only worktrees its own agents created.

Layer 3: how you know it worked

The exit code that was the wrapper's

What happened. On 23 November 2026 a backgrounded test run, pytest ... > log; echo exit $?, reported exit code 0. The log held a FAILED line. The batch records said the suites passed.

Why. The status was that of the last command, echo, not of pytest.

A wrapper command line, pytest redirected to a log and then echo. The wrapper reports exit code 0 while the log holds a failure. The fixed line appends pytest's own status to the log The wrapper's exit status is the status of the last command in it pytest ... > run.log; echo exit $? wrapper reports: exit code 0 the status of echo run.log holds: 1 failed the status of pytest was lost pytest ... > run.log; echo exit $? >> run.log log ends: exit 1 pytest's own status and: grep FAILED run.log the log is the evidence In the lab the same failing test file gives wrapper status 0 and a FAILED line in the log; the fixed wrapper logs exit 1.
Figure 6. The reported status is the last command's.

In the lab, a test file with one failing assertion gives wrapper status 0 and a FAILED line in the log. With echo exit $? >> run.log, the log ends in exit 1.

The check. Write pytest's own status into the log, grep the log for FAILED and ERROR, and have the batch record read that:

pytest -q > run.log 2>&1; echo "exit $?" >> run.log
grep -E 'FAILED|ERROR|^exit [1-9]' run.log

A check should read the evidence, not a status passed along. The harness post makes the same point.

Targeted tests missed the importers

What happened. On 7 November 2026 the agents' own targeted tests passed. Breakage in packages that import the changed one showed up only at pre-push, after I had merged.

Why. An agent tests what it changed. The dependency points the other way.

The check. Before merging, run the suites of every package that imports the changed one.

Five checks of my own before a refactor ships

For agent refactors I now run five checks myself before release:

  • rerun a pre-recorded oracle, with exact array equality;
  • build and install the wheel in a clean virtual environment, and rerun the oracle there;
  • spot-check real outputs;
  • read both diffs;
  • run lint, tests and audits.

A refactor can pass its own tests and still change behaviour. The clean install catches code that only worked because the source tree was on the import path. The agent's report that it checked is a claim. These checks are the evidence.

The merge script

The checks before a merge fit in one script. It returns a list of problems, and an empty list means go on to read the diffs.

A chain of five boxes: pinned sha in the branch, only paths in the brief, no symlinks added, importers' suites pass, read diffs then merge. Each of the first four has a reject action beneath it Before merging an agent branch: four checks, then the diffs Pinned sha in the branch? no: stale base, reset and redo Only paths in the brief? no: reject, or widen the brief No symlinks added? any: reject, list the links Importers' suites pass? no: fix, then check again Read diffs, then merge then remove that worktree The first three are one script in the lab; the fourth is the importing packages' own test commands.
Figure 7. The pre-merge checks, in order.
"""Pre-merge check for one agent branch. Returns a list of problems; an empty list means go on to read the diff."""
import subprocess


def _git(repo, *args):
    return subprocess.run(["git", *args], cwd=repo, capture_output=True, text=True)


def premerge_problems(repo, sha, branch, allowed=("src/", "tests/"), importer_suites=()):
    """Check `branch` in `repo` against the commit `sha` the brief pinned."""
    problems = []
    if _git(repo, "merge-base", "--is-ancestor", sha, branch).returncode:
        problems.append(f"{branch} does not contain {sha[:10]}: stale base")
    changed = _git(repo, "diff", "--raw", "--no-renames", f"{sha}...{branch}").stdout.splitlines()
    for line in changed:
        meta, path = line.split("\t")
        if meta.split()[1] == "120000":
            problems.append(f"symlink added: {path}")
        if not path.startswith(tuple(allowed)):
            problems.append(f"outside the allowed paths: {path}")
    for cmd in importer_suites:           # suites of the packages that import what changed
        if subprocess.run(cmd, shell=True, cwd=repo).returncode:
            problems.append(f"importer suite failed: {cmd}")
    return problems

In the lab it passes a clean branch. It rejects a stale base, an added symlink, a path outside the brief and a failing importer suite, and it names each one. For a branch that adds src/data as a link and also a file notes.txt outside the brief, it returns:

['symlink added: src/data', 'outside the allowed paths: notes.txt']

The script does not read the diff for me. It removes the cases where reading the diff would have been too late.

Layer 4: the machine

The disk and the 14 hours

What happened. On 2 November 2026 parallel agents' full test runs needed about 5 GB of temporary space each and filled the disk. Another long-running job hit its free-space floor and paused for about 14 hours, unnoticed.

Why. Each worktree also takes about 1.3 GB, and nothing watched the total. The agents' temp files crossed the other job's floor.

The check. Before each wave, free disk must cover every agent's temp space and worktree, plus the other job's floor:

free ≥ n × (t + w) + f

Here n is the number of agents, t the temp space of a full test run (about 5 GB), w the worktree (about 1.3 GB) and f the floor of the other job (20 GB at its launch). For five agents that is 5 × (5 + 1.3) + 20 = 51.5 GB. For ten it is 83 GB, and for fifteen 114.5 GB. Targeted tests shrink t. Removing each worktree right after its merge gives w back. The lab's preflight.sh runs the formula against the free space of the current filesystem:

Three stacked bars for 5, 10 and 15 agents. Each bar adds temp space n times 5 GB, worktrees n times 1.3 GB and the other job's 20 GB floor, giving 51.5, 83 and 114.5 GB Disk a wave needs: n x (t + w) + f, with t = 5 GB, w = 1.3 GB, f = 20 GB 5 agents 51.5 GB 10 agents 83 GB 15 agents 114.5 GB temp space of full test runs, n x 5 GB worktrees, n x 1.3 GB the other job's floor, 20 GB Targeted tests shrink the first part; removing each worktree after its merge gives the second back.
Figure 8. The disk a wave needs, from the formula above.
sh preflight.sh 5 20     # need 51.5 GB, free ... GB; exits 1 if free is smaller

An editor that could not keep up

What happened. One very long session ran about 60 agents. On 28 October 2026 its transcript reached 2 GB and the editor refused to reopen it. The editor's extension host also crashed repeatedly while watching 167 worktrees, 212 GB in all, until I excluded those paths from watching.

Why. Each worktree is a full checkout, and tools that watch a folder see all of them.

The check. Exclude the worktree folder from watching. Keep handoff notes in the repository, and start a fresh session every few batches.

The variable that sent a test to the real repository

What happened. On 17 November 2026 a git push from a worktree ran the pre-push test suite with GIT_DIR exported. A test that ran git init in a temporary directory re-initialised the real repository and set core.bare = true. Every checkout then failed with "this operation must be run in a work tree", and two unrelated tests failed.

Why. The git-init documentation says that if the GIT_DIR environment variable is set, it specifies the path to use instead of ./.git for the base of the repository. So a test that makes a repository in a temp directory is sent to the one in the environment. The git manual lists the other variables that locate a repository, among them GIT_WORK_TREE and GIT_INDEX_FILE.

A chain: git push, a pre-push hook exporting GIT_DIR, a test suite inheriting it, a plain git init in a temp directory, and the real repository ending with core.bare true. A fix box drops the variables in the test config A variable set for the push reaches a test's own git commands git push from a worktree pre-push hook exports GIT_DIR test suite inherits GIT_DIR git init -q in a temp directory real repository: core.bare = true every checkout fails (lab) fix: root test config drops GIT_DIR and the other locating variables With GIT_DIR set, git init targets that directory, not the current one (git-init documentation).
Figure 9. How a variable meant for the push reached a test.

The lab uses the form of the real tests: a plain git init -q with a temporary directory as the current directory. The push exported the worktree's own git directory, .git/worktrees/<name>. In the lab, with GIT_DIR set to that directory, the scratch directory gets nothing and the real repository's core.bare becomes true. git status there then fails with "this operation must be run in a work tree". With GIT_DIR set to the main repository's .git, git 2.39.5 also redirects the init, but core.bare stays false. So the lab shows the flip only for the worktree form. With the variables removed, the scratch directory gets its own repository.

The check. The root test configuration drops GIT_DIR and the other locating variables before any test. Tests should not depend on the caller's environment. In pytest, that is a conftest.py at the project root:

"""Root test configuration: drop the variables that tell git which repository to use.

A pre-push hook or a worktree can export these. Without this, a test that runs `git init` in a
temporary directory can act on the caller's repository instead.
"""
import os

for name in ("GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_OBJECT_DIRECTORY", "GIT_COMMON_DIR",
             "GIT_NAMESPACE", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_PREFIX"):
    os.environ.pop(name, None)

To see whether a repository was hit, ask it. This prints nothing when the repository is healthy:

test "$(git config core.bare)" = false || echo "core.bare flipped"

In the lab, a suite run under a leaked worktree GIT_DIR flips core.bare without this file and leaves it false with it.

Layer 5: the human loop

An amend on someone else's commit

What happened. Another session committed to the same main branch hourly. On 11 November 2026 an amend I made landed on that session's commit instead of mine, and was pushed.

Why. git commit --amend rewrites whatever is at the tip, and the tip had changed.

The check. Never amend a shared main. If you must, check the tip first:

test "$(git log -1 --format=%s)" = "my subject" || echo "tip is not mine"

Two commits can share a subject, so comparing the commit hash you recorded is stricter. In the lab, two sessions commit in turn on one branch. The guard reports that the tip is not the commit expected. The unguarded amend rewrites the other session's.

Two session lanes over time on one branch. Session A commits A1, session B commits B1 on top an hour later, then A runs git commit --amend meaning to fix A1, which rewrites B1 instead; the guard compares the tip with A1 first An amend rewrites whatever is at the tip, and another session moved it Session A Session B main A1 A commits B1 B commits, an hour later B1' A amends, meaning to fix A1 B's commit rewritten, then pushed The guard: compare the tip with the commit you recorded before amending test "$(git rev-parse HEAD)" = "$A1" || echo "tip is not mine" In the lab the guard catches the moved tip; the unguarded amend rewrites the other session's commit.
Figure 10. Why an amend hit the other session's commit.

What I would set up first

Start with the checks that cost the most when they fail:

  1. Ignore with a leading slash, and back up large ignored directories. That failure had no recovery.
  2. Pin the commit in every brief. One line covers the stale base and the wrong repository.
  3. Drop the locating variables in the root test configuration.
  4. Make batch records read the log, not the wrapper's status.
  5. Check free disk before each wave, and remove each worktree after its merge.
  6. Write the handoff note, then start the next session.

The rest are habits: check pwd, keep task lists disjoint, never message a running workflow, never amend a shared main, and clean up only what your own agents made.

Minimum setup for five agents

The lab ships each piece, so you can copy the file and run its test.

PieceWhat it doesLab file
Brief templatePins the sha; first step proves the repositorybrief.py, brief_example.txt
Pre-merge scriptBase, paths, symlinks, importer suitespremerge.py
Ignore rules/data, not data/fleetlab.py (symlink test)
Test config scrubDrops the git locating variablesconftest.py
Disk preflightn × (t + w) + f against free diskpreflight.sh
Handoff noteOne file in the repository; fresh session every few batchesnone, it is yours to write

Before the first wave, run preflight.sh. Before each merge, run premerge.py and read the diff. After each merge, remove that worktree.

What still goes wrong

  • A pinned commit goes stale if main moves after the brief is written. The merge-base check then passes while the branch is behind the new main.
  • The pre-merge script finds symlinks and stray paths in a branch's diff. It does not find an agent that copies data, or two branches that conflict in meaning.
  • It runs only the importer suites you list. A package missing from the list is not tested.
  • A log grep misses a run that crashed before printing anything. Check that the log is not empty.
  • The disk check is a snapshot. Another job can fill the disk after it passes.
  • The list of git variables comes from the manual today. A future git version may add more.
  • A handoff note goes stale. It only helps if the next session reads it first.

All thirteen in one table

Most rows have the same shape. Something was assumed, such as a base commit, an ignore rule, an exit status or a free-space figure, and nothing read it back. Each check reads the thing and fails when the assumption is false.

The table follows the layers of the post, and each row names its layer and date. Nine of the thirteen run in the lab; the other four depend on the agent tool or the editor, which a test repository cannot reproduce.

Horizontal bars, one per layer, splitting its incidents into those reproduced in the lab and those not: start 3 and 0, touch 1 and 3, verify 2 and 0, machine 2 and 1, human 1 and 0 The thirteen incidents by layer: reproduced in the lab, or not Start 3 in the lab Touch 1 in the lab, 3 not Verify 2 in the lab Machine 2 in the lab, 1 not Human 1 in the lab reproduced in the lab: 9 not reproducible there (agent tool, editor): 4
Figure 11. The thirteen incidents by layer, and how many the lab reproduces.
What brokeCostThe checkLab
Stale base
Start, 23 Oct
290 commits behindPin the sha in the briefyes
Wrong repository
Start, 28 Oct
3 agents misplacedProve the repo firstyes
Wrong repository again
Start, 8 Nov
5 agents, all stoppedSame checkyes
Second copy from a message
Touch, 28 Oct
Lost editsStop the workflow firstno
Others' worktrees removed
Touch, 9 Nov
21 worktreesRemove only your ownno
Link replaced a folder
Touch, 10 Nov
40 GB, no backup/data, not data/yes
Two agents, one task
Touch, undated
Work done twiceDisjoint task listsno
Importers broke
Verify, 7 Nov
Found at pre-pushRun importers' suitesyes
Wrapper hid a failure
Verify, 23 Nov
Suites marked passedRead the logyes
Editor overwhelmed
Machine, 28 Oct
167 worktrees, 212 GBExclude from watchingno
Disk filled
Machine, 2 Nov
Job paused 14 hDisk preflightyes
GIT_DIR reached a test
Machine, 17 Nov
Checkouts failedScrub git variablesyes
Amend hit another commit
Human, 11 Nov
PushedCheck the tip firstyes

A small lab you can run

The lab is a few short modules, a brief template, a disk script, a conftest.py and twenty-two tests. Each test builds throwaway repositories in a temporary directory, with git's user and system configuration switched off. It shows the bug, then the check:

  • a worktree from the remote ref is five commits behind the unpushed main, a reset to the pinned sha is not, and the merge-base check tells them apart;
  • a pinned commit exists in the right repository and not in another;
  • data/ lets a committed link replace the directory and leaves 0 of 2 ignored files, while /data refuses the link and leaves 2 of 2;
  • a wrapper with a failing test returns 0 while its log holds FAILED, and the fixed wrapper logs exit 1;
  • a leaked worktree GIT_DIR flips core.bare on the real repository under a plain git init, and scrubbing the variables prevents it;
  • the disk formula gives 51.5, 83 and 114.5 GB for 5, 10 and 15 agents;
  • an amend lands on another session's commit unless the log is checked first;
  • the one-liners for the disk check, core.bare, the tip check and the pytest status each run in a throwaway repository, once where they stay quiet and once where they speak;
  • a suite with the conftest.py keeps its git init off the real repository, and the same suite without it does not.

Run it with nice python -m pytest -q. It needs Python 3.9 or later, git and pytest, and no network.

Limits of this post

  • The incidents come from one person, one machine, one agent tool and a few repositories. The counts are what I recorded, not a survey.
  • The lab reproduces git and shell behaviour. It cannot show that the tool branched from the remote's main, that a message resumed a second copy, or that an extension host crashed.
  • The git results come from git 2.39.5 on macOS. Other versions may behave differently, the GIT_DIR case most of all.
  • The lab's stale base is five commits. Mine was 290. The disk figures come from my runs, and the formula is arithmetic on them.
  • The checks are cheap, but they do not replace reading the diffs. The five pre-release checks cost real time.
  • I did not compare batch sizes systematically. Five worked and I did not tune further.

Sources

  • git-worktree documentation: git worktree add <path> [<commit-ish>]; a worktree shares everything except per-worktree files such as HEAD and index.
  • gitignore documentation: a separator at the end of a pattern makes it match only directories.
  • git-init documentation: the GIT_DIR environment variable specifies the base of the repository instead of ./.git.
  • git manual: environment variables that locate the repository, work tree and index.