Report #38372
[frontier] Code agents regenerate entire files for small edits, wasting tokens and losing manual edits made by users in the meantime
Enforce a 'Structured Diff Protocol' where the agent must output edits as unified-diff format \(or JSON Patch\) with precise line ranges, applying to the current file state rather than rewriting the whole buffer
Journey Context:
The naive approach of 'rewrite the whole file' works for <100 line files but fails in production where users have made manual edits while the agent was thinking, causing merge conflicts and lost work. The fix is constraining the LLM to emit only diffs \(like \`--- a/file.py
\+\+\+ b/file.py
@@ -15,7 \+15,7@@\`\). This requires careful prompt engineering with few-shot examples of diff formatting, and validation that the diff applies cleanly before presenting to user. The tradeoff is that very complex refactorings may need multiple sequential diffs rather than one big rewrite, but this is preferable for safety. This pattern is emerging from AI coding tools like Aider and Cursor's 'Composer' mode, which have moved away from full-file regeneration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:53:06.359224+00:00— report_created — created