Code Repair with LLMs gives an Exploration-Exploitation Tradeoff

Hao Tang, Keya Hu, Jin Peng Zhou, Sicheng Zhong, Wei-Long Zheng +2 more
2/3/2026

No official code found. Best implementation: haotang1995/REx (6 stars, MIT, last commit 2024-12-07).

Abstract

Iteratively improving and repairing source code with large language models (LLMs), known as refinement, has emerged as a popular way of generating programs that would be too complex to construct in one shot. Given a bank of test cases, together with a candidate program, an LLM can improve that program by being prompted with failed test cases. But it remains an open question how to best iteratively refine code, with prior work employing simple greedy or breadth-first strategies. We show here that refinement exposes an explore-exploit tradeoff: exploit by refining the program that passes the most test cases, or explore by refining a lesser considered program. We frame this as an arm-acquiring bandit problem, which we solve with Thompson Sampling. The resulting LLM-based program synthesis algorithm is broadly applicable: Across loop invariant synthesis, visual reasoning puzzles, and competition programming problems, we find that our new method can solve more problems using fewer language model calls.

View on arXivView PDF

Code Implementations(1)

haotang1995/RExCommunity66%
MIT

REx: Code Repair with LLMs gives an Exploration-Exploitation Tradeoff

61C, PythonJun 6, 20241 years agoMIT

Similar Papers

Cite this paper

@article{tang2026code,
  title  = {Code Repair with LLMs gives an Exploration-Exploitation Tradeoff},
  author = {Hao Tang and Keya Hu and Jin Peng Zhou and Sicheng Zhong and Wei-Long Zheng and Xujie Si and Kevin Ellis},
  year   = {2026},
  eprint = {2405.17503},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2405.17503},
  url    = {https://arxiv.org/abs/2405.17503},
  journal = {NEURIPS 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2405.17503.svg)](https://codeofpaper.com/paper/2405.17503)

Discussion