Abstract
Automated Program Repair (APR) has made significant strides, yet a persistent "trust gap" remains between automated tools and human developers. Traditional APR systems often function as black boxes, providing patches without clear reasoning, which forces developers to spend excessive time verifying correctness. This paper introduces AutoSD (Automated Scientific Debugging), a framework that leverages Large Language Models (LLMs) to emulate the human scientific debugging process. By iteratively formulating hypotheses, conducting experiments via a real debugger, and drawing conclusions from observations, AutoSD generates both a fix and a transparent reasoning trace. Our evaluation shows that AutoSD is competitive with state-of-the-art repair tools and significantly enhances developer accuracy in patch assessment.
Introduction
The "last-mile" problem in automated debugging is developer trust. While modern LLM-based tools can generate plausible code fixes, they often rely on statistical correlations rather than causal reasoning. When a developer receives a patch "out of the blue," the cognitive load required to verify it can outweigh the benefits of automation. To bridge this gap, we propose a system that interacts with the code execution environment to build a mental model, mirroring how human experts debug.
Methodology: The AutoSD Pipeline
AutoSD implements a structured loop based on the Scientific Debugging (SD) framework. Instead of a one-shot generation, the LLM (specifically ChatGPT) is prompted to follow a four-stage cycle:
- Hypothesize: The model suggests a potential cause for the bug based on the source code and error logs.
- Experiment: The model generates a debugger script (e.g., using
pdborjdb) or a command in a custom domain-specific language (DSL) to test the hypothesis. - Observe: The system executes the experiment in a live environment, capturing variable states and stack traces.
- Conclude: The model evaluates whether the observation supports or rejects the hypothesis.
This process continues until the model predicts a <DONE> token, signaling it has sufficient information to produce a final patch. To facilitate precise code modifications during the experiment phase, we developed a specialized DSL for the LLM to interact with the codebase.
Evaluation and Benchmarks
We evaluated AutoSD across three diverse datasets:
- Defects4J (v1.2 & v2.0): Standard Java benchmarks for real-world software bugs.
- BugsInPy (BIP): A collection of real-world Python bugs used for our human study.
- Almost-Right HumanEval (ARHE): A new benchmark created by mutating the HumanEval dataset to produce subtle logic errors that fail only a single test case, specifically designed to test reasoning capabilities and mitigate data leakage.
Key Results and Insights
AutoSD demonstrated high performance, fixing 113 bugs in Defects4J v2.0, outperforming several specialized deep learning baselines. Beyond raw performance, the study yielded several critical insights:
- Grounding and Reliability: The interaction with a real debugger is essential. In tests where the debugger was removed, performance dropped significantly, confirming that the model's reasoning is grounded in actual execution data rather than hallucination.
- Confidence as a Signal: The
<DONE>token served as a reliable indicator of patch quality; patches generated when the model signaled confidence were correct 89% of the time. - Human-AI Synergy: In a study with 20 developers, the presence of AutoSD's reasoning traces improved patch assessment accuracy in 83% of the real-world bugs studied. Participants noted that the explanations acted as a "rubber duck," helping them align their mental models with the tool's logic.
Conclusion and Future Work
AutoSD demonstrates that explainability in APR is not just a secondary feature but a primary driver of developer trust and accuracy. While the iterative process introduces a time overhead (averaging ~9 minutes per bug), the resulting transparency is invaluable for professional software engineering. Future work will focus on scaling this approach to multi-file architectural bugs and integrating these reasoning traces directly into IDE environments.
Summary updated