A local-first multi-agent app development platform, built on PenguinHarness
edit_file and write_file serialize per file
- Date: 2026-09-12
- Type: fix
- Scope:
core,docs - PR: #709
edit_file and write_file hold a per-file mutex across their whole read-modify-write. Both tools
read a file, compute the new content and replace it with an atomic temp-file + rename, and the
engine runs a turn's approved tool calls concurrently — so two edits of one file, whether from one
turn or from two subagents in the same process, both read the original bytes and the later rename
won. One edit was silently lost while both calls reported success.
Details
- The key is the file's real path, so every name that reaches one file folds onto one key: a
symlink and the file it points at, a path crossing a linked directory. A path that does not exist
yet keys on its deepest real ancestor plus the segments below it —
write_filecreates missing parents, so the directory is often still absent too — and awrite_filethat creates the file and anedit_filethat follows therefore share one key. Resolution failures are absorbed rather than raised, leaving the tool's own error wording intact. - The lock spans the read and the write: stat, read, match, atomic write. The diff rendering and
the tool's output happen after it is released. A call interrupted while queued behind another
writer ends as
aborted, the same as one interrupted during its own read or write. - An
old_stringan earlier edit removed now fails. Two concurrent edits of the sameold_stringwithoutreplace_allend as one replacement plus the existingold_string not foundmessage, instead of the second edit overwriting the first. read_filetakes no lock — the atomic rename already leaves a reader with either the old content or the new one, never a mix.- The scope is one process. No OS-level file lock is taken, so a separate CLI run, an editor or the user's own shell writing the same file is not serialized against these tools.