← All papers
First page of A Self-Hosted, Time-Budgeted Agent for Lean Proof Refactoring with an Open-Weight Model

A Self-Hosted, Time-Budgeted Agent for Lean Proof Refactoring with an Open-Weight Model

Ke Zhang, Pengzhen Lin, Zhouxing Shi, Maziar Raissi

cs.AI Nov 30, 2026 · v1
An LLM agent refactors Lean 4 proofs in Mathlib-based projects, using tools that compile, profile, and kernel-check candidates across Lean versions.
We describe our open-track entry in the Lean Refactor Arena, a general LLM agent harness for formal theorem proving and proof refactoring rather than a trained model: it applies to any Lean 4 proof (including Mathlib-based projects), and its prompts contain no proof techniques or content written for particular problems. A single open-weight LLM, Qwen3.8-Flash-Next in its FP8 release without fine-tuning, is served with vLLM on four A100 80 GB GPUs 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 KV cache and evict cached prefixes at 60 concurrent problems (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), and every one is fully checked by Lean's kernel. Code: https://github.com/grenadeComing/lean-refactor-arena

The Lean Refactor Arena asks entrants to rewrite reference Lean 4 proofs from six Mathlib-based repositories. The goal is shorter, faster proofs that still compile on target Lean versions. The open track limits entries to open-weight models on four A100 GPUs within 48 hours, setup included.

A frozen open-weight model, Qwen3.8-Flash-Next FP8, is served with vLLM and drives one tool-calling agent per problem, with 60 problems running concurrently. Its tools compile, edit, try tactics, inspect goals, and search the project and Mathlib (via LeanSearch). Every valid proof is stored as a scored candidate after a forbidden-construct filter and a kernel axiom check. Each session has a discovery phase and a refinement phase; long conversations are rebuilt from checkpoints, Lean-only heartbeat and length passes improve the best candidate, and the final choice compiles candidates on every listed version.

The submitted proofs score 79.25 Combined (62.48% length reduction, 76.96% heartbeat reduction, 98.3% zero-shot version transfer), all kernel-checked, in 47.8 hours. A 60k-token rebuild threshold with CPU KV offloading balanced per-request quality against GPU KV-cache overflow, which at 80k cut throughput from about 1,700 to 530 output tokens/s.

ModelLength (%)Heartbeats (%)Combined
Qwen3.8-Flash45.370.471.9
DeepSeek-V4-Flash23.763.162.3
MiniMax-M2.78.635.748.1
Step-3.7-Flash5.836.447.4
gpt-oss-120b1.621.841.1
Open-weight model comparison on 15 warm-up problems (300 requests)