mountable.io
By mountable.io · Cookbooks
  • agents
  • filesystem
  • cookbook

When Two Agent Jobs Edit One File, Keep the Newer Change

Both jobs read the same task file. The second write sends the ETag from that read, so it cannot erase the first job's change.

Two agent jobs both read a short task file that says the work is open. The first job marks it in review. The second job writes that open copy back and adds a line of its own.

The review mark is gone, and the write did not fail. The first job had already finished, so nothing tells the team the mark disappeared. The next person sees an open task and repeats the review.

mountable.io is a persistent filesystem for AI agents. Each file has an ETag that changes when the bytes change, so send the ETag you read with the write. If the other job changed the file, the write is refused and the newer file stays as it is.

Editor one and editor two both read version A of a task file. Editor one writes version B. Editor two's stale write is refused. Editor two reads again and writes version C, keeping the review status and adding only its own line.
Both jobs read version A. The stale write is refused. The second job rereads, then sets its own field.

What each version contains

The companion example runs the two jobs as separate processes. Both read version A. It is 25 bytes:

status: open
note: ready

Editor one writes version B with the ETag from that read. Version B is 27 bytes:

status: review
note: ready

Editor two still holds version A. Its write would put the status back to open and add its own line.

uv run python edit.py commit \
  --filesystem "$MOUNTABLE_FILESYSTEM_ID" \
  --run "$RUN" \
  --if-match "$ETAG_A" \
  --editor two

That command sends the ETag from version A. The files API answers 412 precondition_failed, and version B is still the file.

Editor two then reads the file again. It copies what it just read and sets editor to two. Version C is 39 bytes:

status: review
note: ready
editor: two

The review mark from editor one stays. Your code chooses the field. The filesystem does not combine the two copies for you.

Run the same steps

Follow the cookbook or run the companion. The headers are in conditional writes. mountable.io maintains this example using its Python SDK.