Two-Stage Reinforcement Learning for Sound and Adversarial Test Generation in Code LLMs
Jiacheng Xu, Wentao Zhang, Zhiyi Lyu, Fuxiang Zhang, Chaojie Wang, Yang Liu, Bo An
Abstract
Reinforcement learning (RL) has substantially advanced code generation with large language models (LLMs) through executable feedback. The feedback for coding problems mainly comes from specific test cases, where high-quality test cases are often scarce since they should be both sound and discriminative. We thus turn to study the auto-generation of test cases using the learned model. We find this is naturally an adversarial RL problem: the model is expected to generate effective test cases as counterexamples, depending on the solver's current failure modes. We propose Test Cases Scaling (TCS), a two-stage RL framework for effective test generation. Both stages train a test generator from a rolling policy-aligned buffer: Stage 1 generates tests consistent with the reference solution, and Stage 2 restricts the buffer to current failure modes and learns counterexample tests. Across TACO and LiveCodeBench, TCS improves both pass@1 and inference-time answer selection according to generated tests. We find the learned test generator also enables effective selection among other LLM outputs.
Create a lesson
Metadata
- Categories
- cs.CL, cs.LG
- Comments
- 21 pages, 7 figures. Accepted to Findings of the Association for Computational Linguistics: EMNLP 2026
Related papers
When Does Continual Pre-Training Help? An Empirical Study of Decoupled Knowledge and Generation Trajectories in Clinical LLMs
Shared title terminologycs.CLNiclas Doll, Jasper Schulze Buschhoff, Shalaka Satheesh et al.
LLMs Mirror Country-Specific Gender Patterns If Asked, but Skew Male When Generating Media in Local Languages
Shared title terminologycs.CLSharif Kazemi, Tanya Popli, Neil K. R. Sehgal et al.
Generating Adversarial Texts for Machine Translation via GRPO
Shared title terminologycs.CLFlorian Zogaj, Jakob Hütteneder, Giovanni De Muri et al.
SurveyAgent-HKA: A multi-agent framework for scientific survey generation with LLMs and human knowledge augmentation
Shared title terminologycs.CLTong Bao, Mir Tafseer Nayeem, Yi Zhao et al.
Compression Beyond the Uncompressed: A Two-Stage Training Recipe for Soft Context Compression in RAG
Shared title terminologycs.CLShuyu Guo, Shuo Zhang, Zhaochun Ren
Generating Constructive Feedback on Stories via Reinforcement Learning
Shared title terminologycs.CLMaja Stahl, Timon Ziegenbein, Henning Wachsmuth