arXiv:2610.26942cs.AIOct 2026

Manuscript Offprint

arXiv:2610.26942

Fix, Not Just Resample: Bounded Compiler-Guided Repair in Lean 4

Haotian Deng, Chris Farber, Sonal Narasimha, Samskrithi Sivakumar, Yexiang Xue

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Automated theorem provers often rely on sampling language models, but proof assistants like Lean reject each failed step with a precise error message — information that pure sampling discards. To overcome this, we introduce a bounded, online step-level repair module. Our search samples K candidate tactics at each step and repairs a failed tactic at most R times. Instead of discarding failed tactics, we feed the compiler's error message to a pretrained repair model to fix individual rejected steps in place. This approach improves the solve rate over a sampling-only baseline across all tested candidate budgets ( K∈{1,3,5,8}K \in \{1, 3, 5, 8\}), achieving up to a 32% relative gain and solving 82 additional theorems on a 1,990-theorem subset of the LeanDojo benchmark. Repair is not free: it trades extra runtime for reachable proofs. But the trade is predictable: repair pays most when sampling is constrained; its return is front-loaded, with the first repair attempt capturing 84–96% of the total gain; and the gain comes almost entirely from shallow tactic-execution failures rather than structural errors such as type mismatches. This targeted repair successfully replicates on a second benchmark (Lean Workbook), nearly doubling the solve rate with zero regressions.

1 Introduction

A growing share of AI systems produce output that a machine can check for correctness automatically: generated code can be run against a test suite (Chen et al. 2021), and a generated math proof can be checked step by step by a proof assistant. Because checking is cheap and automatic, the standard way to solve a hard problem with such a system is simply to have the model guess many times and keep whichever guess the checker accepts. This works, but it runs into a wall: every guess is drawn from the same fixed model, so guesses cluster around what that model already tends to produce, and solutions that lie outside its distribution are hard to discover no matter how many times you sample (Brown et al. 2024). Within any realistic budget, many problems the model could in principle solve go unsolved, because a correct candidate is never drawn.

We study this problem in neural theorem proving, where an AI model tries to prove a formal math statement using the Lean proof assistant. A typical proof in Lean consists of tactics — single proof steps, similar to lines of code. The Lean compiler steps through the proof one tactic at a time: for each tactic the model proposes, it either accepts it, moving the proof forward, or rejects it with a precise error message, much like a compiler error. Today's neural provers in the ReProver family, built on LeanDojo (Yang et al. 2023), handle a rejected tactic exactly like the guessing strategy above: they discard it and simply propose a new one. That hits the same wall — guessing more tactics has rapidly diminishing returns, so many provable theorems are missed simply because the prover never happens to guess the tactic that works.

A rejected tactic, however, is not a dead end: it comes back with Lean's error message, which states exactly what went wrong. Instead of discarding that message and guessing blindly again, we hand the failed tactic and its error message to a second, already-trained model whose only job is to repair it — to propose a fixed version of that one step. Repair is thus not a cheaper substitute for sampling but a complement to it: a second, error-conditioned source of candidates. This differs from prior systems that also use compiler feedback. Those systems, detailed below, wait until an entire proof attempt has already failed, then run the whole broken proof through a separate, heavyweight pipeline — a multi-agent loop, a symbolic rule engine, or extra training — to patch it after the fact. We instead repair a single broken step immediately, in the middle of the search, using an existing repair model with no extra training. This lets us ask a precise allocation question no prior work answers: the moment one tactic fails, is it worth more to fix that tactic or to just try guessing again?

Concretely: APOLLO (Ospanov, Farnia, and Yousefzadeh 2025) takes a proof attempt that has already failed end-to-end, breaks it into sub-lemmas with a multi-agent loop, and re-solves the failing pieces with auxiliary solvers. PALM (Lu, Delaware, and Zhang 2024) first generates a complete proof, then patches its low-level errors afterward with symbolic, rule-based methods. APRIL (Wang et al. 2026) trains a dedicated repair model on 260,000 supervised (failure, diagnostic, fix) tuples, but likewise applies it to whole finished proofs, not to individual steps mid-search. In each case, existing systems apply it to a whole failed proof after search has finished and embed it in enough surrounding machinery that repair's own contribution is hard to isolate. We reuse APRIL's pretrained repair model exactly as released — no extra training, no agent orchestration, no symbolic solver — and directly measure that allocation question.

We integrate a bounded repair loop into tree search, with two budgets: K, how many fresh tactics are sampled at a state, and R, how many times a failed tactic may be repaired before it is abandoned. Setting R=0 recovers the pure-sampling baseline exactly, since no failed tactic is ever repaired. Our findings are:

• Repair reliably expands what the prover can solve. At every candidate budget K we test, enabling repair recovers proofs that same-budget sampling does not reach, lifting Pass@1 — the percentage of theorems proved within the search budget — by 2.3–4.1 percentage points, up to a 32% relative gain at the tightest budget, and solving up to 82 additional theorems on our LeanDojo subset.

• This coverage comes at a cost, measured fairly. The repair model is slower than the tactic generator, so repair buys reachable proofs in exchange for wall-clock, and at large sampling budgets that same time could instead buy more samples. Comparing repair-on and repair-off at the same K would hand repair extra compute for free, so we instead read every configuration against pure-sampling ones of similar wall-clock — an iso-runtime comparison.

• The benefit is front-loaded and narrowly sourced. A single repair attempt ( R=0→1R=0 \rightarrow 1) captures 84–96% of everything repair ever provides, while further repairs saturate quickly; it is most valuable in the sample-constrained regime, where drawing more samples is not an option, and it comes almost entirely from a narrow, identifiable slice of failures — shallow tactic-execution errors, not structural ones like type mismatches.

• The effect generalizes. A second, retrieval-free benchmark (Lean Workbook), with a weaker generator and an untuned budget, reproduces the same pattern, nearly doubling the solve rate with zero regressions, so the effect is not an artifact of one generator or search configuration.

Together these turn repair from an all-or-nothing feature into a cheap, well-scoped policy: add one targeted repair step to a generation-first prover, and lean on it hardest when the sampling budget is scarce.