Manuscript Offprint
arXiv:2610.27694Enhancing Bug-Exposing Test Generation via Step-Level Credit Assignment and Self-Distillation from Valuable Failures
Abstract
Large Language Models have shown strong code generation capabilities, yet their outputs often contain subtle bugs. Automatically repairing such code requires informative tests: inputs that expose faulty behavior, paired with correct expected outputs. Recent RL-based test generation methods apply the same outcome reward to all reasoning steps, which can discourage useful reasoning and reinforce flawed steps. They also fail to effectively learn from trajectories that find bug-triggering inputs but predict incorrect outputs, leaving their verified bug-triggering progress insufficiently exploited. To address these limitations, we propose SCALF, a process-supervised RL approach that combines Step-level Credit Assignment with targeted Learning from valuable Failed trajectories. SCALF derives step-specific advantages from process rewards, allowing each reasoning stage to receive its own learning signal. It further routes trajectories that expose bugs but predict incorrect outputs to on-policy self-distillation, using execution feedback to learn from their valuable bug-triggering progress. Across three benchmarks, SCALF outperforms strong prompting and post-training baselines by up to 2.97, 5.26, and 3.53 percentage points in joint success rate, output correctness rate, and bug-triggering rate, respectively. Our code and datasets are available at https://anonymous.4open.science/r/SCALF-F4D1.
1 Introduction
Large Language Models (LLMs) have demonstrated strong capabilities in code generation (Rozière et al., 2023; Luo et al., 2024), yet their outputs often contain subtle bugs and logical flaws (Liu et al., 2025). Bug-exposing test cases provide
Example: count distinct values

Figure 1: An example of different progress toward bug exposure under equal outcome rewards. BT denotes bug triggering and PC denotes prediction correctness (1: satisfied; 0: unsatisfied). For BT=1, PC=0, correcting the output completes a bug-exposing test. For BT=0, PC=1, a new input is needed to distinguish the buggy and reference programs.
useful feedback for program repair by pairing inputs that trigger faulty behavior with correct expected outputs (Bouzenia et al., 2025; Zhao et al., 2024; Hossain and Dwyer, 2025; Molinelli et al., 2025). Constructing such tests manually is time-consuming and difficult to scale, motivating automated bug-exposing test generation with LLMs (Nan et al., 2025; Pan et al., 2025).
Existing LLM-based bug-exposing test generation methods primarily rely on prompting or task-specific post-training. Prompting-based methods use general-purpose LLMs to generate test cases through zero- or few-shot prompts (Chu et al., 2025). Among post-training methods, UT-Gen (Prasad et al., 2025) fine-tunes test generators on synthetically perturbed data, while ATGen (Li et al., 2026) uses adversarial reinforcement learning to dynamically generate buggy programs and train test generators with execution-based outcome rewards.
However, outcome-based optimization over-
Corresponding authors.
looks two key characteristics of bug-exposing test generation. First, generating bug-triggering inputs and their expected outputs involves interdependent reasoning stages (Prasad et al., 2025; Dinella et al., 2022). Even successful trajectories may contain flawed steps, yet a uniform outcome-based learning signal rewards these steps alongside correct ones. Although process reward models (PRMs) enable step-level supervision in mathematical (Zhang et al., 2025b; Zhu et al., 2025) and code reasoning (Li et al., 2025; Ye et al., 2025), they remain underexplored for bug-exposing test generation. Second, partial successes offer different opportunities for further learning (Hossain and Dwyer, 2025; Molinelli et al., 2025; Hossain et al., 2023). As Figure 1 illustrates, a trajectory with a verified bug-triggering input but an incorrect output can yield a valid test by correcting the output. In contrast, a trajectory with a correct output but a non-triggering input still requires discovering a new input. However, standard GRPO does not distinguish the learning value of these partial outcomes, leaving the valuable progress in bug-triggering failures insufficiently exploited.
To address these challenges, we propose SCALF, a process-supervised RL approach that combines step-level credit assignment with targeted learning from valuable failed trajectories. We first train a task-specific PRM to evaluate intermediate reasoning steps in bug-exposing test generation. During RL training, SCALF derives step-specific advantages from these process rewards, allowing each reasoning stage to receive its own learning signal. It further routes trajectories that expose bugs but predict incorrect outputs to on-policy self-distillation, using execution feedback to guide output prediction while preserving their verified bug-triggering inputs.
Across three benchmarks, SCALF-7B achieves the highest output correctness, bug-triggering, and joint success rates, exceeding the strongest baselines by up to 5.26, 3.53, and 2.97 percentage points, respectively. In downstream program repair, its generated tests yield the highest repair success rate of 44.16%, using seven tests and up to three repair attempts per test.
Our contributions are:
• We propose SCALF for bug-exposing test generation through step-level credit assignment and targeted learning from valuable failures.
• We construct step-level supervision data and train a task-specific PRM for step-specific policy optimization.
• Experiments on three benchmarks show gains in output correctness, bug triggering, and joint success over prompting and post-training baselines, with further improvements in program repair.
LLM-based Test Generation. LLM-based test generation has been explored through prompting and task-specific guidance (Lemieux et al., 2023; Schäfer et al., 2024; Ryan et al., 2024; Hossain and Dwyer, 2025; Molinelli et al., 2025). Post-training methods further improve bug-exposing tests: UT-Gen (Prasad et al., 2025) fine-tunes on perturbed data, and ATGen (Li et al., 2026) applies adversarial RL with execution-based outcome rewards. However, ATGen assigns a single outcome reward to the entire trajectory, giving all reasoning steps the same credit. SCALF introduces process rewards (Zhang et al., 2025b; Li et al., 2025; Ye et al., 2025) so that each reasoning step receives its own learning signal, and further learns from the progress of bug-triggering failed trajectories by routing them to on-policy self-distillation (Zhao et al., 2026b).
3 Problem Formulation
Given a problem description and its corresponding incorrect solution , our goal is to generate a test case , where is the input and is the expected output. Let denote a validated reference solution; a successful test case should satisfy both Prediction Correctness, i.e., , and Bug Triggering, i.e., .
We formulate the test generation as a Markov Decision Process. Following the prompt template provided in Appendix G, the generator pro-duces explicit reasoning steps, mainly including Bug Analysis, Test Design, and Output Prediction. At each step , the state is the prefix context, and the action is the next structured component to generate. This step-wise formulation enables process rewards to provide step-specific credit for policy optimization.
4 Dataset Construction
To support the training of the PRM and the test generator, we construct two types of training data from CodeContests+ (Wang et al., 2025), which provides a large collection of correct and incorrect solutions submitted by real users across multiple programming platforms. The construction follows a three-stage pipeline: Stage 1 filters problems for PRM training and test generator training, and Stages 2 and 3 derive step-level labels for PRM training.
Stage 1: Difficulty Filtering. We first filter CodeContests+ to retain problems of moderate difficulty, since overly easy or hard problems provide weak learning signals. Specifically, for each (problem, incorrect solution) pair, we sample eight test-generation responses with Qwen2.5-Coder-32B-Instruct (Hui et al., 2024) and discard pairs whose responses all succeed or all fail. For each retained problem, validated correct solutions serve as references, and clustered incorrect solutions serve as diverse buggy programs. This yields two disjoint problem sets: 2,000 problems for PRM data construction, and 1,843 problems with 15,695 (problem, incorrect solution) tasks for test generator training and evaluation.
Stage 2: MC-based Step Labeling. To enable the PRM to distinguish effective processes from ineffective ones, we collect a balanced set of positive and negative test-generation trajectories. Specifically, we prompt Qwen2.5-Coder-32B-Instruct to generate multiple trajectories for each pair of problem description p and buggy program . We execute the generated test case from each trajectory and label the trajectory as positive if it both exposes the bug and predicts the correct expected output; otherwise, it is labeled as negative. For each pair, we retain up to four positive trajectories and the same number of negative trajectories to reduce label-distribution bias.
We then decompose each trajectory into structured reasoning steps and derive step-level labels through Monte Carlo estimation. Given an intermediate step with prefix state and action , we sample continuations from the updated state , yielding completed trajectories . We compute its MC score as the average execution success rate:
where returns 1 if the completed trajectory produces a bug-exposing test case with the correct expected output, and 0 otherwise.
We convert the MC score into a hard label, as hard labels have been shown to be more effective than soft labels for PRM training (Zhang et al., 2025b; Xu et al., 2025). Specifically, following the relative progress criterion in GenPRM (Zhao et al., 2026a), we define the hard label for action as:
Thus, a step is labeled as positive only when it provides sufficient relative progress toward a successful bug-exposing test case. We set ; an analysis of this threshold is provided in Appendix A.4.
Stage 3: LLM-based Consistency Filtering. MC estimation relies on sampled continuations to infer step quality, making the resulting labels sensitive to the completion model and potentially noisy (Zhang et al., 2025b). To improve label reliability, we further introduce an LLM-based judge as an independent verifier. Specifically, we use DeepSeek-V3.2 (DeepSeek-AI, 2025) to assess whether each step is valid under the current context and output a binary decision. We retain only trajectories with full step-level agreement between MC labels and LLM judgments, so the final PRM training data is supported by both execution-based evidence and semantic inspection. Detailed statistics of the constructed PRM labels are provided in Appendix A.1.
Using the constructed step-level supervision data, we train a task-specific PRM to score intermediate reasoning steps. Details of PRM training are provided in Appendix A.2.
5 Method
This section presents the policy optimization framework of SCALF. As illustrated in Figure 2, SCALF combines step-level GRPO for fine-grained credit assignment with failure-routed OPSD for learning from valuable failed trajectories. We describe the two components and their joint training objective below.
5.1 Step-level GRPO
Outcome-based optimization evaluates the final test but does not directly distinguish the quality of individual reasoning steps (Li et al., 2026). To address this limitation, we incorporate process rewards into GRPO to provide step-specific learning signals (Wang et al., 2024; Shao et al., 2024). Given , we sample trajectories from , with denoting the token indices of reasoning step .
Let and indicate whether the generated test satisfies bug triggering and prediction correctness, respectively. The outcome reward is
where for invalid formats and 0 otherwise. To mitigate reward hacking arising from PRM behavior on out-of-distribution trajectories (Song et al., 2026), we add the step score only when both objectives are satisfied:
This condition anchors process supervision to verified task success, allowing the PRM to distinguish reasoning quality within successful trajectories. Further analysis is provided in Appendix B. We normalize these rewards across all G trajectories at each step:
where and are the step-specific group mean and standard deviation, and ensures numerical stability.
Each advantage applies only to tokens in its corresponding step. For token in , define
Aggregating the step-specific updates yields the policy loss for trajectory :
where is the clipping parameter and controls KL regularization. Each reasoning step is thus optimized using its own advantage, enabling step-specific credit assignment.
5.2 Failure-routed OPSD
Correctly predicting the output for an easy input that does not trigger the bug offers limited progress toward bug exposure. In contrast, trajectories that trigger bugs but predict incorrect outputs have already discovered a useful input; correcting the output can turn this progress into a valid bug-exposing test. Standard GRPO does not explicitly exploit this difference in learning value. To better learn from these valuable failures, we route them to on-policy self-distillation (OPSD) (Zhao et al., 2026b), replacing their step-level GRPO loss. The routing indicator is
For each routed trajectory, we retain its input and obtain the correct output through reference execution. The verified pair and execution feedback form privileged information , enabling the self-teacher to guide output correction for the discovered bug-triggering input.
The student and self-teacher share model parameters but receive different contexts. At each on-policy prefix , the student distribution conditions on , while the teacher distribution additionally conditions on . We minimize their token-wise divergence:
This provides targeted learning signals for valuable failed trajectories, using verified execution feedback to guide output prediction while retaining their bug-triggering inputs.
5.3 Joint Training Objective
SCALF combines step-specific credit assignment with targeted learning from valuable failed trajectories through loss-level routing. For each rollout group, we first compute step-level GRPO advantages across all G trajectories to retain the full group-relative comparison. We then replace the step-level GRPO loss with the OPSD loss for trajectories satisfying , while keeping the GRPO

Figure 2: Overall framework of SCALF policy optimization, consisting of step-level GRPO, failure-routed OPSD, and joint loss aggregation.
loss for the remaining trajectories:
(10)
where is the routing indicator defined in Section 5.2, and weights the distillation loss. Thus, valuable failed trajectories contribute to the group-relative baseline while receiving targeted distillation updates.
6 Experimental Setup
Benchmarks. We evaluate on three benchmarks: CodeContests+ (Wang et al., 2025), TestCase-Eval (Yang et al., 2025), and MBPP+Fix (Hard) (Prasad et al., 2025). For CodeContests+, we split the task pool at the problem level, yielding 437 evaluation tasks with no problem overlap with the training split. For TestCase-Eval, we retain 3,341 tasks after excluding those whose task contexts exceed 2,048 tokens. For MBPP+Fix (Hard), we use the 170 evaluation tasks introduced by UTGen. Each task provides a problem description and an incorrect solution, requiring a bug-triggering input and its correct expected output.
Baselines. We compare SCALF against two categories of methods:
• Prompting-based Methods: We evaluate models from the Qwen2.5-Coder (Hui et al., 2024), Qwen3 (Qwen Team, 2025), Yi-Coder (01.AI, 2024), and SeedCoder (Zhang et al., 2025a) families, directly prompting them to generate bug-exposing tests without task-specific post-training.
• Post-training Methods: We evaluate the 3B and 7B variants of UTGen (Prasad et al., 2025) and ATGen (Li et al., 2026), which use supervised fine-tuning and adversarial reinforcement learning for test generation, respectively.
Evaluation Metrics. For generated tests , we report three metrics:
• Prediction Correctness Rate (PCR, %): The percentage of generated test cases whose predicted output is correct, i.e., .
• Bug Triggering Rate (BTR, %): The percentage of generated inputs that expose the buggy behavior, i.e., .
• Joint Success Rate (PCR ∩ BTR, %): The percentage of generated test cases that satisfy both prediction correctness and bug triggering.
Implementation Details. SCALF uses the 3B and 7B variants of Qwen2.5-Coder-Instruct (Hui et al., 2024), with policy training implemented in veRL (Sheng et al., 2025). The SFT and RL-based baselines use the same training split as SCALF. The PRM is initialized from Qwen2.5-Coder-7B-Instruct and trained with OpenRLHF (Hu et al., 2025). Training is performed on 8 NVIDIA H100 GPUs. Detailed training settings and baseline configurations are provided in Appendix F.
| Method | CodeContests+ | TestCase-Eval | MBPP+Fix (Hard) | ||||||
|---|---|---|---|---|---|---|---|---|---|
| PCR | BTR | PCR ∩ BTR | PCR | BTR | PCR ∩ BTR | PCR | BTR | PCR ∩ BTR | |
| Baselines | |||||||||
| QWC-3B | 38.67% | 22.20% | 8.70% | 31.61% | 9.70% | 3.47% | 25.88% | 18.82% | 12.35% |
| QWC-7B | 39.82% | 22.88% | 10.98% | 25.26% | 10.30% | 4.64% | 34.12% | 24.12% | 18.82% |
| QWC-14B | 45.08% | 24.71% | 13.50% | 35.17% | 13.89% | 6.41% | 35.29% | 26.47% | 20.59% |
| QWC-32B | 37.99% | 25.40% | 15.79% | 35.95% | 14.10% | 6.76% | 36.47% | 28.82% | 23.53% |
| Qwen3-4B | 49.89% | 28.38% | 19.68% | 32.45% | 10.75% | 3.89% | 28.82% | 20.00% | 14.71% |
| Qwen3-8B | 59.04% | 28.15% | 20.82% | 39.72% | 14.61% | 6.44% | 37.06% | 26.47% | 21.18% |
| Qwen3-14B | 54.46% | 32.04% | 20.37% | 43.58% | 16.79% | 7.60% | 40.00% | 32.35% | 26.47% |
| Qwen3-32B | 55.15% | 33.18% | 23.34% | 40.20% | 18.71% | 9.10% | 41.18% | 34.12% | 28.82% |
| Yi-Coder | 25.17% | 21.05% | 7.32% | 12.90% | 7.21% | 2.45% | 24.12% | 22.94% | 11.18% |
| SeedCoder | 40.27% | 23.80% | 12.59% | 25.65% | 11.49% | 4.67% | 33.53% | 24.71% | 15.88% |
| UTGen-3B | 37.76% | 21.97% | 9.84% | 27.12% | 9.61% | 3.71% | 32.35% | 22.35% | 15.29% |
| UTGen-7B | 38.44% | 23.11% | 10.98% | 28.64% | 12.30% | 4.91% | 37.06% | 24.71% | 20.59% |
| ATGen-3B | 69.11% | 35.01% | 20.37% | 60.16% | 20.59% | 8.98% | 68.82% | 33.53% | 25.88% |
| ATGen-7B | 82.15% | 38.44% | 25.86% | 63.84% | 22.81% | 9.22% | 74.12% | 37.06% | 28.24% |
| Ours | |||||||||
| SCALF-3B | 73.91% | 37.76% | 24.71% | 62.68% | 23.89% | 11.10% | 74.12% | 36.47% | 27.06% |
| SCALF-7B | 87.41% | 41.19% | 28.83% | 67.08% | 24.48% | 11.37% | 78.82% | 40.59% | 31.18% |
Table 1: Main results of SCALF and baselines. PCR denotes Prediction Correctness Rate, BTR denotes Bug Triggering Rate, and PCR ∩ BTR denotes the rate satisfying both criteria. Best results are bolded and second-best results are underlined.
7 Evaluation Results
7.1 Main Results
Table 1 reports the main evaluation results on CodeContests+, TestCase-Eval, and MBPP+Fix (Hard). We compare SCALF with two categories of baselines: prompting-based models, including the Qwen2.5-Coder series (abbreviated as QWC in the table), Qwen3 series, Yi-Coder-9B-Chat (abbreviated as Yi-Coder), and Seed-Coder-8B-Instruct (abbreviated as SeedCoder), and task-specific post-training baselines, including UTGen and ATGen. Based on the experimental results, we make the following observations:
(1) SCALF consistently improves both prediction correctness and bug triggering. SCALF-7B achieves the best PCR, BTR, and PCR ∩ BTR on all three benchmarks. On CodeContests+, it reaches 87.41% PCR, 41.19% BTR, and 28.83% PCR ∩ BTR, improving over ATGen-7B by 5.26, 2.75, and 2.97 percentage points, respectively. Similar gains are observed on TestCase-Eval, where PCR ∩ BTR improves from 9.22% to 11.37%. On MBPP+Fix (Hard), SCALF-7B achieves 31.18% PCR ∩ BTR, outperforming the strongest baseline result of 28.82%. These results demonstrate that SCALF consistently improves both prediction correctness and bug triggering, leading to higher PCR ∩ BTR across all three benchmarks.
(2) SCALF provides consistent gains across backbone scales while maintaining strong parameter efficiency. Compared with the same-scale ATGen baselines, SCALF improves PCR ∩ BTR at both 3B and 7B scales across all three benchmarks. For example, on CodeContests+, SCALF improves PCR ∩ BTR from 20.37% to 24.71% at 3B and from 25.86% to 28.83% at 7B. Notably, despite using roughly 10× fewer parameters, SCALF-3B surpasses Qwen3-32B in both PCR and BTR on all three benchmarks, and also achieves higher PCR ∩ BTR on CodeContests+ and TestCase-Eval. This demonstrates that the improvements of SCALF are consistent across model scales rather than being driven solely by a larger backbone.
7.2 Ablation Studies
To better understand the contribution of each component in SCALF, we conduct ablation studies on step-level GRPO and failure-routed OPSD. Starting from standard GRPO, we separately introduce step-level GRPO and failure-routed OPSD, and further combine them to form the full SCALF. We perform the same comparison on both 3B and 7B backbones. Table 2 reports the results, leading to the following observations.
Step-level GRPO improves optimization effectiveness through more precise credit assign-
| Variant | CodeContests+ | TestCase-Eval | MBPP+Fix (Hard) | ||||||
|---|---|---|---|---|---|---|---|---|---|
| PCR | BTR | PCR ∩ BTR | PCR | BTR | PCR ∩ BTR | PCR | BTR | PCR ∩ BTR | |
| QWC-3B | |||||||||
| Standard GRPO | 67.51% | 35.01% | 20.14% | 61.06% | 20.02% | 8.74% | 67.06% | 29.41% | 22.35% |
| + Step-GRPO | 69.34% | 35.24% | 22.20% | 61.54% | 21.19% | 9.82% | 69.41% | 32.35% | 24.12% |
| + Routed OPSD | 70.25% | 36.84% | 23.11% | 61.72% | 20.98% | 10.48% | 72.94% | 35.29% | 26.47% |
| SCALF | 73.91% | 37.76% | 24.71% | 62.68% | 23.89% | 11.10% | 74.12% | 36.47% | 27.06% |
| QWC-7B | |||||||||
| Standard GRPO | 81.69% | 37.30% | 25.17% | 62.32% | 22.18% | 8.98% | 71.18% | 37.65% | 27.06% |
| + Step-GRPO | 84.21% | 38.67% | 27.69% | 65.25% | 23.17% | 9.67% | 75.88% | 39.41% | 28.24% |
| + Routed OPSD | 86.73% | 40.27% | 28.38% | 64.20% | 24.12% | 10.84% | 77.06% | 40.00% | 30.59% |
| SCALF | 87.41% | 41.19% | 28.83% | 67.08% | 24.48% | 11.37% | 78.82% | 40.59% | 31.18% |
Table 2: Ablation results of SCALF under different training variants.
ment across reasoning stages. Introducing step-specific credit assignment improves PCR ∩ BTR across both model scales and all three benchmarks. For example, on CodeContests+, Step-level GRPO improves PCR ∩ BTR from 20.14% to 22.20% for the 3B model and from 25.17% to 27.69% for the 7B model. Similar gains are observed on MBPP+Fix (Hard), where the 7B model improves from 27.06% to 28.24%. These results show that assigning advantages at the reasoning-step level provides more effective supervision than applying a single trajectory-level signal.
Failure-routed OPSD effectively exploits valuable partial successes and complements step-level GRPO. Adding failure-routed OPSD to standard GRPO consistently improves PCR ∩ BTR across all benchmarks, reaching 23.11%, 10.48%, and 26.47% for the 3B model on CodeContests+, TestCase-Eval, and MBPP+Fix (Hard), respectively. The same trend holds for the 7B model, where PCR ∩ BTR increases from 25.17% to 28.38% on CodeContests+ and from 27.06% to 30.59% on MBPP+Fix (Hard). Combining failure-routed OPSD with step-level GRPO yields the strongest results, with full SCALF achieving the highest PCR ∩ BTR across both model scales and all three benchmarks. This demonstrates that step-level credit assignment and targeted learning from routed trajectories provide complementary benefits.
7.3 Does Step-Level Credit Assignment Matter?
To distinguish the effect of process supervision from that of step-level credit assignment, we compare Step-GRPO with GRPO and several PRM aggregation baselines on CodeContests+. These base- lines aggregate the same step-wise PRM scores using Last, Mean, Product, or Min, and add the aggregated process reward to the outcome reward. Group normalization then yields a single trajectory-level advantage, which is applied to all tokens in the entire trajectory. In contrast, Step-GRPO computes a separate advantage for each reasoning step and applies it only to the corresponding tokens.
| Method | PCR | BTR | PCR ∩ BTR |
|---|---|---|---|
| GRPO | 81.69% | 37.30% | 25.17% |
| PRM Aggregation (Last) | 80.09% | 35.01% | 23.80% |
| PRM Aggregation (Mean) | 82.38% | 36.84% | 24.71% |
| PRM Aggregation (Product) | 83.52% | 37.53% | 25.86% |
| PRM Aggregation (Min) | 85.81% | 38.22% | 26.77% |
| Step-GRPO | 84.21% | 38.67% | 27.69% |
Table 3: Comparison of step-level credit assignment and trajectory-level PRM aggregation on CodeContests+ with QWC-7B.
Preserving step-specific feedback helps reduce cross-stage credit interference. As shown in Table 3, Last and Mean aggregation yield lower joint success rates than GRPO, while Product and Min improve performance. All four variants assign the same advantage to every reasoning step within a trajectory, so differences in step quality are not directly reflected in their respective updates. Step-GRPO retains this distinction and achieves the highest BTR and PCR ∩ BTR, increasing joint success from 25.17% to 27.69%. Although Min aggregation achieves the highest PCR, its lower joint success rate (26.77% vs. 27.69%) shows that better output correctness does not necessarily translate into more successful bug-exposing tests. Together, these results suggest that step-specific credit assignment helps reduce interference from shared
(a) Outcome Distribution

(b) Outcome Transition
Figure 3: Outcome analysis of failure-routed OPSD on CodeContests+ with QWC-7B. (a) Outcome distributions. (b) Row-normalized transitions (%) from GRPO to GRPO with routed OPSD.
trajectory-level updates, better supporting the combined objective of bug triggering and output correctness.
7.4 Where Do the Gains of Failure-Routed OPSD Come From?
To investigate the effect of failure-routed OPSD, we categorize test outcomes by bug triggering (BT) and prediction correctness (PC), with 1 indicating success and 0 failure. The four categories are denoted as 00, 01, 10, and 11, with BT first and PC second. Figure 3(a) compares their distributions under GRPO and GRPO with failure-routed OPSD. Figure 3(b) tracks category changes for the same evaluation cases, with rows indicating their outcomes under GRPO and columns indicating their outcomes under GRPO with failure-routed OPSD. Each cell reports the percentage of cases in a given GRPO category that fall into the corresponding category after adding failure-routed OPSD.
Failure-routed OPSD helps recover output-prediction failures while largely retaining bug-triggering success. As shown in Figure 3(a), adding failure-routed OPSD increases the proportion of fully successful BT1PC1 cases from 25.17% to 28.38%, while reducing BT0PC0 from 6.18% to 1.37%. Figure 3(b) further shows that 30.2% of cases categorized as BT1PC0 under GRPO become fully successful with failure-routed OPSD, whereas only 13.2% move to non-triggering categories. The transition to full success is more frequent among BT1PC0 cases than among BT0PC1 cases (30.2% vs. 6.9%). This pattern is consistent with the intended mechanism: learning from verified bug-triggering inputs helps improve output prediction while largely retaining bug-triggering success.
Effect of Generated Tests on Program Repair

Figure 4: Program repair performance with different numbers of generated tests. We fix the maximum number of repair attempts to and vary the number of sampled generated tests, denoted by .
7.5 Can SCALF Improve Downstream Program Repair?
To investigate the practical applicability of SCALF, we evaluate whether its generated tests can serve as effective feedback for downstream program repair. We conduct this application experiment on the CodeContests+ evaluation set, where each instance consists of a problem description and an incorrect solution.
For each instance, each test generator samples test cases. Each test is supplied separately to Qwen3-4B, which generates up to candidate patches using that test as feedback. An instance is considered successfully repaired if any of the up to candidate patches passes all official test cases. We report the results with here, and provide the results for and in Appendix E.
Figure 4 shows that SCALF-7B consistently outperforms all baselines across different values of . At a small feedback budget of , SCALF-7B already achieves a repair success rate of 38.44%, outperforming the strongest baseline ATGen-7B. As increases, the success rate of SCALF-7B further improves, reaching 44.16% at . This trend suggests that SCALF-7B improves program repair by increasing the chance that the repair model observes bug-revealing evidence.
8 Conclusion
In this paper, we propose SCALF, a process-supervised RL approach for bug-exposing test generation. SCALF combines step-level GRPO for step-specific credit assignment with failure-routed
OPSD to learn from trajectories that trigger bugs but predict incorrect outputs. Experiments on three benchmarks show consistent improvements over prompting-based and post-training baselines, while downstream program repair experiments demonstrate the practical value of the generated tests. Together, these results show that learning from both intermediate reasoning steps and valuable failed trajectories improves the generation of tests that expose bugs and provide correct expected outputs.
Limitations
Although SCALF improves bug-exposing test generation, it has several limitations. First, to mitigate reward hacking on out-of-distribution trajectories, we apply process rewards only to fully successful trajectories, leaving failed trajectories without direct process supervision. Even within this scope, process rewards distinguish step quality beyond identical outcome rewards, enabling finer-grained credit assignment. Second, SCALF introduces additional training overhead through PRM scoring and self-teacher evaluation for routed trajectories. These computations provide step-level and token-level learning signals but increase training resource requirements compared with outcome-only GRPO.
Ethical Considerations
We discuss potential ethical considerations as follows. (1) Intellectual property and artifact licenses. This work uses publicly available datasets, benchmarks, pretrained models, and software frameworks. CodeContests+ is released under CC BY 4.0 , and Qwen2.5-Coder models are released under Apache 2.0 for most model sizes, while the 3B variant is released under the Qwen Research License . The main software frameworks used in our experiments, including veRL, OpenRLHF, and vLLM, are released under Apache 2.0. For MBPP+Fix (Hard), we follow the UTGenDebug release, whose evaluation code is distributed under the MIT license . All artifacts are used for research purposes consistent with their released licenses, terms of use, and intended use when specified. Our released code and constructed datasets are provided for research use, with redistribution limited to materials permitted by the licenses and terms of the original artifacts. (2) Privacy and sensitive content. Our data primarily consists of programming problem statements, code submissions, and generated test cases, and does not require personal identifiers, demographic attributes, or user profiles. We exclude directly identifying metadata from released artifacts and do not intentionally collect or introduce sensitive personal information. (3) Potential risks. Our work targets controlled programming benchmarks for bug-exposing test generation and test-feedback-driven program repair. Generated tests with incorrect expected outputs may provide misleading feedback to downstream repair systems. Therefore, practical deployment, particularly in safety-critical software settings, should combine generated tests with execution-based validation, additional verification, or human review.
References
01.AI. 2024. Yi: Open foundation models by 01.AI. arXiv preprint arXiv:2403.04652.
Azat Abdullin, Pouria Derakhshanfar, and Annibale Panichella. 2025. Test wars: A comparative study of SBST, symbolic execution, and LLM-based approaches to unit test generation. In 2025 IEEE Conference on Software Testing, Verification and Validation (ICST), pages 221–232.
Adam Bodicoat, Gunel Jahangirova, and Valerio Terragni. 2025. Understanding LLM-driven test oracle generation. In 2025 2nd IEEE/ACM International Conference on AI-powered Software (AIware), pages 29–39. IEEE.
Islem Bouzenia, Premkumar Devanbu, and Michael Pradel. 2025. RepairAgent: An autonomous, LLM-based agent for program repair. In Proceedings of the IEEE/ACM 47th International Conference on Software Engineering, ICSE '25, pages 2188–2200. IEEE Press.
Frank Busse, Pritam Gharat, Cristian Cadar, and Alastair F. Donaldson. 2022. Combining static analysis error traces with dynamic symbolic execution (experience paper). In Proceedings of the 31st ACM SIGSOFT International Symposium on Software Testing and Analysis, ISSTA 2022, pages 568–579, New York, NY, USA. Association for Computing Machinery.
https://creativecommons.org/licenses/by/4.0/
https://www.apache.org/licenses/LICENSE-2.0
https://huggingface.co/Qwen/Qwen2.
5-Coder-3B-Instruct/blob/main/LICENSE
https://github.com/archiki/UTGenDebug/blob/main/LICENSE
Bei Chu, Yang Feng, Kui Liu, Zhaoqiang Guo, Yichi Zhang, Hange Shi, Zifan Nan, and Baowen Xu. 2025. Large language models for unit test generation: Achievements, challenges, and opportunities. arXiv preprint arXiv:2511.21382.
DeepSeek-AI. 2025. DeepSeek-V3.2: Pushing the frontier of open large language models. CoRR, abs/2512.02556.
Elizabeth Dinella, Gabriel Ryan, Todd Mytkowicz, and Shuvendu K. Lahiri. 2022. TOGA: a neural method for test oracle generation. In Proceedings of the 44th International Conference on Software Engineering, ICSE '22, pages 2130–2141, New York, NY, USA. Association for Computing Machinery.
Lishui Fan, Yu Zhang, Mouxiang Chen, and Zhongxin Liu. 2026. ReCode: Reinforcing code generation with reasoning-process rewards. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 43896–43914. Association for Computational Linguistics.
Martin Gruber, Muhammad Firhard Roslan, Owain Parry, Fabian Scharnböck, Phil McMinn, and Gordon Fraser. 2024. Do automatic test generation tools generate flaky tests? In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, ICSE '24, pages 1–12, New York, NY, USA. Association for Computing Machinery.
Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Yu Wu, Y. K. Li, Fuli Luo, Yingfei Xiong, and Wenfeng Liang. 2024. DeepSeek-Coder: When the large language model meets programming – the rise of code intelligence. arXiv preprint arXiv:2401.14196.
Adrian Herrera, Hendra Gunadi, Shane Magrath, Michael Norrish, Mathias Payer, and Antony L. Hosking. 2021. Seed selection for successful fuzzing. In Proceedings of the 30th ACM SIGSOFT International Symposium on Software Testing and Analysis, ISSTA 2021, pages 230–243, New York, NY, USA. Association for Computing Machinery.
Soneya Binta Hossain and Matthew B. Dwyer. 2025. TOGLL: Correct and strong test oracle generation with LLMs. In Proceedings of the IEEE/ACM 47th International Conference on Software Engineering, ICSE '25, pages 1475–1487. IEEE Press.
Soneya Binta Hossain, Antonio Filieri, Matthew B. Dwyer, Sebastian Elbaum, and Willem Visser. 2023. Neural-based test oracle generation: A large-scale evaluation and lessons learned. In Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering, pages 120–132. Association for Computing Machinery.
Jian Hu, Xibin Wu, Wei Shen, Jason Klein Liu, Weixun Wang, Songlin Jiang, Haoran Wang, Hao Chen, Bin Chen, Wenkai Fang, Xianyu, Yu Cao, Haotian Xu, and Yiming Liu. 2025. OpenRLHF: A ray-based easy-to-use, scalable and high-performance RLHF framework. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, pages 656–666,
Suzhou, China. Association for Computational Linguistics.
Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Kai Dang, An Yang, Rui Men, Fei Huang, Xingzhang Ren, Xuancheng Ren, Jingren Zhou, and Junyang Lin. 2024. Qwen2.5-Coder technical report. CoRR, abs/2409.12186.
Caroline Lemieux, Jeevana Priya Inala, Shuvendu K. Lahiri, and Siddhartha Sen. 2023. CodaMosa: Escaping coverage plateaus in test generation with pretrained large language models. In 45th IEEE/ACM International Conference on Software Engineering, ICSE 2023, Melbourne, Australia, May 14-20, 2023, pages 919–931. IEEE.
Qingyao Li, Xinyi Dai, Xiangyang Li, Weinan Zhang, Yasheng Wang, Ruiming Tang, and Yong Yu. 2025. CodePRM: Execution feedback-enhanced process reward model for code generation. In Findings of the Association for Computational Linguistics: ACL 2025, pages 8169–8182, Vienna, Austria. Association for Computational Linguistics.
Qingyao Li, Xinyi Dai, Weiwen Liu, Xiangyang Li, Yasheng Wang, Ruiming Tang, Yong Yu, and Weinan Zhang. 2026. ATGen: Adversarial reinforcement learning for test case generation. In The Fourteenth International Conference on Learning Representations.
Hunter Lightman, Vineet Kosaraju, Yuri Burda, Harrison Edwards, Bowen Baker, Teddy Lee, Jan Leike, John Schulman, Ilya Sutskever, and Karl Cobbe. 2024. Let's verify step by step. In The Twelfth International Conference on Learning Representations.
Kaibo Liu, Zhenpeng Chen, Yiyang Liu, Jie M. Zhang, Mark Harman, Yudong Han, Yun Ma, Yihong Dong, Ge Li, and Gang Huang. 2025. LLM-powered test case generation for detecting bugs in plausible programs. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 430–440, Vienna, Austria. Association for Computational Linguistics.
Ziyang Luo, Can Xu, Pu Zhao, Qingfeng Sun, Xiubo Geng, Wenxiang Hu, Chongyang Tao, Jing Ma, Qingwei Lin, and Daxin Jiang. 2024. WizardCoder: Empowering code large language models with Evol-Instruct. In The Twelfth International Conference on Learning Representations.
Davide Molinelli, Luca Di Grazia, Alberto Martin-Lopez, Michael D. Ernst, and Mauro Pezzè. 2025. Do LLMs generate useful test oracles? an empirical study with an unbiased dataset. In 2025 40th IEEE/ACM International Conference on Automated Software Engineering (ASE), pages 278–290.
Zifan Nan, Zhaoqiang Guo, Kui Liu, and Xin Xia. 2025. Test intention guided LLM-based unit test generation. In 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE), pages 1026–1038.
Rangeet Pan, Myeongsoo Kim, Rahul Krishna, Raju Pavuluri, and Saurabh Sinha. 2025. ASTER: Natural and multi-language unit test generation with LLMs. In 2025 IEEE/ACM 47th International Conference on Software Engineering: Software Engineering in Practice (ICSE-SEIP), pages 413–424.
Archiki Prasad, Elias Stengel-Eskin, Justin Chen, Zaid Khan, and Mohit Bansal. 2025. Learning to generate unit tests for automated debugging. In Second Conference on Language Modeling.
Qwen Team. 2025. Qwen3 technical report. CoRR, abs/2505.09388.
Baptiste Rozière, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Tal Remez, Jérémy Rapin, Artyom Kozhevnikov, Ivan Evtimov, Joanna Bitton, Manish Bhatt, Cristian Canton-Ferrer, Aaron Grattafiori, Wenhan Xiong, Alexandre Défossez, Jade Copet, and 6 others. 2023. Code Llama: Open foundation models for code. CoRR, abs/2308.12950.
Gabriel Ryan, Siddhartha Jain, Mingyue Shang, Shiqi Wang, Xiaofei Ma, Murali Krishna Ramanathan, and Baishakhi Ray. 2024. Code-aware prompting: A study of coverage-guided test generation in regression setting using LLM. Proc. ACM Softw. Eng., 1(FSE):951–971.
Max Schäfer, Sarah Nadi, Aryaz Eghbali, and Frank Tip. 2024. An empirical evaluation of using large language models for automated unit test generation. IEEE Transactions on Software Engineering, 50(1):85–105.
Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, Y. K. Li, Y. Wu, and Daya Guo. 2024. DeepSeekMath: Pushing the limits of mathematical reasoning in open language models. arXiv preprint arXiv:2402.03300.
Guangming Sheng, Chi Zhang, Zilingfeng Ye, Xibin Wu, Wang Zhang, Ru Zhang, Yanghua Peng, Haibin Lin, and Chuan Wu. 2025. HybridFlow: A flexible and efficient RLHF framework. In Proceedings of the Twentieth European Conference on Computer Systems, EuroSys '25, pages 1279–1297, New York, NY, USA. Association for Computing Machinery.
Ruike Song, Zeen Song, Huijie Guo, and Wenwen Qiang. 2026. Causal reward adjustment: Mitigating reward hacking in external reasoning via backdoor correction. In Fortieth AAAI Conference on Artificial Intelligence, Thirty-Eighth Conference on Innovative Applications of Artificial Intelligence, Sixteenth Symposium on Educational Advances in Artificial Intelligence, AAAI 2026, Singapore, January 20-27, 2026, pages 33019–33027. AAAI Press.
Peiyi Wang, Lei Li, Zhihong Shao, Runxin Xu, Damai Dai, Yifei Li, Deli Chen, Yu Wu, and Zhifang Sui. 2024. Math-Shepherd: Verify and reinforce LLMs
step-by-step without human annotations. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 9426–9439, Bangkok, Thailand. Association for Computational Linguistics.
Zihan Wang, Siyao Liu, Yang Sun, Ming Ding, and Hongyan Li. 2025. CodeContests+: High-quality test case generation for competitive programming. In Findings of the Association for Computational Linguistics: EMNLP 2025, pages 5576–5600, Suzhou, China. Association for Computational Linguistics.
Ratnadira Widyasari, Sheng Qin Sim, Camellia Lok, Haodi Qi, Jack Phan, Qijin Tay, Constance Tan, Fiona Wee, Jodie Ethelda Tan, Yuheng Yieh, Brian Goh, Ferdian Thung, Hong Jin Kang, Thong Hoang, David Lo, and Eng Lieh Ouh. 2020. BugsInPy: A database of existing bugs in Python programs to enable controlled testing and debugging studies. In Proceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, pages 1556–1560.
Linhao Wu, Yifei Pei, Zhen Yang, Kainan Li, Zhonghang Lu, Hao Tan, Xiran Lyu, Jia Li, Yizhou Chen, Pengyu Xue, Kunwu Zheng, and Dan Hao. 2026. DebugRepair: Enhancing LLM-based automated program repair via self-directed debugging. CoRR, abs/2604.19305.
Huimin Xu, Xin Mao, Feng-Lin Li, Xiaobao Wu, Wang Chen, Wei Zhang, and Anh Tuan Luu. 2025. SCOPE: Compress mathematical reasoning steps for efficient automated process annotation. In Findings of the Association for Computational Linguistics: ACL 2025, pages 24382–24394, Vienna, Austria. Association for Computational Linguistics.
Zheyuan Yang, Zexi Kuang, Xue Xia, and Yilun Zhao. 2025. Can LLMs generate high-quality test cases for algorithm problems? TestCase-eval: A systematic evaluation of fault coverage and exposure. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers), pages 1050–1063, Vienna, Austria. Association for Computational Linguistics.
Yufan Ye, Ting Zhang, Wenbin Jiang, and Hua Huang. 2025. Process-supervised reinforcement learning for code generation. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, pages 14213–14226, Suzhou, China. Association for Computational Linguistics.
Yuyu Zhang, Jing Su, Yifan Sun, Chenguang Xi, Xia Xiao, Shen Zheng, Anxiang Zhang, Kaibo Liu, Daoguang Zan, Tao Sun, Jinhua Zhu, Shulin Xin, Dong Huang, Yetao Bai, Lixin Dong, Chao Li, Jianchong Chen, Hanzhi Zhou, Yifan Huang, and 7 others. 2025a. Seed-Coder: Let the code model curate data for itself. CoRR, abs/2506.03524.
Zhenru Zhang, Chujie Zheng, Yangzhen Wu, Beichen Zhang, Runji Lin, Bowen Yu, Dayiheng Liu, Jingren Zhou, and Junyang Lin. 2025b. The lessons of developing process reward models in mathematical reasoning. In Findings of the Association for Computational Linguistics: ACL 2025, pages 10495–10516, Vienna, Austria. Association for Computational Linguistics.
Jian Zhao, Runze Liu, Kaiyan Zhang, Zhimu Zhou, Junqi Gao, Dong Li, Jiafei Lyu, Zhouyi Qian, Biqing Qi, Xiu Li, and Bowen Zhou. 2026a. GenPRM: Scaling test-time compute of process reward models via generative reasoning. Proceedings of the AAAI Conference on Artificial Intelligence, 40(41):34932–34940.
Siyan Zhao, Zhihui Xie, Mengchen Liu, Jing Huang, Guan Pang, Feiyu Chen, and Aditya Grover. 2026b. Self-distilled reasoner: On-policy self-distillation for large language models. In Proceedings of the 43rd International Conference on Machine Learning, volume 306 of Proceedings of Machine Learning Research, pages 162433–162448. PMLR.
Yuze Zhao, Zhenya Huang, Yixiao Ma, Rui Li, Kai Zhang, Hao Jiang, Qi Liu, Linbo Zhu, and Yu Su. 2024. RePair: Automated program repair with process-based feedback. In Findings of the Association for Computational Linguistics: ACL 2024, pages 16415–16429, Bangkok, Thailand. Association for Computational Linguistics.
Jiachen Zhu, Congmin Zheng, Jianghao Lin, Kounianhua Du, Ying Wen, Yong Yu, Jun Wang, and Weinan Zhang. 2025. Retrieval-augmented process reward model for generalizable mathematical reasoning. In Findings of the Association for Computational Linguistics: ACL 2025, pages 8453–8468, Vienna, Austria. Association for Computational Linguistics.
A Process Reward Model Details
A.1 PRM Data Quality Analysis
We further analyze the quality of the automatically constructed step-level labels used for PRM training. As described in Section 4, each candidate step is first assigned an MC-derived label based on sampled continuations, and is then verified by an LLM-based judge. We retain a trajectory only if the MC-derived labels and LLM judgments agree at every reasoning step, and discard the entire trajectory otherwise. The retained step-level labels are thus supported by both execution-based evidence and semantic inspection.
| Source | #Traj. | #Steps | #Pos. | #Neg. | Pos. % |
|---|---|---|---|---|---|
| MC labels | 55.2K | 165.7K | 92.6K | 73.1K | 55.9 |
| LLM judgments | 55.2K | 165.7K | 87.9K | 77.8K | 53.0 |
| Consensus | 23.1K | 69.4K | 37.4K | 32.0K | 53.9 |
Table 4: Statistics of step-level labels used for PRM data construction. #Traj. denotes the number of response trajectories, and #Steps denotes the number of step-level labels. #Pos. and #Neg. denote the numbers of positive and negative step labels, respectively, while Pos. % denotes the positive-label ratio. The consensus set contains all step-level labels from trajectories retained by this agreement criterion.
Table 4 reports the statistics of step-level labels used for PRM data construction. Starting from 165.7K step labels annotated by both MC estimation and LLM judgment, we obtain 69.4K consensus labels from 23.1K response trajectories. By requiring agreement between the two sources, the filtering step removes labels that are likely to be affected by either rollout noise in MC estimation or subjective errors in LLM-based judgment. The retained data contains 53.9% positive steps and 46.1% negative steps, suggesting that the filtering process improves label reliability without collapsing the supervision into a single dominant label.
A.2 Process Reward Model Training
Bug-exposing test generation requires rigorous multi-step reasoning over program semantics, input design, and expected outputs. To effectively supervise this intermediate process, a Process Reward Model is essential. However, existing PRMs are mostly trained on math or general reasoning (Lightman et al., 2024; Wang et al., 2024; Zhu et al., 2025). To provide task-specific process supervision, we train a PRM on the step-level data from Section 4.
| Model | Accuracy | Precision | Recall | F1 |
|---|---|---|---|---|
| PRM | 77.11% | 80.80% | 78.60% | 79.68% |
Table 5: PRM evaluation results on the independent human-verified step-level evaluation set.
Concretely, we instantiate this as a binary step verification problem. Let denote the collection of all retained step instances. Each retained step instance is denoted as , where is the filtered step-level label. Let denote the PRM input, where . We train the PRM to predict a designated reward token at the end of the sequence. The training loss is defined as:
After training, the predicted probability is used as the process score of the current step.
A.3 PRM Quality Verification
To further assess the reliability of the trained PRM, we construct an independent human-verified evaluation set that is completely excluded from PRM training. The evaluation set contains 150 examples. We manually inspect all step-level annotations and correct inconsistent labels according to the corresponding reasoning context. Among the 450 labels, 404 are consistent with human judgments, while 46 are corrected, corresponding to a disagreement rate of .
We then evaluate the trained PRM on this human-corrected evaluation set. For each step, the PRM predicts the probabilities of the positive and negative reward tokens, and the label with the higher probability is used as the binary prediction. Table 5 reports the results.
The PRM achieves 77.11% accuracy, 80.80% precision, 78.60% recall, and 79.68% F1. These results indicate that the trained PRM maintains reasonable agreement with human judgments on unseen step-level reasoning instances.
A.4 Effect of the MC Labeling Threshold
The relative-progress threshold controls how strictly a step is labeled as positive during MC-based step labeling. A smaller admits steps with lower relative MC scores, which may introduce noisy positive labels, while a larger imposes a stricter criterion and may exclude useful intermediate steps.
We use PRM-guided beam search as a proxy evaluation of how the labeling threshold affects the PRM's utility in test generation, without repeatedly training the full test generator. Specifically, we evaluate PRMs trained under different values on CodeContests+ using Qwen2.5-Coder-7B-Instruct without task-specific post-training as the generator. During search, the generator expands each retained reasoning path with four candidate continuations. The PRM scores all expanded paths, and we retain the three highest-scoring paths for the next search step. After the final search step, we select the highest-scoring trajectory to produce a single test case for evaluation. For the first reasoning step or a step whose preceding prefix has an MC score of zero, we use an absolute threshold of 0.5: the step is labeled positive if its current MC score is at least 0.5, and negative otherwise. The relative-progress threshold applies to all remaining steps.
We report the joint success rate (PCR BTR), which measures the percentage of evaluated instances for which the generated test both triggers the bug and provides the correct expected output. Table 6 shows that the joint success rate increases from to as rises from 0.1 to 0.9, before decreasing to at . Under the MC estimator, accepts steps whose MC scores are at least as high as those of their preceding prefixes, whereas accepts only steps with higher MC scores. The decrease at is consistent with a stricter criterion excluding useful intermediate steps that preserve the estimated success probability. Based on this proxy evaluation, we select for our main experiments.
| ε | 0.1 | 0.5 | 0.7 | 0.8 | 0.9 | 1.1 |
|---|---|---|---|---|---|---|
| PCR ∩ BTR (%) | 11.44 | 13.27 | 13.73 | 14.65 | 15.10 | 13.96 |
Table 6: Effect of the MC labeling threshold on joint success rate using PRM-guided beam search on CodeContests+. The generator is Qwen2.5-Coder-7B-Instruct without task-specific post-training.
B Process Reward Activation Timing
In Section 5.1, we activate the PRM-based process reward only when the generated output is correct and the generated test case exposes the bug. This section further analyzes this design choice by comparing different activation conditions for the process reward.
| Activation Strategy | PCR | PCR ∩ BTR |
|---|---|---|
| Ungated PRM | 78.26% | 23.34% |
| Subgoal-gated PRM | 80.32% | 24.03% |
| Full-success gated PRM | 84.21% | 27.69% |
Table 7: Effect of different activation conditions for the PRM-based process reward on CodeContests+. All variants use the same backbone, training data, PRM, and RL algorithm, and differ only in when is activated.
We conduct this analysis on the Qwen2.5-Coder-7B-Instruct backbone, using the same training data, PRM, and step-level GRPO configuration as the Step-GRPO baseline in our main experiments. The comparison includes three variants: Ungated PRM, which applies the PRM-based process reward to all generated samples; Subgoal-gated PRM, which activates the process reward when either prediction correctness or bug triggering is satisfied; and Full-success gated PRM, which activates the process reward only when both objectives are satisfied and is the design adopted in SCALF.
Table 7 shows that applying the PRM-based process reward more broadly does not necessarily improve final task performance. The ungated variant obtains the lowest joint success rate of . Activating the PRM when either sub-objective is satisfied increases the joint success rate by 0.69 percentage points to . The full-success gated strategy achieves the best performance on both metrics, with a PCR of and a joint success rate of . Its joint success rate exceeds those of the ungated and subgoal-gated variants by 4.35 and 3.66 percentage points, respectively.
These results suggest that the PRM should not be used as an unconditional reward. When PRM scores are assigned to failed or partially successful trajectories, the policy may optimize toward patterns favored by the PRM rather than toward the final task objective. This can make the training process vulnerable to reward hacking, especially because the PRM is trained to evaluate meaningful intermediate reasoning steps but may behave unpredictably on out-of-distribution responses.
Figure 5 illustrates this failure mode. The response preserves the required section headers, but the intermediate reasoning is either empty or semantically uninformative. Such responses are outside the intended input distribution of the PRM,
Reward-hacking example from Ungated PRM
Bug Analysis
Logical flaw.
Test Design
Output Prediction
Input
0
...
Expected Output
a
...
Figure 5: A reward-hacking example produced by the ungated PRM variant. The model keeps the required response structure but provides almost no meaningful reasoning process.
which is designed to judge meaningful reasoning steps rather than empty process templates. When the PRM is applied to all samples, the policy can exploit this weakness by producing degenerate reasoning formats that may receive favorable process scores without actually supporting the generated test case.
Therefore, SCALF adopts the full-success gated strategy. By activating process rewards only when both prediction correctness and bug triggering are satisfied, this strategy anchors PRM-based optimization to execution-verified task success and reduces incentives to exploit process scores on failed trajectories. The PRM remains useful after gating because successful trajectories can still differ in how they arrive at a valid test: some rely on accurate bug analysis and targeted test design, while others succeed despite flawed or redundant reasoning. Process rewards distinguish these reasoning processes and encourage the policy to reinforce higher-quality steps within successful trajectories (Fan et al., 2026). Thus, full-success gating provides informative process supervision while mitigating reward hacking.
C Training Curve Analysis
To further understand how failure-routed OPSD affects the optimization process, we compare the training dynamics of standard GRPO and GRPO with routed OPSD. Figure 6 reports three complementary statistics throughout training: the mean training score, the fraction of trajectories routed to OPSD, and the KL loss. Together, these curves characterize both the optimization progress of the policy and the behavior of the selective routing mechanism.
Selective routing is sufficient to produce stronger policy improvement. As shown in Figure 6(a), GRPO with routed OPSD achieves a higher mean score than standard GRPO after the early training stage and converges to a better final level. Figure 6(b) shows that only about 8–12% of trajectories are routed to OPSD, indicating that selectively recovering a small subset of partial-success trajectories is sufficient to provide useful additional supervision. The routing rate further decreases in later training, suggesting that fewer trajectories require targeted recovery as the policy improves.
Failure-routed OPSD induces larger but meaningful policy updates. Figure 6(c) shows that routed OPSD produces a consistently larger KL divergence than standard GRPO, indicating a stronger policy shift. Importantly, this larger deviation is accompanied by the higher mean score in Figure 6(a), suggesting that the additional movement reflects task-relevant improvement rather than unstable drift. Meanwhile, the KL curve gradually stabilizes, indicating that these stronger updates eventually reach a stable regime.
D Additional Generalization Results
We further evaluate the generalization of SCALF from two perspectives: generalization to a different model family and generalization to real-world software bugs. These experiments examine whether the effectiveness of SCALF depends on the Qwen2.5-Coder backbone or on the competitive-programming-style data used for training.
D.1 Generalization to Another Model Family
Our main experiments use Qwen2.5-Coder as the generator backbone. To examine whether SCALF transfers to a different model family, we additionally conduct experiments with DeepSeek-Coder-6.7B-Instruct (abbreviated as DSC-6.7B) (Guo et al., 2024). We keep the training data, reward definitions, routing criterion, and evaluation protocol unchanged, and replace only the generator backbone. The task-specific PRM is kept fixed so that the experiment isolates the effect of changing

Figure 6: Training dynamics of standard GRPO and GRPO with failure-routed OPSD. (a) Mean score during training. (b) Fraction of trajectories routed to OPSD. (c) KL loss during training.
| Method | PCR | BTR | PCR ∩ BTR |
|---|---|---|---|
| DSC-6.7B | 27.69% | 16.93% | 8.01% |
| GRPO | 59.27% | 27.92% | 18.76% |
| SCALF | 64.07% | 29.52% | 20.37% |
Table 8: Cross-family generalization results on Code-Contests+ using DSC-6.7B as the generator backbone.
the policy model family.
Table 8 reports the results on CodeContests+. Compared with standard GRPO, SCALF improves PCR from to , BTR from to , and PCR BTR from to , corresponding to gains of 4.80, 1.60, and 1.61 percentage points, respectively. These results show that the improvements brought by step-level credit assignment and failure-routed OPSD are not specific to the Qwen2.5-Coder generator backbone.
D.2 Generalization to Real-World Software Bugs
The benchmarks used in our main experiments mainly consist of programming problems paired with incorrect solutions. To further examine whether SCALF transfers to real-world software bugs, we construct an additional evaluation set from BugsInPy (Widyasari et al., 2020), which contains real bugs collected from open-source Python projects. We retain 30 instances whose relevant code context fits within the model context window. For each instance, we provide the buggy code together with the dependency context required to understand and execute the target behavior, thereby avoiding repository-level retrieval as an additional confounding factor. No BugsInPy instances are used during SCALF training.
We use Qwen2.5-Coder-7B-Instruct (abbrevi- ated as QWC-7B) as the generator backbone. Table 9 reports the results. Compared with standard GRPO, SCALF improves PCR from to , BTR from to , and PCR BTR from to , corresponding to gains of 6.67 percentage points on all three metrics. These results indicate that the effectiveness of SCALF extends beyond the training-domain benchmarks to real-world software bugs.
| Method | PCR | BTR | PCR ∩ BTR |
|---|---|---|---|
| QWC-7B | 26.67% | 23.33% | 6.67% |
| Standard GRPO | 60.00% | 33.33% | 20.00% |
| SCALF | 66.67% | 40.00% | 26.67% |
Table 9: Out-of-domain generalization results on the real-world BugsInPy evaluation set.
Overall, these additional experiments provide complementary evidence that SCALF generalizes across both generator model families and task domains, rather than relying on a particular backbone or benchmark distribution.
E More Repair Results
We provide additional program repair results under different numbers of repair attempts. In Section 7.5, we report the main results with . Here, we further evaluate and while varying the number of sampled generated tests .
Figure 7 shows that SCALF-7B remains effective under both smaller and larger numbers of repair attempts. When , SCALF-7B achieves the best repair success rate at three of the four values and reaches at , indicating that its generated tests can provide useful failure evidence even when the repair model has only one


Figure 7: Additional program repair results under different numbers of repair attempts. (a) Results with . (b) Results with .
repair attempt per test. When , all methods benefit from more repair attempts, while SCALF-7B achieves the best result at with 47.37%. These results further support the conclusion that SCALF-7B generates effective test cases for test-feedback-driven program repair across different repair settings.
F Implementation Details
F.1 Training Configuration
Table 10 and Table 11 summarize the key training hyperparameters used in our experiments. UTGen and ATGen share the applicable common training settings with SCALF, while method-specific hyperparameters apply only to the corresponding methods. All experiments are conducted on 8 NVIDIA H100 GPUs. A single model training run takes approximately 26 hours on 8 NVIDIA H100 GPUs, corresponding to approximately 208 GPU-hours per run. For evaluation, all models are decoded with a temperature of 0.8.
| Hyperparameter | Value |
|---|---|
| Training framework | OpenRLHF |
| Training epochs | 1 |
| Learning rate | |
| Global batch size | 32 |
| Micro-batch size | 2 |
| Maximum sequence length | 4096 |
| Precision | bf16 |
| ZeRO stage | 2 |
Table 10: Hyperparameters for PRM training.
| Hyperparameter | Value |
|---|---|
| Training framework | veRL |
| Training epochs | 2 |
| Learning rate | |
| Learning-rate scheduler | Cosine |
| Training batch size | 32 |
| PPO mini-batch size | 32 |
| PPO micro-batch size per device | 1 |
| PPO clipping parameter () | 0.2 |
| Reference KL coefficient () | 0.001 |
| Maximum prompt length | 2048 |
| Maximum response length | 2048 |
| Rollout engine | vLLM |
| Rollouts per prompt | 8 |
| Rollout temperature | 0.7 |
| Rollout top-p | 0.95 |
| Tensor parallel size | 2 |
| Entropy coefficient | 0 |
| OPSD loss weight () | 0.1 |
| OPSD pointwise clipping threshold | 0.05 |
| Random seed | 42 |
Table 11: Hyperparameters for Test Generator training.
F.2 Training Algorithm
Algorithm 1 summarizes the training procedure of SCALF described in Section 5. For each task, the policy samples a group of trajectories and obtains execution feedback for prediction correctness and bug triggering. PRM scores are added to the outcome reward only for trajectories satisfying both objectives. Step-level advantages are then computed across the entire rollout group, including trajectories subsequently routed to self-distillation.
The execution feedback also determines the optimization route. Trajectories that trigger the bug but predict an incorrect output are optimized through OPSD: the current policy uses reference-derived feedback to form a teacher distribution and supervises its unconditioned student distribution on the same sampled prefixes. All remaining trajectories are optimized through Step-GRPO, with each step's advantage applied to its corresponding token span.
The losses from both routes are aggregated to update the policy.
G Prompt Template
In this section, we present the prompts used in training and inference for an LLM to perform various operations.
Figures 8 and 9 present the prompt templates used for test-case generation and program repair, respectively.
The Prompt for Test Case Generation
You are given a programming task description and an incorrect code solution. Your goal is to identify the bug in the code and construct a Hack Test Case that triggers the failure of the solution.
Task Description
{description}
Incorrect Code Solution
{code}
Response Format
Your response MUST exactly follow the format below:
Bug Analysis
Briefly describe the logic or implementation error in the code.
Test Design
Based on the bug analysis, describe the input values chosen to trigger the bug.
Output Prediction
Concisely derive the correct output based on the Task Description logic.
Input
Provide the raw standard input that follows the exact input specification. Do NOT include ANY reasoning, explanations, or markdown formatting.
Expected Output
Provide the correct standard output according to the task description. Do NOT include ANY reasoning, explanations, or markdown formatting.
Figure 8: Prompt template for test-case generation.
The Prompt for Program Repair
You are given a programming task description and an incorrect code solution. Your goal is to repair the incorrect code according to the task specification. A failing test case is provided as evidence: it includes the test input, the correct output, and the output produced by the incorrect code. Use this evidence to identify the bug and then repair the code.
Task Description
{description}
Incorrect Code Solution
{code}
Failing Test Input
{test_input}
Correct Output
{expected_output}
Incorrect Code Output
{buggy_output}
Important Notes
The repaired code must solve the original task generally and preserve the required input/output behavior.
Response Format
Think step by step.
Finally, output only the complete repaired code wrapped in a single code block.
Do not output any explanation outside the code block.
<complete repaired code>Figure 9: Prompt template for program repair.
Algorithm 1 Training Procedure of SCALF
Require: Training tasks ; initial policy
Require: Fixed PRM ; fixed reference policy
Require: Training epochs ; rollout group size ; clipping parameter
Require: OPSD loss weight ; KL coefficient ; stability constant
Ensure: Trained policy
1: for do
2: for each training mini-batch from do
3:
4: for each do
5:
6: Sample
7: for do
8: Extract test and reasoning-step token spans
9: Evaluate format and test execution to obtain , , , and execution feedback
10:
11: if and then
12: Score each reasoning step with the fixed PRM to obtain
13: for all
14: else
15: for all
16: end if
17: end for
18: for do
19:
20:
21: for all
22: end for
23: for do
24:
25: if then
26: Retrieve the reference output
27: Construct privileged information from and execution feedback
28: for all tokens
29: for all tokens
30:
31:
32: else
33: Compute token-wise policy ratios against
34: Apply only to tokens
35: Compute using clipping parameter and KL regularization coefficient , as defined in Section 5.1
36:
37: end if
38: end for
39:
40: end for
41: Update by minimizing with the training optimizer
42: end for
43: end for
44: return