OPAL: Optimizing Proofs at Library Scale via Metric-Driven Coding Agents
Liu et al. in Agents
What stops an agent from deleting the mathematics it is asked to optimize?
OPAL: Optimizing Proofs at Library Scale via Metric-Driven Coding Agents
Maintenance often crosses file boundaries

Left: 41.4% of 27,594 post-port mathlib commits were maintenance; 62.1% of those touched multiple files. Right: six tendency shares; commits may carry multiple labels.
OPAL moves optimization from proofs to libraries
Prior proof optimizers usually rewrite one theorem toward a stated goal; cross-file maintenance and library-wide objectives fall outside that unit.
Each task minimizes one repository metric: code tokens, import closure, elaboration heartbeats (a deterministic work proxy), mathlib duplicates, deprecated API references, or blueprint-link gaps. The agent chooses edits, not a patch recipe.
Claude Opus 4.8 on Lite: 26/30 repo-level passes versus 7/30 proof-body-only; 17 tasks need cross-file edits.
Blueprint links define the protected interface
Blueprint `\lean{}` links name project-local targets; their statements stay α-equivalent. Anchors cover only about 5–19% of local declarations.
Proof bodies and auxiliary declarations may be refactored; further checks guard definitions anchors depend on, axiom/sorry regressions, unauthorized deletions, and build integrity.
This preserves the anchored interface, not every auxiliary statement.
The score is computed outside the sandbox

The agent edits inside Docker; self-measurements are advisory. Only its working tree crosses the trust boundary; an external gate checks the contract and recomputes all six metrics.
Most full-benchmark tasks passed verification
40/162: 34 failed contract, integrity, or ε-budget checks; 6 had no target-metric gain.
Claude Opus 4.8 passed 122/162 tasks (75.3%): 100 clean gains and 22 tradeoffs with side regressions inside ε budgets.
Across 18 Lean blueprint projects: 56 historical-parent tasks and 106 in-the-wild debts.
A 9.6× headroom ratio needs context

All 40 historical passes exceeded the human commit's gain; median ratio: 9.6×. It compares a same-region sweep with one incremental commit, not per-edit skill; 34 code-token passes show larger ratios on smaller commits.
Lite results differ by model
OPAL-Bench Lite (30 tasks); same environment, contract and budgets. One Kimi run counted as fail after a deterministic build-tool failure.
Rules alone cut fabricated gains from 48% to 7%
OPAL-Bench Lite (30 tasks), same setup. Advisory shows rules only; fabricated = accepted then rejected on offline full-contract rescoring.
What these results do not settle
Uneven objective mix
66 tasks target code_tokens, but only 2 target deprecated_refs; the aggregate 162-task pass rate hides objective-level variation.
One model, one rollout
Main results: one Claude Opus 4.8 rollout per task, capped at 250 turns or six hours; repeated-run variance is unknown, other models appear only on Lite.
Scoped contract
The contract protects anchors and checked dependencies; conservative rules can reject logically equivalent or more general rewrites.
Selected projects
The benchmark selects 18 active Lean blueprint projects on a recent toolchain.
Why it matters
- OPAL makes blueprint-linked target statements a checkable boundary for repository-wide optimization; auxiliary code remains refactorable.
- For Lean-library maintenance, set a measurable debt objective and recompute gains outside the agent's sandbox.
- Can agents sustain gains on larger projects and longer runs? PrimeNumberTheoremAnd, the largest project, passed only 3 of 11 instances.
11 slides, 3 min
4 days ago