Less is More: Adaptive Program Repair with Bug Localization and Preference Learning

Zhenlong Dai, Bingrui Chen, Zhuoluo Zhao, Xiu Tang, Sai Wu, Chang Yao, Zhipeng Gao, Jingyuan Chen · 2025

Read Less is More: Adaptive Program Repair with Bug Localization and Preference Learning by Zhenlong Dai, Bingrui Chen, Zhuoluo Zhao, Xiu Tang, Sai Wu, Chang Yao, Zhipeng Gao, Jingyuan Chen (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2503-06510.txt.

Introduction

Zhenlong Dai and co-authors fix code bugs with the smallest change that works in a 2025 paper. Most auto repair work chases a right fix and skips how far the fix drifts from the flawed code. Wide drift can break trust and add risk, so the team sets a new task around tight fixes.

Their two-stage tool first finds the bug site with a self-taught locator. It then writes the patch with a modifier trained to stay close to the source. Tests beat a set of rivals by a wide gap, the team reports.

Catalog record

CREATORZhenlong Dai, Bingrui Chen, Zhuoluo Zhao, Xiu Tang, Sai Wu, Chang Yao, Zhipeng Gao, Jingyuan Chen
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE60 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2503-06510

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Less is More: Adaptive Program Repair with Bug Localization and Preference Learning Zhenlong Dai, Bingrui Chen, Zhuoluo Zhao, Xiu Tang, Sai Wu, Chang Yao, Zhipeng Gao, Jingyuan Chen Abstract Automated Program Repair (APR) is a task to automatically generate patches for the buggy code. However, most research focuses on generating correct patches while ignoring the consistency between the fixed code and the original buggy code. How to conduct adaptive bug fixing and generate patches with minimal modifications have seldom been investigated. To bridge this gap, we first introduce a novel task, namely AdaPR ( Ada ptive P rogram R epair). We then propose a two-stage approach 𝑨 ​ 𝒅 ​ 𝒂 ​ 𝑷 ​ 𝒂 ​ 𝒕 ​ 𝒄 ​ 𝒉 ​ 𝒆 ​ 𝒓 \boldsymbol{AdaPatcher} ( Ada ptive Patch G e nerato r ) to enhance program repair while maintaining the consistency. In the first stage, we utilize a Bug Locator with self-debug learning to accurately pinpoint bug locations. In the second stage, we train a Program Modifier to ensure consistency between the post-modified fixed code and the pre-modified buggy code. The Program Modifier is enhanced with a location-aware repair learning strategy to generate patches based on identified buggy lines, a hybrid training strategy for selective reference and an adaptive preference learning to prioritize fewer changes. The experimental results show that our approach outperforms a set of baselines by a large margin, validating the effectiveness of our two-stage framework for the newly proposed AdaPR task. The code and dataset are available at https://github.com/zhenlongDai/AdaPatcher . Figure 1: Example of AdaPR. The adaptive repaired code is correct and minimizes code modifications. Introduction As software systems become more and more prevalent in everyday life, software bugs also become inevitable. These software bugs can potentially cause security issues or even financial losses ( Shahriar and Zulkernine 2012 ; Dissanayake et al. 2022 ; Krasner 2021 ) . Usually, developers need to fix these buggy codes manually by spending a significant amount of time and effort. To alleviate developers’ burden for bug fixing, Automated Program Repair (APR) has been introduced to automatically generate patches given the original buggy code. APR techniques take a buggy code and a correct specification as input, aiming to generate the fixed program satisfying the given specifications. Nowadays, inspired by the promising performance of Large Language Models (LLMs) in code generation ( Jiang et al. 2024 ; Li et al. 2023 ) and code understanding ( Li et al. 2022 ; Chen et al. 2021 ) , researchers have applied LLMs to perform the APR task ( Ye et al. 2022 ; Fan et al. 2023 ; Jin et al. 2023 ) and demonstrated remarkable results. However, most studies focus on generating correct patches, the consistency between the fixed code and the buggy code is often ignored and cannot be guaranteed, which greatly hinders the practical use of LLM for bug fixing. Consider the practical scenario in Fig. 1 as an example, Alice is a developer, she implemented the Solution class to achieve her goal. Nonetheless, her program failed to pass the tests which indicates potential bugs within her written code. The error message suggested “AssertionError: Expected output is 4, but the received output is 3”. Alice tried to use LLM to help her fix this bug by feeding LLMs with the original buggy code and error message. However, the patch generated by LLMs overwrote most code lines in function ( e.g. , colored in blue). It is difficult for Alice to accept this patch because the generated code is too far from her original written one. The extensive modifications made by LLMs make the fixed code hard to trace and understand. As a result, Alice refused to integrate this patch into her codebase. To address this gap, we propose a new task in this paper, namely Adaptive Program Repair , denoted as AdaPR . Different from APR, AdaPR not only aims to generate “ correct ” patches for the buggy code, but also aims to generate “ consistent ” patches with minimal modifications. More formally, given the buggy code and the correct specifications ( e.g. , failed test cases), AdaPR adaptively fixes the buggy program with the least possible changes to satisfy the given specification. For example, in Fig. 1 , Alice can fix this bug by only changing one line of code, i.e. , from c = min(c, j - i) to c = min(c, j - i + 1) . This newly generated patch aligns with her design intentions and existing code structures, the consistency between the fixed code and the original buggy code makes Alice easy to understand the code changes and increases her confidence of this fix pattern. Consequently, Alice accepted this patch without a doubt and incorporated it into her codebase. So far, the existing studies focus on generating correct patches, there is no research investigating how to adaptively fix buggy code with minimal modifications. AdaPR is a non-trivial task regarding the following key challenges: (i) Where to fix: Identifying the precise location(s) where the bug has been introduced is challenging. When a bug occurs, different parts of the program may exhibit abnormal behaviors according to the bug. To fix the bug adaptively, AdaPR first requires locating the root cause of the problem and pinpointing the exact buggy line(s) that need modifications. (ii) How to fix: Generating patches with minimal modifications is challenging. Because LLMs are typically trained on general programming corpus ( e.g. , comment-code pairs, question-solution pairs), LLMs’ primary goal is to generate correct and functional code. Regarding program repair, LLMs tend to repair a program by rewriting it from scratch without considering the existing code structure or semantics. AdaPR requires the patches to be both correct and consistent. In other words, the generated patches should involve as few modifications as possible while still addressing bugs effectively. How to fix the program incrementally and adaptively is another challenge in this work. To tackle the above challenges, we propose a novel two-stage approach named \boldsymbol{AdaPatcher} , which is designed to patch a buggy program correctly and consistently. To address the first where to fix challenge, we propose a diff-based component, namely Bug Locator, to pinpoint the exact bug locations within the buggy code. Specifically, for a passed program and a failed program written by the same developer, we first record the run-time values of different variables respectively. Following that, we teach LLM to do self-debug learning to identify bug locations, i.e., the LLM is guided to debug and analyze the differences ( e.g. , code deletions, modifications) between the passed program and the failed program and finally determine which code line causes the test failures. To address the second how to fix challenge, we design a Program Modifier component for our second stage. The Program Modifier is enhanced with three techniques to ensure the consistency and correctness of the fixed program and the original buggy program. Particularly, to avoid LLMs repairing the program from scratch, we leverage location-aware repair learning to generate patches based on the identified buggy lines. To reduce the negative effects of the incorrect bug locations, we propose a hybrid training strategy that enables the Program Modifier to selectively reference

Read the complete text