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
分类: cs.AI, cs.SE
发布日期: 2026-08-25
备注: Accepted by EMNLP 2026
💡 一句话要点
提出RobustTests框架以解决代码生成中的测试覆盖不足问题
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 强化学习 代码生成 测试用例合成 故障代码 密集奖励
📋 核心要点
- 现有的自动生成测试用例方法在测试覆盖率上存在不足,导致误报和策略退化。
- 本文提出的RobustTests框架通过故障代码驱动的测试用例合成,提升了测试用例的质量和覆盖率。
- 实验表明,使用RobustTests对Qwen3-32B进行微调后,在LiveCodeBench基准测试中性能提升了3%。
📝 摘要(中文)
可验证奖励的强化学习(RLVR)已成为提升大型语言模型(LLMs)代码生成能力的重要技术。然而,RLVR在编码实现中的有效性受到测试用例全面性的限制,测试覆盖不足常导致误报,从而引发奖励操控和策略退化。为此,本文提出RobustTests框架,采用故障代码驱动的测试用例合成策略,利用“近正确”的故障代码指导模型捕捉潜在的逻辑差异,并结合行为特征聚类的验证代理,精细过滤无效和冗余的测试用例。此外,RobustTests还引入基于通过率的逐步密集奖励函数,以增强训练的鲁棒性。通过该流程,构建了高质量的数据集,显著提升了CodeContests中的测试用例质量。实验结果表明,利用RobustTests对Qwen3-32B进行强化学习微调,在LiveCodeBench基准测试中相比基线方法提升了3%的性能,验证了RobustTests框架在提升LLMs代码生成能力方面的有效性。
🔬 方法详解
问题定义:本文旨在解决现有RLVR方法在代码生成中因测试用例覆盖不足而导致的误报和策略退化问题。现有的自动生成测试用例方法往往无法全面覆盖代码的潜在缺陷,导致模型在训练时受到干扰。
核心思路:RobustTests框架的核心思路是利用“近正确”的故障代码来引导测试用例的合成,从而帮助模型更准确地捕捉逻辑差异。此外,通过行为特征聚类的验证代理,精细过滤无效和冗余的测试用例,提升测试的有效性。
技术框架:RobustTests框架包括两个主要模块:故障代码驱动的测试用例合成模块和基于通过率的逐步密集奖励函数模块。前者负责生成高质量的测试用例,后者则通过细粒度的反馈增强训练的鲁棒性。
关键创新:本文的关键创新在于引入了故障代码驱动的测试用例合成策略和逐步密集奖励函数,这与传统的随机测试用例生成方法有本质区别,能够显著提高测试用例的质量和覆盖率。
关键设计:在设计中,RobustTests框架采用了行为特征聚类算法来过滤测试用例,并通过设置合适的损失函数和奖励机制,确保模型在训练过程中获得有效的反馈,从而提升整体性能。
🖼️ 关键图片
📊 实验亮点
实验结果显示,使用RobustTests框架对Qwen3-32B进行强化学习微调后,在LiveCodeBench基准测试中实现了3%的性能提升,相较于基线方法,验证了该框架在提升代码生成能力方面的有效性。
🎯 应用场景
该研究具有广泛的应用潜力,尤其在软件开发和自动化测试领域。通过提升代码生成的准确性和鲁棒性,RobustTests框架能够帮助开发者更高效地发现和修复代码中的潜在缺陷,进而提高软件的质量和可靠性。未来,该方法还可能扩展到其他领域,如自动化代码审查和智能合约生成等。
📄 摘要(原文)
Reinforcement learning from verifiable rewards (RLVR) has emerged as a pivotal technique for enhancing the code generation capabilities of Large Language Models (LLMs). However, the efficacy of RLVR in coding implementations is fundamentally limited by the comprehensiveness of test cases, because insufficient test coverage in code validation often causes false positives, further leading to reward hacking and policy degradation. To mitigate the reward bias stemming from the suboptimal quality of current automated generation methods, we propose the RobustTests framework, which introduces a faulty-code-driven test case synthesis strategy that leverages "near correct" faulty codes to guide the model in precisely capturing latent logical discrepancies and further integrates validator agents with behavioral feature clustering to facilitate the granular filtering of invalid and redundant test cases. To address false negatives caused by inherent hallucination noise in synthetic test cases, RobustTests also incorporates a stepwise dense reward function based on pass rates, bolstering training robustness through fine-grained feedback. By employing this pipeline, we construct a high-quality dataset that augmented the test cases in CodeContests, encompassing a broader spectrum of faulty code scenarios and significantly enhances diagnostic utility. Experimental results demonstrate that, by leveraging a moderately challenging subset of problems from CodeContests for training, RL fine-tuning of Qwen3-32B via RobustTests achieves an absolute 3% performance gain on the LiveCodeBench benchmark compared to baseline methods, confirming the effectiveness of the RobustTests framework in advancing the code generation proficiency of LLMs.