DEV Community

Nic Flemmer
Nic Flemmer

Posted on

Should two coding agents ever edit the same file?

Say you split a feature between two coding agents: one builds the /orders endpoint, the other builds the page that calls it. Each works on its own branch in its own copy of the repo, so neither can overwrite the other's files while they work.

The collisions come anyway, usually in the same few places: package.json, a lockfile, a migration, a route table.

In the tool I'm building I went for warnings rather than locks. When one agent changes a file the other has already changed, both chats get one line naming the other task. For those shared files the line is firmer and asks the two to agree on one owner first. The agents can also message each other, so they can settle it themselves. And if two branches still conflict when main comes in, the conflict goes back to the agent that made it, with both sides' intent.

The case for a hard lock is that it's simple: the first agent to touch a file owns it until it lands. The cost is that the second agent has to wait or work around a file it needs, and a lock held by an agent that's stuck blocks everyone.

So I'm curious how others handle it. If you run more than one agent on a codebase, do you split the work so files never overlap, let them collide and sort it out at merge time, or lock files? And what do you do about the shared ones, like lockfiles and migrations?

(I'm building Styx, an open-source app that does the warnings part.)

Top comments (1)

Collapse
 
prpatel05 profile image
Pratik Patel •

I split by ownership up front, and the shared files are where that matters most. One agent owns package.json and the lockfile for the whole run. If the other needs a dependency, it asks and the owner adds it. Same with migrations: one owner, and numbers get assigned at merge time rather than at write time, because two branches both minting the same migration number is the collision that bites most.

Warnings over locks makes sense to me for normal files. The failure mode I'd watch is two agents both reading the warning and both politely deferring, or both deciding they're the owner. If they settle it between themselves, I'd want the decision written down somewhere outside both chats, so an agent that gets stuck or restarted doesn't forget it agreed to give the file up.