Is Three the Magic Number? An Empirical Evaluation of LLM-Based Repair Loops


1 Introduction↩︎

Large Language Models (LLMs) are far from perfect. Nevertheless, they are increasingly used in software engineering (SE) research and practice [1]. A common pattern when using LLMs for programming tasks is iterative refinement: users generate a solution, validate the output, identify remaining issues such as compiler errors, failing test cases, or missing edge cases, and feed these back to the model for repair. This process is repeated until the generated artifact either satisfies the requirements or the user abandons the attempt and reformulates the prompt. This iterative repair behavior has also been adopted by many LLM-based SE tools [2][11].

Instead of relying on manual feedback, such systems automatically validate generated artifacts using mechanisms such as compilation, static analysis, or test execution. When validation fails, the observed errors are provided to the model in order to generate a repaired version automatically. To prevent infinite repair cycles or oscillating behaviors in which one repair introduces new faults, these systems typically enforce an arbitrary fixed iteration limit [12], [13]. Furthermore, with the emergence of autonomous LLM agents [14][16] repair loops are becoming even more relevant. Such agents internally perform iterative cycles of tool calls, generation, validation, testing, and repair in order to accomplish complex SE tasks. As agent-based workflows become increasingly common, the choice of repair-loop limits directly affects the practicality and efficiency of these systems.

Choosing the right limit for repair loop iterations is important and impactful for several reasons. First, each additional repair attempt increases API usage costs and energy consumption, contributing both to higher economic as well as environmental impact [17]. Second, repeated inference calls increase runtime which can lead to slower development workflows. Third, iteration limits directly influence reproducibility and comparability across studies. Different repair budgets may lead to substantially different performance outcomes, making it difficult to fairly compare approaches when iteration limits are selected arbitrarily or are insufficiently documented [18].

Figure 1: Generalized SE workflow with LLM-repair loop

Despite their importance, iteration limits are rarely studied systematically. Existing work often selects a small fixed number of repair attempts without providing empirical justification for this choice [6], [11], [12]. To the best of our knowledge, no prior work systematically studies the impact of repair-loop iteration limits across SE tasks and LLMs. In this work, we investigate the effectiveness of repair loops across multiple SE tasks, including code generation, test generation, and code translation. Using several low-cost LLMs and representative LLM-based SE tools, we analyze whether the commonly used limit of three or five repair attempts is sufficient or whether meaningful improvements continue to occur beyond this threshold. Our findings aim to contribute to a better understanding of how repair budgets should be selected and reported in future LLM-based SE research and systems.

Our central question is:

2 Repair Loops in LLM-Based SE-Tools↩︎

We define a repair-loop-based system as any LLM-based software engineering workflow, tool, or approach that iteratively generates, validates, and repairs artifacts until either a correct solution is produced or a predefined iteration limit is reached. 1 illustrates the general structure of such an approach.

These systems typically receive input in the form of task-specific context and an initial generation prompt. For example, a system may receive a textual specification and is prompted to generate source code, or receive source code and is prompted to generate corresponding test cases. Based on this input, the LLM generates an initial candidate artifact. The generated output is then validated using task-dependent mechanisms. In code generation scenarios, this may involve compilation, static analysis, or test execution. In test-generation tasks, generated tests may be checked for syntactic validity, coverage, or execution behavior.

If the produced artifact satisfies the validation criteria, the workflow terminates successfully and returns the generated output. Otherwise, the system extracts feedback from the failed validation step and provides this information back to the LLM to generate a repaired version of the artifact.

The repaired artifact is then validated again, resulting in an iterative generate \(\rightarrow\) validate \(\rightarrow\) repair cycle. This process continues until either a valid artifact is produced or a predefined iteration limit is reached and an error is returned. In practice these iteration limits are commonly implemented implicitly through bounded loops or explicitly through retry counters within the orchestration logic of the system. Despite being a central configuration parameter, these limits are often selected heuristically and rarely justified empirically [4], [6], [7].

In the context of this work, repair generally refers to feedback-driven regeneration conditioned on previous validation failures and we define a repair step as one iteration of the repair loop following a failed validation attempt.

3 Empirical Study↩︎

To answer our posed question we conduct an empirical study across a set of tools with different tasks, datasets, and programming languages. The tasks span code generation, test-case generation and code translation. To ensure that any observed results are not due to a particular model’s behavior we select three models: Google’s Gemma-41, Qwen3.52 and OpenAI’s gpt-4o-mini3.

We study four existing repair-based tools and a baseline that simulates human-style iterative chat interactions solving coding problems. The tools include INTERVENOR [7], Large Language Model Debugger (LDB) [8], from which we use the code translation component, CASCADE [5] and OpenCodeInterpreter (OCI) [12] in two versions. First, the original version where the initial prompt contains all test-cases that should pass and a second version without test-cases in the initial prompt. 1 lists the tools and their datasets. Each datasets was also used in the tools original papers. For the baseline (Basic LLM Call) we use Defects4J [19].

Table 1: Tools, datasets, and tasks used in our empirical study.
Tool Dataset Task
Basic LLM Call Defects4J [19] Test Generation
OCI [12] MBPP [20] Code Generation
INTERVENOR [7] HumanEval [21] Code Generation
CASCADE [5] CASCADE [5] Test Generation
LDB [8] TransCoder [22] Code Translation

To enable a comparison between the tools, we made two types of modifications. First, all tools were adapted to support the backbone LLMs that were hosted on a local server (Gemma-4 and Qwen3.5). For INTERVENOR this entailed a change from the OpenAI completions to the chat.completions API to enable the usage of the contemporary models since the completions API is deprecated. OCI was restructured to use a multi-turn conversation format rather than rebuilding the prompt from scratch each iteration, as in the original. These changes slightly alter the semantics of OCI and INTERVENOR, however, the change to the API call would be needed anyways to use contemporary models and were not specific to our study.

Second modification was to LDB, where the original implementation only evaluated correctness when the final repair loop is finished. We added per-iteration evaluation against the full held-out test suite at every step. For CASCADE, whose primary purpose is detecting inconsistent documentation-method pairs, we extracted only its test-case generation stage and discarded the later inconsistency analysis stages, since the initial test-generation component is the only part that implements a complete iterative repair loop suitable for our study. Crucially, the repair loop control logic and correctness criteria remained unchanged in all tools. The only changes were with respect to measurement and model compatibility. Furthermore, we fixed the temperature for all experiments at 0.2.

Figure 2: Completion rate as a function of repair steps across six tool–dataset combinations and three LLM backbones.

For each tool with every backbone LLM we compute the percentage of completed tasks on the respective dataset after the initial generation, step 0, and at each subsequent repair step up to a maximum of ten repairs. Those results are shown in 2, where each panel corresponds to one tool and each curve to a model.

Across all tools the curves share a consistent concave shape. From the initial generation to the first few repair steps the completion rate rises steeply and then flattens, with each additional step resulting in smaller improvements than the last. 2 shows this in concrete numbers, where we calculated the average relative improvements from each repair step to the next. Notably, the largest relative improvement occurs at step 1 and that by step 3 the marginal gains have dropped to single digit percentages or below. This pattern holds across all three backbone models and all tasks including outliers such as Qwen on LDB starting with only 30% completion rate and then improving drastically. This suggests that diminishing returns are a recurring characteristic of the evaluated repair-loop workflows.

Table 2: Mean relative improvement per repair step.
Percentage increase to previous step
1 2 3 4 5 6 7 8 9 10
Basic LLM Call 0.0
INTERVENOR 0.0
CASCADE 0.0 0.0 0.0 0.0
OCI 0.0 0.0 0.0 0.0
OCI (w/out tests) 0.0 0.0
LDB 0.0 0.0

When examining where tools differ, the main distinction lies in how quickly the return on repair diminishes. OCI shows only marginal improvements after the first repair step, while the Basic LLM Call and CASCADE are still rising at step 3. Furthermore, within each panel, models may start at different absolute levels but follow the same curve shape. The gap between models is largest at step 0 and narrows with each repair step, visible most clearly in LDB where Qwen starts near 30% and Gemma near 85% yet both curves flatten at roughly the same point. Furthermore, we can observe that each tool, independent of the model backbone, provides a different performance ceiling and a different rate at which repairs approach it.

4 Discussion↩︎

The first three to four repair steps contribute the vast majority of the total achievable gain. Following iterations can still repair additional cases, however, improvements drop to near zero shortly after steps 5 to 7 across all evaluated tasks and tools. Hence we argue that the costs that come with these improvements require a careful trade-off analysis with respect to parameters such as API costs and energy usage. This consideration is increasingly relevant for agent systems, where repair loops are often deeply integrated into the execution workflow and may trigger multiple expensive inference calls per task or even result in infinite loops.

Interestingly, our results indicate that factors such as feedback design and content, orchestration logic, and the validation strategy substantially influence how effective additional repair attempts are at improving generated artifacts. This comes from the observation that completion curves for the same tool have similar shapes across all models, even when the absolute performance levels differ.

The comparison between the two OCI variants particularly highlights this effect. While both variants share nearly identical repair behavior in later iterations, they differ substantially in their initial success rates. The primary difference between the two approaches is that one variant already includes tests during the initial generation step, whereas the other only incorporates the output of the test suite as repair feedback during subsequent iterations. Despite this relatively small architectural difference, the resulting repair trajectories differ noticeably during the early repair stages before converging toward similar trends.

At the same time, model-specific performance characteristics remain visible across tools. For almost all evaluated workflows, the Gemma model achieves the strongest overall performance, while the older GPT variant generally performs worst. However, CASCADE represents a notable exception to this trend. One possible explanation is that CASCADE was originally evaluated and probably optimized around the specific output of GPT-based models. This observation further reinforces that the interaction between tool repair logic and model behavior needs to be examined carefully.

Furthermore, our replication effort revealed that many existing LLM-based SE tools are not easily transferable across models. In practice, substantial modifications to prompts, parsing logic, validation mechanisms, or orchestration strategies are often required when replacing the originally intended backbone model. This raises broader concerns regarding comparability and reproducibility in LLM-based SE research. While a detailed investigation of reproducibility challenges is outside the scope of this work, our findings indicate that LLM tools and specifically repair-loop behavior cannot always be studied independently of the surrounding tool architecture and model assumptions and therefore cannot always be compared directly.

5 Threats to Validity↩︎

5.0.0.1 Internal Validity

Our study does not use the original models employed by the evaluated tools and prior work. In addition, due to computational and financial constraints, we do not perform repeated executions for every experimental configuration. Since LLMs exhibit non-deterministic behavior, repeated runs may produce variance in absolute performance values. However, the goal of this work is not to reproduce exact performance numbers, but to analyze repair-loop trends across different iteration limits. We therefore use the same set of models consistently across all evaluated tools and tasks.

Furthermore, the evaluation generally relies on task-specific automated validation procedures such as compilation and test execution. While these mechanisms provide scalable correctness signals, they may not fully capture semantic correctness or overall software quality, however, they ensure consistency with existing evaluation methodologies.

5.0.0.2 External Validity

Our experiments focus primarily on cost-efficient LLMs, and the observed results may therefore not generalize directly to larger, newer models. More capable models may require fewer repair attempts due to stronger reasoning and generation capabilities.

Furthermore, the selected tasks may not represent the full spectrum of repair-loop-based SE workflows. Nevertheless, we evaluate three substantially different SE tasks across five datasets, providing diversity in both generation objectives and validation mechanisms. Code generation in particular represents one of the most widely studied and practically relevant applications of LLMs in SE, increasing the practical relevance of the evaluated tools and benchmarks. The consistency of observed trends across multiple tasks and datasets partially mitigates this threat even further.

6 Related Work↩︎

Prior work on LLM-based repair can be categorized into three types. The first category is feedback driven generation that only uses an LLM and no information from the external executions [10], [11].

The next category characterizes tools that utilize some form of execution based feedback [6], including runtime and compilation errors [4], [12], [13], natural language [3] and execution graphs [8].

Another category distributes the repair process across multiple agents or structured components. INTERVENOR [7] separates a Code Teacher, which constructs a Chain-of-Repair from compiler feedback, from a Code Learner, which executes the revisions, within three turns. PairCoder [9] combines planning and implementation agents with execution-guided repair within ten iterations.

Finally, our work is also related to empirical studies of repair and self-correction. Critical surveys note that self-correction effectiveness depends strongly on the feedback source and evaluation design, and that unclear protocols can overestimate gains [23]. Closest to our motivation, Olausson et al. [2] compare repair with drawing additional independent samples under comparable compute budgets, while Tang et al. [24] frame repair as an exploration–exploitation tradeoff. In contrast, we ask a complementary question: Given that many LLM-based SE tools already implement repair loops, how much does each additional iteration help? We therefore measure per-iteration completion rates across existing tools, tasks, datasets, and model backbones, shifting the focus from whether to use repair to how iteration limits should be selected, justified, and reported.

7 Conclusion↩︎

Repair loops have become a fundamental component of modern LLM-based software engineering systems, ranging from code-generation tools to autonomous agent workflows. Despite their widespread use, the choice of repair-loop iteration limits is often treated as an arbitrary implementation detail and rarely justified empirically.

In this work, we conducted an empirical study across multiple repair-loop-based software engineering tools, tasks, datasets, and backbone models to analyze the effectiveness of additional repair iterations. Across all evaluated settings, we observe a consistent pattern of diminishing returns: the majority of achievable gains are obtained within the first three to four repair steps, while later iterations can still contribute marginal improvements.

Our results suggest that repair-loop behavior depends more strongly on orchestration logic, validation strategy, and feedback design than on the selected backbone model itself. At the same time, the observed interaction effects between tools and models indicate broader reproducibility and comparability challenges in LLM-based software engineering research.

Overall, our findings suggest that repair budgets should be explicitly reported and justified in future work, as they directly influence evaluation outcomes, computational cost, runtime, and environmental impact. As repair loops become increasingly integrated into autonomous agent systems, understanding and standardizing repair-loop behavior will become even more important for the development of reliable and reproducible LLM-based software engineering workflows. For future work we plan to extend on our results by adding more tools, models and conducting a larger scale reproducibility study for LLM-based SE tools.

References↩︎

[1]
A. Fan et al., “Large language models for software engineering: Survey and open problems,” in 2023 IEEE/ACM international conference on software engineering: Future of software engineering (ICSE-FoSE), 2023, pp. 31–53.
[2]
T. X. Olausson, J. P. Inala, C. Wang, J. Gao, and A. Solar-Lezama, “Is self-repair a silver bullet for code generation?” in The twelfth international conference on learning representations, ICLR 2024, vienna, austria, may 7-11, 2024, 2024, [Online]. Available: https://openreview.net/forum?id=y0GJXRungR.
[3]
T. Ridnik, D. Kredo, and I. Friedman, “Code generation with AlphaCodium: From prompt engineering to flow engineering,” CoRR, vol. abs/2401.08500, 2024, doi: 10.48550/ARXIV.2401.08500.
[4]
R. Pan, M. Kim, R. Krishna, R. Pavuluri, and S. Sinha, ASTER: Natural and multi-language unit test generation with LLMs,” in 47th IEEE/ACM international conference on software engineering: Software engineering in practice, SEIP@ICSE 2025, ottawa, ON, canada, april 27 - may 3, 2025, 2025, pp. 413–424, doi: 10.1109/ICSE-SEIP66354.2025.00042.
[5]
T. Kiecker, J. A. Sparka, M. Reuter, A. Ziegler, and L. Grunske, “Cascade: Detecting inconsistencies between code and documentation with automatic test generation,” Proceedings of the ACM on Software Engineering, vol. 3, no. FSE, pp. 1–23, Jul. 2026, doi: 10.1145/3808175.
[6]
T.-T. Nguyen, T. T. Vu, H. D. Vo, and S. Nguyen, “An empirical study on capability of large language models in understanding code semantics,” Information and Software Technology, vol. 185, p. 107780, 2025, doi: 10.1016/j.infsof.2025.107780.
[7]
H. Wang et al., INTERVENOR: Prompting the coding ability of large language models with the interactive chain of repair,” in Findings of the association for computational linguistics, ACL 2024, bangkok, thailand and virtual meeting, august 11-16, 2024, 2024, pp. 2081–2107, doi: 10.18653/V1/2024.FINDINGS-ACL.124.
[8]
L. Zhong, Z. Wang, and J. Shang, “Debug like a human: A large language model debugger via verifying runtime execution step by step,” in Findings of the association for computational linguistics, ACL 2024, bangkok, thailand and virtual meeting, august 11-16, 2024, 2024, pp. 851–870, doi: 10.18653/V1/2024.FINDINGS-ACL.49.
[9]
H. Zhang, W. Cheng, Y. Wu, and W. Hu, “A pair programming framework for code generation via multi-plan exploration and feedback-driven refinement,” in Proceedings of the 39th IEEE/ACM international conference on automated software engineering, ASE 2024, sacramento, CA, USA, october 27 - november 1, 2024, 2024, pp. 1319–1331, doi: 10.1145/3691620.3695506.
[10]
F. Zhang et al., RepoCoder: Repository-level code completion through iterative retrieval and generation,” in Proceedings of the 2023 conference on empirical methods in natural language processing, EMNLP 2023, singapore, december 6-10, 2023, 2023, pp. 2471–2484, doi: 10.18653/v1/2023.emnlp-main.151.
[11]
A. Madaan et al., SELF-REFINE: Iterative refinement with self-feedback,” in Proceedings of the 37th international conference on neural information processing systems, NeurIPS 2023, new orleans, LA, USA, december 10-16, 2023, 2023, pp. 46534–46594, doi: 10.5555/3666122.3668141.
[12]
T. Zheng et al., “OpenCodeInterpreter: Integrating code generation with execution and refinement,” in Findings of the association for computational linguistics, ACL 2024, bangkok, thailand and virtual meeting, august 11-16, 2024, 2024, pp. 12834–12859, doi: 10.18653/V1/2024.FINDINGS-ACL.762.
[13]
A. Sapozhnikov, M. Olsthoorn, A. Panichella, V. Kovalenko, and P. Derakhshanfar, TestSpark: IntelliJ IDEA’s ultimate test generation companion,” in Proceedings of the 2024 IEEE/ACM 46th international conference on software engineering: Companion proceedings, ICSE-Companion 2024, lisbon, portugal, april 14-20, 2024, 2024, pp. 30–34, doi: 10.1145/3639478.3640024.
[14]
Y. Zhang, H. Ruan, Z. Fan, and A. Roychoudhury, “AutoCodeRover: Autonomous program improvement,” in Proceedings of the 33rd ACM SIGSOFT international symposium on software testing and analysis, ISSTA 2024, vienna, austria, september 16-20, 2024, 2024, pp. 1592–1604, doi: 10.1145/3650212.3680384.
[15]
I. Bouzenia, P. T. Devanbu, and M. Pradel, “RepairAgent: An autonomous, LLM-based agent for program repair,” in 47th IEEE/ACM international conference on software engineering, ICSE 2025, ottawa, ON, canada, april 26 - may 6, 2025, 2025, pp. 2188–2200, doi: 10.1109/ICSE55347.2025.00157.
[16]
J. Yang et al., “SWE-agent: Agent-computer interfaces enable automated software engineering,” 2024, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2024/hash/5a7c947568c1b1328ccc5230172e1e7c-Abstract-Conference.html.
[17]
K. S. Cheung, M. Kaul, G. Jahangirova, M. R. Mousavi, and E. Zie, “Comparative analysis of carbon footprint in manual vs. LLM-assisted code development,” in Proceedings of the 1st international workshop on responsible software engineering, ResponsibleSE 2025, trondheim, norway, june 23-28, 2025, 2025, pp. 13–20, doi: 10.1145/3711919.3728678.
[18]
C. Gao, X. Hu, S. Gao, X. Xia, and Z. Jin, “The current challenges of software engineering in the era of large language models,” ACM Trans. Softw. Eng. Methodol., vol. 34, no. 5, pp. 127:1–127:30, 2025, doi: 10.1145/3712005.
[19]
R. Just, D. Jalali, and M. D. Ernst, “Defects4J: A database of existing faults to enable controlled testing studies for java programs,” in International symposium on software testing and analysis, ISSTA ’14, san jose, CA, USA - july 21 - 26, 2014, 2014, pp. 437–440, doi: 10.1145/2610384.2628055.
[20]
J. Austin et al., “Program synthesis with large language models,” CoRR, vol. abs/2108.07732, 2021, [Online]. Available: https://arxiv.org/abs/2108.07732.
[21]
M. Chen et al., “Evaluating large language models trained on code,” CoRR, vol. abs/2107.03374, 2021, [Online]. Available: https://arxiv.org/abs/2107.03374.
[22]
B. Rozière, M.-A. Lachaux, L. Chanussot, and G. Lample, “Unsupervised translation of programming languages,” in Advances in neural information processing systems 33: Annual conference on neural information processing systems 2020, NeurIPS 2020, december 6-12, 2020, virtual, 2020, [Online]. Available: https://proceedings.neurips.cc/paper/2020/hash/ed23fbf18c2cd35f8c7f8de44f85c08d-Abstract.html.
[23]
R. Kamoi, Y. Zhang, N. Zhang, J. Han, and R. Zhang, “When can LLMs actually correct their own mistakes? A critical survey of self-correction of LLMs,” Trans. Assoc. Comput. Linguistics, vol. 12, pp. 1417–1440, 2024, doi: 10.1162/TACL\_A\_00713.
[24]
H. Tang et al., “Code repair with LLMs gives an exploration-exploitation tradeoff,” 2024, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2024/hash/d5c56ec4f69c9a473089b16000d3f8cd-Abstract-Conference.html.

  1. huggingface.co/google/gemma-4-31B-it↩︎

  2. huggingface.co/Qwen/Qwen3.5-27B↩︎

  3. platform.openai.com/docs/models/gpt-4o-mini↩︎