NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

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 ZhouarXiv 2026

TL;DR

Reinforcement Learning from Verifiable Rewards (RLVR) is a powerful tool for improving LLM code generation, but it suffers from "reward hacking" when test suites are too sparse or noisy. To solve this, the authors introduce RobustTests, a framework that uses "near-correct" faulty code to systematically generate high-coverage test cases, paired with a dense reward function to handle synthetic noise. Applying this method to fine-tune Qwen3-32B yields a 3% absolute performance gain on the LiveCodeBench benchmark.

What Problem Does This Paper Address?

When training Large Language Models (LLMs) to write code, researchers often use Reinforcement Learning from Verifiable Rewards (RLVR). In this setup, the model's generated code is executed against a suite of test cases; if it passes, it gets a reward.

However, this approach hits a major bottleneck: test case quality.

  1. False Positives (Reward Hacking): If the test suite is too simple or sparse, buggy or incomplete code might accidentally pass all tests. The model learns to exploit these gaps rather than writing truly correct code.
  2. False Negatives (Noisy Feedback): If we use an LLM to automatically generate more test cases, the synthetic tests themselves often contain hallucinations or invalid constraints. This causes correct code to be rejected, sending misleading gradient signals to the model during training.

Existing automated test-generation methods either lack boundary-condition coverage or rely heavily on manual annotations. This paper addresses how to automatically synthesize high-coverage, diverse test suites and safely integrate them into RL training without derailing the model with noisy feedback.

Methods

The authors propose RobustTests, a framework consisting of three core components:

Figure 2: Overview of the proposed RobustTests framework. The framework consists of three core components: (i) Automated Test case Generation in 3.1, aims to generate high-quality test cases inputs capable of effectively distinguishing correct code from faulty codes; (ii) Test case Validation and Selection in 3.2, ensures that the generated test cases are semantically sound and capable of diagnosing a broad spectrum of faulty code while simultaneously maximizing set parsimony; and (iii) Dense Reward Function Design in 3.3, accounts for the potential fallibility of the synthesized test case suite.
  1. Faulty-Code-Driven Test Case Generation: Instead of asking an LLM to generate test cases from scratch, the framework first generates a pool of "near-correct" faulty code implementations. It dynamically filters these implementations to ensure they pass some baseline tests but fail on subtle edge cases. The framework then uses these faulty programs as negative examples in a prompt, instructing the LLM to generate new test cases specifically designed to expose those exact logical flaws.
  2. Test Case Validation and Selection: To clean up the generated tests, the framework uses a three-stage pipeline:
  3. Input Validation: An executable validator ensures the test inputs obey the problem's constraints.
  4. Instruction-Compliance Validation: The ground-truth outputs are re-generated using a trusted reference solution.
  5. Diversity-Driven Selection: The framework runs the test cases against the pool of faulty code snippets to create a binary "pass/fail" behavior vector for each test. It then applies K-means clustering to select a small, parsimonious subset of test cases that cover the widest possible variety of failure modes.
  6. Stepwise Dense Reward Function: Because automated validators are imperfect and some noise always slips through, the authors replace standard binary (0 or 1) rewards with a stepwise dense reward function based on the percentage of test cases passed. This allows the model to receive granular, progressive feedback and learn from partially correct solutions.

Datasets

  • CodeContests+: The base dataset used to harvest programming problems. The authors filtered this dataset down to a refined training subset of approximately 3.3k problems of moderate difficulty (where Qwen3-32B achieved a pass@10 score between 0.2 and 0.9).
  • RobustTests Dataset: The newly introduced, augmented version of the dataset. It features roughly 200 highly diverse, filtered test cases per problem to maximize diagnostic utility.
  • Evaluation Benchmarks: The models were evaluated on LiveCodeBench (2024.08–2025.01), a contamination-free benchmark, and CodeForces, a standardized competitive programming platform.

Key Insights and Ideas

  • Negative Examples Drive Edge-Case Discovery: LLMs are notoriously bad at guessing boundary conditions in a vacuum. By showing the model exactly how a piece of code is subtly broken, it becomes much better at generating targeted inputs that expose that specific vulnerability.
  • Quantifying Quality via TSP: The authors introduce Test case Space Polarization (TSP), a metric that measures how effectively a test suite partitions and exposes diverse failure modes across a pool of faulty code. They found that a higher TSP score correlates strongly with better downstream RL performance, serving as a cheap proxy to estimate dataset potential before running expensive training loops.
Figure 4: Relationship between TSP values and Live- CodeBench performance across different test cases.
  • Dense Rewards Mitigate Imperfect Validators: An audit of their pipeline revealed that even after strict filtering, about 10% of accepted synthetic test cases remained invalid. Switching from sparse to dense rewards prevents these false negatives from ruining the optimization trajectory, acting as a buffer against inevitable dataset noise.

Key Results

The authors evaluated their framework by fine-tuning a Qwen3-32B model using Generalized Relative Policy Optimization (GRPO):

  • LiveCodeBench: RobustTests achieved a 68.39% pass rate, marking an absolute 3% gain over the standard CodeContests+ baseline (65.41%) and outperforming other competitive test-augmentation baselines like HardTests and CodeContests-O.
  • CodeForces: The model improved its problem-solving accuracy score from 35.56 to 38.50, boosting its simulated competitive rating to 85.99, which outperforms 94.67% of historical human contestants.
  • Ablation Studies: Removing either the directed test case synthesis or the diversity-driven clustering dropped performance significantly, proving that both targeted generation and behavior-based filtering are necessary for robust RL training.

Limitations and Future Work

  • Dependency on Reference Solutions: The framework relies on having an existing, correct ground-truth solution to filter out bad test cases and generate correct outputs. This limits its immediate applicability to real-world software engineering scenarios where no reference implementation exists.
  • Domain Generalization: While highly effective for competitive programming benchmarks, the framework's generalizability to broader, multi-file software development tasks and different programming languages remains to be fully explored.

Summary updated

BibTeX
@misc{zhang2026robust,
  author = {Yiwen Zhang and Xiaodong Yan and Zhenyu Huang and Deng Zhao and Liang Jiang and Qing Cui and Zujie Wen and Zhiqiang Zhang and Jun Zhou},
  title = {{Robust Code RL via Faulty-Code-Driven Test case Synthesis and Dense Reward Shaping}},
  year = {2026},
  eprint = {2608.24135},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.24135},
}
Figure