NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Multi-Turn Code Generation Through Single-Step Rewards

Arnav Kumar Jain, Gonzalo Gonzalez-Pumariega, Wayne Chen, Alexander M Rush, Wenting Zhao, Sanjiban Choudhury

Introduction

When human developers write code, they rarely achieve perfection on the first attempt. The natural workflow involves writing a draft, executing it, analyzing the error messages, and applying fixes. This multi-turn process is essential for solving complex programming problems. However, training artificial intelligence to replicate this iterative debugging process has proven surprisingly difficult.

Most current code generation models are either "single-turn"—making one attempt and stopping—or rely on Reinforcement Learning (RL) to navigate multi-step error correction. RL is notoriously unstable for code generation due to sparse rewards (success is only known at the very end) and the credit assignment problem (determining which specific turn fixed the bug). To address this, researchers introduce $\mu$CODE, a framework that simplifies multi-turn code repair by treating it as a "one-step recoverable" problem, bypassing the instability of traditional RL.

The $\mu$CODE Framework

The core theoretical insight behind $\mu$CODE is that code generation can be modeled as a one-step recoverable Markov Decision Process (MDP). In practical terms, this means that no matter how broken the current code state is, there exists a single-step fix that can correct it.

Because of this property, complex multi-step RL is unnecessary. Instead, the model can utilize Imitation Learning, learning to mimic an "expert" capable of fixing code in a single turn. The $\mu$CODE training loop operates in three iterative stages:

  1. Rollout: The current model generates multiple code attempts for a given problem.
  2. Train Verifier: A reward model (the verifier) is trained to score these attempts based on unit test execution. The researchers found that utilizing a Bradley-Terry loss—which ranks which code snippet is better—outperforms simple binary classification.
  3. Train Generator: The verifier acts as a local expert, selecting the best possible code from the rollouts. The generator is then fine-tuned to produce this optimal code, conditioned on previous failed attempts and their corresponding error messages.

During inference, $\mu$CODE employs Multi-turn Best-of-N (BoN). At each turn, the model generates $N$ candidates, uses the learned verifier to select the most promising one, executes it, and feeds the resulting feedback into the next turn if the code still fails.

Datasets and Evaluation

The researchers evaluated $\mu$CODE across several prominent Python benchmarks:

  • MBPP (Mostly Basic Python Problems): Entry-level programming tasks.
  • HumanEval (HE): A standard benchmark for evaluating logic and coding proficiency.
  • CodeContests (CC): A highly challenging dataset featuring competitive programming problems.
  • MBPP (POMDP): A custom "Partially Observable" version of MBPP. By removing unit tests from the initial prompt, the model is forced to rely entirely on the execution feedback received after its first attempt.

Key Insights and Results

The $\mu$CODE framework yielded several critical insights into multi-turn code generation:

  • The "One-Step" Shortcut: By proving code generation is one-step recoverable, the authors bypass the exploration burden of RL. The model does not need long-term planning; it only needs to excel at single-step repairs.
  • Dense Rewards via Verifiers: Standard pass/fail oracle rewards are binary and uninformative. A learned verifier provides dense scores, helping the model understand incremental improvements (e.g., failing 1 out of 10 tests is better than failing all 10).
  • Effective Feedback Utilization: The MBPP (POMDP) experiment demonstrated the method's efficacy. While base models struggled when tests were removed from the prompt, $\mu$CODE successfully utilized error messages to recover the correct logic.
  • State-of-the-Art Performance: Using a Llama-3.2-1B base model, $\mu$CODE outperformed Rejection Fine-Tuning (RFT) by 4.4% on MBPP and 5.8% on HumanEval. On the rigorous CodeContests benchmark, it achieved a 16.3% success rate, beating the base model (+BoN) by 2.5%.
  • Inference Scaling: Performance scales linearly with the number of candidates ($N$) generated per turn, demonstrating that test-time compute is a powerful lever for this framework.

Limitations and Future Directions

While $\mu$CODE presents a significant step forward, the study notes several limitations. Due to compute constraints, experiments were limited to models up to 8 billion parameters, leaving it an open question whether these gains scale to frontier models (100B+ parameters). Additionally, training was conducted on a small dataset (374 MBPP problems); expanding this data could improve generalization.

Currently, the framework has only been tested on Python. Future research must determine if one-step recoverability applies as cleanly to languages with different error-handling paradigms or complex compilation steps. Finally, while code generation fits the one-step recoverable MDP model, other multi-turn tasks—such as long-form creative writing or multi-step robotics—may not, potentially limiting the broader applicability of this specific imitation learning shortcut.

Summary updated

BibTeX
@inproceedings{jain2025multi,
  author = {Arnav Kumar Jain and Gonzalo Gonzalez-Pumariega and Wayne Chen and Alexander M Rush and Wenting Zhao and Sanjiban Choudhury},
  title = {{Multi-Turn Code Generation Through Single-Step Rewards}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=aJeLhLcsh0},
}
Figure