gemini-cli PR Fixes Silent Lost Updates From Concurrent Tool File Writes

ranjan-del · ghdev · 2026-09-08

gemini-cli PR #29244 (priority/p1) exposes and fixes a subtle class of agent concurrency bugs: when parallel tool calls write the same path, two concurrent replace calls both read the original content and the second silently discards the first's edit — while both tool calls report success to the model. The PR fixes four races: (1) non-atomic writes (fs.writeFile truncates then streams, exposing 129 distinct partial states on a 64MB write) now go through a temp file + rename, copying file mode before renaming and retrying transient Windows EBUSY/EPERM; (2) lost updates in replace, caused by await points between read and write, fixed with an in-process per-path async mutex (utils/pathMutex.ts). Every race was reproduced on main first, each with a regression test.

Original post →

More from coding & agent

coding & agent channel →