iCode Workbench · Guide · Isolation

Parallel agents without merge conflicts

Git worktrees stop two agents from overwriting each other's files. They do not stop the merge conflict. Two branches can change the same shared file, pass their own tests, and still fail — or silently drop one side — when they land together.

This guide is about the second problem: how to scope, order, and test parallel work so the merge is boring.

This guide is currently available in English only.

Why conflicts happen

A merge conflict is a disagreement about the same lines in the same file. Two agents can create one without ever sharing a checkout: branch A changes a function, branch B changes the same function from an older read of main, and Git cannot choose between them.

There is a quieter failure too. Git can merge both changes cleanly, and the result can still be wrong: two features compile, but the combined behavior breaks. That is a semantic conflict, and it is the one a passing branch-level test will not catch.

The fix is not a smarter merge. It is to reduce the overlap before the agents start, and to test the combined result after they finish.

Hub files

Most parallel-agent conflicts concentrate in a small set of files that every task seems to touch:

  • Dependency manifests and lockfiles. package.json, pnpm-lock.yaml, pyproject.toml, uv.lock.
  • Route tables and export lists. The files that register every feature in one place.
  • Shared types and API schemas. A change here affects every caller.
  • Migration directories. Two migrations that assume different schemas.
  • Test fixtures and factories. Shared setup used by several tasks.
  • Configuration and environment files. The same key changed for different reasons.

Treat these as shared contracts, not as ordinary files. Land the shared change on main first, or give the hub file to one task and make every other task wait. Do not let two agents “coordinate” through commit messages.

Scope by file, not by feature

“Auth” and “billing” are features, not scopes. A feature name can hide the fact that both tasks need the same route table. Scope by the paths the agent may change:

## Task
Add token refresh to the auth client.

## Owned paths
- src/auth/**
- tests/auth/**

## Shared files
- src/routes.ts — coordinate; do not edit without announcing

## Done when
- pnpm test -- auth passes
- The refresh path is covered for an expired token

## Out of scope
- Public types
- Billing
- Formatting-only changes

The owned paths are a boundary, not a guarantee. Agents drift. Review the diff for files outside them, especially the hub files above.

If two tasks must change the same shared file, merge that change first, then rebase both worktrees. If the change is small and local, give the file to one task and have the other wait.

Isolate with worktrees

A worktree gives each task its own checkout and branch while sharing the repository history. It prevents the overwrite problem and makes the diff reviewable in place. It does not prevent the merge conflict; that is what scoping and merge order are for.

For the mechanics, read Git worktrees for coding agents, explained. For the full fleet workflow, read the parallel-agents pillar.

The merge queue

Merge one branch at a time. For each branch:

  1. Rebase on main. Resolve any conflict in the branch, not in the merge commit.
  2. Run the full test suite. Not just the task's tests.
  3. Merge with --ff-only. If it does not fast-forward, rebase again.
  4. Test the combined result. The next branch now starts from a different main.
git checkout main
git pull
git checkout feature-auth
git rebase main
pnpm test
git checkout main
git merge --ff-only feature-auth

Lockfiles get their own rule: do not hand-merge them. Restore the target branch's lockfile, re-run the package manager's add command, and commit the regenerated file.

A queue makes this order explicit. If you run three agents and merge them in the order they finish, you are choosing merge order by accident.

Semantic conflicts

A semantic conflict is a merge that applies cleanly and breaks behavior. Examples: one task renames a function while another adds a caller; one changes a default while another relies on it; two tasks add migrations that assume different schemas.

The only reliable catch is a test on the merged result. Run the integration tests after each merge, not just the unit tests in each branch. If the suite is flaky, fix that before you add agents; a green run you do not trust cannot catch a semantic conflict.

A worked example: two branches, one route table

The auth task adds /auth/refresh; the billing task adds /billing/portal. Both edit src/routes.ts. Each branch passes its own tests, so both look green.

Merge auth first. Billing rebases on main and hits a conflict in the route table. The resolution is to keep both routes, then run the full suite — including a test that calls both endpoints. If billing had rewritten the table instead of appending, the conflict would be semantic: a clean merge could still drop the auth route.

The same pattern appears with shared types. If both tasks add a field to Session, one branch's type change lands first and the other conflicts. The contract should have been decided on main before either branch started.

The file list is the early warning. A diff that touches a hub file outside the owned paths is a review finding, even when the branch is green.

Merge order by dependency

Merge in dependency order, not completion order:

  1. Schema and migrations. Everything else assumes the new shape.
  2. Shared types and contracts. Route tables, API schemas, exported interfaces.
  3. Feature branches. Rebase each on the new main, test, merge.
  4. Docs and low-risk changes. Last, so they describe the final behavior.

If two branches depend on each other, they are one task until the shared change lands. Splitting them creates a merge order problem that no amount of rebasing fixes.

When to abandon a branch

A branch that has drifted for days is not a merge problem; it is a design debate. If rebasing produces conflicts in files the task never intended to touch, stop. Recreate the branch from main and re-apply the task with the current contract. Keep the old branch for reference until the new one is verified.

Forcing a merge to preserve work is how a small change becomes a large review. The task, not the branch, is the unit of work.

Rebase or merge?

Rebase the feature branch onto main before merging, then merge with --ff-only. That keeps the history linear and puts the conflict resolution in the branch, where it can be tested before it reaches main.

Do not rebase a branch that another person or agent is actively using. Rebasing rewrites commits; a running session can end up on a branch whose history no longer matches its checkout.

If a conflict is large or touches a shared contract, stop and fix the contract on main first. A long conflict resolution is a sign that the task was not independent, not a sign that you need a better merge tool.

Checklist

  1. Are the tasks file-disjoint, not just feature-disjoint?
  2. Are the hub files owned by one task or landed on main first?
  3. Does each task have an out-of-scope list?
  4. Does each branch rebase on main before merging?
  5. Is the full suite green on the merged result?
  6. Are lockfiles regenerated, not hand-merged?