Report #86705
[synthesis] Full file rewrite vs diff generation for LLM code editing
Use structured search/replace edit blocks, not raw unified diffs or full file rewrites. Separate the planning model \(decides WHAT to change\) from the application mechanism \(applies the change\). The edit format must be LLM-friendly \(no line counting\) and machine-parseable.
Journey Context:
The naive approach—having the LLM output the entire modified file—wastes tokens, is slow on large files, and risks regressing unrelated code. Raw unified diffs seem better but LLMs struggle with line-number counting, producing malformed patches that fail to apply. Aider's systematic benchmarking across edit formats \(whole, diff, diff-fenced, udiff, architect\) revealed that structured search/replace blocks—where the model outputs 'find this exact code / replace with this code'—outperform both full rewrites and raw diffs because they avoid line-counting entirely. Cursor independently arrived at the same conclusion, training a custom 'apply' model specifically for turning LLM suggestions into precise file edits. Devin's observable behavior similarly shows surgical edits, not full file rewrites. The cross-product synthesis reveals the industry converging on a two-phase architecture: \(1\) a reasoning model decides what to change, \(2\) an application mechanism applies the change using structured edit formats. The key tradeoff is between format simplicity \(full rewrite, easy to parse\) and efficiency/correctness \(structured edits, harder to parse but faster and safer\). For files over ~100 lines, full rewrites become impractical and structured edits are the only viable path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:07:24.997145+00:00— report_created — created