Read the paper
A Self-Hosted, Time-Budgeted Agent for Lean Proof Refactoring with an Open-Weight Model
on GitHub
A general agent harness, not a trained model, scores 79.25 Combined on the Lean Refactor Arena's 60 final problems using one open-weight model self-hosted on four A100 GPUs within 48 hours.
| Threshold | Requests | Length (%) | Heartbeats (%) | Combined |
|---|---|---|---|---|
| 40k | 100 | 43.0 | 70.2 | 71.0 |
| 40k | 400 | 57.1 | 78.9 | 78.6 (79.09) |
| 45k | 400 | 57.2 | 80.9 | 79.4 |
| 60k | 400 | 60.3 | 82.8 | 81.1 |
| 60k, trimmed notes | 400 | 59.4 | 82.1 | 80.5 |
| 80k | 400 | 60.7 | 81.8 | 80.9 (81.21) |
| 80k (replicate) | 400 | 60.3 | 83.0 | 81.1 |
| 80k | 800 | 67.9 | 82.7 | 83.5 |
| 45k, trimmed notes | 400 | 56.0 | 80.5 | 78.8 |
| 80k, trimmed notes | 400 | 59.1 | 80.4 | 79.8 |
| Configuration | Output tokens/s | Prefix hits | Requests / problem / h |
|---|---|---|---|
| =80k | 530 | 22–40% | – |
| =60k | 950 | 62–75% | – |
| =45k | 1,150–1,300 | 69–86% | 27 |
| =60k, CPU KV offloading† | 1,250–1,500 | 50–82%∗ | 29 |
†With GPU memory utilization 0.95 (0.92 otherwise). ∗GPU hits only; prefixes reloaded from host memory count as misses.
Going deeper
| Tool | What it does |
|---|---|
| Inference time: offered to the model | |
| lean_compile | check a full proof; a valid proof is saved and scored as a candidate |
| lean_edit | apply line replacements to a draft, then check it as lean_compile |
| lean_try | try several tactic snippets at one proof state; optionally apply and check one |
| lean_inspect | tactics with the goals and hypotheses before each |
| lean_inspect_name | type and start of the definition of an identifier |
| search_project | declarations by name or statement fragment in the project and its dependencies |
| lean_search | natural-language Mathlib search through the LeanSearch service (Gao et al., 2024) |
| read_file, write_file | drafts, notes and saved tool output in the problem’s run directory |
| Local time: run by the runner on the best candidate, not offered to the model | |
| lean_profile | heartbeats per tactic of each new best; the three slowest go back to the model |
| lean_optimize | heartbeat pass (before each rebuild and at the end) |
| lean_shorten | length pass (before each rebuild and at the end) |
Imagine you hire an editor to shorten and speed up 60 essays, all at once. You give them a desk, a spell-checker that scores every draft, and a 48-hour deadline. The editor reads each essay, tries a few rewrites, picks the most promising one, and polishes it until time runs out. The spell-checker keeps every draft that passes.
The twist is the editor's notebook. After every few pages of notes the desk runs out of space, so you photograph the best drafts, clear the desk, and hand the photos back. If you let the notebook grow to 80 pages, the copier jams and the editor slows to a crawl. At 60 pages with a spillover shelf the copier keeps up. Meanwhile a tireless assistant runs two mechanical clean-up passes on whatever the editor's best draft is, keeping a change only when it raises the score.
That is what this system does with Lean 4 proofs. The editor is an open-weight language model, the desk is GPU memory, the spell-checker is Lean's own compiler, and the 48-hour deadline is real. The score of 79.25 Combined means proofs got about 62% shorter and 77% cheaper to check, and almost all compile on every required Lean version. But the editor only got one shift, so nobody knows how much the score would change on a second try.
The abstract, word for word, with the five densest phrases unpacked.
We describe our open-track entry in the Lean Refactor Arena, a general agent harness rather than a trained model1: it applies to any Lean 4 proof, and its prompts contain no proof techniques or content written for particular problems. A single open-weight model, Qwen3.8-Flash-Next in its FP8 release without fine-tuning2, is served with vLLM on four A100 80 GB GPUs3 and drives one tool-calling agent per problem, while the node’s CPUs compile, measure and search around it. The agent edits the reference proof through tools that compile and score it in the problem’s own Lean project, and every valid proof is kept as a scored candidate. Each problem runs a discovery and then a refinement phase; long conversations are rebuilt from checkpoints, model-free passes improve the best candidate, and the final choice compiles candidates on every Lean version the problem lists. All problems run concurrently in one job that ends within the 48-hour limit, setup included (the submitted proofs took 47.8 hours from the first setup step, selection included). Self-hosting on A100 required three compatibility fixes, and the context length at which a conversation is rebuilt has a sweet spot: shorter contexts score less per request, while longer ones overflow the GPU cache at 60 concurrent problems4 (at 80k, throughput falls from about 1,700 to 530 output tokens/s). The submitted run uses 60k with CPU KV offloading. The submitted proofs score 79.25 Combined (62.48% length reduction, 76.96% heartbeat reduction, 98.3% zero-shot)5, and every one is fully checked by Lean’s kernel.
Two lines converge: LLM agents for formal proofs and efficient inference serving.
Read four parts, in this order.
Skip Appendix A (full prompts) and Appendix D (pinned versions) unless you are reproducing the run.
If the score is fragile, these places show why.
Sampling at temperature 1.0, concurrent scheduling and batching on the server make every run different, and the number of requests a problem gets depends on how fast the server runs. The lean_search tool also depends on the public LeanSearch service, whose availability and index we do not control. On the warm-up problems, three API runs of one 400-request configuration had 15-problem means of 80.4, 80.9 and 81.1 Combined (a standard deviation of about 0.5 for one run’s mean, 2 points per problem). Four concurrent self-hosted copies of the 15 problems, stopped after 3.5 hours, ended at 70.4–71.3. The final configuration ran once, so its own spread is not measured; in the submitted run the 60-problem mean still rose by about 0.05–0.1 Combined per hour in the last ten hours. On slower hardware (for example A100s connected by PCIe instead of NVLink) the run still ends on time because the schedule is time-based, but problems get fewer requests and scores can be lower.
On the GPU the context threshold also decides how many requests the server can sustain (Table 10). Below about 65–70% use of the KV cache (2.98M tokens) nearly every prompt reuses its cached prefix (93–95% hits) and the server produces about 1,700 output tokens/s. Above it, throughput collapses: the model’s linear-attention layers need one saved recurrent state at the end of the previous prompt to reuse a prefix, vLLM releases that state to its least-recently-used free list while the request is still decoding, and under memory pressure it is evicted, so the next request recomputes its whole context, which adds pressure and causes more evictions. With R =80k the hit rate fell to 22–40% and throughput to about 530 tokens/s. Keeping the sum of all contexts within about two thirds of the cache avoids this; vLLM’s CPU KV offloading, which keeps evicted blocks in host memory and reloads them, raised a 60k threshold from about 950 to 1,250–1,500 tokens/s. Since quality per request is flat from 60k to 80k (Section 5.1, item 5), the server sets the threshold. We chose R = 60k with CPU KV offloading: it sustains about the same request rate as 45k without offloading (29 against 27 requests per problem per hour) and scores 1.7 points more per request (Table 8). At that rate a problem gets roughly 1,300 requests in 46 hours, more than in any development run; the submitted run made 784 per problem (Section 4).
| Construct | Arena | Ours | Used | Accepted |
|---|---|---|---|---|
| sorry, admit, axiom | rejected | rejected | 58 | 0 |
| native_decide, ofReduceBool | rejected | rejected | 65 | 0 |
| decide +native | rejecteda | axiom check | 82 | 0 |
| set_option, e.g. debug.skipKernelTC | allowed | rejected | 20 | 0 |
| metaprograms, code execution (run_tac, #eval, …) | rejected | rejected | 17 | 0 |
| declarations, commands (def, attribute, …) | rejected | rejected | 5 | 0 |
| heartbeat names other than maxHeartbeats | rejecteda | allowed | 9 | 6b |
| unsafe | allowedc | allowed | 3 | 2 |
aSince 2026-10-28. bgrind’s canonHeartbeats; none selected. cExcept before def, fun, theorem, lemma; the reference proof of Combine.master_lemma uses aesop’s add unsafe rules.
Nothing on this page was recomputed. Every claim points to the paper so you can check it.
More latest news
Read all