Report #70820
[synthesis] LLM-generated code edits are applied with simple string replacement or diff patching — how do production AI coding tools actually apply edits to real files?
Treat edit application as its own specialized problem requiring a dedicated model or fuzzy-matching algorithm. Never assume LLM-generated diffs apply cleanly to current file state. Build a reconciliation layer between generation and application.
Journey Context:
The naive approach — LLM generates a diff, you apply it — fails constantly in practice because the model's view of the file is stale, whitespace differs, or the model hallucinated surrounding context. Cursor dedicates an entire separate model \('apply model'\) specifically for fuzzy-matching generated edits to actual file content. Aider uses a search-and-replace block approach with fallback strategies. The synthesis across these: edit application is where most user-visible failures occur, not generation. A brilliant code suggestion that can't be applied is worse than a mediocre one that can. The non-obvious architectural requirement: the apply layer must handle indentation normalization, partial context matching, and multi-hunk coordination. Cursor's apply model is specifically trained/fine-tuned for this, not just a general-purpose model. The tradeoff: a dedicated apply model adds latency \(extra inference\) and engineering complexity. But without it, edit success rates in real codebases drop to unusable levels, especially for large files or files modified since the model's context was built.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:27:13.517771+00:00— report_created — created