Skip to main content
QUICK REVIEW

[Paper Review] RAP-Gen: Retrieval-Augmented Patch Generation with CodeT5 for Automatic Program Repair

Weishi Wang, Yue Wang|arXiv (Cornell University)|Sep 12, 2023
Software Engineering ResearchComputer Science4 citations
TL;DR

RAP-Gen is a retrieval-augmented framework for automatic program repair that enhances CodeT5-based patch generation by retrieving relevant fix patterns from a codebase. By integrating a hybrid lexical-semantic retriever and a unified CodeT5 backbone, RAP-Gen improves repair accuracy across JavaScript and Java benchmarks, achieving state-of-the-art results, including a 54.15% repair rate on TFix and 15 additional fixes on Defects4J compared to prior methods.

ABSTRACT

Automatic program repair (APR) is crucial to reduce manual debugging efforts for developers and improve software reliability. While conventional search-based techniques typically rely on heuristic rules or a redundancy assumption to mine fix patterns, recent years have witnessed the surge of deep learning (DL) based approaches to automate the program repair process in a data-driven manner. However, their performance is often limited by a fixed set of parameters to model the highly complex search space of APR. To ease such burden on the parametric models, in this work, we propose a novel Retrieval-Augmented Patch Generation framework (RAP-Gen) by explicitly leveraging relevant fix patterns retrieved from a codebase of previous bug-fix pairs. Specifically, we build a hybrid patch retriever to account for both lexical and semantic matching based on the raw source code in a language-agnostic manner, which does not rely on any code-specific features. In addition, we adapt a code-aware language model CodeT5 as our foundation model to facilitate both patch retrieval and generation tasks in a unified manner. We adopt a stage-wise approach where the patch retriever first retrieves a relevant external bug-fix pair to augment the buggy input for the CodeT5 patch generator, which synthesizes a ranked list of repair patch candidates. Notably, RAP-Gen is a generic APR framework that can flexibly integrate different patch retrievers and generators to repair various types of bugs. We thoroughly evaluate RAP-Gen on three benchmarks in two programming languages, including the TFix benchmark in JavaScript, and Code Refinement and Defects4J benchmarks in Java, where the bug localization information may or may not be provided. Experimental results show that RAP-Gen significantly outperforms previous state-of-the-art approaches on all benchmarks, e.g., repairing 15 more bugs on 818 Defects4J bugs.

Motivation & Objective

  • To reduce the burden on parametric deep learning models in automatic program repair by incorporating explicit, external fix patterns.
  • To improve repair accuracy by retrieving relevant bug-fix pairs from a codebase using a language-agnostic, hybrid retrieval mechanism.
  • To unify patch retrieval and generation within a single framework using CodeT5 as a foundation model.
  • To demonstrate the effectiveness of retrieval-augmented generation in diverse APR benchmarks across JavaScript and Java.
  • To validate that developer-like debugging behavior—referring to prior fixes—can be effectively modeled and leveraged in APR.

Proposed method

  • A hybrid patch retriever is designed to perform both lexical and semantic matching on raw source code without code-specific features, enabling language-agnostic retrieval.
  • The retriever identifies the most relevant bug-fix pair from a codebase of historical patches to serve as a guiding signal for the generator.
  • CodeT5 is fine-tuned as a unified model for both retrieval and generation, enabling end-to-end training with shared representations.
  • A stage-wise framework first retrieves a relevant fix pattern, then augments the buggy input with it before generating candidate patches.
  • The framework is generic and supports integration with various retrievers and generators, enabling flexible deployment across bug types and languages.
  • Retrieval is performed using a top-k strategy, and the retrieved fix pattern is concatenated with the buggy code to guide the generation process.

Experimental results

Research questions

  • RQ1Can retrieval of relevant historical fix patterns improve the performance of deep learning-based program repair models?
  • RQ2How does a retrieval-augmented approach compare to purely parametric models in terms of repair accuracy across diverse benchmarks?
  • RQ3Which types of fix patterns (e.g., insert block, delete statement) are most effective in guiding repair generation?
  • RQ4To what extent does the retrieval mechanism reflect real-world developer debugging behaviors?
  • RQ5Can the framework generalize across programming languages and bug types without requiring code-specific features?

Key findings

  • RAP-Gen achieves a 54.15% repair accuracy on the TFix benchmark in JavaScript, a 4.45% absolute improvement over the T5-large baseline (49.70%).
  • On the Defects4J benchmark in Java, RAP-Gen repairs 15 more bugs than the previous SoTA method, demonstrating significant gains in real-world repair scenarios.
  • The hybrid retriever effectively retrieves relevant fix patterns, with P13 ('insert an existing block') and P14 ('delete statement') being the most effective fix patterns across 39 hard-to-repair bugs.
  • Retrieval from rule-based fix patterns (e.g., from SelfAPR) improves CodeT5’s performance on 39 previously unfixable Defects4J bugs, confirming the value of retrieval-guided generation.
  • The framework maintains strong performance even when bug localization is not provided, indicating robustness in practical settings.
  • Ablation studies confirm that both lexical and semantic matching in the retriever contribute significantly to retrieval quality and downstream repair accuracy.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.