How Should Diffusion Language Models Edit Code?

Xijia Tao, Ziru Liu, Shansan Gong, Jiacheng Ye, Kecheng Chen, Zirui Wu, Lin Zheng, Xinyu Fu, Rui Liu, Lingpeng KongarXiv 2026

TL;DR

Masked diffusion language models (MDLMs) are remarkably good at filling in code gaps when they know exactly where to look, but they struggle to autonomously decide where those gaps should be. This paper identifies a significant "composition gap" in code editing: while these models can coordinate complex, multi-site changes if given perfect locations, their performance plummets when they must predict the edit boundaries themselves.

What Problem Does This Paper Address?

AI coding assistants don't just write code from scratch; they edit existing programs. This requires a model to perform three tasks simultaneously: locate the necessary changes, generate new content, and preserve the rest of the file.

While Masked Diffusion Language Models (MDLMs) are naturally suited for "infilling" (filling in missing tokens using surrounding context), they don't come with pre-defined masks. The authors investigate the edit interface—the contract between the model and the runtime that determines how much structure the model must predict versus how much the runtime preserves. They specifically look at why models that are powerful at infilling often fail as autonomous editors.

Methods

The researchers compared four distinct editing interfaces:

  1. Whole-file rewrite: The model regenerates the entire file.
  2. Search-and-replace: The model identifies a specific "old" string and provides a "new" replacement.
  3. Locate-then-infill: A two-stage process where the model first predicts line-based "headers" (e.g., replace lines 3-4) to create a scaffold (a file with holes), and then a second stage fills those holes.
  4. Token-level editing: The model makes keep/delete/insert decisions for every individual token.

To isolate why models fail, they used oracle diagnostics. By providing the model with "gold" (perfect) edit locations and boundaries, they could measure the model's pure infilling capability separately from its ability to locate changes.

Four interfaces assign different structural decisions to the model and preservation to the runtime.

Datasets

  • EditPackFT (Python subset): Used for fine-tuning the models (approx. 20,000 examples).
  • CanItEdit: The primary evaluation benchmark, consisting of Python problems requiring both single-span and complex multi-span edits.
  • HumanEval-Infilling: Used for a placement probe to compare middle-of-file vs. end-of-file generation.
  • FineEdit Wiki: A sentence-level natural language editing probe used to see if the findings generalize beyond code.

Key Insights and Ideas

  • The Composition Gap: There is a massive performance drop when moving from "gold" locations to predicted ones. For multi-span edits, a model given perfect locations achieved a 25.4% pass rate, which dropped to 10.6% when it had to predict the locations itself.
  • The "Old-Visible" Advantage: Infilling is significantly more successful when the model can see the "old" code it is replacing as read-only context. This helps the model recover identifiers and maintain control flow.
  • The Goldilocks Problem: Successful editing requires a delicate balance. If a model misses even one required edit site, the change fails ("catastrophic" drop). However, if the model makes the "holes" too wide to ensure coverage, it forces itself to regenerate perfectly good code, which introduces new opportunities for errors.
A worked example of the locate-then-infill process with old-visible conditioning.
  • Localization is the Bottleneck: The study suggests that the "locator" (deciding where to edit) is the primary weak link, not the "infiller" (generating the code). Even small boundary errors (shifting a hole by one line) can be more damaging than adding an entirely unnecessary extra hole.

Key Results

  • Oracle Performance: On multi-span CanItEdit tasks, providing gold locations allowed the model to reach 25.4% pass@1.
  • Autonomous Performance: The best autonomous interface (Search-and-replace) only reached 11.3% pass@1 on the same tasks.
  • Sensitivity to Boundaries: Expanding the edit boundaries by just one line (forcing the model to regenerate one extra line of correct code) caused performance to drop from 25.4% to 7.7%.
  • Wiki Probe: The same qualitative gap appeared in natural language editing, suggesting this is a fundamental challenge for diffusion models, not just a quirk of programming languages.
Multi-span pass@1 under controlled scaffold corruptions shows that complete coverage alone is insufficient.

Limitations and Future Work

The authors acknowledge that their study focused on single-file Python edits. They did not test repository-level or multi-file editing, which are common in real-world software engineering. Additionally, while they tested several interfaces, different "adaptive-length" decoding mechanisms might show different sensitivities to boundary errors.

Future work could focus on building more robust "locators" or developing infilling techniques that are less sensitive to being forced to regenerate unchanged code. The paper concludes that simply having a "strong infiller" is not enough; the interface must be designed to expose all necessary changes while strictly limiting the regeneration of unchanged code.

Summary updated

BibTeX
@misc{tao2026how,
  author = {Xijia Tao and Ziru Liu and Shansan Gong and Jiacheng Ye and Kecheng Chen and Zirui Wu and Lin Zheng and Xinyu Fu and Rui Liu and Lingpeng Kong},
  title = {{How Should Diffusion Language Models Edit Code?}},
  year = {2026},
  eprint = {2609.38257},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.38257},
}
Figure