Accelerating Automatic Program Repair with Dual Retrieval-Augmented Fine-Tuning and Patch Generation on Large Language Models

Hanyang Guo, Xiaoheng Xie, Hong-Ning Dai, Peng Di, Yu Zhang, Bishenghui Tao, Zibin ZhengarXiv 2025 · DOI

Abstract

Automated Program Repair (APR) is critical for reducing software maintenance costs, which can consume up to 90% of total maintenance resources. While Large Language Models (LLMs) have advanced the field, they often struggle with contextual noise and structural ignorance in retrieval-augmented settings. This paper introduces SelRepair, a framework that combines full-parameter fine-tuning of a StarCoder2-7B model with a dual retrieval strategy targeting both code semantics and structural syntax (ASTs). By implementing a "selection gate" to filter irrelevant context, SelRepair achieves state-of-the-art accuracy on multiple benchmarks while simultaneously reducing inference latency.

Introduction

Traditional APR methods rely on rigid manual templates or rules, which lack the flexibility needed for complex software bugs. Modern LLMs offer a promising alternative but face three major hurdles:

  1. Contextual Noise: Standard Retrieval-Augmented Generation (RAG) often retrieves "similar" code that is irrelevant, confusing the model.
  2. Structural Blindness: Most RAG systems treat code as natural language, ignoring the underlying logic structures like Abstract Syntax Trees (ASTs).
  3. Efficiency: Long, noisy prompts lead to high latency and "information loss" during inference.

Methodology

SelRepair moves beyond simple prompt engineering toward an integrated architecture designed for code-specific nuances. The framework consists of three primary components:

  • Dual Patch Retriever: This system utilizes two specialized retrievers. The Semantics Retriever (SR) matches code based on textual meaning, while the Static Structure and Dependency Retriever (SSDR) uses a custom AST traversal algorithm to convert code structure into a sequence the model can interpret, capturing logic rather than just keywords.
  • RAG Selection Gate: To prevent prompt bloating, a similarity threshold is applied. If a retrieved bug-fix pair is not sufficiently similar to the target bug, it is discarded, keeping the prompt concise.
  • Full-Parameter Fine-Tuning: Unlike Parameter-Efficient Fine-Tuning (PEFT/LoRA), SelRepair performs full fine-tuning on a StarCoder2-7B base, allowing the model to deeply learn specific bug-fix patterns.
The SelRepair architecture, highlighting the Dual Patch Retriever, RAG Selection Gate, and the fine-tuning pipeline.

Evaluation

The researchers evaluated SelRepair across several diverse benchmarks:

  • Tufano Datasets: Java subsets categorized by code length.
  • VulRepair: A C/C++ dataset focused on security vulnerabilities.
  • Defects4J: A classic benchmark for Java program repair.
  • Enterprise Dataset: A real-world benchmark of 200 bug-fix pairs from a software company, focusing on "bad practices" and style issues.

Key Results and Insights

SelRepair consistently outperformed state-of-the-art (SOTA) models like RAP-Gen and generalized giants like GPT-4o.

  • Accuracy: It achieved 26.29% Exact Match (EM) on Tufano Subset 1 and 17.64% on Subset 2, significantly surpassing previous methods.
  • Efficiency: The selection gate reduced average input lengths, leading to an inference time reduction of 6.42% to 15.96% compared to standard RAG.
  • Structure Matters: Encoding ASTs into the retrieval process allowed the system to find much more relevant "fix templates" than textual matching alone.
Performance comparison of SelRepair against SOTA models across Tufano and VulRepair benchmarks.

Conclusion

SelRepair demonstrates that for specialized tasks like APR, full-parameter fine-tuning combined with structure-aware retrieval significantly outperforms general-purpose LLM prompting. While currently focused on method-level fixes, future work aims to expand the system to handle cross-module bugs and dynamic similarity thresholds to further optimize performance and resource intensity.

Summary updated

BibTeX
@misc{guo2025accelerating,
  author = {Hanyang Guo and Xiaoheng Xie and Hong-Ning Dai and Peng Di and Yu Zhang and Bishenghui Tao and Zibin Zheng},
  title = {{Accelerating Automatic Program Repair with Dual Retrieval-Augmented Fine-Tuning and Patch Generation on Large Language Models}},
  year = {2025},
  eprint = {2507.10103},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.10103},
}
Figure