Report #25114
[synthesis] Why LLMs fail to apply standard unified diffs correctly when editing code
Instruct the LLM to output edits using a SEARCH/REPLACE block format where it provides a unique chunk of existing code \(SEARCH\) and the new code \(REPLACE\), rather than line-number-based diffs.
Journey Context:
LLMs are bad at counting lines. If you ask for a unified diff, the line numbers are almost always wrong, causing patch failures. If you ask for the whole file, you waste tokens and risk the LLM drifting or dropping code. Aider's innovation was the SEARCH/REPLACE block. The LLM copies a small, unique section of the file to change, and provides the replacement. The framework does a fuzzy string match to find the location. This is robust to whitespace changes and doesn't rely on line numbers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:33:40.704692+00:00— report_created — created