Leveraging Causal Inference for Explainable Automatic Program Repair

Jianzong Wang, Shijing Si, Zhitao Zhu, Xiaoyang Qu, Zhenhou Hong, Jing Xiao · DOI

Introduction

Automated Program Repair (APR) has the potential to significantly reduce the manual effort required for software maintenance by automatically generating patches for identified bugs. Recent advancements in deep learning, particularly Sequence-to-Sequence (Seq2Seq) architectures and pre-trained models like CodeBERT, have pushed the boundaries of what these systems can achieve. However, these models often operate as "black boxes," providing little to no rationale for their suggested repairs. This lack of interpretability creates a barrier to adoption, as developers are hesitant to merge code changes they do not fully understand. Furthermore, these models can be prone to learning spurious correlations rather than the underlying logic of the code.

To address these challenges, this research introduces Causal Program Repair (CPR), a framework designed to provide human-readable explanations for repairs while simultaneously enhancing the model's bug-fixing performance. By framing the repair process through the lens of causal inference, CPR identifies the specific input features—such as particular tokens in the buggy code or natural language comments—that drive the model's output.

Methodology: The CPR Framework

The core of CPR lies in treating the relationship between the buggy input and the repaired output as a causal inference problem.

Causal Modeling

The authors define a causal graph where the input buggy code and its associated comments are treated as the Treatment (X), and the predicted repaired code is the Outcome (Y). To probe the causal relationship between specific parts of the input and the output, the framework introduces Confounders (A) in the form of data disturbances or perturbations.

The CPR Pipeline

The CPR process follows a three-stage pipeline:

  1. Perturbation (Data Augmentation): To observe how changes in the input affect the output, CPR generates multiple variations of the original buggy code. Unlike complex generative models, CPR utilizes lightweight text augmentation techniques:
  2. Synonym Replacement (SR): Replacing words in comments with their synonyms.
  3. Random Operations (RI, RS, RD): Randomly inserting, swapping, or deleting tokens.
  4. Back-Translation (BT): Translating comments into a target language and back to English to create semantic paraphrases.
  5. Causal Inference: These perturbed inputs are fed into a trained APR model (e.g., SequenceR or CodeBERT). By analyzing the resulting changes in the output tokens, the system quantifies the causal influence of specific input components.
  6. Explanation Generation: The system constructs an "explanation graph" that maps the most causally relevant input tokens to the output tokens. This graph provides a visual rationale, allowing developers to see which parts of the code or comments triggered the fix.

Experimental Evaluation

The effectiveness of CPR was evaluated across four programming languages using established benchmarks:

  • Java: Defects4J and QuixBugs.
  • Python: QuixBugs.
  • C: ManyBugs.
  • JavaScript: BugAID.

The framework was integrated with three distinct architectures: SequenceR, FConv (Convolutional Seq2Seq), and CodeBERT.

Key Results and Insights

The experiments demonstrated that CPR provides a consistent performance boost across nearly all benchmarks and models.

Performance Gains

The integration of causal inference significantly increased the number of successfully fixed bugs:

  • Java (Defects4J): For the SequenceR model, the number of fixed bugs increased from 12 to 20. For CodeBERT, the count rose from 14 to 23.
  • Python (QuixBugs): CodeBERT's performance improved from 12 to 19 fixed bugs.
  • C (ManyBugs): Across all tested models, CPR resulted in a 30-50% increase in the number of bugs fixed.
  • JavaScript (BugAID): While improvements were noted (e.g., from 6 to 7 fixes), the gains were limited by the small size of the dataset.

The Importance of Semantic Meaning

A critical finding was that semantic-preserving perturbations, specifically Synonym Replacement (SR) and Back-Translation (BT), were the most effective. These techniques allow the model to focus on the relationship between the developer's intent (expressed in comments) and the code logic, rather than being distracted by syntactic noise.

Efficiency and Interpretability

The study proves that simple data augmentation is a viable, low-cost alternative to heavy generative models for causal analysis in the code domain. The resulting explanation graphs offer a practical tool for "visual debugging," bridging the gap between automated suggestions and human understanding.

Conclusion and Future Work

CPR demonstrates that causality is not just a tool for interpretability but also a mechanism for improving model robustness and accuracy. By identifying and leveraging causal relationships, the framework helps APR models move beyond simple pattern matching.

Future research will focus on addressing current limitations, such as the reliance on large datasets for effective causal inference. Additionally, the authors suggest exploring "code-aware" perturbations—techniques that understand the syntax and structure of programming languages more deeply than standard NLP augmentations—to further refine the causal mapping and explanation quality.

Summary updated

BibTeX
@inproceedings{wang2022leveraging,
  author = {Jianzong Wang and Shijing Si and Zhitao Zhu and Xiaoyang Qu and Zhenhou Hong and Jing Xiao},
  title = {{Leveraging Causal Inference for Explainable Automatic Program Repair}},
  booktitle = {IJCNN},
  year = {2022},
  url = {https://openreview.net/forum?id=X4mqzBomHB},
}
Figure