arXiv:2608.24135cs.AIAug 2026

Manuscript Offprint

arXiv:2608.24135

Robust Code RL via Faulty-Code-Driven Test case Synthesis and Dense Reward Shaping

Yiwen Zhang, Xiaodong Yan, Zhenyu Huang, Deng Zhao, Liang Jiang, Qing Cui, Zujie Wen, Zhiqiang Zhang, Jun Zhou

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Reinforcement Learning from Verifiable Rewards (RLVR) is pivotal for enhancing LLM code generation, yet its efficacy is often hindered by insufficient test case coverage, leading to reward hacking and policy degradation. To address this, we propose RobustTests, a framework featuring a faulty-code-driven test case synthesis strategy. By leveraging "near-correct" faulty codes, RobustTests captures latent logical discrepancies and employs validator agents with behavioral feature clustering to filter invalid or redundant test cases. Additionally, a stepwise dense reward function based on pass rates is introduced to mitigate false negatives and enhance training robustness. Using this pipeline, we construct an augmented version of the CodeContests +^{+} dataset with superior diagnostic utility. Experimental results show that RL fine-tuning of Qwen3-32B via RobustTests achieves a 3% absolute gain on LiveCodeBench, demonstrating its effectiveness in advancing LLM code generation proficiency. Codes and data are available at https://huggingface.co/datasets/sid6/RobustTests.

1 Introduction

Reinforcement Learning from Verifiable Rewards (RLVR) has emerged as a pivotal technique for enhancing the code generation capabilities of Large Language Models (LLMs) (El-Kishky et al., 2025; Jiang et al., 2026; Hou et al., 2024). However, its efficacy is fundamentally limited by the comprehensiveness of test cases. Insufficient coverage often causes false positives (Le et al., 2022), where faulty code passes sparse test cases, leading to reward hacking and subsequent policy degradation (Guo et al., 2025). Consequently, synthesizing high-coverage test cases is essential to refine RL feedback and ensure sustained performance gains (Ma et al., 2025; Lin et al., 2025).

Figure

(a) Generate Test-cases Directly

Figure

(b) Generate Test-cases by Generator Program

Figure 1: Illustration of current methods for test cases synthesis by LLM.(a) Generate Test cases Directly, instructing the LLM to directly synthesize a suite of test cases compliant with the problem specifications.(b) Generate Test cases by Generator Program, where LLM is first instructed to generate generator programs designed to automate the synthesis of test case inputs.

Nevertheless, the automated generation of high-quality test cases and their subsequent integration into a performance-boosting RLVR paradigm remain formidable challenges. Firstly, the lack of precise metrics to characterize test case quality obscures which data distributions are truly conducive to the RLVR process (Liu et al., 2023). Secondly, the optimal methodology for integrating even high-quality test cases into RLVR frameworks remains under-explored (Gunjal et al., 2025). Although existing attempts leverage LLMs for direct test case augmentation (e.g., via few-shot prompting

∗^{*}Corresponding authors with problem descriptions) (Zeng et al., 2025; Xu et al., 2025; Li and Yuan, 2024), as shown in Figure 1(a), the resulting outputs often fail to regard boundary condition coverage. Furthermore, test cases synthesized by this approach frequently exhibit hallucination instances that violate the underlying problem constraints. Adopting such erroneous verification signals as reward feedback in reinforcement learning induces significant reward bias, which misguides the optimization trajectory and constrains further enhancement of the model's proficiency. (Kwa et al., 2024).

To enhance synthetic quality, subsequent efforts have transitioned to a generator program paradigm (He et al., 2025), using various logical hypotheses to improve the coverage of test cases, as shown in Figure 1(b). While this approach reduces the hallucination rate, it remains heavily reliant on manual annotation, which restricts its scalability. Building on this, (Wang et al., 2025) introduced verification agents to automatically craft validator programs for constraint verification, further suppressing the hallucination rate. However, the completeness of automated validators is difficult to formally guarantee (Olausson et al., 2023). Their intrinsic residual hallucinations, particularly under binary sparse rewards, frequently induce false negatives (Liu et al., 2023). This results in correct code generating misleading gradient signals due to erroneous labeling (Ouyang et al., 2022). Consequently, within the context of RL reward signaling, simply improving data quality has hit a bottleneck. It is imperative to refine the learning mechanisms or introduce robust reward modeling (Casper et al., 2023) to mitigate the deleterious effects of residual hallucinations and ensure stable model evolution under noisy feedback.

To address these challenges, we propose RobustTests, which at its core incorporates faulty-code-driven test case synthesis and a robust dense reward mechanism. During the synthesis stage, we first utilize LLMs to generate "near-correct" faulty programs refined via original test cases to guide the directed synthesis of test cases capable of triggering specific logical defects. Subsequently, we perform validity verification on these generated test cases to eliminate invalid ones. We further conduct clustering and filtering based on behavior feature vectors (i.e., the pass/fail status encodings of test cases over different faulty code snippets), which ensures that the test case suite can cover diverse error scenarios and alleviate false positives. During the training stage, to address the false negatives caused by unavoidable hallucinatory noise in synthetic test case suit, we introduce a stepwise dense reward function based on pass rates. This improves the robustness of the model to continuously learn from partially correct signals.

Within the RobustTests framework, we augmented the test cases of the CodeContests +^{+} dataset to construct a code high-quality dataset, and evaluated its properties using Test case Space Polarization (TSP) metric. The results demonstrate that RobustTests achieves a 7% improvement in TSP relative to the original CodeContests +^{+}, indicating its enhanced capacity to uncover a broader spectrum of failure modes. In our experiments, using problems of moderate difficulty from CodeContests +^{+} as the training set, RL fine-tuning of Qwen3-32B via RobustTests yields an absolute 3% performance gain on the LiveCodeBench benchmark compared to the baseline methods. These findings not only confirm the effectiveness of the RobustTests framework in bolstering the code generation proficiency of LLMs but also establish a clear correlation between the TSP metric and model performance.

In summary, the main contributions of this study are as follows:

• We propose a novel approach for automated high-quality test case synthesis and RLVR reward modeling, utilizing faulty-code-driven synthesis and a robust dense reward mechanism to expand test case coverage and bolster resilience against synthetic noise during RL.

• We construct a code dataset with more diverse test cases, significantly strengthens diagnostic utility across various faulty code scenarios.

• An abosulte 3-percentage point performance gain on the LiveCodeBench benchmark when training Qwen3-32B compared to baselines, substantially advancing the code generation performance of LLMs.