Manuscript Offprint

arXiv:2610.27694

Enhancing Bug-Exposing Test Generation via Step-Level Credit Assignment and Self-Distillation from Valuable Failures

Wenjie Gan, Zhaoxi Zhang, Jiahui Liang, Weikang Li, Wanyuan Wang, Li Zhang, Jian Dong

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

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.

References (24)