arXiv:2608.23632cs.AIAug 2026

Manuscript Offprint

arXiv:2608.23632

Function-Level Execution Feedback for Code Preference Optimization

Idris Nechnech, Sehwan Kim, Jimin Seo, Yeongoon Kim, Minhae Oh, Sangwoo Hong, Jungwoo Lee

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Process supervision has improved mathematical reasoning, where intermediate steps are naturally expressed as chains of thought. In code generation, however, process supervision remains underexplored because there is no standard notion of a step. Supervision can target lines, reasoning traces, or program states, making it unclear what to label and optimize. We propose STEP-KTODER, a framework for code preference optimization that defines steps as module-level functions in decomposed multi-function programs and assigns binary correctness labels via automatically generated unit tests. Our method provides a code-specific instantiation of stepwise KTO, combining function-level process supervision with outcome-level feedback on the full program. We evaluate on HumanEval(+), MBPP(+), BigCodeBench, and LiveCodeBench, showing that STEP-KTODER improves over outcome-only KTO and DPO. Further analysis shows that execution-based labels are essential: LLM-as-a-judge annotations systematically over-predict function failures, corrupt positive step labels, and degrade downstream preference optimization. Code is available at: https://github.com/inechnech/STEP-KTODER.

1 Introduction

Code generation has become a major application of Large Language Models (LLMs), with recent code-specialized models achieving strong performance on a wide range of programming tasks (Guo et al., 2024; Hui et al., 2024). These models are typically improved through two stages: supervised fine-tuning (SFT) (Wei et al., 2022) on high-quality code data, followed by an alignment stage that adapts the model toward better outputs (Ouyang et al., 2022). Among alignment methods, Direct Preference Optimization (DPO) (Rafailov et al., 2023) is widely used to learn from paired preference data, whereas Kahneman–Tversky Optimization (KTO) (Ethayarajh et al., 2024) learns from binary desirability labels on individual outputs.

However, applying these techniques to code generation is nontrivial. These methods are typically instantiated at the level of the entire program, treating a full solution as a single unit of feedback. This provides only a coarse training signal: a program can be mostly correct and fail only on a narrow edge case, but outcome-level supervision still marks the entire output as undesirable. Such supervision does not reveal which component is correct and which is responsible for the failure, motivating finer-grained supervision for code generation.

In mathematical reasoning, process supervision—providing feedback on intermediate reasoning steps—has proven highly effective (Lightman et al., 2024; Luo et al., 2024; Wang et al., 2024), with process reward models (PRMs) underpinning state-of-the-art reasoning systems. Building on this success, Lin et al. (2025a) combined stepwise binary feedback with KTO to jointly optimize intermediate and final-answer quality for mathematical problem solving. Transferring this idea to code generation, however, remains an open challenge: code does not naturally decompose into a single standardized sequence of intermediate logical steps, making the very definition of a “step” ambiguous.

We address this ambiguity by defining steps as module-level functions in decomposed programs, and propose STEP-KTODER, a framework that brings function-level process supervision to code generation. Our key idea is that decomposed programs provide an executable step structure: when a solution is written as multiple functions, each can be tested independently using automatically generated unit tests, yielding binary labels of local correctness. STEP-KTODER uses these labels to extend outcome-level KTO with function-level supervision, guiding training by both global pro-

†^{\dagger}Corresponding author.

Figure

Figure 1: Overview of the STEP-KTODER framework. A reference solution y∗y^* is decomposed into module-level functions s1,…,sns_1, \ldots, s_n, and function-level unit tests are generated for each function. Candidate completions are evaluated against these tests to obtain step labels ziz_i indicating local correctness, alongside an outcome label oo from the dataset-provided test suite. The resulting labeled data is used to train the model with a joint objective that combines outcome-level KTO ( Lout\mathcal{L}_{\text{out}}) and function-level supervision ( Lstep\mathcal{L}_{\text{step}}), reinforcing locally correct functions while penalizing locally incorrect ones.

gram success and local correctness, as indicated in Figure 1.

Beyond the main empirical gains, we investigate two design choices that are important to STEP-KTODER's effectiveness. First, programs that pass dataset-provided tests but contain a locally incorrect function provide a form of supervision that outcome-only training cannot express. We find that preserving these local/global mismatches strengthens the benefit of step-level supervision, whereas masking such mismatches substantially weakens the signal. Second, we assess whether automatically generated unit tests are necessary for reliable step supervision by replacing execution-based step labels with LLM-as-a-judge annotations. Although these annotations show moderate agreement with execution-based labels, they systematically over-predict step failures, and when used for STEP-KTODER training, they degrade performance. Even for already instruction-tuned Qwen2.5-Coder models, STEP-KTODER achieves substantial improvements: it improves over the base model by up to +26.7% on BigCodeBench Hard (Zhuo et al., 2025) and +27.0% on LiveCodeBench (Jain et al., 2025).

Our contributions are as follows:

• We propose STEP-KTODER, a code-specific instantiation of stepwise KTO that combines function-level process supervision with outcome-level feedback.

• We introduce an automatic data construction pipeline that decomposes solutions into functions, generates function-level unit tests, and derives execution-based step labels for training.

• Experiments across widely used benchmarks show that STEP-KTODER improves post-trained code models. We further demonstrate that replacing execution-based step labels with LLM-as-a-judge annotations weakens the step-level signal and degrades performance.