Paper deep dive
How Many Tries Does It Take? Iterative Self-Repair in LLM Code Generation Across Model Scales and Benchmarks
Johin Johny Arimbur
Intelligence
Status: succeeded | Model: google/gemini-3.1-flash-lite-preview | Prompt: intel-v1 | Confidence: 98%
Last extracted: 4/14/2026, 2:18:51 AM
Summary
This paper investigates iterative self-repair in LLM code generation across seven models (Llama 3.1/3.3/4, Qwen3, Gemini 2.5) and two benchmarks (HumanEval, MBPP). It demonstrates that modern instruction-tuned models can effectively perform self-repair using only prompting, even at the 8B scale, with Gemini 2.5 Flash achieving the highest pass rates. The study provides a comparative analysis of dense vs. MoE architectures and identifies that assertion errors are the most difficult to repair, while two rounds of repair capture the majority of performance gains.
Entities (5)
Relation Signals (3)
Gemini 2.5 Flash → performedon → HumanEval
confidence 100% · Gemini 2.5 Flash achieves the highest final pass rates (96.3% HumanEval)
Llama 4 Scout → usesarchitecture → Mixture-of-Experts
confidence 100% · Llama 4 Scout (MoE, 16 experts)
Iterative self-repair → improves → Pass rate
confidence 95% · self-repair universally improves pass rates
Cypher Suggestions (0)
No Cypher suggestions yet.
Abstract
Abstract:Large language models frequently fail to produce correct code on their first attempt, yet most benchmarks evaluate them in a single-shot setting. We investigate iterative self-repair (feeding execution errors back to the model for correction) across seven models spanning three families and both open-weight and proprietary providers: Llama 3.1 8B, Llama 3.3 70B, Llama 4 Scout (MoE, 16 experts), Llama 4 Maverick (MoE, 128 experts), Qwen3 32B, Gemini 2.5 Flash, and Gemini 2.5 Pro. On HumanEval (164 problems) and MBPP Sanitized (257 problems) with up to five attempts, self-repair universally improves pass rates: +4.9 to +17.1 pp on HumanEval and +16.0 to +30.0 pp on MBPP. Gemini 2.5 Flash achieves the highest final pass rates (96.3% HumanEval, 93.8% MBPP). Most gains concentrate in the first two this http URL-type analysis shows assertion errors (logical mistakes) are the hardest to repair at ~45%, while syntax and name errors are repaired at substantially higher rates, connecting to broader findings on the limits of LLM self-correction. Prior work found that weaker models fail at self-repair or require fine-tuning; we show that modern instruction-tuned models succeed with prompting alone, even at 8B scale. We also provide the first comparison of dense and MoE architectures for self-repair, and extend the repair-vs-resampling tradeoff analysis to modern models. A prompt ablation reveals chain-of-thought repair yields up to +5.5 pp additional self-repair gain (measured as improvement in repair delta) over minimal prompting for capable models.
Tags
Links
- Source: https://arxiv.org/abs/2604.10508v1
- Canonical: https://arxiv.org/abs/2604.10508v1
Trouble viewing inline? Open PDF directly →
Full Text
57,000 characters extracted from source content.
Expand or collapse full text
How Many Tries Does It Take? Iterative Self-Repair in LLM Code Generation Across Model Scales and Benchmarks Johin Johny Arimbur Independent Researcher johinjohny144@gmail.com Abstract—Large language models frequently fail to produce correct code on their first attempt, yet most benchmarks evaluate them in a single-shot setting. We investigate iterative self-repair (feeding execution errors back to the model for correction) across seven models spanning three families and both open- weight and proprietary providers: Llama 3.1 8B, Llama 3.3 70B, Llama 4 Scout (MoE, 16 experts), Llama 4 Maverick (MoE, 128 experts), Qwen3 32B, Gemini 2.5 Flash, and Gemini 2.5 Pro. On HumanEval (164 problems) and MBPP Sanitized (257 problems) with up to five attempts, self-repair universally improves pass rates: +4.9 to +17.1 p on HumanEval and +16.0 to +30.0 p on MBPP. Gemini 2.5 Flash achieves the highest final pass rates (96.3% HumanEval, 93.8% MBPP). Most gains concentrate in the first two rounds. Error-type analysis shows assertion errors (logical mistakes) are the hardest to repair at∼45%, while syntax and name errors are repaired at substantially higher rates, connecting to broader findings on the limits of LLM self- correction. Prior work found that weaker models fail at self-repair or require fine-tuning; we show that modern instruction-tuned models succeed with prompting alone, even at 8B scale. We also provide the first comparison of dense and MoE architectures for self-repair, and extend the repair-vs-resampling tradeoff analysis to modern models. A prompt ablation reveals chain-of-thought repair yields up to +5.5 p additional self-repair gain (measured as improvement in repair delta) over minimal prompting for capable models. Index Terms—large language models, code generation, self- repair, iterative refinement, HumanEval, MBPP, self-debugging I. INTRODUCTION The ability of large language models (LLMs) to generate functionally correct code from natural-language specifications has improved dramatically in recent years [1]–[3]. Benchmarks such as HumanEval [1] and MBPP [4] have become standard yardsticks, typically reporting a pass@1 metric: the fraction of problems solved correctly on a single attempt. While informa- tive, this single-shot evaluation protocol diverges sharply from how human programmers actually write code. A professional developer routinely writes an initial draft, runs it, reads the error message, and iterates, often multiple times, before arriving at a correct solution. Iterative self-repair replicates this workflow within an LLM pipeline. When a generated program fails its test suite, the model receives the error traceback and is asked to produce a corrected version. This cycle can repeat for a fixed number of rounds. Prior work has explored self-repair with proprietary models such as GPT-3.5 and GPT-4 [5], [6], yielding mixed conclusions about its effectiveness. Olausson et al. [5] notably argued that self-repair is “not a silver bullet,” observing that weaker models may introduce new errors during repair attempts. However, the landscape has changed significantly since those studies. A new generation of open-weight models (2024–2025) exhibits substantially stronger instruction-following and error- comprehension capabilities, and novel architectures such as mixture-of-experts (MoE) have become prevalent. No prior work has evaluated self-repair on these modern models or compared dense vs. MoE architectures for repair. These developments motivate a fresh empirical investigation: does self-repair now work universally, even for smaller models? How do dense and MoE architectures differ in their repair dynamics? And what practical guidelines can we derive for deployment? In this paper, we address these questions with a sys- tematic evaluation across seven models from three families: Llama 3.1 8B (8B dense) [7], Llama 3.3 70B (70B dense) [8], Llama 4 Scout 17B (17B active, MoE with 16 experts) [9], Llama 4 Maverick 17B (17B active, MoE with 128 experts) [9], Qwen3 32B (32B dense) [10], Gemini 2.5 Flash [11], and Gemini 2.5 Pro [11]. The five open-weight models are accessed via the Groq free-tier API; the two Gemini models are accessed via Google Cloud Vertex AI. All use greedy decoding (temperature= 0.0) for reproducibility. We evaluate on two benchmarks, HumanEval (164 problems) and MBPP Sanitized (257 problems), with up to five attempts per problem. Our contributions are as follows: 1) We demonstrate that prompt-based self-repair is now effective across seven models from three families, even at 8B scale, updating the finding by Olausson et al. [5] that weaker models are harmed by self-repair, and contrasting with Chen et al. [12] who found limited gains for a 7B model. Prior work required fine-tuning to enable small-model self-repair [13], [14]; we show that modern instruction-tuned models succeed without it. 2) We present, to our knowledge, the first direct comparison of dense and mixture-of-experts architectures for self- repair across multiple model families, revealing distinct interaction patterns: on HumanEval, Scout (16 experts) achieves the highest repair gain among open-weight arXiv:2604.10508v1 [cs.SE] 12 Apr 2026 models (+14.0 p), while the Gemini models establish new ceiling performance levels. 3)We provide cross-benchmark validation on both Hu- manEval and MBPP Sanitized, showing consistent model rankings and diminishing-returns patterns, strengthening generalizability beyond single-benchmark studies. 4) We present fine-grained error-type analysis revealing that error category is a strong predictor of repair success: name errors are repaired at∼77% rates, while assertion errors succeed at only∼45%, connecting to the broader literature on LLM self-correction limits [15]. 5)We quantify the diminishing-returns curve and derive practical deployment guidelines: two repair rounds cap- ture the majority (76–95%) of achievable gains. Our token-efficiency comparison against independent resam- pling extends the exploration-exploitation framework of Tang et al. [16] to modern models, confirming that self- repair is increasingly advantageous for capable models. 6) We conduct a repair prompt ablation comparing minimal, explain-then-fix, and chain-of-thought strategies, finding that CoT prompting yields +5.5 p additional repair gain over minimal prompting for the 70B model. I. RELATED WORK A. Code Generation with LLMs The emergence of Codex [1] demonstrated that LLMs fine- tuned on code repositories could generate functionally correct programs from docstrings. Subsequent work scaled this capa- bility through larger models [2], code-specific pre-training [3], and reinforcement learning from execution feedback [17]. The HumanEval benchmark [1] and the Mostly Basic Programming Problems (MBPP) dataset [4] have become standard evaluation suites, while more challenging benchmarks such as APPS [18] and SPoC [19] test competition-level reasoning. B. Self-Debugging and Self-Repair Chen et al. [6] proposed Self-Debug, demonstrating that LLMs can identify and fix bugs in their own code when provided with execution results. Their approach included several feedback strategies: simple error messages, code explanations, and unit test traces. Olausson et al. [5] conducted a thorough investigation of self-repair, concluding that while GPT-4 benefited substantially, weaker models like GPT-3.5 often failed to improve or even degraded in performance. More recently, Chen et al. [12] revisited self-debugging with self- generated tests, finding that even a 7B model (Qwen2.5-Coder) showed limited or negative gains from prompt-based self- debugging on HumanEval. Two concurrent lines of work have shown that fine-tuning can unlock self-repair for smaller models: CYCLE [13] trained 350M–3B models to self-refine through iterative code generation, and LeDex [14] used supervised fine- tuning and reinforcement learning to enable self-debugging in CodeLlama-7B/13B. Our work differs from all of these in demonstrating that modern 2024–2025 instruction-tuned models benefit from prompt-based self-repair without any fine-tuning, even at the 8B scale. C. Iterative Refinement Beyond Code The principle of iterative self-improvement has been explored in broader contexts. Madaan et al. [20] introduced Self-Refine, a general framework in which LLMs iteratively critique and revise their own outputs across diverse tasks. Shinn et al. [21] proposed Reflexion, using verbal reinforcement signals to improve agent performance over multiple episodes. However, Huang et al. [15] cautioned that LLMs cannot reliably self- correct reasoning without external feedback, an observation consistent with our finding that assertion errors (which require reasoning corrections) are the hardest to repair. Tang et al. [16] formalized the repair-vs-resampling decision as an exploration- exploitation tradeoff, proposing a Thompson Sampling strategy (REx) that dynamically allocates between repair and resampling. Our resampling comparison extends this line of work with modern 2024–2025 models, confirming that the tradeoff is model-dependent. D. Multi-Turn and Collaborative Code Generation Recent work has also investigated multi-turn interactions for code generation. Key et al. [22] explored multi-turn code generation with instruction-tuned models, while Zhang et al. [23] investigated self-collaboration patterns with ChatGPT. Zhong et al. [24] proposed LDB, a debugger that verifies runtime execution step-by-step. SelfEvolve [25] used LLMs to iteratively evolve code through self-generated feedback. Our work differs in its focus on the simplest possible self-repair protocol (feeding back raw error messages) and its systematic comparison across seven models from three families and two benchmarks. I. METHODOLOGY A. Self-Repair Protocol Our iterative self-repair protocol operates as follows. Given a programming problem specified by a function signature and docstring (as in HumanEval and MBPP), the model generates an initial code solution at roundR 0 . This solution is extracted from the model’s response, combined with the corresponding test cases, and executed in a sandboxed Python environment. If all test cases pass, the problem is marked as solved. If execution produces an error, we capture the error type and traceback message, then construct a repair prompt containing: (1) the original problem specification, (2) the model’s previous code attempt, and (3) the error message. The model is then asked to generate a corrected solution. This cycle repeats for up to four repair rounds (R 1 throughR 4 ), for a maximum of five total attempts per problem. Formally, for a problempand modelM, letc 0 = M (p)be the initial code generation. Ifexec(c 0 )succeeds, we record success atR 0 . Otherwise, lete 0 = error(c 0 )be the captured error. For each subsequent round i∈1, 2, 3, 4: c i = M (p, c i−1 , e i−1 )(1) where the model receives the problem, its previous attempt, and the error message. Ifexec(c i )succeeds at any round, the problem is marked as solved at roundR i and no further attempts are made. B. Code Extraction LLM outputs frequently contain natural-language expla- nations, markdown formatting, and other non-code content surrounding the actual solution. We employ a code ex- traction pipeline that: (1) removes chain-of-thought traces (e.g.,<think>...</think>tags) that reasoning mod- els may prepend; (2) extracts code from markdown fences (‘python ... ‘), including handling of unclosed fences from truncated responses; and (3) if no complete function definition is found, prepends the function signature to body-only responses with appropriate indentation. C. Error Classification When a solution fails, we classify the error into one of the following categories based on the Python exception type: •AssertionError: The code runs without crashing but pro- duces incorrect output, failing one or more test assertions. These errors indicate logical mistakes. • SyntaxError: The generated code is not valid Python. • TypeError / ValueError: Runtime type mismatches or invalid values, often indicating misunderstanding of the expected input/output types. •NameError: References to undefined variables or func- tions, typically caused by incomplete code generation. • IndexError / KeyError: Out-of-bounds access or missing dictionary keys, indicating edge-case handling failures. •Timeout: The code does not terminate within the allotted time, suggesting infinite loops or excessive computational complexity. D. Metrics Our primary metric is cumulative pass@1 at each roundR i , defined as the fraction of problems solved by roundR i (inclusive of all preceding rounds). Because each problem receives exactly one attempt per round with greedy decoding (temperature= 0.0), pass@1 is deterministic and does not require the unbiased estimator used for stochastic sampling [1]. We also report the self-repair gain∆, defined as the difference between the final cumulative pass@1 (atR 4 ) and the initial pass@1 (atR 0 ), measured in percentage points (p). We note that on HumanEval (n = 164), a single problem corresponds to≈0.6 p; differences smaller than∼2 p (3 problems) should be interpreted cautiously. IV. EXPERIMENTAL SETUP A. Models We evaluate seven models from three families, spanning open-weight and proprietary providers: 1) Open-Weight Models (Groq API): 1)Llama 3.1 8B [7]: An 8-billion-parameter dense trans- former from Meta. This serves as our smallest baseline and represents the class of efficient, instruction-tuned models commonly deployed in resource-constrained settings. 2)Llama 3.3 70B [8]: A 70-billion-parameter dense trans- former from Meta. This is the largest dense open-weight model in our evaluation and provides a strong baseline for comparing against mixture-of-experts architectures. 3)Llama 4 Scout 17B [9]: A mixture-of-experts (MoE) model from Meta with 17 billion active parameters distributed across 16 experts. The MoE architecture allows the model to maintain a large total parameter count while activating only a fraction of parameters per token. 4)Llama 4 Maverick 17B [9]: A mixture-of-experts model from Meta with 17 billion active parameters and 128 experts. Compared to Scout, Maverick uses significantly more experts, providing an interesting comparison point for how MoE granularity affects code generation and self-repair. 5) Qwen3 32B [10]: A 32-billion-parameter dense trans- former from Alibaba. Qwen3 supports both reasoning (thinking) and non-reasoning modes. Thinking mode was disabled via the/no_thinksetting to ensure fair comparison with non-reasoning models. 2) Proprietary Models (Vertex AI): 6) Gemini 2.5 Flash [11]: A lightweight model from Google optimized for speed and cost-efficiency. Gem- ini 2.5 Flash is designed as a fast-inference model suitable for high-throughput applications, making it an interesting comparison for self-repair efficiency. 7) Gemini 2.5 Pro [11]: Google’s flagship reasoning model with extended “thinking” capabilities. Unlike Qwen3’s optional thinking mode, Gemini 2.5 Pro integrates reasoning natively. This model represents the frontier of proprietary model capability in our evaluation. The inclusion of Gemini models extends our evaluation from two model families (Meta, Alibaba) to three (Meta, Alibaba, Google), and from open-weight-only to a mix of open-weight and proprietary models. This broadens the generalizability of our findings. All models are queried with greedy decoding (temperature= 0.0) to ensure deterministic, reproducible outputs. A minimal system prompt is used for all models: “You are an expert Python programmer. Complete the given function. Return ONLY the Python code, no explanations, no markdown formatting.” No few-shot examples are provided. For initial generation, each model receives only the function signature and docstring. For repair rounds, the model receives the original problem, its previous code attempt, and the error message. The repair prompt is minimal: it presents the error and asks for a corrected function (see Section I). TABLE I CUMULATIVE PASS@1 (%) ON HUMANEVAL (164 PROBLEMS) BY REPAIR ROUND. R 0 IS THE INITIAL ATTEMPT; R 1 –R 4 ARE REPAIR ROUNDS. ∆ DENOTES THE TOTAL SELF-REPAIR GAIN (R 4 − R 0 ) IN PERCENTAGE POINTS. ModelFamilyR 0 R 1 R 2 R 3 R 4 ∆ Llama 3.1 8BMeta67.173.275.676.276.8+9.8 Llama 3.3 70BMeta82.989.690.992.793.3+10.4 Scout 17B (16E)Meta75.684.887.289.089.6+14.0 Maverick 17B (128E)Meta87.291.592.793.993.9+6.7 Qwen3 32BAlibaba87.890.292.192.792.7+4.9 Gemini 2.5 FlashGoogle86.695.795.796.396.3+9.8 Gemini 2.5 ProGoogle73.282.986.689.690.2+17.1 B. Benchmarks We evaluate on two standard code generation benchmarks: 1) HumanEval [1]: 164 hand-written Python programming problems, each with a function signature, docstring, and test cases. Problems range from simple string manipulations to moderately complex algorithmic tasks. All 164 problems were evaluated for all seven models. 2)MBPP Sanitized [4]: 257 problems from the Mostly Basic Programming Problems dataset (sanitized subset). MBPP problems tend to be shorter and more focused than HumanEval, but cover a broader range of programming concepts. All 257 problems were evaluated for all seven models. We acknowledge that these benchmarks are considered relatively easy by 2025 standards. We discuss the implications of this choice and the need for evaluation on harder benchmarks in Section VII. C. Infrastructure Open-weight model experiments were conducted using the Groq free-tier API, which provides rate-limited access to hosted models at no monetary cost. Gemini experiments were conducted using Google Cloud Vertex AI, with total Gemini API costs under $20 USD (including initial debugging runs). Code execution was performed in isolated Python subprocesses with a 15-second timeout per test case. All code and results are publicly available. 1 V. RESULTS A. HumanEval Results Table I presents the cumulative pass@1 rates on HumanEval across all repair rounds for all seven models. Several key observations emerge: Universal improvement. Self-repair improves pass rates for every model tested, across all three families and both open- weight and proprietary models. Every model gains at least +4.9 p. Gemini 2.5 Flash achieves the highest final rate. At 96.3%, Flash surpasses all open-weight models, including Maverick (93.9%) and Llama 3.3 70B (93.3%). Its R1 jump from 86.6% 1 https://github.com/Johin2/iterative-code-repair R0R1R2R3R4 Repair Round 0 20 40 60 80 100 Cumulative Pass Rate (%) Cumulative Pass@1 by Repair Round (HumanEval) Llama 3.1 8B Llama 3.3 70B Scout 17B (16E) Maverick 17B (128E) Qwen3 32B Gemini 2.5 Flash Gemini 2.5 Pro Fig. 1. Cumulative pass@1 rate on HumanEval across repair rounds for all seven models. Gemini 2.5 Flash achieves the highest final rate (96.3%), while most gains concentrate in the first two rounds. TABLE I CUMULATIVE PASS@1 (%) ON MBPP SANITIZED (257 PROBLEMS) BY REPAIR ROUND. ModelFamilyR 0 R 1 R 2 R 3 R 4 ∆ Llama 3.1 8BMeta55.666.969.670.871.6+16.0 Llama 3.3 70BMeta67.786.489.589.990.7+23.0 Scout 17B (16E)Meta65.477.480.582.983.3+17.9 Maverick 17B (128E)Meta72.085.688.791.892.6+20.6 Qwen3 32BAlibaba70.881.785.687.988.3+17.5 Gemini 2.5 FlashGoogle63.886.891.893.493.8+30.0 Gemini 2.5 ProGoogle66.585.289.192.292.2+25.7 to 95.7% (+9.1 p in a single round) is among the largest first-round gains (comparable to Pro’s +9.8 p and matching Scout’s +9.1 p), suggesting strong error comprehension. Gemini 2.5 Pro shows the largest repair gain. Pro achieves +17.1 p, the highest∆on HumanEval. However, its lower initial pass rate (73.2%) reflects overhead from its native reasoning traces, which embed extended chain-of- thought within the response and occasionally interfere with code extraction despite our extraction pipeline (see Section I). A similar pattern appears with Qwen3’s thinking mode (see Section VII). Pro’s final rate (90.2%) is competitive but below Flash, illustrating that stronger reasoning does not always translate to better code generation in a simple prompt- completion paradigm. Diminishing returns from higher baselines. Among the open-weight models, the pattern holds: Qwen3 32B starts at 87.8% and gains only +4.9 p, while Scout starts lower at 75.6% and gains +14.0 p. Flash is a notable exception: it starts high (86.6%) yet still achieves a substantial +9.8 p gain, suggesting that its repair capability exceeds the diminishing-returns trend. Figure 1 visualizes these trajectories. The curves illustrate the universal upward trend, with Flash breaking through the ∼94% ceiling observed among the open-weight models. B. MBPP Results Table I presents results on MBPP Sanitized. The MBPP results reinforce and extend the findings from HumanEval: TABLE I CROSS-BENCHMARK COMPARISON OF SELF-REPAIR GAINS (∆, IN PERCENTAGE POINTS) ON HUMANEVAL AND MBPP SANITIZED. ModelFamilyHumanEval ∆MBPP ∆ Llama 3.1 8BMeta+9.8+16.0 Llama 3.3 70BMeta+10.4+23.0 Scout 17B (16E)Meta+14.0+17.9 Maverick 17B (128E)Meta+6.7+20.6 Qwen3 32BAlibaba+4.9+17.5 Gemini 2.5 FlashGoogle+9.8+30.0 Gemini 2.5 ProGoogle+17.1+25.7 R0R1R2R3R4 Repair Round 0 20 40 60 80 100 Cumulative Pass Rate (%) HumanEval Llama 3.1 8B Llama 3.3 70B Scout 17B (16E) Maverick 17B (128E) Qwen3 32B Gemini 2.5 Flash Gemini 2.5 Pro R0R1R2R3R4 Repair Round MBPP Llama 3.1 8B Llama 3.3 70B Scout 17B (16E) Maverick 17B (128E) Qwen3 32B Gemini 2.5 Flash Gemini 2.5 Pro Cross-Benchmark Self-Repair Comparison Fig. 2. Cross-benchmark comparison of self-repair gains for all seven models. MBPP consistently yields larger gains than HumanEval, with Gemini 2.5 Flash showing the largest MBPP gain (+30.0 p). Larger absolute gains. Self-repair gains on MBPP are substantially larger than on HumanEval for every model. Among open-weight models, gains range from +16.0 p to +23.0 p. The Gemini models show even larger gains: Flash achieves +30.0 p and Pro +25.7 p, the two highest in our study. Flash dominates on MBPP. Gemini 2.5 Flash achieves the highest final pass rate (93.8%), despite starting at only 63.8%, lower than four of the five open-weight models. Its +30.0 p repair gain exceeds the best open-weight model on MBPP (+23.0 p) by 7 p, suggesting qualitatively different repair behavior. Flash’s R1 jump (+23.0 p in a single round) accounts for the majority of its gain. Consistent model ranking. The relative ordering of models is largely consistent across benchmarks. Llama 3.1 8B has the lowest final rate on both benchmarks, while Flash leads on both. On MBPP (n = 257), one problem corresponds to ∼0.4 p, providing finer resolution for ranking comparisons. C. Cross-Benchmark Comparison Table I summarizes the self-repair gains across both benchmarks. MBPP consistently yields higher repair gains than HumanEval for every model. This difference likely reflects two factors: (1) lower initial pass rates on MBPP provide more room for improvement, and (2) MBPP problems, while numerous, tend to be shorter and more focused, making their errors potentially easier to diagnose and repair. The Gemini models show the largest MBPP gains (+30.0 and +25.7 p), suggesting that their error comprehension scales particularly well on shorter, focused problems. Llama 3.1 8B Llama 3.3 70B Scout 17B (16E) Maverick 17B (128E) Qwen3 32B Gemini 2.5 Flash Gemini 2.5 Pro Model 0 10 20 30 40 Count Error Type Distribution at R0 (HumanEval) assertion index_key_error name_error recursion runtime_other syntax timeout type_error value_error Fig. 3. Distribution of error types at the initial attempt (R 0 ) on HumanEval for each model. assertion index_key_error name_error recursion runtime_other syntax timeout type_error value_error Error Type 0 20 40 60 80 100 Repair Success Rate (%) n=157 n=6 n=13 n=1 n=1 n=38 n=1 n=9 n=3 Self-Repair Success Rate by Initial Error Type Fig. 4. Repair success rate by error type across all models. Assertion errors (logical mistakes) are the hardest to repair. Figure 2 visualizes the cross-benchmark comparison, high- lighting the consistent pattern of larger MBPP gains across all models and families. D. Error Distribution Analysis Figure 3 shows the distribution of error types at the initial attempt (R 0 ) on HumanEval. Across all seven models, assertion errors dominate, indicating that most failures produce syntac- tically valid but logically incorrect code. Higher-capability models have fewer total failures but the same error-type profile, confirming that assertion errors are the irreducible core of failure regardless of model scale or family. E. Repair Success by Error Type Figure 4 analyzes repair success rates broken down by error type. A clear hierarchy emerges: •Name errors are repaired at high rates (∼77%). These errors provide specific diagnostic information (undefined variable or function names) that guides the model toward the fix. •Syntax errors are repaired at moderate rates (∼66%). While many syntax errors are straightforward to fix, some reflect deeper structural issues in code generation (e.g., incomplete functions or mismatched indentation) that are harder to resolve. •Assertion errors are the hardest to repair, with success rates around 45%. An assertion error indicates that the R0R1R2R3R4 Repair Round 0 20 40 60 80 Newly Passing (%) New Problems Solved Per Round (HumanEval) Llama 3.1 8B Llama 3.3 70B Scout 17B (16E) Maverick 17B (128E) Qwen3 32B Gemini 2.5 Flash Gemini 2.5 Pro Fig. 5. Marginal improvement in pass@1 per repair round on HumanEval. The first repair round (R 0 → R 1 ) yields the largest gain for all models. code ran successfully but produced the wrong output. The error message provides minimal diagnostic information about what the code computed incorrectly or why, requir- ing the model to re-examine its logic. This finding is consistent with Huang et al.’s observation [15] that LLMs struggle to self-correct reasoning without external feedback. On MBPP, assertion errors are repaired at higher rates (∼63%) than on HumanEval (∼45%), likely because MBPP’s shorter problems make logical errors easier to diagnose. F. Per-Round Improvement Figure 5 shows the marginal improvement at each repair round on HumanEval. The pattern of diminishing returns is consistent across all models: • R 0 → R 1 (first repair): The largest single-round gain for all seven models. Gemini 2.5 Pro gains +9.8 p (the largest first-round gain), followed by Scout and Flash (both +9.1 p), while Qwen3 gains +2.4 p (the smallest, reflecting its high baseline). • R 1 → R 2 (second repair): Still meaningful but reduced for all models. • R 2 → R 3 andR 3 → R 4 : Minimal additional gains. For Qwen3, Maverick, and Gemini 2.5 Flash,R 4 yields no additional improvement overR 3 , indicating that these models have solved all problems amenable to self-repair by round 3. The concentration of gains in early rounds has practical implications: for most applications, two repair rounds capture the bulk of the benefit, and additional rounds offer diminishing marginal returns relative to their computational cost. G. Token Cost Analysis Table IV reports total token usage for each model on HumanEval. Token counts reflect prompt and completion tokens only. For Gemini models, internal reasoning (“thinking”) tokens are excluded from this count; including them would increase Flash’s total to∼489K and Pro’s to∼994K. Since thinking tokens are not directly comparable to standard input/output tokens, we report prompt+completion for fair cross-model comparison. Gemini 2.5 Pro achieves the best cost-effectiveness TABLE IV TOTAL TOKEN USAGE (PROMPT + COMPLETION) AND SELF-REPAIR GAIN ON HUMANEVAL (164 PROBLEMS). GEMINI MODELS’ INTERNAL REASONING TOKENS ARE EXCLUDED FOR COMPARABILITY; SEE TEXT. ModelTotal Tokens∆ (p)Tokens/p Llama 3.1 8B195K+9.819.9K Llama 3.3 70B112K+10.410.8K Scout 17B (16E)155K+14.011.1K Maverick 17B (128E)93K+6.713.9K Qwen3 32B102K+4.920.8K Gemini 2.5 Flash121K+9.812.3K Gemini 2.5 Pro162K+17.19.5K TABLE V PER-ROUND REPAIR BREAKDOWN ON HUMANEVAL: NUMBER OF PROBLEMS FIRST SOLVED AT EACH ROUND, AND THE REPAIR SUCCESS RATE (FRACTION OF INITIALLY-FAILED PROBLEMS EVENTUALLY REPAIRED). ModelR 0 R 1 R 2 R 3 R 4 NeverRep. % Llama 3.1 8B110104113829.6 Llama 3.3 70B136112311160.7 Scout 17B (16E)124154311757.5 Maverick 17B (128E)14372201052.4 Qwen3 32B14443101240.0 Gemini 2.5 Flash14215010672.7 Gemini 2.5 Pro120166511663.6 at 9.5K tokens per percentage point of improvement, followed by Llama 3.3 70B at 10.8K tokens/p. Table V provides a fine-grained breakdown of when prob- lems are first solved. The first repair round (R 1 ) accounts for the majority of all repairs across every model. Repair success rate (the fraction of initially-failed problems that are eventually fixed) correlates positively with model capability: Gemini 2.5 Flash repairs 72.7% of its failures (the highest), followed by Gemini 2.5 Pro at 63.6% and Llama 3.3 70B at 60.7%, while Llama 3.1 8B repairs only 29.6%. H. Repair Prompt Ablation Our main experiments use a minimal repair prompt that provides only the error message and asks for a corrected function. To assess sensitivity to prompt design, we compare up to three repair prompt strategies on four models: Llama 3.1 8B (dense, 8B), Llama 3.3 70B (dense, 70B), Llama 4 Scout (MoE, 17B active), and Qwen3 32B (dense, 32B). We evaluate all 164 HumanEval problems with up to two repair rounds (R 0 – R 2 ). All three strategies were evaluated for three models; for Scout, only CoT and Explain-then-fix are available because the Minimal run was interrupted by Groq API rate limits and could not be re-run before the evaluation window closed. 1)Minimal: The baseline strategy used throughout this paper. The repair prompt presents the error message and requests a corrected function. 2)Explain-then-fix: The model is asked to first explain the bug in 1–2 sentences, then provide the corrected code. This follows the explain-before-fix paradigm from Self-Debug [6]. TABLE VI REPAIR PROMPT ABLATION ON HUMANEVAL. CUMULATIVE PASS@1 (%) AT EACH ROUND FOR UP TO THREE PROMPT STRATEGIES ON FOUR MODELS. SCOUT’S MINIMAL RUN IS UNAVAILABLE (SEE TEXT). DELTAS COMPUTED FROM RAW PROBLEM COUNTS BEFORE ROUNDING. R 0 AND SUBSEQUENT ROUNDS MAY VARY SLIGHTLY ACROSS RUNS DUE TO API-LEVEL NON-DETERMINISM; ∆ COMPUTED FROM EACH RUN’S OWN R 0 . ModelStrategyR 0 R 1 R 2 ∆ Llama 3.1 8BChain-of-thought65.972.677.4+11.6 Explain-then-fix65.972.076.2+10.4 Minimal65.973.275.6+9.8 Llama 3.3 70BChain-of-thought84.193.996.3+12.2 Explain-then-fix82.990.293.9+11.0 Minimal81.186.687.8+6.7 Scout 17B (16E)Chain-of-thought79.387.289.6+10.4 Explain-then-fix78.087.287.2+9.1 Qwen3 32BChain-of-thought89.697.097.0+7.3 Explain-then-fix88.493.394.5+6.1 Minimal87.890.291.5+3.7 R0R1R2 Round 0 20 40 60 80 100 Cumulative Pass@1 (%) 65.9 72.6 77.4 67.1 73.2 75.6 Llama-3.1-8B Chain-of-thought Minimal (error only) R0R1R2 Round 84.1 93.9 96.3 82.9 90.2 93.9 82.9 89.6 90.9 Llama-3.3-70B Chain-of-thought Explain-then-fix Minimal (error only) R0R1R2 Round 79.3 87.2 89.6 78.0 87.287.2 75.6 84.8 87.2 Llama-4-Scout-17B Chain-of-thought Explain-then-fix Minimal (error only) R0R1R2 Round 89.6 97.097.0 88.4 93.3 94.5 87.8 90.2 92.1 Qwen3-32B Chain-of-thought Explain-then-fix Minimal (error only) Prompt Strategy Ablation on HumanEval Fig. 6. Prompt strategy ablation on HumanEval. CoT consistently achieves the highest final pass rate across all models, with the benefit scaling with model capability. 3)Chain-of-thought (CoT): The model is prompted to reason step-by-step: (1) what does the error tell us, (2) what is the root cause, (3) what is the fix. The corrected code follows the analysis. Table VI and Figure 6 present the results across four models. Note that each ablation configuration involves a complete re-execution of all 164 problems, including initial generation atR 0 . Since the repair strategy does not affect the initial generation prompt, anyR 0 variation across strategies for the same model reflects non-determinism in the Groq API’s served model weights across sessions. For example, Llama 3.3 70B showsR 0 values of 84.1%, 82.9%, and 81.1% across the three strategies. The∆column is computed relative to each run’s ownR 0 , making repair gain measurements independent of this baseline variation. However, run-to-run variation is non-trivial (e.g., 70B’sR 2 ranges from 87.8% to 96.3%), and some of this gap may reflect session-level variance. Crucially, the key finding holds regardless of whichR 0 baseline is used: CoT achieves the highest final R 2 rate for every model. CoT consistently wins across all models. Chain-of-thought achieves the highest final pass rate for every model: 77.4% (8B), 96.3% (70B), 89.6% (Scout), and 97.0% (Qwen3). Qwen3 with CoT achieves the highest pass rate of any model-strategy combination in our ablation (97.0% at R 2 ). The benefit of richer prompts scales with model capability. Measured by the additional self-repair gain (∆ CoT − ∆ minimal ), the advantage of CoT is modest for the 8B model (+1.8 p) but widens for stronger models: +5.5 p for Llama 3.3 70B and TABLE VII SELF-REPAIR (GREEDY, 5 ROUNDS) VS. INDEPENDENT RESAMPLING (TEMPERATURE 0.8, 5 SAMPLES) ON HUMANEVAL (164 PROBLEMS). BOLD INDICATES HIGHER PASS RATE. NOTE: REPAIR USES GREEDY DECODING (T = 0) WHILE RESAMPLING USES T = 0.8; SEE TEXT. ModelSelf-RepairResampling Final %Tokenspass@5 %Tokens Llama 3.1 8B76.8195K79.9219K Llama 3.3 70B93.3112K90.9231K Scout 17B (16E)89.6155K86.0255K Qwen3 32B92.7102K92.7223K +3.6 p for Qwen3. In absolute terms, CoT achieves finalR 2 rates 1.8–8.5 p higher than minimal, though part of this gap reflectsR 0 variation across runs (see above). This confirms the interaction between model capability and prompt strategy across the three models with complete ablation data, spanning 8B to 70B parameters. The practical implication is clear: for capable models (≥32B), chain-of-thought repair prompting is strongly recommended and can yield gains comparable to an additional 1–2 repair rounds. For smaller models, the benefit is present but modest, and the simpler minimal prompt remains a competitive choice. I. Self-Repair vs. Independent Resampling A key question is whether the token budget spent on iterative repair could be better used by simply drawing multiple independent samples. Tang et al. [16] formalized this as an exploration-exploitation tradeoff and proposed a Thompson Sampling strategy (REx) to dynamically allocate between repair and resampling. We extend this analysis to modern 2024–2025 models by comparing self-repair (greedy decoding, T = 0, up to 5 sequential attempts with error feedback) against independent resampling (T = 0.8, 5 independent samples) on HumanEval. This comparison involves two differences: error feedback (present in repair, absent in resampling) and decoding temperature (T = 0vs.T = 0.8). A fully controlled study would also require stochastic repair (T > 0with feedback); we leave this to future work. Nevertheless, this comparison addresses the practical question: given a token budget, should one invest in sequential repair or parallel resampling? For resampling, we report the unbiased pass@k estimator [1]. Table VII and Figure 7 compare self-repair against indepen- dent resampling on HumanEval for four models. 2 The results reveal a clear, model-dependent pattern: Self-repair is always more token-efficient. Across all four models, self-repair uses fewer tokens than resampling to achieve comparable or better pass rates, with savings ranging from 11% (8B) to 54% (Qwen3). The savings are largest for models 2 Maverick was unavailable on the Groq free-tier API during the resampling experiments; Gemini models were excluded because stochastic resampling on Vertex AI would have required additional paid API calls beyond our budget. The four evaluated models span the full capability range (8B–70B) and both architecture types (dense and MoE), providing sufficient evidence for the observed patterns. Llama-3.1-8B Llama-3.3-70B Llama-4-Scout-17B Qwen3-32B 0 20 40 60 80 100 Pass Rate (%) Pass Rate: Self-Repair vs Resampling (HUMANEVAL) Self-Repair (final) Resampling (pass@5) Llama-3.1-8B Llama-3.3-70B Llama-4-Scout-17B Qwen3-32B 0 50 100 150 200 250 Total Tokens (K) Token Usage Comparison Self-Repair Resampling Fig. 7. Self-repair vs. independent resampling on HumanEval. Self-repair matches or exceeds resampling for all models except the 8B, while consistently using fewer tokens. whose strong error comprehension enables efficient single- attempt repairs, while the 8B model’s longer repair traces narrow the gap. This efficiency advantage arises because self- repair generates only the corrected function at each round, while resampling generates a complete solution from scratch each time. Self-repair becomes increasingly competitive with model capability. For the weakest model (Llama 3.1 8B), resampling achieves a modestly higher pass@5 (79.9% vs. 76.8%); the diversity of independent samples compensates for the model’s limited error comprehension. For the three stronger models, self-repair matches or exceeds resampling: Scout (89.6% vs. 86.0%), Llama 3.3 70B (93.3% vs. 90.9%, a difference of 4 problems), and Qwen3 32B (92.7% tied) all favor repair. The 70B result is particularly striking: self-repair achieves +2.4 p higher pass rate while using less than half the tokens (112K vs. 231K). This pattern has a clear interpretation: as models become more capable, their ability to diagnose and fix errors from feedback improves, making the informational signal from error messages more valuable than the diversity from independent samples. We note that this comparison does not fully disen- tangle the value of error feedback from the effect of decoding temperature; a stochastic repair condition would be needed to isolate these factors. The practical implication is that self- repair is the preferred strategy for capable models, while a hybrid approach (repairing diagnosable errors and resampling for assertion errors) may be optimal for weaker models. VI. DISCUSSION A. Self-Repair as a Universal Improvement Strategy Our results demonstrate that iterative self-repair with error feedback is a universally effective strategy for improving LLM code generation across all seven models tested, spanning three families (Meta, Alibaba, Google), both open-weight and proprietary models, and both dense and MoE architectures. This finding updates the conclusions of Olausson et al. [5], who found that weaker models could be harmed by self-repair, and contrasts with Chen et al. [12], who found limited gains for Qwen2.5-Coder-7B with prompt-based self-debugging. Prior work demonstrated that fine-tuning can enable small-model self-repair [13], [14]; our results suggest that the 2024–2025 generation of instruction-tuned models has closed this gap without task-specific training. The discrepancy with earlier findings likely reflects improvements in instruction-following and error-comprehension capabilities: all models in Olausson et al.’s study were released in 2022–2023, while ours cover 2024–2025. The cross-benchmark consistency of our findings strengthens this conclusion. Self-repair improves every model on both HumanEval and MBPP, with largely consistent model rankings across benchmarks. The inclusion of Gemini models from a third family further strengthens generalizability: self-repair effectiveness is a robust property of modern LLMs rather than an artifact of a particular model family or benchmark. B. Dense vs. Mixture-of-Experts Architectures Our evaluation includes dense models (Llama 8B, 70B, Qwen3 32B) and MoE models (Scout 16E, Maverick 128E) among the open-weight models, as well as two proprietary Gemini models whose architectures have not been publicly disclosed, enabling comparisons across three families. Several observations are noteworthy: •Among open-weight models, Scout (16 experts) achieves the highest repair gain on HumanEval (+14.0 p), suggest- ing that its MoE architecture particularly benefits from the opportunity to repair its errors. •Gemini 2.5 Flash achieves the highest final pass rates on both benchmarks (96.3% HumanEval, 93.8% MBPP), surpassing all open-weight models. Its combination of high initial accuracy and strong repair capability sets a new ceiling. • Gemini 2.5 Pro, despite being a frontier reasoning model, underperforms Flash on both benchmarks (90.2% vs. 96.3% on HumanEval). This suggests that reasoning over- head can hurt in a simple prompt-completion paradigm, echoing our findings with Qwen3’s thinking mode. • The 70B dense model approaches Maverick’s performance (93.3% vs. 93.9% on HumanEval; 90.7% vs. 92.6% on MBPP), suggesting that a large dense model can compete with a smaller MoE model. These comparisons are suggestive but must be interpreted cautiously: models differ not only in architecture but also in training data, parameter counts, and other confounds that we cannot isolate. We report these observations as correlations rather than causal claims. C. Qualitative Analysis of Repair Outcomes To complement our quantitative findings, we examine representative cases from HumanEval. Successful repairs. On HumanEval/38, Llama 3.3 70B pro- duced code that failed atR 0 with aNameErrorand repaired it in a single round. More interestingly, on HumanEval/26, Llama 3.1 8B failed with assertion errors for three consecutive rounds before finally producing a correct solution atR 3 , demonstrating that persistence can resolve even logical errors. On HumanEval/77, Scout exhibited error-type mutation across rounds (type error→assertion→type error→pass), showing TABLE VIII LIVECODEBENCH RESULTS (50 PROBLEMS). SELF-REPAIR IMPROVES ALL FOUR MODELS EVALUATED. ModelR 0 Final∆ Llama 3.1 8B10.012.0+2.0 Scout 17B (16E)6.014.0+8.0 Qwen3 32B8.010.0+2.0 Gemini 2.5 Flash0.016.0+16.0 the model genuinely restructuring its approach rather than making superficial edits. Persistent failures. On HumanEval/10, Llama 3.1 8B pro- duced assertion errors on all five attempts, never resolving the underlying logic error. On HumanEval/32, Maverick exhibited error thrashing: assertion→name error→assertion→ assertion→timeout, the failure mode described by Olausson et al. [5]. We identified several “universally hard” problems (e.g., HumanEval/132, HumanEval/145) that defeated all models even with four repair rounds. D. Preliminary Evaluation on Harder Benchmarks To assess whether self-repair generalizes beyond the rel- atively easy HumanEval and MBPP benchmarks, we con- ducted a preliminary evaluation on LiveCodeBench [26], a contamination-free benchmark of competitive programming problems. We evaluated four models on 50 LiveCodeBench problems (18 easy, 23 medium, 9 hard) with the same 5-round self-repair protocol. The four models (8B, Scout, Qwen3, Flash) span the capability range; the remaining three were omitted due to API availability constraints. We emphasize that this evaluation is exploratory: the small sample size (50 problems) limits statistical power. Table VIII shows that self-repair improves all four models on LiveCodeBench. Gemini 2.5 Flash achieves the largest gain (+16.0 p), reaching 16% from an initial pass rate of 0%; all solved problems come entirely from repair rounds. Flash’s 0% R 0 reflects the difficulty of competitive programming problems combined with stdin/stdout format requirements, yet its repair capability recovers 8 problems. Scout achieves the second- largest gain (+8.0 p), more than doubling its pass rate from 6% to 14%. While the absolute pass rates are much lower than on HumanEval (as expected for competitive programming), self- repair remains effective. The relative repair gains are actually larger than on HumanEval, suggesting that self-repair may scale to harder benchmarks where the lower baseline leaves more room for improvement. Atn = 50, each problem corresponds to 2 p, so differences smaller than∼4 p should be interpreted cautiously. E. Practical Implications Our findings suggest several practical guidelines for deploy- ing LLM code generation systems: 1) Always include at least one repair round: The first repair round consistently provides the largest marginal improvement for all models tested. 2) Two rounds capture most gains: For cost-sensitive ap- plications, two repair rounds (R 0 throughR 2 ) capture the majority (76–95%) of the total achievable improvement. 3)Consider error type for routing: Name errors are repaired at the highest rates (∼77%), while assertion errors are the hardest (∼45%). For assertion-dominated failures, alternative strategies (e.g., sampling multiple independent solutions) may be more cost-effective. 4)Model selection matters: For applications where final pass rate is paramount, Gemini 2.5 Flash (96.3%) or Maverick (93.9%) should be preferred. For self-repair gain per token, Gemini 2.5 Pro and Llama 3.3 70B offer the best efficiency. VII. LIMITATIONS AND FUTURE WORK We identify several limitations of this study that suggest directions for future work. Resampling comparison scope. Our resampling comparison (Section V, Table VII) covers four of seven models on HumanEval only. While the results clearly show that self- repair is more token-efficient and increasingly advantageous for stronger models, extending this comparison to MBPP and controlling for token budget more precisely (e.g., allocating the exact same number of tokens to each strategy) would strengthen the analysis. Additionally, we compare greedy repair against stochastic resampling (temperature= 0.8), which conflates two differences: error feedback vs. diversity, and greedy vs. stochastic decoding. A fairer comparison might use stochastic repair as well. Benchmark scope. Our main evaluation uses HumanEval and MBPP, which are considered relatively easy by 2025 stan- dards. Our preliminary LiveCodeBench evaluation (Section VI) shows that self-repair remains effective on harder competitive programming problems, but covers only four models on 50 problems. A comprehensive evaluation across all models on LiveCodeBench [26], BigCodeBench [27], or SWE-Bench [28] would more fully characterize self-repair on problems requiring deep algorithmic reasoning. Greedy decoding only. Our use of temperature= 0.0 ensures deterministic, reproducible results but eliminates sam- pling variance, precluding confidence intervals or statistical significance tests. On HumanEval (164 problems), a single problem corresponds to±0.6 p, meaning differences of ∼1.2 p or less (e.g., Maverick at 93.9% vs. Qwen3 at 92.7%, a gap of just two problems) should not be over-interpreted. Experiments with stochastic decoding across multiple seeds would provide more robust estimates and enable statistical analysis. Ablation scope. Our prompt ablation covers four of seven models (8B, 70B, Scout, Qwen3) with two repair rounds (R 0 – R 2 ). Extending to all five repair rounds would characterize whether CoT’s advantage persists or converges in later rounds. The ablation uses HumanEval only; prompt sensitivity on MBPP or LiveCodeBench may differ. API-served model weights. Open-weight models were accessed via the Groq free-tier API, which may serve quantized or otherwise optimized model variants. We did not verify that the served weights exactly match the canonical model releases. Gemini models were accessed via Google Cloud Vertex AI, where the served model versions are controlled by Google. Pass rates may differ slightly across API versions or on locally- hosted weights. Model family diversity. Our evaluation covers three model families (Llama, Qwen, and Gemini) across two inference providers (Groq and Vertex AI), including both open-weight and proprietary models. Code-specialized models (e.g., DeepSeek- Coder [29]) may exhibit different repair dynamics due to code- focused pre-training and remain a direction for future work. Qwen3 reasoning mode. We evaluated Qwen3 with thinking mode enabled on all 164 HumanEval problems. Thinking mode achieves a lower final pass rate (89.0% vs. 92.7% for no-think), despite a much larger repair gain (+14.0 p vs. +4.9 p). The explanation lies in the initial pass rate: thinking mode’sR 0 drops to 75.0% (vs. 87.8% for no-think) because long reasoning traces contaminate the code output, causing syntax errors. Self-repair compensates by fixing 23 additional problems, but 18 problems fail due to API errors or persistent extraction issues. Our decision to disable thinking mode in the main experiments is validated: with the current code extraction pipeline, thinking mode reduces net performance. A more robust extraction approach (or native tool-use integration) could potentially unlock the reasoning benefits without the extraction overhead. VIII. THREATS TO VALIDITY Internal validity. Our use of greedy decoding ensures deterministic, reproducible results but reflects a single point in the sampling distribution. Prior work [5], [6] similarly reports single-run results under fixed decoding settings. Our prompt ablation (Table VI) shows that repair prompt design does affect outcomes, meaning the main results represent a lower bound for capable models. Additionally, minorR 0 variation in the ablation table suggests the Groq API may serve slightly different model versions across sessions. External validity. Our model selection (seven models from three families) spans a meaningful range, including both open- weight and proprietary models, but may not capture behaviors of all architectures. We do not evaluate code-specialized models (e.g., DeepSeek-Coder) or models with native tool use. Additionally, because HumanEval and MBPP are widely known, evaluated models may have been exposed to these problems during pre-training, which could inflate initial pass rates. However, this affects all models equally and does not invalidate relative comparisons. Construct validity. Our cumulative pass@1 metric counts a problem as solved if it passes all provided test cases. However, test suites may not cover all edge cases, meaning some “passing” solutions could contain latent bugs. Our error classification relies on Python exception types, which may conflate distinct failure modes. IX. CONCLUSION We have presented a systematic study of iterative self- repair across seven models from three families (Meta, Alibaba, Google), spanning both open-weight and proprietary models, dense and MoE architectures, and two benchmarks (HumanEval and MBPP Sanitized). Self-repair is universally effective: every model improves on every benchmark. Error-type analysis confirms that name errors are repaired at high rates, while assertion errors remain the most challenging, connecting to broader findings on the limits of LLM self-correction. Two repair rounds capture the majority of achievable gains, providing clear deployment guidance. Our prompt ablation shows that chain-of-thought repair can yield additional gains for capable models, though the benefit is model-dependent. These results establish iterative self-repair as a practical, training- free technique for improving LLM code generation, while identifying code-specialized models and harder-benchmark evaluation as important directions for future work. ACKNOWLEDGMENT The author thanks Groq for providing free-tier API access that enabled the open-weight model experiments, and Google Cloud for Vertex AI credits used for the Gemini experiments. All experimental code and results are publicly available at https: //github.com/Johin2/iterative-code-repair. The author declares no conflicts of interest. REFERENCES [1]M. Chen, J. Tworek, H. Jun, Q. Yuan, H. P. d. O. Pinto, J. Kaplan, H. Edwards, Y. Burda, N. Joseph, G. Brockman et al., “Evaluating large language models trained on code,” arXiv preprint arXiv:2107.03374, 2021. [2]Y. Li, D. Choi, J. Chung, N. Kushman, J. Schrittwieser, R. Leblond, T. Eccles, J. Keeling, F. Gimeno, A. Dal Lago et al., “Competition-level code generation with AlphaCode,” in Science, vol. 378, no. 6624, 2022, p. 1092–1097. [3] B. Rozi ` ere, J. Gehring, F. Gloeckle, S. Sootla, I. Gat, X. E. Tan, Y. Adi, J. Liu, R. Sauvestre, T. Remez et al., “Code Llama: Open foundation models for code,” arXiv preprint arXiv:2308.12950, 2024. [4] J. Austin, A. Odena, M. Nye, M. Bosma, H. Michalewski, D. Dohan, E. Jiang, C. Cai, M. Terry, Q. Le, and C. Sutton, “Program synthesis with large language models,” arXiv preprint arXiv:2108.07732, 2021. [5]T. X. Olausson, J. P. Inala, C. Wang, J. Gao, and A. Solar-Lezama, “Is self-repair a silver bullet for code generation?” arXiv preprint arXiv:2306.09896, 2024. [6]X. Chen, M. Lin, N. Sch ̈ arli, and D. Zhou, “Teaching large language models to self-debug,” arXiv preprint arXiv:2304.05128, 2024. [7]A. Grattafiori, A. Dubey, A. Jauhri et al., “Llama 3 model card,” arXiv preprint arXiv:2407.21783, 2024. [8]Meta AI, “Llama 3.3: Large language model,” Meta AI Blog, 2024, https://ai.meta.com/blog/llama-3-3/. [9] —, “Llama 4: Maverick, scout, and behemoth,” Meta AI Blog, 2025, https://ai.meta.com/blog/llama-4-multimodal-intelligence/. [10]Qwen Team, “Qwen3 technical report,” arXiv preprint arXiv:2505.09388, 2025. [11] Google DeepMind, “Gemini 2.5: Our most intelligent AI model,” Google Blog, 2025, https://blog.google/technology/google-deepmind/ gemini-model-thinking-updates-march-2025/. [12] X. Chen, Z. Tao, K. Zhang, C. Zhou, X. Zhang, W. Gu, Y. He, M. Zhang, X. Cai, H. Zhao, and Z. Jin, “Revisit self-debugging with self-generated tests for code generation,” in Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (ACL), 2025, p. 18 003– 18 023. [13]Y. Ding, M. J. Min, G. Kaiser, and B. Ray, “CYCLE: Learning to self- refine the code generation,” Proceedings of the ACM on Programming Languages, vol. 8, no. OOPSLA1, 2024. [14]N. Jiang, X. Li, S. Wang, Q. Zhou, S. B. Hossain, B. Ray, V. Kumar, X. Ma, and A. Deoras, “LeDex: Training LLMs to better self-debug and explain code,” Advances in Neural Information Processing Systems, vol. 37, 2024. [15]J. Huang, C. Xia, P. Shenoy, and J. Zhao, “Large language models cannot self-correct reasoning yet,” arXiv preprint arXiv:2310.01798, 2024. [16]H. Tang, K. Hu, J. P. Zhou, S. Zhong, W.-L. Zheng, X. Si, and K. Ellis, “Code repair with LLMs gives an exploration-exploitation tradeoff,” Advances in Neural Information Processing Systems, vol. 37, 2024. [17]H. Le, Y. Wang, A. D. Gotmare, S. Savarese, and S. C. H. Hoi, “CodeRL: Mastering code generation through pretrained models and deep reinforcement learning,” Advances in Neural Information Processing Systems, vol. 35, p. 21 314–21 328, 2022. [18]D. Hendrycks, S. Basart, S. Kadavath, M. Mazeika, A. Zou, D. Song, and J. Steinhardt, “Measuring coding challenge competence with APPS,” arXiv preprint arXiv:2105.09938, 2021. [19]S. Kulal, P. Pasupat, K. Chandra, M. Lee, O. Padon, A. Aiken, and P. Liang, “SPoC: Search-based pseudocode to code,” Advances in Neural Information Processing Systems, vol. 32, 2019. [20] A. Madaan, N. Tandon, P. Gupta, S. Hallinan, L. Gao, S. Wiegreffe, U. Alon, N. Dziri, S. Prabhumoye, Y. Yang et al., “Self-refine: Iter- ative refinement with self-feedback,” Advances in Neural Information Processing Systems, vol. 36, 2023. [21]N. Shinn, F. Cassano, A. Gopinath, K. Shakkottai, A. Labash, and S. Liu, “Reflexion: Language agents with verbal reinforcement learning,” Advances in Neural Information Processing Systems, vol. 36, 2023. [22]D. Key, S. Lee, J. Shin, and S. Hwang, “Multi-turn code generation with single-turn instruction tuning,” arXiv preprint arXiv:2404.11137, 2024. [23]Y. Zhang, J. Chen, D. Li, and Y. Zheng, “Self-collaboration code generation via ChatGPT,” arXiv preprint arXiv:2304.07590, 2023. [24]L. Zhong, Z. Wang, and J. Shang, “LDB: A large language model debugger via verifying runtime execution step-by-step,” arXiv preprint arXiv:2402.16906, 2024. [25]S. Jiang, Y. Wang, and Y. Wang, “Selfevolve: A code evolution framework via large language models,” arXiv preprint arXiv:2306.02907, 2023. [26]N. Jain, K. Han, A. Gu, W.-D. Li, F. Yan, T. Zhang, S. Wang, A. Solar-Lezama, K. Sen, and I. Stoica, “LiveCodeBench: Holistic and contamination free evaluation of large language models for code,” arXiv preprint arXiv:2403.07974, 2024. [27]T. Y. Zhuo, M. C. Vu, J. Chim, H. Hu, W. Yu, R. Widyasari, I. N. B. Yusuf, H. Zhan, J. He, I. Paul et al., “BigCodeBench: Benchmarking code generation with diverse function calls and complex instructions,” arXiv preprint arXiv:2406.15877, 2024. [28]C. E. Jimenez, J. Yang, A. Wettig, S. Yao, K. Pei, O. Press, and K. Narasimhan, “SWE-bench: Can language models resolve real-world GitHub issues?” arXiv preprint arXiv:2310.06770, 2024. [29]D. Guo, Q. Zhu, D. Yang, Z. Xie, K. Dong, W. Zhang, G. Chen, X. Bi, Y. Wu, Y. Li et al., “DeepSeek-Coder: When the large language model meets programming – the rise of code intelligence,” arXiv preprint arXiv:2401.14196, 2024.