AI Research
Diffusion Models Struggle to Find Where Code Edits Should Go
Masked diffusion language models can generate code changes well when given exact edit locations, but falter when forced to identify those locations themselves.
Researchers studying how diffusion-based language models handle code editing have identified a fundamental weakness: the models excel at producing new code content when told exactly where to make changes, but their performance collapses when they must first locate those change points on their own.
The Editing Interfaces Tested#
The investigation examined four distinct approaches to code editing through masked diffusion models:
- Whole-file rewriting — regenerating an entire code file from scratch
- Search-and-replace — finding specific text patterns and replacing them
- Locate-then-infill — predicting edit locations, then generating replacement content
- Token-level editing — modifying individual tokens in context
The Location Problem#
Using the CanItEdit benchmark, the researchers uncovered a "composition gap" between two scenarios. When the exact regions needing edits were provided to the model, diffusion approaches generated coordinated, multi-part changes effectively. However, asking the model to simultaneously predict where edits belonged and what they should be produced dramatically worse results.
Having access to the original intact code helped the model fill multiple sections of a file, yet this advantage did not extend to identifying which sections required editing in the first place. Two distinct challenges emerged: covering every necessary change and setting precise boundaries around each one. Skipping a required region meant that change never happened. Conversely, expanding edit regions too far to guarantee coverage forced the model to regenerate surrounding code that hadn't changed—a burden that sharply degraded success rates.
Beyond Code#
The pattern held for non-code text as well. A parallel experiment editing sentences on Wikipedia revealed the same qualitative gap between scenarios where edit locations were known versus where they had to be inferred.
Why It Matters#
The findings challenge assumptions about code generation capability. Strong ability to fill in missing content alone does not guarantee reliable editing workflows. The interface and approach to specifying editable regions fundamentally shapes whether those models can complete the task successfully.