Code Repair with LLMs gives an Exploration-Exploitation Tradeoff
Hao Tang, Keya Hu, Jin Zhou, Sicheng Zhong, Wei-Long Zheng, Xujie Si, Kevin Ellis
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.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
20 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Is Programming by Example Solved by LLMs? cites CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- Is Programming by Example Solved by LLMs? cites Self-Refine: Iterative Refinement with Self-Feedback
- Is Programming by Example Solved by LLMs? cites Teaching Large Language Models to Self-Debug
- Teaching Large Language Models to Self-Debug cites CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- Teaching Large Language Models to Self-Debug cites Self-Refine: Iterative Refinement with Self-Feedback
- Wider or Deeper? Scaling LLM Inference-Time Compute with Adaptive Branching Tree Search cites Self-Refine: Iterative Refinement with Self-Feedback
- CodeJudgeBench: Benchmarking LLM-as-a-Judge for Coding Tasks cites Teaching Large Language Models to Self-Debug
- Generating Code World Models with Large Language Models Guided by Monte Carlo Tree Search cites CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- Generating Code World Models with Large Language Models Guided by Monte Carlo Tree Search cites Self-Refine: Iterative Refinement with Self-Feedback
- Generating Code World Models with Large Language Models Guided by Monte Carlo Tree Search cites WorldCoder, a Model-Based LLM Agent: Building World Models by Writing Code and Interacting with the Environment
- WorldCoder, a Model-Based LLM Agent: Building World Models by Writing Code and Interacting with the Environment cites Teaching Large Language Models to Self-Debug
Cited by top-tier papers20
- WorldCoder, a Model-Based LLM Agent: Building World Models by Writing Code and Interacting with the EnvironmentHao Tang, Darren Key, Kevin EllisNeurIPS 2024 · 123 citations
- Wider or Deeper? Scaling LLM Inference-Time Compute with Adaptive Branching Tree SearchYuichi Inoue, Kou Misaki, Yuki Imajuku, So Kuroki et al.NeurIPS 2025 · 67 citations
- Generating Code World Models with Large Language Models Guided by Monte Carlo Tree SearchNicola Dainese, Matteo Merler, Minttu Alakuijala, Pekka MarttinenNeurIPS 2024 · 49 citations
- Is Programming by Example Solved by LLMs?Wen-Ding Li, Kevin EllisNeurIPS 2024 · 45 citations
- CodeJudgeBench: Benchmarking LLM-as-a-Judge for Coding TasksHongchao Jiang, Yiming Chen, Yushi Cao, Hung-Yi Lee et al.ACL 2026 · 33 citations
Builds on16
- Self-Refine: Iterative Refinement with Self-FeedbackAman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan et al.NeurIPS 2023 · 4,972 citations
- Teaching Large Language Models to Self-DebugXinyun Chen, Maxwell Lin, Nathanael Schärli, Denny ZhouICLR 2024 · 1,085 citations
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement LearningHung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese et al.NeurIPS 2022 · 571 citations
- Automated Program Repair in the Era of Large Pre-trained Language ModelsChunqiu Steven Xia, Yuxiang Wei, Lingming ZhangICSE 2023 · 321 citations
- Automated Repair of Programs from Large Language ModelsZhiyu Fan, Xiang Gao, Martin Mirchev, Abhik Roychoudhury et al.ICSE 2023 · 213 citations
Related papers
- RLEF: Grounding Code LLMs in Execution Feedback with Reinforcement LearningJonas Gehring, Kunhao Zheng, Jade Copet, Vegard Mella et al.ICML 2025
- Online Prompt Selection for Program SynthesisYixuan Li, Lewis Frampton, Federico Mora, Elizabeth PolgreenAAAI 2025 · 2 citations
- Ranking LLM-Generated Loop Invariants for Program VerificationSaikat Chakraborty, Shuvendu K. Lahiri, Sarah Fakhoury, Akash Lal et al.EMNLP Findings 2023 · 36 citations
- Steering Tree-of-Thought Reasoning via Deductive VerificationHaoliang Cheng, Enyi Tang, Shuoxiao Zhang, Jiahe Mao et al.ISSTA 2026
- Once Upon an Input: Reasoning via Per-Instance Program SynthesisAdam Stein, Neelay Velingker, Mayur Naik, Eric WongNeurIPS 2025
