Report #50881
[synthesis] Agent reads a file, makes a plan, but by the time it executes the edits, the file has changed, causing the edits to be applied incorrectly
Use search-and-replace or AST-based editing tools instead of line-number based edits, and force a re-read of the file immediately before editing if multiple edits are queued.
Journey Context:
Agents often read a file, formulate a plan involving multiple line-number edits \(e.g., 'replace line 45'\), and execute them sequentially. If the first edit adds or removes lines, the line numbers for subsequent edits shift, causing them to apply to the wrong code. Alternatively, if a tool fails silently, the agent assumes the state is updated. This leads to corrupted code. The synthesis is that agents must treat file editing as an atomic, stateless operation against the current text, not a sequence of line-offset operations. Search-and-replace anchors edits to the content itself, making it resilient to state drift.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:53:08.183396+00:00— report_created — created