FMTechnical notes
Portfolio
Back to the blog

AI & Agents · Intermediate · Agentic

Several agents, one repo: splitting work without collisions

Parallelising agents is not opening five chats. It is declaring who owns each file, who runs git, and how the diff is checked against what was allowed.

After reading this
  • Recognise when two agents will collide
  • Define units with disjoint surfaces
  • Keep git in a single pair of hands
  • Check the diff against the declared surface
01 / 04

The collision

Two agents working in the same repo without coordination produce what two people editing the same file without talking produce: someone loses work.

The usual case is not the obvious file, it is the shared stylesheet. One agent appends a rule at the end of a five-thousand-line CSS while another rewrites a block in the middle. Neither is “wrong”, and the merge still fails.

  • Same file: guaranteed conflict.
  • Same sheet, different blocks: likely conflict.
  • Same component and its test: intent conflict.
02 / 04

A unit is behaviour plus files

A work unit is one independent behaviour with its code, its tests, and its docs. It is assigned to a single agent together with the exact list of files it may touch.

If two units need the same file they are not parallel: they are one unit, or they run in sequence.

text
| Unit | Behaviour            | Files                                     |
|------|----------------------|-------------------------------------------|
| U1   | Hero magnetic CTA    | src/components/sections/hero-section.tsx  |
|      |                      | src/styles/hero-life.css                  |
| U2   | Card spotlight       | src/components/sections/selected-work.tsx |
|      |                      | src/styles/work-life.css                  |
03 / 04

The parent runs git

Subagents write; the orchestrator commits. An agent running `git add -A` can drag another agent's changes into a commit that does not belong to it.

The parent checks each diff against the surface, makes one commit per unit, and runs the full suite once at the end, on the seam between units.

bash
# the parent, not the subagent
git status --short
git diff --name-only
git add src/components/sections/hero-section.tsx src/styles/hero-life.css
git commit -m "feat(hero): magnetic CTA"

# once, when closing the seam
npm test && npm run build
04 / 04

Checking the diff

A declared surface is worth little if nobody checks it. A short script compares the changed files against the allowed list and fails on anything outside.

It is the same idea as a test: the rule lives in code, not in the reviewer's memory.

js
import { execSync } from "node:child_process";

const allowed = new Set([
  "src/components/sections/hero-section.tsx",
  "src/styles/hero-life.css",
]);

const changed = execSync("git diff --name-only HEAD", { encoding: "utf8" })
  .split("\n")
  .filter(Boolean);

const outside = changed.filter((file) => !allowed.has(file));
if (outside.length > 0) {
  console.error("Write outside the surface:", outside);
  process.exit(1);
}
console.log(`${changed.length} files, all inside the surface.`);
Component tree● interactive

Layout-level composition. Owns the document structure and orchestrates which features render.

Practice

Split one feature in two

Pick a small feature and split it into two units with disjoint files. Write the ownership table and the script that validates each diff. If you cannot separate the files, explain why they run in sequence.

Show a hint

If both units share a stylesheet, create one sheet per component before parallelising.