From Historical Patches to Repair Plans: Outcome-Conditioned Reasoning for Repository-Level Program Repair

Chenglin Li, Yisen Xu, Zehao Wang, Shin Hwei Tan, Tse-Hsun Chen

Automated Program Repair (APR) at the repository level is a notoriously difficult "long-horizon" reasoning challenge. To successfully fix a bug, an AI agent must navigate thousands of files, pinpoint the exact faulty function, and generate a patch that respects project-specific constraints.

Most current Large Language Model (LLM) approaches treat every new bug as an isolated event. They rely on "forward exploration"—essentially guessing a path and hoping it leads to a correct fix. This approach suffers from significant drawbacks: high outcome uncertainty (models easily drift into hallucinated reasoning paths), massive computational overhead (methods like Monte Carlo Tree Search require hundreds of expensive LLM calls), and a complete disregard for the repository's history. Real-world software repositories are full of related bugs and recurring patterns, yet most AI agents ignore this valuable context.

To address these inefficiencies, researchers have introduced ConRAD (Conditional Reasoning Distillation), a framework that shifts the APR paradigm from forward guessing to backward distillation. By learning from a project's history, ConRAD reverse-engineers the reasoning behind successful past patches to create step-wise plans that guide the LLM through current repairs.

The ConRAD Framework

ConRAD operates by leveraging in-repository resolved issues, reconstructing repair reasoning backward from verified patches, and distilling outcome-consistent plans. The process unfolds in three distinct stages:

1. Repository-Level Exemplar Mining

When faced with a new bug, ConRAD does not immediately start guessing. Instead, it searches the repository's history for a "twin"—a previously resolved issue that is textually and semantically similar to the current problem.

2. Exemplar Guardian

Not all similar bugs are helpful; some share symptoms but have entirely different root causes. To prevent "negative transfer" (following a misleading analogy), ConRAD employs an LLM-based "judge" to act as a conservative filter. This Guardian evaluates whether the historical bug is truly transferable to the current context, discarding matches that might lead the repair agent astray.

3. Backward Reasoning Distillation (BRD)

This is the core innovation of the framework. Rather than simply showing the model the old patch, ConRAD asks the LLM to reconstruct the reasoning steps backward from that verified patch. Because the final answer (the patch) is already known, the resulting reasoning plan is globally consistent and free of the trial-and-error noise inherent in forward reasoning.

At inference time, these distilled plans are injected into the prompt as in-context guidance. This helps the model navigate file localization, function localization, and patch generation for the new bug without requiring fine-tuning or exhaustive search.

Key Insights and Advantages

  • The Power of Hindsight: Reasoning is significantly more stable when the destination is known. By reverse-engineering a plan from a known-good patch, ConRAD creates a "gold standard" reasoning trajectory that forward-looking models cannot easily replicate.
  • Scaffold Agnostic: ConRAD is not a standalone bot but a flexible reasoning layer. It can be plugged into simple scaffolds like Agentless or more complex, multi-step agents like mini-SWE-agent.
  • Efficiency over Brute Force: A high-quality map eliminates the need to explore a massive search tree. ConRAD provides superior guidance compared to search-based methods while using a fraction of the compute.

Empirical Results on SWE-Bench Lite

The researchers evaluated ConRAD on SWE-Bench Lite, a benchmark of 300 real-world GitHub issues from 13 Python repositories, using historical datasets constructed from those same projects. The results demonstrate substantial gains across multiple state-of-the-art LLMs:

  • Pass@1 Success Rate Improvements:
    • GPT-4o: Improved from 27.3% to 37.7% (+10.4%).
  • DeepSeek-V3: Improved from 27.0% to 35.6% (+8.6%).
  • GPT-5: Improved from 29.7% to 40.0% (+10.3%).
  • Enhanced Localization: On GPT-4o, function-level localization accuracy improved from 51.0% to 59.3%, proving that historical plans actively help the model pinpoint the bug's location.
  • Massive Compute Savings: Compared to a Monte Carlo Tree Search (MCTS) baseline, ConRAD achieved a +13.0% higher Pass@1 rate while consuming 9.71x fewer LLM calls and 2.47x fewer tokens.

Limitations and Future Directions

While highly effective, ConRAD has a few limitations. The current evaluation is restricted to Python projects; while the underlying logic should transfer, different programming languages may feature repository structures that complicate exemplar mining. Furthermore, ConRAD inherently relies on a repository having a rich history of resolved bugs, making it less effective for brand-new "greenfield" projects.

Future work will explore how to handle more complex, multi-file historical fixes (the current study limited historical exemplars to fixes affecting three or fewer files to ensure clarity). Additionally, researchers aim to expand this backward-distillation framework to other complex software engineering tasks beyond automated bug fixing.

Summary updated

BibTeX
@inproceedings{li2026from,
  author = {Chenglin Li and Yisen Xu and Zehao Wang and Shin Hwei Tan and Tse-Hsun Chen},
  title = {{From Historical Patches to Repair Plans: Outcome-Conditioned Reasoning for Repository-Level Program Repair}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=MjGhDpCtF9},
}

Loading related content...

Figure