PatchPilot: A Cost-Efficient Software Engineering Agent with Early Attempts on Formal Verification

Hongwei Li, Yuheng Tang, Shiqi Wang, Wenbo Guo

TL;DR

PatchPilot is a new rule-based AI agent designed to fix software bugs with a rare combination of high accuracy, rock-solid stability, and extreme cost-efficiency. By introducing an iterative "refinement" loop and a structured 5-stage workflow, it outperforms existing open-source tools on the SWE-bench benchmark while keeping the average cost under $1 per fix.

What Problem Does This Paper Address?

Automated Program Repair (APR) has entered a new era with Large Language Models (LLMs). Currently, the field is split into two camps:

  1. Agent-based planning: These agents use LLMs to "think" and decide their own workflow for every bug. They are powerful but suffer from high "hallucination" rates in their planning, leading to instability and massive API costs (sometimes thousands of dollars for a single benchmark run).
  2. Rule-based planning: These follow a fixed, human-defined pipeline. They are stable and cheap but often too rigid to solve complex bugs that require multiple attempts or deep context.

The authors of PatchPilot argue that for AI agents to be useful in real-world engineering, they must be stable (produce the same result twice) and cost-effective without sacrificing the ability to solve difficult, multi-step issues.

Methods

PatchPilot employs a novel, five-stage rule-based workflow that mimics how a human developer actually works:

PatchPilot's 5-stage rule-based workflow
  1. Reproduction: Instead of just reading a bug report, it uses "self-reflection" to generate a Proof-of-Concept (PoC) test case that triggers the bug.
  2. Localization: It uses a hierarchical approach—narrowing down from files to classes/functions, and finally to specific lines. Crucially, it includes a "review" step where the LLM checks if the identified "root cause" actually provides enough context to write a fix.
  3. Generation: It separates planning from coding. It first asks the LLM to write a multi-step plan, then generates the code. It also uses three distinct prompting strategies (comprehensive, minimal, and standard) to ensure a diverse set of candidate patches.
  4. Validation: Patches are tested against the PoC and "benign" functionality tests (existing tests in the repo) to ensure the fix doesn't break something else.
  5. Refinement (The Secret Sauce): Unlike other rule-based tools that give up if the first patch fails, PatchPilot enters a loop. It feeds the test failure feedback back into the model to iteratively improve the patch.

Additionally, the authors include an "early attempt" at Formal Verification, using the CrossHair tool and Z3 solver to mathematically prove the correctness of a subset of patches.

Datasets

The researchers evaluated PatchPilot on the industry-standard SWE-bench, specifically:

  • SWE-bench Lite: A subset of 300 real-world GitHub issues from popular Python libraries.
  • SWE-bench Verified: A collection of 500 issues where the "gold" solutions have been manually verified by humans to be correct.

Key Insights and Ideas

  • Refinement over Regeneration: The biggest "aha moment" is that fixing a partially correct patch is much more efficient than starting from scratch. This iterative loop is what allows a rule-based system to match the performance of more expensive, "autonomous" agents.
  • Stability is a Feature: By using a fixed workflow, PatchPilot significantly reduces the randomness inherent in LLMs. In head-to-head tests against the popular agent OpenHands, PatchPilot showed much lower variance in its success rate across multiple runs.
  • Context is King: The "Review" step in localization prevents the agent from trying to fix a bug with "tunnel vision." If the identified lines aren't enough, the agent is forced to pull in more surrounding code before attempting a fix.

Key Results

PatchPilot sets a new bar for open-source patching agents:

Performance and cost comparison on SWE-bench
  • Performance: It resolved 45.33% of issues on SWE-bench Lite and 53.60% on SWE-bench Verified, outperforming SOTA open-source methods like Agentless and OpenHands.
  • Cost-Efficiency: It achieved these results at an average cost of $0.97 to $0.99 per instance. For comparison, some high-performing closed-source agents cost upwards of $20 per instance.
  • Formal Verification: While still in early stages, they successfully verified 11 patches using formal methods, providing a "gold standard" guarantee of correctness that unit tests alone cannot offer.

Limitations and Future Work

The authors identify a few hurdles for the future:

  • Formal Verification Scaling: Current Python formal verifiers struggle with complex data structures and dynamic function calls, limiting the number of patches that can be mathematically proven.
  • "Too Simple" Patches: LLMs still have a tendency to propose overly simplistic fixes that might pass tests but don't address the underlying architectural issue.
  • Model Dependency: While PatchPilot works with various models (GPT-4o, Claude 3.5 Sonnet), its performance still fluctuates based on the underlying LLM's reasoning capabilities.

Future work will focus on integrating more advanced reasoning models (like OpenAI's o3-mini) and refining specialized patching models that better understand complex program logic.

Summary updated

BibTeX
@inproceedings{li2025patchpilot,
  author = {Hongwei Li and Yuheng Tang and Shiqi Wang and Wenbo Guo},
  title = {{PatchPilot: A Cost-Efficient Software Engineering Agent with Early Attempts on Formal Verification}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=ybODpT8ydV},
}
Figure