- Two successful saves, one missing change
- “Save only if this is still the version I read”
- The editing API determines what protection exists
- An atomic replacement can still lose an update
- Separate workspaces move the conflict to a visible boundary
- A rejected save needs a different response from a timeout
- Sources
An AI agent can finish an edit successfully and still have its work disappear a moment later. Another agent only needs permission to save an older view of the same file over it.
No model failure is required. Both agents might follow their instructions correctly. The problem lies in how their editing tools coordinate access to shared storage.
When two AI agents edit the same file, the decisive detail is whether each save checks what changed since that agent read it.
Two successful saves, one missing change
Consider a small, illustrative configuration file. It contains a retry limit of three and a timeout of ten seconds. Agent A is asked to increase the retry limit. Agent B is asked to lengthen the timeout. Both read the original file before either saves.
A changes its copy to five retries and writes the whole file. B later writes its own copy with a twenty-second timeout. B’s copy still contains the original retry limit of three. The last save restores that old value while adding B’s requested change.
This is a lost update: A’s intended change has been replaced, even though the resulting file remains readable and valid. The HTTP documentation for If-Match describes precisely this class of problem when several clients update a resource.
| Event | Agent’s view | Saved file |
|---|---|---|
| Both read | A and B each see the original. | retries: 3 |
| A saves | A changes only retries. | retries: 5 |
| B saves | B writes its older copy with a new timeout. | retries: 3A’s change is gone. |
“Save only if this is still the version I read”
A storage service can refuse a stale edit instead of accepting whichever write arrives last. The client sends the identifier of the version it used. The service compares that identifier with the current version as part of deciding whether to accept the update.
HTTP provides a standard form of this condition. A client can submit If-Match with a strong ETag, a version validator received from the server. If it does not match, the server can reject the request with 412 Precondition Failed, as specified in RFC 9110, section 13.1.1.
In the example, B would learn that the shared resource changed. It could fetch the current file, reapply the timeout change and submit a new conditional update. The final version could then retain both edits.
The comparison must be enforced at the write boundary. An agent that reads the file a second time and then performs an unconditional save still leaves a gap in which another writer can act. Telling agents to “check first” does not close that gap.
The editing API determines what protection exists
GitHub’s repository contents API requires the blob SHA of the file being replaced when updating an existing file. That makes the expected file version part of the operation, rather than leaving it only in the agent’s conversation. The endpoint also documents conflict responses.
A local filesystem tool might instead expose an unconditional write. Another tool might offer a patch that must match an exact fragment. Those interfaces have different conflict behaviour; an AI agent is not guaranteed protection merely because it uses a tool called “edit.”
This is an important consequence of the separation between a model choosing an action and software executing it. Coordination guarantees come from the executor and storage system, not from the wording of the model’s intention.
An atomic replacement can still lose an update
“Atomic write” sounds as if it should solve simultaneous editing. It addresses a narrower property. Python’s os.replace documentation says that a successful replacement is atomic, while an existing destination file can be silently replaced when permissions allow.
That helps distinguish a complete replacement from an interrupted write that leaves a partial result. It does not, by itself, compare the replacement’s starting version with the destination’s current contents.
Both A and B could atomically replace the file in succession, each with a complete, valid document. A’s update would still disappear. Atomicity of one replacement and protection of the entire read–modify–write sequence are separate requirements.
Separate workspaces move the conflict to a visible boundary
For code changes, one useful arrangement is a working directory and branch for each agent. Git worktrees allow multiple working trees associated with the same repository, so agents can edit different checked-out files rather than compete over one live copy.
Integration becomes a deliberate step. Git’s branching and merging documentation explains both automatic merges and conflicts that need resolution. An overlapping edit can become visible instead of silently replacing another writer’s file.
A clean merge still needs review. Two changes can fit together textually while disagreeing in meaning: one agent might remove a feature flag that another agent’s new code expects. Separate workspaces preserve the opportunity to assess both contributions; they do not prove the combined behaviour is correct.
A rejected save needs a different response from a timeout
When a write fails because its base version is stale, retrying the same old contents is the wrong recovery. Fetch the new state and reconcile the intended change. When a request times out, first establish whether the original operation succeeded: otherwise a retry can repeat an action that already happened.
For a simple workflow, assigning one writer to each shared file may be easier than supporting concurrent edits. For parallel code work, isolated workspaces plus a reviewed integration step often make the ownership explicit. A shared document service needs its own enforced version or coordination mechanism.
The useful success condition is not that both agents received “saved.” It is that the final stored version contains the intended contributions, and any disagreement was surfaced before one silently erased the other.
Sources
- MDN: If-Match — conditional writes and lost updates.
- RFC 9110, section 13.1.1 — protocol semantics for If-Match.
- GitHub: create or update file contents — SHA requirement and conflict responses.
- Python: os.replace — atomic replacement behaviour.
- Git: worktree and branching and merging — isolated working trees and integration.







