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

PATCH: Empowering Large Language Model with Programmer-Intent Guidance and Collaborative-Behavior Simulation for Automatic Bug Fixing

Yuwei Zhang, Zhi Jin, Ying Xing, Ge Li, Fang Liu, Jiaxin Zhu, Wensheng Dou, Jun Wei

TL;DR

PATCH is a novel framework that transforms automatic bug fixing from a "single-shot" code generation task into a collaborative, multi-stage simulation. By equipping Large Language Models (LLMs) with broader code context, programmer intent (via commit messages), and a multi-agent workflow (Tester, Developer, and Reviewer), PATCH significantly outperforms state-of-the-art models like GPT-4 on standard benchmarks.

What Problem Does This Paper Address?

Despite the impressive coding capabilities of LLMs, they often fail at Automatic Bug Fixing (ABF) for two main reasons:

  1. Information Scarcity: Most tools only feed the LLM the specific "buggy hunk" of code. Without understanding repository-level dependencies or the intent of the original programmer, the LLM often suggests syntactically correct but logically wrong fixes.
  2. Process Oversimplification: Human bug fixing isn't a one-step process. It involves a collaborative cycle of reporting, diagnosing, drafting, and reviewing. Existing LLM approaches treat it as a simple text-completion task, missing the benefits of iterative reasoning and peer feedback.

Methods

The authors introduce PATCH, a stage-wise framework that simulates a software development team using three specialized ChatGPT agents:

  • Stage 1: Bug Reporting (The Tester): An agent adopts the persona of a software tester. It analyzes the buggy code alongside "programmer intent" (extracted from commit messages) and repository dependencies to generate a detailed report on the bug's root cause.
  • Stage 2: Bug Diagnosis (The Developer): The developer agent performs "rubber duck debugging"—explaining the code line-by-line in natural language. It also uses BM25 retrieval to find similar bug-fix pairs from a historical corpus to identify common fixing patterns.
  • Stage 3: Patch Generation (The Developer): Using the bug report, the code explanation, and the identified patterns, the Developer generates an initial candidate patch.
  • Stage 4: Patch Verification (The Reviewer): A Reviewer agent assesses the patch against the "Desired Fixing Goal." If the patch fails, it provides feedback to the Developer, triggering an iterative loop (up to three turns) to refine the fix.

Datasets

The study primarily uses the BFP (Bug-Fixing Pairs) benchmark, which the authors augmented with class-level and repository-level dependency contexts and GitHub commit messages to serve as proxies for programmer intent.

To test generalizability, they also evaluated PATCH on four classic Automated Program Repair (APR) benchmarks:

  • Bugs.jar (1,000 bugs)
  • Bears (119 bugs)
  • Defects4J (313 bugs)
  • QuixBugs (37 bugs)

Key Insights and Ideas

  • Intent is the "Missing Link": The authors found that commit messages are incredibly potent. Even a high-level description like "fixing different data type errors" provides the "why" that allows an LLM to choose the correct fix among several syntactically valid options.
  • Behavior > Model Size: One of the most striking findings is that PATCH (built on GPT-3.5) can outperform "vanilla" GPT-4. This suggests that how we prompt and structure the workflow is just as important as the raw power of the underlying model.
  • The Power of "Rubber Ducking": Forcing the LLM to explain the code line-by-line (Diagnosis stage) before fixing it helps the model avoid pattern-matching traps and engage in deeper logical reasoning.
  • Collaboration Reduces Hallucination: The iterative loop between the Developer and Reviewer agents acts as a filter, catching "lazy" fixes that might satisfy the local code structure but violate the broader project requirements.

Key Results

  • Superior Performance: On the BFP benchmark, PATCH achieved a Fix@1 accuracy of 33.97%, outperforming the best baseline (GPT-4) by 14.01 percentage points.
  • Ablation Success: Removing any single component (intent guidance, dependency context, or the multi-agent interaction) led to a significant drop in performance, proving that the framework's strength lies in its holistic design.
  • Generalizability: PATCH demonstrated a significant performance advantage across three out of four APR benchmarks. For instance, on Bears, it surpassed the best baseline by 27.27%.
  • Open Source Friendly: The framework also boosted the performance of open-source models like CodeLLaMA and Mistral, showing that the "PATCH method" is model-agnostic.

Limitations and Future Work

  • Single-Hunk Focus: The current implementation primarily targets "single-hunk" bugs (bugs contained within one continuous block of code). While the authors provide a case study on multi-hunk bugs, more work is needed to scale this to complex, multi-file architectural flaws.
  • Commit Message Dependency: PATCH relies on high-quality commit messages to understand intent. In a real-time development scenario, these messages might not exist yet. Future work could explore using compiler error messages or test failure logs as alternative sources of intent.
  • Token Limits: Including extensive repository-level context can quickly hit LLM token limits. The authors currently restrict context to one layer of dependencies, but more sophisticated context pruning could improve results for very large projects.

Summary updated

BibTeX
@article{zhang2026patch,
  author = {Yuwei Zhang and Zhi Jin and Ying Xing and Ge Li and Fang Liu and Jiaxin Zhu and Wensheng Dou and Jun Wei},
  title = {{PATCH: Empowering Large Language Model with Programmer-Intent Guidance and Collaborative-Behavior Simulation for Automatic Bug Fixing}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2026},
  doi = {10.1145/3718739},
}
Figure