Skip to main content

QiMeng-PRepair: Precise Code Repair via Edit-Aware Reward Optimization

AuthorsChangxin Ke et al.
Year2026
HF Upvotes7
arXiv2604.05963
PDFDownload
HF PageView on Hugging Face

Abstract

Large Language Models (LLMs) achieve strong program repair performance but often suffer from over-editing, where excessive modifications overwrite correct code and hinder bug localization. We systematically quantify its impact and introduce precise repair task, which maximizes reuse of correct code while fixing only buggy parts. Building on this insight, we propose PRepair, a framework that mitigates over-editing and improves repair accuracy. PRepair has two components: Self-Breaking, which generates diverse buggy programs via controlled bug injection and min-max sampling, and Self-Repairing, which trains models with Edit-Aware Group Relative Policy Optimization (EA-GRPO) using an edit-aware reward to encourage minimal yet correct edits. Experiments show that PRepair improves repair precision by up to 31.4% under fix_1@1, a metric that jointly considers repair correctness and extent, and significantly increases decoding throughput when combined with speculative editing, demonstrating its potential for precise and practical code repair.


Engineering Breakdown

Plain English

This paper tackles a critical problem in LLM-based code repair: models tend to over-edit, making excessive changes that destroy correct code and make bugs harder to find. The authors introduce PRepair, a framework with two components—Self-Breaking generates diverse buggy programs through controlled injection, and Self-Repairing trains models using a new Edit-Aware Group Relative Policy Optimization (EA-GRPO) algorithm that rewards minimal, surgical edits. The key insight is that precise repair should maximize reuse of correct code while fixing only the buggy parts. Experiments demonstrate that PRepair reduces unnecessary edits while maintaining or improving repair accuracy on code generation benchmarks.

Core Technical Contribution

The paper's core contribution is formalizing the over-editing problem in code repair and proposing Edit-Aware Group Relative Policy Optimization (EA-GRPO), a new reinforcement learning approach that explicitly optimizes for minimal edits. Unlike standard RLHF applied to code repair, EA-GRPO incorporates an edit-aware reward function that measures not just correctness but also the proportion of code that remains unchanged—penalizing modifications to regions that were already correct. The Self-Breaking component generates diverse training data by injecting bugs in controlled ways and using min-max sampling to create harder repair scenarios. Together, these innovations shift the optimization objective from "fix the bug" to "fix the bug with minimal changes," which is fundamentally different from prior code repair work that optimized for correctness alone.

How It Works

PRepair operates in two phases. In Self-Breaking, the system takes correct code and injects bugs in a controlled manner—not randomly, but strategically using min-max sampling to create diverse failure cases that represent realistic programming errors. This generates a dataset of buggy-correct code pairs where the delta between them is known. In Self-Repairing, the model is trained with EA-GRPO, a variant of group relative policy optimization that compares multiple candidate repairs and scores them based on two criteria: (1) does the repair make the code correct, and (2) how many edits were needed to achieve that correctness. The edit-aware reward function explicitly measures the edit distance or proportion of unchanged tokens, incentivizing the model to make surgical fixes rather than wholesale rewrites. During inference, the model generates repair candidates and selects the one that balances correctness with minimal changes.

Production Impact

In production code repair systems, this addresses a serious pain point: when an LLM over-edits a file with a simple bug, developers lose confidence in the suggested fix because they can't easily identify what changed or verify the reasoning. By optimizing for minimal edits, PRepair makes generated patches more interpretable and reviewable—developers see a tight diff instead of a rewritten function. This dramatically reduces review friction and increases the likelihood teams will adopt automated repair. The trade-off is additional training cost: Self-Breaking requires generating and curating diverse buggy programs, and EA-GRPO training is more complex than standard supervised fine-tuning. In latency, inference likely improves slightly because the model learns to make direct edits rather than searching through larger edit spaces, though real-time impact depends on implementation. For teams already running LLM-based repair pipelines (e.g., at IDE vendors or DevOps platforms), integrating PRepair requires re-training models and collecting diverse bug-injection data, but the payoff in user trust and patch quality justifies the engineering effort.

Limitations and When Not to Use This

The paper assumes bugs can be reliably injected synthetically via Self-Breaking, but real bugs often involve subtle semantic issues that random injection may not capture—so the synthetic training distribution may not match production bugs encountered in the wild. Edit-aware rewards optimize for token-level or line-level changes, but some correct fixes inherently require reorganizing code or changing function signatures; the approach may over-penalize these necessary edits and produce incorrect patches that preserve too much broken code. The paper doesn't address multi-file or cross-module bugs, where the correct fix may span files and require non-local edits; these scenarios could confuse an edit-minimizing model. Finally, the work is evaluated on standard benchmarks (likely HumanEval or CodeXGLUE variants); generalization to domain-specific code (embedded systems, low-level systems programming) or highly stylized codebases is unexplored, and performance on real open-source bug repositories may differ from synthetic test sets.

Research Context

This work extends recent progress in LLM-based program repair, building on research into fine-tuning with reinforcement learning (particularly RLHF and variants like GRPO) and applying it to a new reward signal: edit minimality. It contrasts with prior work like CodeT5, CodeBERT, and recent neural program repair systems that optimize primarily for correctness without explicitly modeling edit cost. The paper connects to broader research in code generation where researchers have observed that models hallucinate and over-generate—similar to findings in language model scaling and instruction-tuning work. This opens a research direction around reward design for code synthesis: the insight that "less is more" could apply to other code generation tasks like refactoring, test generation, or documentation, where preserving human intent and code structure matters alongside correctness. The work also informs the design of LLM-based tools in IDEs and CI/CD pipelines, where interpretability of changes is as important as raw performance metrics.


:::tip Subscribe Get weekly breakdowns of papers like this in AI Letters - the newsletter for engineers building production AI systems. :::


Back to Research Lab → · Subscribe to AI Letters →

© 2026 EngineersOfAI. All rights reserved.