Abstract
Automated Program Repair (APR) typically treats code as static text, ignoring the dynamic runtime behavior that human developers rely on for debugging. We introduce TraceFixer, a neural program repair technique that incorporates execution traces and "desired states"—the expected variable values at a point of failure—into the repair process. By leveraging a neural bug injector for training and a multi-modal input format, TraceFixer achieves a 13-20% improvement in bug-fixing accuracy over traditional code-only models, successfully repairing 50% of a real-world bug benchmark.
Introduction
The field of Automated Program Repair (APR) has traditionally treated source code as static text. When a neural model attempts to fix a bug, it typically analyzes the buggy source code and predicts a "correct" version based on patterns observed during training. However, this approach lacks the dynamic context that human developers use during debugging.
A developer identifies a bug by running the code and noticing a divergence point—a specific line where a variable's state differs from the expected outcome. This "desired state" provides a powerful guide for backtracking and fixing logic. Existing APR tools often lack this context, making it difficult to distinguish between multiple syntactically plausible code edits. TraceFixer addresses this gap by integrating execution traces and desired states into the repair pipeline.
Methodology
TraceFixer is the first learning-based repair technique guided by execution traces. Its workflow consists of several innovative stages:
Neural Bug Injection
To train the model, we developed a "reverse" repair model—a bug injector—based on CodeT5. This component learns to create realistic, human-like single-line bugs in healthy code, providing the massive dataset of buggy/correct code pairs necessary for training.
Input Formatting and Execution Tracing
The core of TraceFixer is its multi-modal input sequence. We instrument the code to capture the program state (variable names and values) at each line. The model is then provided with:
- The buggy line.
- The initial program state.
- A partial execution trace (the last few lines executed and resulting states).
- The Desired State (the correct variable values at the divergence point).
- The surrounding code context.
Model Architecture
We fine-tuned a CodeT5-small backbone using a multi-task learning setup. This allows the model to learn from traces during training while remaining useful even when execution data is unavailable, as the trace-guided training improves the model's underlying understanding of code logic.
Experimental Results
TraceFixer was evaluated on three primary Python datasets: CodeNet (algorithmic challenges), TheAlgorithms (standard algorithm implementations), and a real-world benchmark of 20 complex GitHub bugs.
Performance Gains
TraceFixer demonstrated a significant accuracy boost, improving bug-fixing ability by 13% to 20% compared to baseline models that only analyzed source code. On the CodeNet dataset, the model achieved a 63% top-1 accuracy and an 87% top-10 accuracy.
Real-World Utility
In practical testing against 20 real-world Python bugs, TraceFixer successfully fixed 10 (50%), whereas code-only baselines struggled significantly. This highlights the importance of state as a strong signal; knowing what a variable should be narrows the search space for a fix much more effectively than syntax alone.
Conclusion
TraceFixer represents a shift in NPR from static analysis to dynamic, trace-driven repair. By mimicking the human debugging process, it achieves state-of-the-art results on both synthetic and real-world benchmarks. Future work will focus on extending the model to multi-line repairs and automating the generation of the "desired state" oracle to achieve full automation.
Summary updated