Abstract
Large language models (LLMs) have demonstrated significant advancements in code generation, yet they still face challenges when tackling tasks that extend beyond their basic capabilities. Recently, the concept of self-debugging has been proposed as a way to enhance code generation performance by leveraging execution feedback from tests. However, the availability of high-quality tests in real-world scenarios is often limited. In this context, self-debugging with self-generated tests emerges as a promising solution, though its limitations and practical potential have not been fully explored. To address this gap, we investigate the efficacy of self-debugging in code generation tasks. We propose and analyze two distinct paradigms for the self-debugging process: post-execution and in-execution self-debugging. Our findings reveal that post-execution self-debugging struggles with the test bias introduced by self-generated tests, which can lead to misleading feedback. In contrast, in-execution self-debugging enables LLMs to mitigate this bias and leverage intermediate states during program execution. By focusing on runtime information rather than relying solely on potentially flawed self-generated tests, this approach demonstrates significant promise for improving the robustness and accuracy of LLMs in code generation tasks.
Introduction
While Large Language Models (LLMs) have revolutionized code generation, their outputs often require refinement. "Self-debugging"—a process where a model iteratively improves its code based on test feedback—has emerged as a key technique for boosting performance. However, a critical bottleneck exists: in many real-world applications, high-quality test oracles are unavailable. When models are tasked with generating their own tests, they often fall victim to test bias. This paper investigates why traditional self-debugging fails in these scenarios and proposes a more robust alternative: in-execution self-debugging.
Methodology: Two Paradigms of Self-Debugging
The core of this research lies in comparing two distinct feedback loops for code refinement:
- Post-Execution Self-Debugging: The conventional approach where a model generates a program and a test suite. It executes the program and receives a binary "pass/fail" or a final output mismatch. The model then attempts to repair the code to satisfy the test.
- In-Execution Self-Debugging: A more granular approach where the model analyzes the execution trace. By partitioning the code into logical blocks and observing intermediate variable states, the model can reason about the internal logic of the program independently of the final (and potentially incorrect) test verdict.
The "Output Bottleneck" and Test Bias
A primary finding of this study is that LLMs are remarkably proficient at generating valid test inputs but struggle significantly to predict the correct outputs. This discrepancy creates a "test bias" where a model might generate a correct program but fail it against a flawed self-generated test.
As shown in the figure above, while models like GPT-4o and Claude-3.5-Sonnet achieve near-perfect accuracy in generating valid inputs, their accuracy in predicting the corresponding outputs (and thus creating a valid test suite) drops sharply. In post-execution debugging, this leads to "false negatives" where the model incorrectly "fixes" a correct program to match a buggy test, ultimately degrading performance.
Experimental Results
The study evaluated four frontier models—GPT-4o, Claude-3.5-Sonnet, LLaMA-3-70B, and Qwen2.5-Coder-7B—across HumanEval+, MBPP+, and the competitive LiveCodeBench.
- Performance Gains: In-execution debugging consistently outperformed post-execution methods. On HumanEval+, GPT-4o’s pass rate improved to 89.0% using in-execution traces, whereas post-execution feedback actually caused a drop in performance (from 87.8% to 86.6%).
- Competitive Programming: On LiveCodeBench (Medium), Claude-3.5-Sonnet saw an improvement from 48.0% to 49.1% after one iteration of in-execution debugging.
- Bias Mitigation: By focusing on intermediate states, models were able to identify sound logic even when the final output didn't match their flawed expectations, effectively ignoring misleading test feedback.
Conclusion
The effectiveness of self-debugging depends less on if a model receives feedback and more on how that feedback is structured. By shifting from final output matching to in-execution reasoning, LLMs can overcome the inherent biases of self-generated tests. This approach provides a more robust path for autonomous code improvement, particularly in complex domains where external test oracles are unavailable.
Summary updated