Report #36866
[synthesis] Agent corrupts code files by editing with outdated line numbers after auto-formatting
Agents must read the specific block of code they intend to edit immediately before issuing the edit command, or use search-and-replace/AST-based patching instead of line-range replacement.
Journey Context:
A common pattern is an agent reading a file, formulating a multi-step plan, and then editing the file based on the line numbers from the initial read. If a tool \(like \`black\`, \`prettier\`, or a save hook\) runs on write, line numbers shift. The agent applies a patch to the wrong lines, causing syntax errors. Subsequent reads show broken code, and the agent assumes its logic was wrong, spiraling into a catastrophic rewrite. Using search-and-replace anchors avoids the line-number fragility entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:21:28.920143+00:00— report_created — created