Software workflows · Research feature

DynaFix Uses Real-Time Execution Data to Improve Code Repair Accuracy

Results on Defects4J-Trans indicate higher repair retention and reduced token use compared to ReinFix.

Adapted from research by Zhili Huang, Ling Xu, Chao Liu and colleagues.

arXiv preprint revision · 2026-11-22 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

These dynamic signals are continuously fed back into the repair process to refine patch generation, improving accuracy and robustness. The system outperforms existing baselines on Defects4J by repairing 236 bugs with GPT-4, including 23 previously unsolved cases, and shows better performance under code transformations. Results on Defects4J-Trans indicate higher repair retention and reduced token use compared to ReinFix. The evidence shows that iterative use of execution-level data enhances repair effectiveness and efficiency.

Introduction

Software systems underpin nearly all critical modern domains, including manufacturing, aerospace, energy, and healthcare. As these systems grow in scale and complexity, software bugs inevitably accumulate, posing serious threats to system reliability, security, and maintainability. Program repair therefore plays a crucial role throughout the software lifecycle. Prior studies indicate that developers spend approximately 35%–50% of their time on manual bug diagnosis and repair. To alleviate this substantial overhead, researchers have extensively explored Automated Program Repair (APR) techniques, which aim to autonomously generate patches to correct faulty code.

Early APR approaches can be broadly categorized into heuristic-based, constraint-based, and template-based methods. Heuristic-based approaches explore large patch spaces but often suffer from scalability and efficiency issues as the search space expands. Constraint-based methods offer formal guarantees but typically struggle to scale to complex programs. Template-based methods, a prominent class of traditional APR methods, rely primarily on manually curated or mined templates. While effective in specific scenarios, their applicability is constrained by template coverage and construction cost. More recently, deep learning–based APR methods have gained prominence by framing patch generation as a neural machine translation (NMT) task, trained on large corpora of bug–fix pairs. Despite their promising results, these methods remain highly sensitive to training data quality and distribution, and their repair effectiveness drops substantially when encountering previously unseen bug patterns or code structures.

The rapid advancement of large language models (LLMs) has further reshaped the landscape of APR. Many recent approaches adopt an iterative repair paradigm, where LLMs generate candidate patches and refine them based on feedback from prior repair attempts. Beyond purely static inputs, several studies have explored incorporating dynamic execution information, such as runtime traces and behavioral signals, to improve fault localization and patch generation. While these approaches achieve state-of-the-art (SOTA) performance, they still suffer from two fundamental limitations.

To address these limitations, we propose DynaFix, an LLM-based automated program repair framework that continuously updates and exploits execution-level dynamic information within a closed-loop iterative repair process. First, DynaFix collects fine-grained execution-level dynamic information, including variable states, control-flow paths, and call stacks, providing essential behavioral evidence for understanding program failures and identifying their root causes. Second, DynaFix constructs a progressive iterative workflow that mirrors human debugging logic. Traditional iterative methods typically expect to generate a correct patch in a single shot during each round; in contrast, when a candidate patch of DynaFix fails validation, the system automatically collects execution traces based on the latest code modifications. Using this updated dynamic feedback as a foundation, it guides the LLM to continue reasoning and refine the repair based on its previous attempts.

Motivation

Most existing approaches predominantly rely on static information, including faulty source code, comments, and context. While such information conveys program structure, it remains highly sensitive to syntactic variations and often fails to capture execution semantics. As demonstrated by the Math-79 example, static representations alone are insufficient when surface-level cues are obscured.

Other approaches incorporate dynamic signals but restrict them to result-level information, such as test pass/fail outcomes or exception stack traces. Although these signals confirm the presence of a failure, they provide limited insight into how the failure manifests during execution. In Math-79, the reported NullPointerException obscures the underlying overflow error, leading to incorrect fault localization due to limited visibility into the program’s runtime trajectory.

These observations reveal a systematic deficiency in existing methodologies: the lack of effective and continuous utilization of execution-level information. Although some recent studies have explored leveraging variable states or control-flow information, such information is typically used only during training or injected once into the initial prompt. Its potential to guide iterative repair remains largely unexplored. Moreover, most existing methods lack a principled feedback loop grounded in execution behavior. Static approaches typically generate patches in a single attempt, while iterative methods driven solely by result-level feedback often devolve into inefficient trial-and-error due to insufficient semantic grounding. Consequently, these methods fail to emulate the debugging process of human developers, who rely heavily on observing and reasoning about intermediate execution states.

Bytecode Instrumentation for Execution-Level Data Collection

A core feature of DynaFix is its ability to leverage execution-level dynamic information as iterative feedback to guide program repair. To collect such information from buggy programs during runtime, we integrate a non-intrusive bytecode instrumentation mechanism into the framework. This mechanism records dynamic behaviors such as local variables, method call traces, and control flow during program execution with test cases. By instrumenting bytecode instead of modifying source code directly, our approach ensures the collection of rich execution-level data without disrupting the normal execution flow of the program. Furthermore, the modular design of the instrumentation allows for scalability and automatic adaptation to benchmarks such as Defects4J.

We extended and integrated the DebugRecorder tool from DEVLoRE, which originally utilizes JavaAgent and ASM to instrument Java programs and monitor local variables. In contrast, ByteTrace, our developed bytecode instrumentation tool, serves as the core data collection component of our APR framework. ByteTrace enhances the capabilities of DebugRecorder by adding support for tracing method call stacks and conditional control flow, thereby providing a more comprehensive execution context for program repair. Concretely, ByteTrace registers a ClassFileTransformer during JVM startup and performs selective bytecode instrumentation at class loading time. It inserts lightweight probes at method entry and exit points, as well as at key control instructions, to capture variable states, invocation relationships, branch execution paths, and exception events. The collected runtime information is uniformly structured and tagged with thread identifiers to distinguish execution traces under concurrent settings, while preserving the original program semantics and maintaining controlled runtime overhead. Additionally, ByteTrace modularizes the instrumentation logic, enabling efficient collection of execution-level dynamic data, which is crucial for large-scale APR experiments and benchmarking with datasets such as Defects4J.

For information granularity selection, we adopt function-level instrumentation. Prior studies show that function-level granularity provides sufficient context for fault localization and repair while avoiding the fragmentation problems in statement-level or variable-level tracing. This granularity also aligns well with the input–output paradigm of LLMs, which are typically trained to process and generate code at the function level. Therefore, DynaFix employs function-level instrumentation to balance repair effectiveness with scalability in LLM-based workflows.

Benchmarks

Defects4J. Our primary evaluation is conducted on the widely used Defects4J benchmark. Version 2.0 contains 835 real-world bugs from 17 open-source Java projects, of which five have been removed in later updates. Following prior work, we evaluate on the remaining 830 bugs. As in previous studies, these bugs are categorized into 483 single-function bugs and 347 multi-function bugs. The single-function subset is further divided into v1.2 (255 bugs) and v2.0 (228 bugs). Defects4J provides buggy and fixed program versions together with corresponding test suites, enabling reproducible evaluation and fair comparison with existing APR techniques.

Real-World Benchmark (RWB). To mitigate potential data leakage and evaluate generalization, we use the RWB dataset constructed by. This dataset consists of bug-fixing commits created after the cutoff dates of major LLM pretraining corpora. RWB V1.0 contains 44 single-function bugs collected after October 2021, while RWB V2.0 includes 29 single-function bugs collected after March 2023. This dataset enables evaluation of repair performance on previously unseen real-world bugs.

Defects4J-Trans. To evaluate robustness against syntax-level perturbations, we use the Defects4J-Trans dataset proposed by. This dataset applies semantics-preserving syntactic transformations to 483 single-function bugs from Defects4J. Due to version compatibility constraints, we successfully reproduced 467 transformed bugs. Since the transformations preserve the underlying program behavior while altering its source-level representation, we use Defects4J-Trans as a controlled representation-robustness stress test to evaluate the sensitivity of repair capability to source representation.

Implementation and Configuration

Configuration. We use GPT-4 and GPT-4o as the primary underlying LLMs for the main Defects4J evaluation, accessed through the OpenAI API, while additional backbone models are used in RQ2 according to the corresponding benchmark protocols and baseline configurations. Following prior studies, the temperature is set to 1.0 to balance diversity and stability. For each bug, up to 35 candidate patches are generated.

DynaFix. ByteTrace is implemented in Java to collect execution-level dynamic information at runtime, while the core repair logic of DynaFix is implemented in Python. Based on RQ3, we configure the LPR strategy with a maximum breadth of 7 and a depth of 5. Under this configuration, each bug can undergo at most 35 rounds of candidate patch generation and validation, and the repair process terminates early once a valid patch is found or the exploration budget is exhausted.

Coding-Agent Comparison Configuration. For the controlled coding-agent comparison, we evaluate DynaFix, RepairAgent, and SWE-agent on 388 bugs from Defects4J v1.2, covering both single-function and multi-function defects. Defects4J v1.2 originally contains 395 bugs; seven bugs removed in later Defects4J releases are excluded for all three methods. To ensure consistency, all methods use the same bug set, perfect fault localization, failing tests and failure messages, initial source-code context, and correctness assessment procedure. GPT-4o is used as the LLM backbone for all three methods.

Root Cause Analysis of Performance Disparity

To investigate the underlying cause of this performance disparity, we analyze the retrieval behavior of ReinFix under code perturbation. Specifically, we compare the similarity distributions of retrieved patch fragments for the same 467 bugs on Defects4J and Defects4J-Trans.

These findings explain the sensitivity of static retrieval-based methods to syntactic variation. In contrast, DynaFix leverages execution-level dynamic traces to guide the repair process, reducing its reliance on surface-level syntactic features. Although semantics-preserving transformations may alter the representation and structure of execution traces, DynaFix can still utilize behaviorally relevant information to mitigate the impact of syntactic variations and maintain robust repair performance under the evaluated code perturbations.

Threats to Validity

Language Specificity. Our empirical evaluation focuses exclusively on Java programs, which introduces a potential threat to external validity regarding the generalizability of DynaFix to other programming languages. Nevertheless, the core design of DynaFix—capturing execution-level dynamic information through program instrumentation and integrating it into an iterative repair loop—is not inherently tied to Java. Similar instrumentation and tracing mechanisms are available for many mainstream programming languages. Specifically, the high-level repair components of DynaFix, including prompt construction, LLM interaction, patch validation, and the LPR strategy, can be largely reused across programming languages. In contrast, the current ByteTrace implementation relies on JVM bytecode instrumentation and therefore needs to be replaced by a language-specific tracing backend. For example, in Python, a ByteTrace-like backend could use sys.settrace to capture function call/return events and line-level execution traces, while local-variable states can be obtained from runtime frames. These signals can then be converted into the same variable-state, control-flow, and function-call information used by DynaFix. Other language-dependent interfaces, such as program execution, testing, and patch application, may also require adaptation. Despite this, differences in language semantics, runtime environments, and tooling ecosystems may affect the ease of adaptation and practical effectiveness. Therefore, extending DynaFix to another language mainly requires adapting the tracing and execution-related interfaces rather than redesigning the core repair workflow. We therefore acknowledge that cross-language generalization remains to be empirically validated, and we leave a comprehensive multi-language evaluation to future work.

Cross-Model-Family Generalizability. The main effectiveness evaluation in RQ1 primarily relies on GPT-4 and GPT-4o. Although RQ2 provides additional evidence across the GPT and DeepSeek model families, including comparisons on the same Defects4J-Trans benchmark, these experiments use different benchmarks and configurations from RQ1. Therefore, while these results demonstrate DynaFix’s effectiveness under the evaluated model families and settings, the extent to which the main findings of RQ1 generalize to other model families remains to be further validated.

Representativeness of Code Perturbations. Defects4J-Trans provides a controlled setting for evaluating repair robustness under semantics-preserving changes in source representation. However, the transformations in this benchmark may not capture the full diversity and distribution of source-level changes that arise during real-world software maintenance. Therefore, our results demonstrate repair stability under controlled semantics-preserving perturbations, while robustness to naturally occurring software evolution requires further empirical validation.

APR has been extensively studied from multiple methodological perspectives. Traditional approaches primarily rely on predefined repair templates, heuristic search and rule-based techniques, and constraint- or synthesis-based formulations. More recently, deep learning–based methods have been proposed to learn repair patterns from data, significantly expanding the design space of APR systems.

With the emergence of large language models (LLMs), a growing body of work has explored LLM-based APR. ReinFix analyzes bug causes by mining internal and external repair ingredients to guide patch generation. ThinkRepair improves repair performance by enhancing LLM reasoning through chain-of-thought prompting. ChatRepair formulates APR as a dialogue-driven process, iteratively refining patches using test failure feedback and historical repair attempts. GIANTRepair constrains the search space by extracting patch skeletons from LLM outputs and instantiating them with contextual information. RepairAgent models the LLM as an autonomous agent that plans and executes repair actions via dynamic prompts and a state machine. FitRepair incorporates the plastic surgery hypothesis through patch knowledge and repair-oriented fine-tuning, while SelfAPR and Self-Debug leverage compiler diagnostics, test feedback, and chain-of-thought reasoning to improve self-supervised repair or generation quality. Despite their effectiveness, most existing LLM-based APR techniques predominantly rely on static program representations, such as source code, test failures, and error messages, or only utilize coarse-grained runtime signals (e.g., pass/fail outcomes). As a result, the rich semantic information embedded in fine-grained execution behavior remains largely underexploited.

Several recent studies have begun to explore the use of execution-level dynamic information for APR. TraceFixer incorporates local variable values and expected execution states during CodeT5 fine-tuning to enhance repair accuracy. Towards Effectively Leveraging Execution Traces systematically analyzes the role of execution traces in APR and demonstrates their utility for explaining failing test behaviors. Similarly, LDB partitions programs into basic blocks, tracks intermediate variable values, and employs LLMs for step-by-step verification of program states. InspectCoder uses debugger breakpoints to selectively inspect specific runtime states at suspicious program locations and leverages these observations to support program repair. Cited researchers use spectrum-based fault localization (SBFL) to derive suspiciousness scores from test execution coverage and leverage the ranked suspicious code locations to guide LLM-based repair.

In contrast to these approaches, DynaFix repeatedly updates and exploits execution-level dynamic information throughout iterative repair through an automated instrumentation-and-re-execution loop. When a candidate patch remains refinable after validation, DynaFix re-executes the updated program, recollects structured execution information, and feeds the updated runtime evidence into the next repair iteration, so that the feedback remains aligned with the evolving candidate program.

Conclusion and Future Work

In this paper, we presented DynaFix, an LLM-based automated program repair framework that continuously updates and exploits execution-level dynamic information within a closed-loop iterative repair process. By leveraging the ByteTrace tool for runtime data collection and an LPR strategy, DynaFix enables LLMs to reason more effectively about program behavior and to generate context-aware patches within a unified debugging-and-repair workflow. Experimental results on the Defects4J benchmark demonstrate that DynaFix produces 236 correct fixes in total, including 23 bugs that were previously unsolved by existing approaches. Further analyses show that the framework exhibits strong robustness under code perturbations and maintains consistent performance on unseen real-world scenarios. At the same time, DynaFix achieves substantial cost efficiency, with an average token consumption of only 80,058 per bug, reducing token consumption by approximately 60%–70% compared with representative LLM-based APR approaches. These results indicate that systematically integrating execution-level dynamic feedback into automated program repair better aligns LLM-based repair with real-world debugging practices and significantly improves both effectiveness and reliability in complex repair tasks.

In future work, we plan to extend DynaFix along three main directions. First, we aim to generalize the dynamic trace collection mechanism to additional programming languages beyond Java, such as Python and C++, thereby broadening the applicability of the framework. Second, we will explore enhancements to support multi-file and multi-hunk bug repair, which require more sophisticated context management and dependency analysis across larger code scopes. Third, we plan to explore trace-aligned differential feedback between consecutive repair attempts, which may reduce redundant runtime information and more explicitly capture behavioral changes introduced by the latest patch.