AdverMCTS: Combating Pseudo-Correctness in Code Generation via Adversarial Monte Carlo Tree Search

Qingyao Li, Weiwen Liu, Weinan Zhang, Yong Yu, Bo An

TL;DR

This paper introduces AdverMCTS, a novel adversarial search framework that tackles "pseudo-correctness" in code generation. By pitting a code-generating "Solver" against a test-generating "Attacker" in a minimax game, AdverMCTS creates a progressively hostile verification environment, forcing models to generate truly robust code that generalizes beyond sparse public test cases.

What Problem Does This Paper Address?

Large Language Models (LLMs) have become remarkably adept at generating code. However, a significant challenge remains: pseudo-correctness. This occurs when generated code passes the limited set of public test cases provided but fails on hidden, more challenging test cases. This is akin to a student memorizing answers for a specific quiz but not truly understanding the subject. Existing search-based methods, while improving code generation, often rely on these sparse public tests, inadvertently encouraging models to "overfit" to these weak verification signals. This limits their ability to generalize and produce truly reliable code, especially for complex, competition-level programming problems. The authors argue that the bottleneck isn't necessarily the LLM's capacity to generate correct code, but the environment's ability to discriminate it effectively.

Methods

AdverMCTS introduces a minimax-style adversarial game played between two agents within a Monte Carlo Tree Search (MCTS) framework:

  • Solver MCTS: This agent synthesizes code candidates. It uses MCTS to explore reasoning paths (Chain-of-Thought) and generates complete code snippets. Crucially, these candidates are immediately filtered by both public tests and the growing set of adversarial tests.
  • Attacker MCTS: This agent's sole purpose is to discover "vulnerability" test cases that expose logical flaws in the Solver's generated code. It operates on an evolving "Code Pool" (candidates that passed public tests) and uses a "Divergence-driven Test Synthesis" strategy. This means it actively seeks inputs that cause different code candidates to produce different outputs, indicating a potential bug.
  • Global Filtering Hub: This central component acts as a dynamic test suite. When the Attacker finds a test that causes divergence, an LLM-based "Arbiter" determines the correct output. This validated adversarial test is then added to the Global Test Filter, becoming a hard constraint for future Solver candidates.

This adversarial interaction creates a progressively stricter environment, forcing the Solver to produce code that is not just correct on public tests but robust against a widening array of challenging scenarios.

Datasets

The paper evaluates AdverMCTS on two established competition-level code generation benchmarks:

  • APPS (Automated Programming Progress Standard): This dataset includes problems with varying difficulty levels (Introductory, Interview, Competition).
  • TACO (Topics in Algorithmic Code Generation): This dataset is also used, with splits for Easy, Medium, and Hard problems.

The authors use standard pass rate and Pass@1 metrics on the hidden test suites for evaluation.

Key Insights and Ideas

  • Pseudo-correctness is the primary bottleneck: The experiments strongly suggest that LLMs can generate robust solutions, but the sparse public test sets fail to identify them. AdverMCTS directly addresses this by creating a more stringent verification environment.
  • Adversarial interaction is key: The paper demonstrates that a dynamic, adversarial approach, where a "Solver" and an "Attacker" co-evolve, is more effective than simply scaling up search or sampling.
  • Hard constraints are better than soft penalties: The results show that using adversarial tests as discrete filters (hard constraints) is more effective than using them as continuous penalties in the reward function. This aligns with the binary nature of unit testing.
  • Solver awareness is crucial for the Attacker: The Attacker performs significantly better when it has access to the current "Code Pool" (Solver's candidates). This allows it to craft targeted tests that exploit specific logical gaps, rather than generic ones.
  • Test-time compute scaling is more efficient with adversarial purification: AdverMCTS achieves better performance with fewer computational resources (tokens) compared to brute-force scaling of reasoning paths, as it efficiently filters out incorrect solutions early.

Key Results

  • AdverMCTS significantly outperforms state-of-the-art baselines on both APPS and TACO datasets, achieving substantial gains in Pass@1 accuracy. For example, on APPS-Competition, it achieved 72.77% Pass@1, compared to the next best at 70.53%.
  • The adversarial mechanism effectively reduces the false positive rate, meaning fewer incorrect solutions are mistakenly accepted.
  • The framework demonstrates scalability, showing consistent performance improvements across different backbone LLMs, from smaller models to a large 671B parameter model.
  • Ablation studies confirm that all core components of AdverMCTS (Attacker Tree, Divergence-driven Test Synthesis, Global Filtering Hub) contribute positively to its performance.

Limitations and Future Work

  • Attacker Search Budget: While a moderate attacker budget (N=2 rollouts) is optimal, the paper notes an inverted-U trend where too many rollouts can lead to brittle tests that degrade performance. Future work could explore more sophisticated strategies for balancing attacker aggressiveness and test reliability.
  • LLM Arbiter Limitations: The LLM-based Arbiter is crucial for determining ground truth when test outputs diverge. However, it's acknowledged that the Arbiter itself could potentially make errors, especially in complex cases.
  • Generalization to Diverse Programming Tasks: While effective on competition-level problems, further research could explore AdverMCTS's applicability to a broader range of programming tasks and languages.
  • Autonomous Self-Improvement: The authors believe their work opens avenues for enhancing LLM reasoning robustness through autonomous, adversarial self-improvement, suggesting future research could focus on more advanced self-improvement mechanisms.

Summary updated

BibTeX
@inproceedings{li2026advermcts,
  author = {Qingyao Li and Weiwen Liu and Weinan Zhang and Yong Yu and Bo An},
  title = {{AdverMCTS: Combating Pseudo-Correctness in Code Generation via Adversarial Monte Carlo Tree Search}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=0JpXqndUrA},
}
Figure