Abstract
This paper introduces Next Edit Prediction (NEP), a novel AI coding task designed to move beyond reactive autocomplete and chat-based interfaces. By analyzing a developer's recent interaction history, NEP models proactively predict both the location and content of the next logical code modification. We present a robust pipeline for curating high-quality edit sequences from real-world repository data and demonstrate that fine-tuned open-source models can rival or surpass large-scale general-purpose models in anticipating complex, multi-location changes.
1. Introduction
Modern AI coding assistants primarily operate in two modes: low-latency autocomplete (Fill-in-the-Middle) and high-latency chat-based agents. While autocomplete is fast, it is often restricted to the current cursor position. Conversely, chat-based agents can perform complex refactoring but require developers to context-switch and explicitly describe their intent in natural language.
Next Edit Prediction (NEP) bridges this gap by enabling proactive collaboration. Instead of waiting for a prompt, the system infers developer intent from the sequence of past edits. For example, if a developer renames a class in its definition, an NEP-capable model would immediately suggest the corresponding updates in the constructor and dependent methods.
2. The NEP Framework
We frame NEP as a sequence-to-sequence problem where the model receives the history of recent edits and the current state of the code to generate the next modification. To structure this input, we introduced four specialized tokens:
<|original_code|>: The state of the file before the current session.<|edits_diff|>: The sequence of edits performed so far.<|current_version|>: The current state of the code.<|next_version|>: The target output representing the predicted next edit.
This formulation allows the model to "see" the trajectory of changes, making it easier to identify patterns like API migrations or systematic identifier renaming.
3. Dataset Construction and Curation
Training models for NEP requires high-quality, semantically coherent edit sequences. We developed a specialized pipeline to extract these from CommitPackFT, a large-scale dataset of GitHub commits.
3.1 Curation Pipeline
The pipeline involves three critical stages: filtering, labeling, and formulation. We applied strict filters to ensure commits contained multiple small, additive chunks within a limited scope, representing logical steps in a single task.
3.2 Semantic Filtering
To remove "noisy" data—such as commits that combine unrelated bug fixes and feature additions—we utilized GPT-4o mini as a binary classifier. This step ensures that the training data consists of "positive examples" where edits follow a clear, logical flow. We also established a human-verified benchmark of 210 samples from top-starred repositories to serve as a gold standard for evaluation.
4. Experimental Results and Insights
We fine-tuned several open-source models, including Qwen2.5-Coder, CodeGemma, and Codestral, using LoRA. Performance was measured across several dimensions: Exact Match, Position Match (correctly identifying the edit location), and LLM-as-a-Judge (semantic correctness).
4.1 Fine-Tuning Gains
Supervised Fine-Tuning (SFT) proved transformative. For instance, Qwen2.5-Coder-7B improved from near-zero baseline performance to a 49.05% LLM-as-a-Judge score. Notably, fine-tuned smaller models like CodeGemma-7B outperformed massive general-purpose models like GPT-4o on this specific task, highlighting the efficiency of task-specific training.
4.2 Localization vs. Generation
Our results indicate that models are significantly better at finding the correct location for an edit than generating the perfect content. Claude 3.5 Haiku, for example, achieved a 63.8% Position Match but only a 17.1% Exact Match. This suggests that future research could benefit from decoupling the localization and generation components of the NEP task.
5. Conclusion and Future Work
Next Edit Prediction represents a shift toward more intuitive, proactive AI pair programming. While current models assume a linear editing flow, future work will focus on non-linear editing patterns and incorporating cross-file context. Additionally, developing "confidence-based refusal" mechanisms will be essential to ensure that AI suggestions remain helpful without becoming intrusive.
Summary updated