AI
LLMs Rewrite Too Much Code When Fixing Bugs, Study Finds
Research reveals that large language models make unnecessary changes when repairing code, but targeted instructions and reinforcement learning can help keep edits minimal.
Large language models have become popular tools for automatically repairing buggy code, yet a new study highlights a significant blind spot in their approach: they tend to rewrite far more than necessary to fix a problem.
Researchers set out to investigate over-editing—the phenomenon where AI models introduce changes that go beyond what's needed to correct a bug. They found the problem widespread across leading models, including GPT-5.5, and that even when fixes work correctly, they often carry hidden costs in terms of code readability and maintainability.
The Problem with Excessive Rewrites#
The team constructed a rigorous evaluation framework using 400 problems from BigCodeBench. By deliberately introducing controlled bugs at the code structure (AST) level into reference solutions, they could compare each model's repair against a known minimal patch. Their results showed that high accuracy doesn't guarantee elegant solutions: models frequently passed their tests while making significantly larger edits than required and adding unnecessary cognitive complexity to the code.
On average, repairs exceeded the minimal edit distance by 0.195 characters (measured using Levenshtein distance), meaning models changed roughly 20% more of the code than a minimal repair would have.
Techniques to Reduce Over-Editing#
The researchers tested several strategies to tame this behavior. A simple preservation instruction—essentially telling the model to keep changes minimal—proved surprisingly effective, cutting excess edit distance down to 0.131 and reducing added complexity by 26.6%. Interestingly, this gain also boosted overall pass rate by 2.3 percentage points.
However, just giving models more computing budget or using larger models did not automatically solve the problem. Instead, the team found that teaching minimal editing during training produced better results.
Learning Better Editing Habits#
Two post-training approaches were compared:
- Supervised fine-tuning learned from examples but tended to overfit to the specific corruption patterns it had seen during training, limiting its ability to generalize.
- Reinforcement learning achieved a better balance, offering superior out-of-domain edit fidelity while maintaining strong repair performance.

