---
title: 'ReFIne: Patch Refinement for APR'
url: https://www.emergentmind.com/topics/refine
type: topic
---

# ReFIne: Patch Refinement for APR

ReFIne is a patch-refinement framework for repository-level automatic program repair (APR) with large language models, introduced to transform “Draft Patches” into correct patches by addressing limited context understanding, ambiguities in natural-language issue descriptions and large codebases, and over-reliance on incomplete regression tests. In the formulation of the method, a repair instance is $x=(I,D,T)$, where $I$ is the issue description, $D$ the codebase, and $T$ the regression test suite; an existing APR tool $R_{\mathrm{init}}(\cdot)$ produces a draft patch $P_{\mathrm{init}}=R_{\mathrm{init}}(x)$, and refinement applies a function $F$ to obtain a refined patch $P_r$ that maximizes semantic correctness [2510.03588].

## 1. Problem setting and formal objective

ReFIne is motivated by a recurrent failure mode in LLM-based APR: the generation of Draft Patches that are “near-correct” but either incomplete or overfit to the available test suite. The paper characterizes three causes. First, natural-language issue descriptions $I$ and large codebases $D$ contain ambiguities that lead to misinterpretation of root cause. Second, regression tests $T$ are necessary but not sufficient for semantic correctness, so a patch that passes $T$ may still be invalid. Third, current APR pipelines often lack an explicit refinement stage capable of converting a partially correct candidate into a semantically correct repair [2510.03588].

The refinement objective is defined as
$$
P_r = F(P_{\mathrm{init}}; I,D,T)
$$
such that
$$
P_r = \arg\max_P \mathrm{Corr}(P \mid I,D,T),
$$
where
$$
\mathrm{Corr}(P \mid I,D,T)=\Pr(\text{“}P \text{ passes all tests and satisfies issue semantics”}).
$$
This formulation is significant because it makes explicit that ReFIne is not an APR seed generator. It is a post-generation refinement module applied to the output of an existing repair system. The paper states that it is implemented as a general refinement module that can be integrated into both open-agent-based and workflow-based APR systems [2510.03588].

A central misconception addressed by this formulation is that test-passing is equivalent to repair correctness. ReFIne is built precisely around the opposite claim: passing the regression suite does not guarantee that the issue semantics have been satisfied.

## 2. Three-module architecture

ReFIne comprises three LLM-agentic modules: Context Disambiguation, Test-time Scaling for Candidate Diversification, and LLM-powered Aggregation via Code Review. The architecture is explicitly staged so that ambiguity reduction precedes candidate expansion, and candidate expansion precedes synthesis and validation [2510.03588].

| Module | Core representation | Function |
|---|---|---|
| Context Disambiguation | $I'=(\mathrm{Tgt}, \mathrm{Logic}, \mathrm{Actions}, \mathrm{Constraints}, \mathrm{Generalization})$ and $C'(\ell)=(\mathrm{DD}, \mathrm{CD}, \mathrm{IC}, \mathrm{CG})$ | Disambiguates issue and code context |
| Test-time Scaling | $\Delta P_1,\ldots,\Delta P_k$ | Diversifies targeted patch deltas |
| Aggregation via Code Review | $P_{\mathrm{agg}}$ | Reviews, groups, merges, and validates candidates |

The first module performs issue and code context extraction. Issue context extraction maps the issue description $I$ to a structured 5-tuple
$$
I' = (\mathrm{Tgt}, \mathrm{Logic}, \mathrm{Actions}, \mathrm{Constraints}, \mathrm{Generalization}),
$$
where $\mathrm{Tgt}$ denotes affected components, $\mathrm{Logic}$ the intended behavioral change, $\mathrm{Actions}$ a high-level edit plan, $\mathrm{Constraints}$ invariants to preserve, and $\mathrm{Generalization}$ the scope beyond the example. Code context extraction is defined per patch location $\ell$ in $P_{\mathrm{init}}$ as
$$
C'(\ell) = (\mathrm{DD}, \mathrm{CD}, \mathrm{IC}, \mathrm{CG}),
$$
with $\mathrm{DD}$ for data dependencies, $\mathrm{CD}$ for control dependencies, $\mathrm{IC}$ for invariant constraints, and $\mathrm{CG}$ for call-graph context. The prompt-engineering strategy includes templates such as “Given $I$ and $D$, enumerate target modules and invariants,” and analogous prompts for code context [2510.03588].

This stage gives ReFIne a structured intermediate representation absent from many direct patch-generation workflows. A plausible implication is that refinement quality depends not only on the initial patch diff, but on whether issue semantics and surrounding program structure are made explicit before further editing.

## 3. Candidate diversification through test-time scaling

The second module is based on the philosophy of generating $k$ diverse “delta patches” $\Delta P_1,\ldots,\Delta P_k$ by repeated sampling from the LLM in sampling mode with temperature $\tau>0$. The token sampling distribution is written as
$$
P(w_i \mid \mathrm{context}) \propto \exp(\mathrm{logit}_i / \tau),
$$
where a higher $\tau$ yields more exploratory token choices [2510.03588].

Delta-patch generation constructs a prompt combining the structured issue context $I'$, the code context $C'$, and the diff-style $P_{\mathrm{init}}$, then queries the LLM $k$ times to produce small, targeted diffs. In the reported protocol, the default hyperparameters are $\tau=0.7$, $k=5$ samples, and $N_{\mathrm{retries}}=5$. Claude 3.7-Sonnet is used by default for context and delta generation [2510.03588].

The design choice is notable because ReFIne does not attempt to replace the seed patch with an entirely new patch family. Instead, it produces localized deltas around the original draft patch. This suggests a refinement-centric view of APR in which diversity is applied to patch edits rather than to full repair trajectories.

The hyperparameter study directly supports this interpretation. More retries and higher $\tau$ increase diversity and resolved rate: $1$ retry with $\tau=0.7$ yields $49.0\%$, while $5$ retries with $\tau=0.7$ yields $51.67\%$; the comparison of $\tau=0.0$ versus $0.3$ versus $0.7$ shows monotonic improvement with diversity [2510.03588].

## 4. Aggregation, review, and iterative validation

The third module uses an LLM-powered code review process to retain, reconcile, and validate partial fixes. For each candidate
$$
P_j = \mathrm{apply}(P_{\mathrm{init}},\Delta P_j),
$$
a Code Reviewer Agent judges relevance via
$$
y_j = \mathrm{LLM}_{\mathrm{judge}}(P_j; I') \in \{\mathrm{Yes}, \mathrm{No}\},
$$
and only candidates with $y_j=\mathrm{Yes}$ are retained [2510.03588].

Aggregation proceeds in several stages. ReFIne de-duplicates candidates and groups mutually conflicting patches, where two patches conflict if they modify the same line differently. Within each group $G_m$, an LLM is prompted to merge or select the best combined diff based on $I'$. All non-conflicting unified diffs are then merged into a single patch $P_{\mathrm{agg}}$. A Patch Validator executes $P_{\mathrm{agg}}$ on $T$; if $P_{\mathrm{agg}}$ passes, the system returns $P_r=P_{\mathrm{agg}}$, otherwise it sets $P_{\mathrm{init}}\leftarrow P_{\mathrm{agg}}$ and repeats up to $N_{\mathrm{retries}}$ [2510.03588].

Gemini 2.5-Pro is the default reviewer model in the reported setup. Backend selection is not treated as incidental. The paper reports three configurations: homogeneous Claude 3.7 at $44.7\%$ $(+7.7\ \mathrm{pp})$, homogeneous Gemini 2.5 at $50.3\%$ $(+13.3\ \mathrm{pp})$, and a mixed setup using Claude 3.7 for Context/Delta and Gemini 2.5 for Reviewer at $51.67\%$ $(+14.67\ \mathrm{pp})$, which is the best reported combination [2510.03588].

This module encodes the paper’s broader claim that agentic collaboration is a missing component in current APR pipelines. The improvement is not attributed to a single stronger model call, but to a division of labor among extraction, diversification, review, and validation.

## 5. Experimental evaluation and empirical behavior

The evaluation is conducted on SWE-Bench Lite and SWE-Bench Verified. SWE-Bench Lite contains 300 real-world Python GitHub issues, while SWE-Bench Verified contains 500 issues with private test suites for final evaluation. The reported metrics are Resolved Issue Rate, Correct Location Rate, and cost and token usage per issue. The evaluation protocol is single-pass, with no external Internet and hidden test suites [2510.03588].

| Evaluation setting | Baseline or change | Result |
|---|---|---|
| SWE-Bench Lite (AutoCodeRover seed) | AutoCodeRover alone | 37.00% |
| SWE-Bench Lite (AutoCodeRover seed) | REFINE | 51.67% |
| SWE-Bench Verified | Resolution rate | 51.6% $\rightarrow$ 63.8% |

On SWE-Bench Lite, ReFIne boosts AutoCodeRover by $14.67$ percentage points, from $37.00\%$ to $51.67\%$, surpassing all prior baselines and achieving state-of-the-art results among workflow-based approaches. On SWE-Bench Verified, it improves the resolution rate by $12.2$ percentage points, from $51.6\%$ to $63.8\%$. When integrated across multiple APR systems, it yields cross-tool gains of $3.33$ to $20$ percentage points, with an average improvement of $14$ percentage points. The paper also reports that ReFIne fixes $16$ unique issues that no other SOTA tool resolves [2510.03588].

The baseline set spans workflow-based systems—AutoCodeRover, Agentless-1.5, SpecRover, ExpeRepair, and OrcaLoca+Agentless—and agentic systems including SWE-agent, OpenHands, DARS, devlo, BlackBoxAI, Globant Code Fixer, CodeV, Codart AI, CodeStory, Lingxi, and Moatless Tools. This breadth is important because the reported average gain is presented as evidence of broad effectiveness and generalizability rather than seed-specific tuning [2510.03588].

Ablation studies show that removing any module among Context, Delta Generation, and Reviewer reduces resolved rate by $2$ to $7$ percentage points, and that all three modules together yield the best result. This is consistent with the system design: context extraction alone does not substitute for patch diversity, and diversity alone does not substitute for review-driven aggregation [2510.03588].

## 6. Interpretation, scope, and limitations

ReFIne is presented as a general refinement module rather than a monolithic APR agent. Its intended contribution is to close the gap between near-correct and correct patches by systematically transforming draft patches through context disambiguation, diversified delta patch generation via test-time LLM sampling, and LLM-powered aggregation [2510.03588].

The reported results support two methodological conclusions. First, refinement functions as a distinct stage in APR rather than as a by-product of generation. Second, the combination of structured context extraction and agentic collaboration improves both workflow-based and open-agent-based seeds. The paper’s summary claim is that these results highlight “the effectiveness of refinement as a missing component in current APR pipelines” and “the potential of agentic collaboration in closing the gap between near-correct and correct patches” [2510.03588].

The paper also states several threats to validity and limitations. External validity is constrained because SWE-Bench issues may be higher quality than noisy real-world reports. Model dependency remains substantial because the results are tied to Claude and Gemini, and future LLMs may differ. Scalability is a concern because very large codebases may exceed context windows and cost budgets [2510.03588].

Potential extensions identified in the paper include hierarchical context extraction at multi-file and pull-request level, a dynamic retriever to select minimal code slices for context, and integration with fine-tuned code-specialist LLMs. The implementation and replication assets are reported as open source via the anonymous GitHub repository linked in the paper [2510.03588].

Source: https://www.emergentmind.com/topics/refine