The multi-agent isolation checklist (DBs, flags, test forks)
The short version
Two AI agents were run in parallel to move faster. They shared one test database, so each one was resetting state underneath the other and both reported failures that were not real. A full day went into chasing a bug that never existed.
Parallel agents are only faster if they cannot touch each other's state. Give each one its own data, run shared-resource tests one at a time, and put anything multi-agent behind a switch that ships off by default.
Copy these prompts
Paste them into Claude Code (or any AI that can see your project), in this order. Each one answers a different question, and the first is usually the one that matters.
1. Give each one its own data
I want to run more than one AI agent on my project at the same time. Show me how to give each agent its own isolated database and workspace so they cannot corrupt each other's runs.
2. Find the tests that assume they are alone
Tell me which of my tests assume they are the only thing touching the database at that moment. Those are the ones that will fail mysteriously when two agents run together. Show me how to make them safe or run them one at a time.
3. Ship multi-agent features turned off
Show me how to put anything involving more than one agent behind a switch that ships turned off by default, so I can turn it on only after I have watched it behave in the real world.
I ran two AI agents in parallel to go faster. They sabotaged each other. Two agents, one database: each one's test runs corrupted the other's, and I burned hours "certain I'd broken something real" when the only bug was contention. The fixes that stuck: sequential test execution (single fork, shared DB), a timer-leak fix in test teardown, and every multi-agent feature behind its own flag. My whole AI tab shipped default-OFF. Parallel agents need sandboxes like toddlers need separate rooms.
The failure modes
Two agents sharing state produce Heisenbugs: test A's seed data vanishes mid-run because agent B reset the DB; flaky failures that reproduce for neither agent alone; and (the expensive part) you debugging phantom regressions that are actually collisions.
The checklist
- One agent = one database (or schema). Never let two concurrent agents touch the same DB. Cheapest versions: per-agent Postgres schema, per-agent Docker compose project with offset ports, or per-agent Neon branch:
# per-agent docker DB on its own port
docker compose -p agent-a -f compose.yml up -d # postgres on 5433
docker compose -p agent-b -f compose.yml up -d # postgres on 5434
- If the DB must be shared, serialize the tests. My vitest config runs files sequentially in a single fork because test files share one DB. Parallel workers were corrupting each other even without agents:
// vitest.config.ts
test: { poolOptions: { forks: { singleFork: true } }, fileParallelism: false }
- Hunt resource leaks in teardown. A timer leaked by one test run kept firing into the next (and into the other agent's run). Teardown must clear timers, close pools, and unsubscribe listeners. Leaks turn "isolated" runs into roommates.
- One agent = one worktree/branch. Filesystem isolation too:
git worktree addper agent so edits, build artifacts, and node_modules don't interleave. - Every multi-agent-built feature ships behind its own flag, default OFF. Agents merge work faster than you verify it; the flag decouples "merged" from "live." My entire AI tab sat in prod, dark, until it was proven.
- Give agents non-overlapping missions. Two agents editing the same module WILL produce merge carnage. Partition by module/feature, integrate through you.
- Suspect contention before regression. New rule after my lost hours: when tests fail while agents run in parallel, first re-run solo. Only a failure that reproduces alone is a real bug.
- Idempotency keys have TTLs, so mind them in reruns. Rapid agent test loops collided with my cached idempotent responses (same key, cached 2xx from the previous run). Scope keys per run or raise/lower TTLs deliberately.
Steal this for your app
- Parallel agents are a scheduling win only after isolation is solved; before that, they're a bug generator with great throughput.
- The checklist is identical to what CI learned a decade ago (isolated runners, hermetic state). Agents just re-teach it faster and at 2 a.m.
- At agent speed, flags-per-feature is the only way "shipped by an agent overnight" and "safe by morning" coexist.
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo for multi-agent isolation gaps.
Check the test setup for shared databases or state across parallel runners; flag any suite where two concurrent runs touch the same DB, schema, or fixture files.
Check the test runner config for single-fork or sequential execution when the DB is shared; flag parallel workers pointed at one database.
Inspect test teardown for leaked timers, open pools, and unremoved listeners.
Check whether agent-built or multi-agent features sit behind their own feature flags, default OFF.
Find idempotency keys whose TTLs could collide across rapid reruns.
Report findings as a checklist before changing anything.