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

PatchZero: Zero-Shot Automatic Patch Correctness Assessment

Xin Zhou, Bowen Xu, Kisub Kim, DongGyun Han, Thanh Le-Cong, Junda He, Bach Le, David LoarXiv 2023 · DOI

Abstract

Automated Program Repair (APR) tools frequently generate "overfitting" patches that pass test suites but fail to resolve the underlying software bug. Existing Automatic Patch Correctness Assessment (APCA) methods typically require extensive labeled data from specific APR tools to train, creating a "cold start" problem for new repair technologies. This paper presents PatchZero (also known as LLM4PatchCorrect), a zero-shot assessment framework that leverages Large Language Models (LLMs) and In-Context Learning (ICL). By retrieving semantically similar labeled patches from existing tools and providing rich execution context, PatchZero identifies correct patches for unseen APR tools without manual training labels. Evaluation on Defects4J and Bears benchmarks demonstrates an average accuracy of 84.4%, significantly outperforming state-of-the-art static assessment methods.

1. Introduction

The field of Automated Program Repair (APR) aims to reduce manual debugging effort by automatically generating fixes for software bugs. However, the effectiveness of APR is hampered by the "overfitting" problem: patches often pass the provided test cases by exploiting gaps in the test suite rather than implementing a logically correct fix.

To mitigate this, researchers have developed Automatic Patch Correctness Assessment (APCA) tools. Traditional APCA approaches are often supervised, requiring a large corpus of labeled "correct" and "wrong" patches from a specific APR tool to achieve high performance. This creates a significant barrier to entry for new APR tools, as developers would need to manually label a vast majority of a new tool's output just to train an assessment model. PatchZero addresses this "cold start" problem by treating patch assessment as a zero-shot natural language inference task.

2. Methodology: The PatchZero Framework

PatchZero utilizes a frozen Large Language Model (Starcoder-7B) to assess patches through In-Context Learning. The framework does not require fine-tuning on the target APR tool's data. Instead, it constructs a comprehensive prompt that guides the LLM to reason about patch correctness.

Figure 2: The three-stage workflow of PatchZero, including test patch preparation, gathering diverse guiding information, and LLM inference.

2.1 Test Patch Preparation and Semantic Retrieval

The process begins by formatting the candidate patch into a natural language prompt. To provide the LLM with relevant examples, PatchZero performs Semantic Retrieval. It searches a database of labeled patches from other existing APR tools to find examples that are semantically similar to the current test patch.

Figure 4: The semantic retrieval process using a contrastive learning-based embedding model to find similar labeled patches.

This retrieval is powered by a custom contrastive learning-based embedding model. Unlike simple keyword matching, this model is trained to recognize deep semantic similarities in code changes, allowing the system to find analogous fixes even if they come from different tools or address different bugs.

2.2 Guiding Information

A patch in isolation is often ambiguous. PatchZero enriches the prompt with "guiding information" that mimics the context a human developer would use for code review:

  • Bug Description: The natural language explanation of the issue.
  • Execution Traces: The runtime behavior of the buggy code.
  • Failing Test Cases: The specific tests that the original code failed.
  • Test Coverage: Metrics indicating which parts of the code are exercised by the available tests.

2.3 LLM Inference

The final prompt, containing the test patch, retrieved examples, and guiding context, is fed into the frozen LLM. The model then predicts the next token—"correct" or "wrong"—to classify the patch.

3. Experimental Evaluation

The authors evaluated PatchZero using a "leave-one-tool-out" cross-tool validation strategy. This setup simulates a real-world scenario where the system encounters a completely new APR tool.

3.1 Benchmarks

  • Defects4J: A standard benchmark featuring 1,179 patches from 22 different APR tools.
  • Bears: Used to evaluate the generalizability of the approach across different bug datasets.
  • ManySStuBs4J: Utilized for training the contrastive embedding model for semantic retrieval.

3.2 Key Results

PatchZero achieved an average accuracy of 84.4% and an F1-score of 86.5% in the cross-tool setting. It significantly outperformed the previous state-of-the-art static approach, ODS, improving Accuracy and F1-score by approximately 20-33%.

Ablation studies highlighted that the retrieved similar patches were the most critical component of the prompt. Without these in-context examples, performance dropped sharply, confirming that the LLM relies heavily on analogy to reason about specialized software engineering tasks.

4. Discussion and Conclusion

PatchZero demonstrates that LLMs can effectively solve the cold start problem in patch assessment through zero-shot learning. The tool is highly efficient, requiring only 2.4 seconds per assessment.

While successful, the approach has limitations. Performance is sensitive to prompt engineering and the size of the underlying LLM; larger models (e.g., 34B or 70B) would likely yield even better results. Future work will explore automated prompt optimization and extending the framework to other programming languages and software engineering tasks like just-in-time defect prediction.

Summary updated

BibTeX
@misc{zhou2023patchzero,
  author = {Xin Zhou and Bowen Xu and Kisub Kim and DongGyun Han and Thanh Le-Cong and Junda He and Bach Le and David Lo},
  title = {{PatchZero: Zero-Shot Automatic Patch Correctness Assessment}},
  year = {2023},
  eprint = {2303.00202},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.00202},
}
Figure