TL;DR
When AI coding assistants edit code written by other AI models, they often "over-edit," rewriting perfectly functional code just to match their own stylistic preferences. This paper introduces CROCODIL, a reinforcement learning framework that uses a dual similarity and execution reward to train LLMs to make only necessary functional changes. CROCODIL cuts unnecessary edits in half while simultaneously improving compilation and test success rates.
What Problem Does This Paper Address?
Modern software engineering teams rarely rely on a single AI assistant. Developers frequently switch between different Large Language Models (LLMs) like Qwen, Llama, or Claude based on task demands, latency, or cost. This creates a "cross-editing" ecosystem where one model is tasked with modifying code originally generated by another.
Because different LLMs are trained on different datasets, they develop distinct stylistic preferences. The authors discover that when an LLM encounters "foreign" code, it tends to aggressively over-edit—performing cosmetic refactors (such as renaming variables or restructuring loops) that have nothing to do with the requested task. This excessive editing complicates code reviews, inflates test suites, and introduces bugs. Crucially, the authors demonstrate that simple prompt engineering (e.g., telling the model to "make the smallest edit possible") cannot reliably fix this behavior.
Methods
To curb excessive editing while preserving functional correctness, the authors propose CROCODIL (Cross-model Code Editing with LLMs). The framework fine-tunes models using Group Relative Policy Optimization (GRPO) driven by a novel composite reward function:
$$\text{Reward} = R_{\text{sim}} \times R_{\text{exec}}$$
- Similarity Reward ($R_{\text{sim}}$): This component penalizes large changes. It measures character- and line-level modifications made by the model and normalizes them against the size of the developer's original pull request (PR). If the model edits code outside the scope of the requested fix, its reward drops sharply.
- Execution Reward ($R_{\text{exec}}$): This component ensures the code works. It scores whether the edited code compiles (build success) and passes unit tests, specifically tracking both regressions (breaking existing functionality) and the successful introduction of new, requested behaviors.
By multiplying these two rewards, the model is strongly incentivized to find the most surgically precise, minimal edit that satisfies the test suite.
Datasets
The authors built a novel evaluation and training pipeline based on real-world GitHub pull requests for popular Rust crates:
- The Corpus: They collected 4,514 PRs spanning 8,235 functions (limited to 20–200 lines of code) that possessed robust unit test suites.
- Cross-Edit Simulation: To generate stylistically diverse code, they used five different LLMs (Qwen3.5 35B A3B, GPT-OSS 20B, Olmo3 7B, Olmo3.1 32B, and Haiku 4.5) to re-implement the pre-edit functions. This yielded a rich dataset of functionally identical but stylistically distinct code bases.
- Training Set: A separate pool of repositories was used to gather 355 cross-edit tasks for training and 39 for validation, ensuring zero project-level overlap with the evaluation set.
Key Insights and Ideas
- The "Foreign Code" Tax: Open-weight models edit their own code up to 14% less than they edit code written by other models. LLMs possess an inherent bias toward their own training distribution and will actively try to "correct" foreign code to match their own conventions.
- Prompting Fails: Adding strict system guidelines to minimize edits actually worsened performance or increased edit sizes for certain models (like Olmo3 7B). The urge to over-edit is deeply baked into the model's weights, requiring post-training alignment rather than prompt engineering.
- Less is More for Correctness: Restricting an LLM's editing scope naturally prevents it from introducing unrelated bugs. By forcing the model to stay in scope, it avoids "hallucinating" unrequested helper functions or extra structs.
Key Results
The authors evaluated their framework by training Olmo3 7B, which was initially the most aggressive over-editor among the open-weight models.
- Edit Size Halved: Across all open-weight implementors, CROCODIL roughly halved the Levenshtein edit distance compared to the base model.
- Higher Success Rates: Surgically precise editing translated directly to better code. When editing Qwen3.5-generated code, the CROCODIL-trained Olmo3 7B boosted its compilation (build) rate from 32.67% to 41.46% and its all-tests pass rate from 16.92% to 19.07%.
- Outperforming Strict Prompts: CROCODIL consistently achieved smaller edit sizes and higher test pass rates than the baseline model configured with a "strict" minimal-edit prompt.
Limitations and Future Work
- Single Language Focus: The entire framework and corpus are currently limited to Rust. Languages with weaker typing or highly flexible grammar (like Python or JavaScript) might exhibit different cross-editing dynamics.
- Function-Level Scope: The dataset decomposes PRs into single-function edit tasks. In practice, software engineering edits often span multiple functions and files, which CROCODIL does not yet address.
- Model Scale Constraints: Due to budget limitations, post-training was only applied to a 7B parameter model (Olmo3). Testing whether this framework scales effectively to massive state-of-the-art closed-source models remains an open avenue for future research.
Summary updated