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, notdata/. - 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.
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.
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.
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.
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.
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.
"""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:
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.
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.
What I would set up first
Start with the checks that cost the most when they fail:
- Ignore with a leading slash, and back up large ignored directories. That failure had no recovery.
- Pin the commit in every brief. One line covers the stale base and the wrong repository.
- Drop the locating variables in the root test configuration.
- Make batch records read the log, not the wrapper's status.
- Check free disk before each wave, and remove each worktree after its merge.
- 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.
| Piece | What it does | Lab file |
|---|---|---|
| Brief template | Pins the sha; first step proves the repository | brief.py, brief_example.txt |
| Pre-merge script | Base, paths, symlinks, importer suites | premerge.py |
| Ignore rules | /data, not data/ | fleetlab.py (symlink test) |
| Test config scrub | Drops the git locating variables | conftest.py |
| Disk preflight | n × (t + w) + f against free disk | preflight.sh |
| Handoff note | One file in the repository; fresh session every few batches | none, 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.
| What broke | Cost | The check | Lab |
|---|---|---|---|
| Stale base Start, 23 Oct | 290 commits behind | Pin the sha in the brief | yes |
| Wrong repository Start, 28 Oct | 3 agents misplaced | Prove the repo first | yes |
| Wrong repository again Start, 8 Nov | 5 agents, all stopped | Same check | yes |
| Second copy from a message Touch, 28 Oct | Lost edits | Stop the workflow first | no |
| Others' worktrees removed Touch, 9 Nov | 21 worktrees | Remove only your own | no |
| Link replaced a folder Touch, 10 Nov | 40 GB, no backup | /data, not data/ | yes |
| Two agents, one task Touch, undated | Work done twice | Disjoint task lists | no |
| Importers broke Verify, 7 Nov | Found at pre-push | Run importers' suites | yes |
| Wrapper hid a failure Verify, 23 Nov | Suites marked passed | Read the log | yes |
| Editor overwhelmed Machine, 28 Oct | 167 worktrees, 212 GB | Exclude from watching | no |
| Disk filled Machine, 2 Nov | Job paused 14 h | Disk preflight | yes |
GIT_DIR reached a testMachine, 17 Nov | Checkouts failed | Scrub git variables | yes |
| Amend hit another commit Human, 11 Nov | Pushed | Check the tip first | yes |
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/datarefuses 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_DIRflipscore.bareon the real repository under a plaingit 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.pykeeps itsgit initoff 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.