NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Improving automatically generated code from Codex via Automated Program Repair

Zhiyu Fan, Xiang Gao, Abhik Roychoudhury, Shin Hwei Tan · DOI

Large Language Models (LLMs) like OpenAI’s Codex have fundamentally changed the landscape of software development. However, as users of tools like GitHub Copilot frequently observe, these models often produce code that is logically flawed, uncompilable, or semantically "weird." Researchers from the National University of Singapore, Beihang University, and Southern University of Science and Technology recently investigated whether Automated Program Repair (APR)—a field traditionally focused on fixing human errors—can be used to "heal" buggy AI-generated code.

The Challenge of AI-Generated Code

While LLMs excel at "zero-shot" code generation for simple tasks, their success rate plummets as complexity increases. For instance, Codex may achieve a ~24% pass rate on introductory tasks but falls to ~3% on competition-level problems. The core issue is that LLMs treat code as a sequence of tokens rather than a logical structure with strict semantics, leading to "misaligned algorithms" or syntax errors.

This study sought to determine if traditional APR tools, designed for human-written code, are effective for AI errors, and whether the "edit modes" of LLMs themselves can serve as repair mechanisms.

Methodology

The researchers conducted a systematic study using a newly introduced benchmark, LMDefects, consisting of 113 Java programming tasks from LeetCode contests released after Codex's training cutoff to avoid data leakage. The evaluation followed a structured pipeline to identify and fix defects.

The proposed workflow for repairing LLM-generated code using APR tools and Codex edit mode.

The study compared two state-of-the-art Java repair tools—TBar (search-based templates) and Recoder (syntax-guided neural model)—against Codex Edit Mode (Codex-e). Codex-e was tested with various prompting strategies, including providing specific suspicious statements as context (Codex-e$_{stm}$).

Key Insights: AI vs. Human Bugs

A manual analysis of 335 incorrect solutions revealed that 57% of Codex's errors are algorithmic, often sharing patterns with human mistakes (e.g., operator swapping). This suggests that APR tools built for humans are highly relevant for AI.

However, LLMs also exhibit unique "negative symptoms." For example, Codex may use variable names that indicate a misunderstanding of the required algorithm, such as naming a variable dp (dynamic programming) for a problem that requires a simple greedy approach.

Experimental Results and Synergy

The results demonstrated that Codex-e significantly outperformed specialized APR tools. Out of 67 unsolved tasks:

  • Recoder fixed 8 tasks.
  • TBar fixed 6 tasks.
  • Codex-e$_{stm}$ fixed 16 tasks.

One of the most significant findings was the power of flexible localization. Traditional APR tools are often "line-locked," attempting to fix a specific line flagged by a debugger. In contrast, Codex-e can modify the code around a suspicious area, allowing it to fix complex "multi-hunk" bugs (modifications across multiple disconnected parts of the code) that traditional tools struggle to address.

Venn diagram illustrating the unique and overlapping sets of bugs fixed by different repair tools, highlighting their complementary nature.

As shown in the overlap analysis, no single tool is exhaustive. While Codex-e is the most versatile, combining the "patch ingredients" (variables and operators) from both traditional tools and LLMs provides the best coverage for complex defects.

Future Directions

The study highlights that the success of LLM-based repair depends heavily on prompt quality and instruction precision. Future research should explore automating the generation of these "repair prompts" and incorporating software engineering artifacts—such as fault localization results—directly into the LLM generation process to produce higher-quality code from the outset.

Summary updated

BibTeX
@inproceedings{fan2023improving,
  author = {Zhiyu Fan and Xiang Gao and Abhik Roychoudhury and Shin Hwei Tan},
  title = {{Improving automatically generated code from Codex via Automated Program Repair}},
  booktitle = {ICSE},
  year = {2023},
  doi = {10.1109/icse48619.2023.00128},
}
Figure