# Robust Code RL via Faulty-Code-Driven Test case Synthesis and Dense Reward Shaping (RobustTests)

> RobustTests improves LLM code RL by generating test cases from near-correct faulty code and using dense rewards, yielding 3% absolute gains on LiveCodeBench and CodeForces.

- **Source:** [arXiv](https://arxiv.org/abs/2608.24135)
- **Published:** 2026-11-28
- **Permalink:** https://picx.dev/p/2c7UmM
- **Whiteboard:** https://picx.dev/p/2c7UmM/image

## Summary

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

## Summary (Overview)

- **Novel framework**: The paper proposes **RobustTests**, a framework combining faulty-code-driven test case synthesis with a stepwise dense reward mechanism to improve Reinforcement Learning from Verifiable Rewards (RLVR) for LLM code generation.
- **Key innovation**: The framework leverages "near-correct" faulty code implementations to guide the directed synthesis of test cases that can expose latent logical defects, addressing the critical problem of insufficient test case coverage in RLVR.
- **Dense reward design**: A stepwise dense reward function based on pass rates is introduced to mitigate false negatives caused by residual hallucination noise in synthetic test cases, enabling models to learn from partially correct signals.
- **Empirical results**: RL fine-tuning of Qwen3-32B via RobustTests achieves an **absolute 3% performance gain** on LiveCodeBench and CodeForces benchmarks compared to baseline methods.
- **Novel evaluation metric**: The paper introduces **Test case Space Polarization (TSP)** as a low-cost metric to quantify the diagnostic coverage of test case suites, establishing a clear positive correlation between TSP and downstream model performance.

## Introduction and Theoretical Foundation

### Background and Motivation

Reinforcement Learning from Verifiable Rewards (RLVR) has become a pivotal technique for enhancing LLM code generation capabilities (El-Kishky et al., 2025; Jiang et al., 2026; Hou et al., 2024). However, its effectiveness is fundamentally limited by the comprehensiveness of test cases. The paper identifies two critical challenges:

1. **False positives**: Insufficient test case coverage allows faulty code to pass sparse test cases, leading to reward hacking and policy degradation (Guo et al., 2025).
2. **False negatives**: Synthetic test cases with residual hallucinations can incorrectly reject correct code, producing misleading gradient signals (Ouyang et al., 2022).

### Limitations of Existing Approaches

The paper identifies two dominant paradigms for test case synthesis:

**(a) Direct Generation**: LLMs directly generate test cases from problem descriptions (Zeng et al., 2025; Xu et al., 2025; Li and Yuan, 2024). These often fail to cover boundary conditions and frequently exhibit hallucination instances violating problem constraints.

**(b) Generator Program Paradigm**: LLMs generate generator programs to automate test case synthesis (He et al., 2025; Wang et al., 2025). While reducing hallucination rates, this approach relies heavily on manual annotation and the completeness of automated validators is difficult to formally guarantee (Olausson et al., 2023).

### Theoretical Foundation

The paper's approach is grounded in the observation that simply improving data quality has hit a bottleneck. It is imperative to refine 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.

## Methodology

### 3.1 Automated Test Case Generation

The framework consists of two pivotal stages:

#### Faulty Code Generation

For each problem $P_i$, an LLM generates stochastic faulty code via sampling: $f \sim \text{LLM}(\cdot | P_i)$. Each candidate $e$ is executed against an original test case suite $T_{\text{base}}$, producing a binary execution vector $V_i^f \in \{0, 1\}^{|T_{\text{base}}|}$. Only faulty code satisfying the following criterion is retained:

$$\phi(f) \triangleq 0 < \frac{\|V_i^f\|_1}{|T_{\text{base}}|} < 1 \tag{1}$$

This filters out both fully correct and completely incorrect code, preserving only **"near-correct" faulty code** that can capture potential logical defects. Exact deduplication on implementations with the same execution vector ensures the candidate pool $F_{\text{base}}$ encompasses diverse logical discrepancies.

#### Faulty-Code-Driven Test Case Generation

A **failure-inducing prompting strategy** (Mu et al., 2024) is adopted, where batches of faulty codes are provided as negative examples. The model generates constraint-compliant test cases $t_i$ satisfying two criteria:
1. Strict adherence to input specifications of $P_i$
2. Capability to induce logical failure in at least one faulty code while remaining consistent with correct execution of the reference solution

### 3.2 Test Case Validation and Selection

A three-stage filtering pipeline ensures semantic soundness and diagnostic breadth:

#### Input Validation
Executable validators $A_i$ are implemented for each problem $P_i$. The suite of valid test cases is formally defined as:

$$T_{\text{valid}} = \{t \in T_{\text{cand}} \mid A_i(t) = \text{True}\} \tag{2}$$

This prunes inputs that are syntactically correct but semantically invalid.

#### LLM Instruction-Compliance Validation
Each test case is evaluated against the faulty code pool to determine whether it can trigger a logical failure in at least one faulty implementation. Only test cases that simultaneously yield correct outputs and demonstrate capacity to expose code defects are incorporated into $T_{\text{final}}$.

#### Diversity-Driven Selection
A binary execution vector $V_i^t \in \{0, 1\}^{|F_{\text{base}}|}$ is constructed for each test case. K-means clustering (Ahmed et al., 2020) partitions the test case space into $K$ disjoint clusters using Euclidean distance (Rudin, 1976):

$$\min_{\{C_1,\ldots,C_K\}} \sum_{k=1}^{K} \sum_{V_i^t \in C_k} \left\| V_i^t - \mu_k \right\|_2^2 \tag{3}$$

where $\mu_k = \frac{1}{|C_k|} \sum_{V_j^t \in C_k} V_j^t$ denotes the centroid of cluster $C_k$. A round-robin selection strategy extracts representative medoids, ensuring the final suite $T_{\text{synth.}} = \{t_1, \ldots, t_K\}$ spans the maximum range of scenarios.

### 3.3 Dense Reward Function Design

The suite of test cases successfully executed by a candidate solution $s$ is:

$$\text{pass}(s, T_{\text{synth.}}) = \{t \in T_{\text{synth.}} \mid \text{exec}(s, t) = \text{pass}\} \tag{4}$$

The corresponding reward function $r(s)$ is:

$$r(s) = \begin{cases} 1.1 & \text{if } |\text{pass}(s, T_{\text{synth.}})| = 1 \\ -0.1 & \text{if } |\text{pass}(s, T_{\text{synth.}})| = 0 \\ \frac{1}{10} \cdot \frac{|\text{pass}(s, T_{\text{synth.}})|}{|T_{\text{synth.}}|} & \text{otherwise} \end{cases} \tag{5}$$

This stepwise reward strategy provides granular feedback, enhances resilience to test case noise, and fosters stable curriculum learning.

## Empirical Validation / Results

### Experimental Settings

- **Training data**: CodeContests$^+_{\text{train}}$, a filtered subset of CodeContests$^+$ (Wang et al., 2025) with approximately 3.3k problems (pass@10 between 0.2 and 0.9 using Qwen3-32B)
- **Model**: Qwen3-32B fine-tuned via GRPO (Guo et al., 2025)
- **Configuration**: $\beta_{\text{clip}} = 0.2$, Adam ($\eta = 5 \times 10^{-6}$, $\beta_1 = 0.9$, $\beta_2 = 0.95$), batch size 256, 10-step linear warmup, $T = 1.0$, $p_{\text{top}} = 1.0$, $n_{\text{sample}} = 8$
- **Baselines**: Naive LLM Generation, HardTests, CodeContests$^+$, CodeContests-O

### Main Results

**Table 1: Performance on LiveCodeBench and CodeForces benchmarks**

| Method | LiveCodeBench Score | Codeforces Score | Rating | Percentile |
|--------|---------------------|------------------|--------|------------|
| Naive LLM Generation | 65.75 | 35.41 | 83.36 | 91.70 |
| HardTests | 65.25 | 35.65 | 83.58 | 91.35 |
| CodeContests$^+$ | 65.41 | 35.56 | 83.96 | 91.45 |
| CodeContests-O | 66.21 | 36.43 | 84.35 | 91.81 |
| **RobustTests (Ours)** | **68.39** | **38.50** | **85.99** | **94.67** |

RobustTests outperforms baselines by approximately **absolute 3%** on both benchmarks.

### Test Case Diversity Analysis (TSP Metric)

The Test case Space Polarization metric is defined as:

$$TSP = \frac{1}{M} \cdot \sum_{s \in S} \left( -\frac{n_s}{N} \cdot \log_2 \frac{n_s}{N} \right) \tag{6}$$

where $M$ denotes the number of faulty codes in $F_{\text{base}}$, $N$ is the total number of test cases in $T_{\text{synth.}}$, and $n_s$ indicates the frequency of a specific test case $s$.

RobustTests achieves the **highest TSP value** among all compared test cases and obtains the best LiveCodeBench performance, demonstrating a positive correlation between TSP and training utility.

### Ablation Studies

**Table 2: Ablation on test case synthesis strategy (RobustTests\*, sparse rewards)**

| Method | LiveCodeBench Score | Codeforces Score | Rating | Percentile |
|--------|---------------------|------------------|--------|------------|
| RobustTests\* (Ours) | 67.84 | 38.47 | 85.16 | 93.97 |
| w/o Test case Synthesis | 66.91 | 36.41 | 84.4 | 92.12 |
| w/o Diversity-Driven Selection | 66.82 | 36.23 | 84.12 | 91.96 |
| w/o Both Module | 65.41 | 35.56 | 83.96 | 91.45 |

**Table 3: Ablation on reward module**

| Dataset | Method | LiveCodeBench Score | Codeforces Score | Rating | Percentile |
|---------|--------|---------------------|------------------|--------|------------|
| CodeContests$^+_{\text{train}}$ | Sparse Reward | 65.41 | 83.96 | 35.56 | 91.45 |
| | Dense Reward | 66.30 | 84.24 | 37.74 | 92.05 |
| RobustTests\* | Sparse Reward | 67.84 | 85.16 | 38.47 | 93.97 |
| | **Dense Reward** | **68.39** | **85.99** | **38.50** | **94.67** |
| RobustTests\* w/o validator | Sparse Reward | 66.02 | 83.82 | 35.91 | 91.28 |
| | Dense Reward | 67.21 | 85.02 | 38.15 | 93.64 |

### Key Findings from Ablations

1. **Both modules contribute independently**: Test Case Synthesis and Diversity-Driven Selection each yield ~1.5% gains on LiveCodeBench when applied independently, with clear complementarity.
2. **Dense rewards consistently outperform sparse rewards** across all training datasets, demonstrating effectiveness and generalizability.
3. **Validator filtering audit**: Approximately 30% of raw generated test cases are rejected as invalid, but about 10% of accepted test cases remain invalid, causing false-negative judgments for ~10% of all test cases—motivating the dense reward design.
4. **Reward scale sensitivity**: Setting scale to zero causes a clear performance drop; performance remains stable as scale varies from 0.05 to 0.20.

## Theoretical and Practical Implications

### Theoretical Contributions

1. **TSP as a proxy metric**: The paper establishes Test case Space Polarization as a low-cost metric for estimating dataset potential before expensive RL training, providing a principled way to evaluate test case quality.
2. **Faulty-code-driven synthesis**: Demonstrates that "near-correct" faulty code provides more effective guidance for test case generation than direct prompting or generator programs alone.
3. **Robust reward modeling**: Shows that stepwise dense rewards can mitigate the deleterious effects of residual hallucinations in synthetic test cases, addressing a fundamental limitation of binary sparse rewards in noisy settings.

### Practical Implications

1. **Scalable test case generation**: The framework reduces reliance on manual annotation while improving diagnostic coverage, making it suitable for large-scale training corpus construction.
2. **Curriculum learning effect**: The dense reward function provides a progressive optimization trajectory, guiding models toward absolute correctness through intermediate feedback.
3. **Broad applicability**: The synthesis strategy can be adapted for automated mutation testing in software engineering, and the dense reward mechanism is suitable for experimental planning and conclusion analysis in autonomous scientific discovery.

## Conclusion

The paper proposes **RobustTests**, a framework integrating faulty-code-driven test case synthesis and a stepwise dense reward mechanism to establish a robust RL framework for code generation. Key takeaways:

1. **Enhanced diagnostic utility**: The framework significantly improves the diagnostic coverage of the augmented CodeContests$^+$ dataset, minimizing false positives through diverse test case selection.
2. **Robust training signal**: The stepwise dense reward mitigates false negatives by enabling learning from partially correct signals through curriculum learning.
3. **Empirical superiority**: Absolute 3% performance gain on LiveCodeBench and CodeForces benchmarks when training Qwen3-32B.
4. **TSP-performance correlation**: Establishes a clear positive correlation between test case diversity (TSP) and model performance, offering a low-cost evaluation metric.

### Limitations and Future Directions

- **Dependency on solutions**: The approach requires ground-truth solutions, limiting utility in real-world scenarios without reference implementations.
- **Domain generalization**: Evaluated primarily on competitive programming benchmarks; generalizability to broader software development tasks remains to be explored.
- **Future work**: Could extend to scenarios without reference solutions and explore broader software engineering applications.

---

_Markdown view of https://picx.dev/p/2c7UmM, served by PicX — AI-generated visual whiteboard summaries of research papers._
