Reasoning Through Execution: Unifying Process and Outcome Rewards for Code Generation

Zhuohao Yu, Weizheng Gu, Yidong Wang, Xingru Jiang, Zhengran Zeng, Jindong Wang, Wei Ye, Shikun Zhang

TL;DR

Outcome-Refining Process Supervision (ORPS) is an inference-only framework that significantly boosts Large Language Model (LLM) code generation by combining verifiable execution feedback with a tree-structured search. By prompting the model to "think through" execution results and self-critique its strategy, ORPS achieves a 26.9% boost in correctness and a 42.2% improvement in code efficiency—all without requiring expensive, human-annotated training data.

The Challenge of Complex Code Generation

While LLMs are surprisingly adept at writing short code snippets, they often stumble on complex algorithmic problems that demand multi-step reasoning, such as dynamic programming or advanced data structures. Current supervision methods generally fall into two flawed paradigms:

  1. Outcome Supervision: Evaluates only the final code (Pass/Fail). This provides a "sparse" signal; it tells the model it is wrong but gives no hint about where the logic failed or how to optimize a working-but-slow solution.
  2. Process Supervision: Uses Process Reward Models (PRMs) to score intermediate reasoning steps. However, PRMs are notoriously expensive to train (requiring dense human labels), prone to "reward hacking" (where the model learns to please the evaluator without being correct), and often struggle with the structured logic of code compared to mathematical proofs.

Furthermore, models often get stuck in local optima—producing code that passes basic tests but uses an inefficient $O(n^2)$ approach when an $O(n \log n)$ solution is required.

Introducing ORPS: Methods and Framework

To overcome these limitations, the authors introduce ORPS, a framework that unifies process and outcome rewards through a tree-structured search (Beam Search). The core innovation is using the execution environment as the ultimate source of truth, grounding the LLM's reasoning in verifiable reality.

The Outcome-Refining Process Supervision (ORPS) framework, illustrating the tree-structured search and execution-based self-critique.

The process follows a three-phase loop at each step of the search tree:

  1. Candidate Generation: The LLM proposes several "strategic alternatives"—either refining the current logic or pivoting to a completely new algorithmic approach.
  2. Execution & Profiling: Each candidate's code is executed against unit tests. The system collects dynamic metrics (e.g., execution time, CPU instructions, memory usage) and static metrics (e.g., AST node count, cyclomatic complexity).
  3. Self-Critic & Process Rewarding: The LLM acts as its own critic. It reviews the reasoning chain alongside the hard execution data to assign a numerical "process reward."

The final "Step Score" is a weighted combination of this process reward and the outcome reward (the proportion of tests passed). This dual-reward system allows the search to prioritize trajectories that are not only functionally correct but also efficient and readable.

Key Insights

  • Execution as Grounding: Unlike text-based reasoning, code is verifiable. By anchoring the "process reward" in actual execution metrics, ORPS effectively eliminates the hallucination and reward-hacking issues that plague traditional PRMs.
  • Strategy Over Scale: One of the most striking findings is that strategic reasoning is more powerful than model size. A smaller model (e.g., Qwen-7B) using ORPS can outperform a much larger model (e.g., Qwen-14B) relying on standard generation methods.
  • Beyond Local Repair: Previous "self-repair" methods (like Reflexion) usually focus on fixing syntax or small bugs. ORPS operates at a higher abstraction level, encouraging the model to rethink its entire algorithmic strategy if the execution profile looks suboptimal.

Performance and Results

The researchers evaluated ORPS across five different models (including Llama 3.1, Qwen 2.5, and GPT-4o-mini) using benchmarks like HumanEval, MBPP, and LBPP (a new, challenging dataset focused on competitive programming).

Comparison of code efficiency and complexity metrics, demonstrating ORPS's multi-objective optimization capabilities.
  • Correctness: Across all models and benchmarks, ORPS showed consistent gains, averaging 26.9% higher Pass@1 scores.
  • Efficiency: The generated solutions were significantly more optimized, achieving a 42.2% average reduction in execution time. By rewarding lower CPU instruction counts and lower cyclomatic complexity, the framework pushes the LLM toward "elegant" code rather than just "working" code.
  • Superior to Trained PRMs: In head-to-head comparisons, the inference-only ORPS outperformed PRMs trained on thousands of synthetic labels (PRM-GPT) and even those trained on high-quality human annotations (PRM-Human).
  • Scaling Potential: ORPS scales much more effectively with an increased "inference budget" (more LLM calls) compared to simple Best-of-N sampling.

Limitations and Future Work

While powerful, ORPS has a few notable constraints:

  • Unit Test Dependency: The framework relies heavily on the quality of unit tests. Weak tests can lead to "false passes" that misguide the search tree.
  • Computational Cost: Tree search is inherently more expensive than single-pass generation, requiring multiple LLM calls per problem.
  • Static Weights: Currently, the weights for different metrics (speed vs. complexity) are fixed. Future work could explore adaptive reward scaling, where the model dynamically shifts its focus based on specific problem constraints.

Ultimately, ORPS demonstrates that combining verifiable outcomes with structured reasoning is a highly promising direction for tackling complex code generation challenges.

Summary updated

BibTeX
@inproceedings{yu2025reasoning,
  author = {Zhuohao Yu and Weizheng Gu and Yidong Wang and Xingru Jiang and Zhengran Zeng and Jindong Wang and Wei Ye and Shikun Zhang},
  title = {{Reasoning Through Execution: Unifying Process and Outcome Rewards for Code Generation}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=pLQtovjXiw},
}
Figure