iGEN
Visit IGEN World Explore IGEN Expo
EXPLORE UPGRADE PLANS
BREAKING
Apple iPad Air OLED display, M5 chip and biggest redesign expected in 2027 India's soyabean acreage recovers as July rains boost Kharif sowing China’s EV Market Surges Past 16 Million as Battery Waste Wave Arrives WIRED Tests Plastic-Free Stainless Steel Water Filters From $199 to $549 FBI Warns Iran-Linked Hackers Hit Water Systems in Seven US States US Crude Bound for Israel for First Time Since 2023, Times of India Reports RBI's Special Swap Facility Draws $40.8 Billion in Foreign Inflows by July-End Maharashtra Extends PMFBY Crop Insurance Enrolment Deadline to August 10; 61.82 Lakh Farmers Registered Alienware 15 Gaming Laptop Review: Balanced Price and Performance as Hardware Costs Rise OpenAI and Anthropic AI Hacking Sprees Leave Legal Liability Questions Unanswered Apple iPad Air OLED display, M5 chip and biggest redesign expected in 2027 India's soyabean acreage recovers as July rains boost Kharif sowing China’s EV Market Surges Past 16 Million as Battery Waste Wave Arrives WIRED Tests Plastic-Free Stainless Steel Water Filters From $199 to $549 FBI Warns Iran-Linked Hackers Hit Water Systems in Seven US States US Crude Bound for Israel for First Time Since 2023, Times of India Reports RBI's Special Swap Facility Draws $40.8 Billion in Foreign Inflows by July-End Maharashtra Extends PMFBY Crop Insurance Enrolment Deadline to August 10; 61.82 Lakh Farmers Registered Alienware 15 Gaming Laptop Review: Balanced Price and Performance as Hardware Costs Rise OpenAI and Anthropic AI Hacking Sprees Leave Legal Liability Questions Unanswered
Home ›› Technology ›› Ai ›› Llms ›› Tree-like Self-Play Framework Teaches LLMs to Fix Security Flaws in Code Generation

Tree-like Self-Play Framework Teaches LLMs to Fix Security Flaws in Code Generation

Researchers introduce Tree-like Self-Play (TSP), a framework that treats secure code generation as a fine-grained sequential decision process. TSP significantly outperforms standard supervised fine-tuning (SFT) and reinforcement learning (RL) on Python security benchmarks, achieving a 75.8% pass rate and reducing unseen vulnerabilities by 24.5% while generalising across programming languages.

iG
iGEN Editorial
June 16, 2026
Tree-like Self-Play Framework Teaches LLMs to Fix Security Flaws in Code Generation

Enterprise software teams increasingly rely on large language models (LLMs) to generate code, but these models often replicate subtle security vulnerabilities present in training data. Standard alignment techniques such as supervised fine-tuning (SFT) and reinforcement learning (RL) apply coarse-grained optimisation at the sequence level, which fails to address the localised nature of security flaws—where a single incorrect token can compromise an entire program.

Researchers from the paper "Learn from Your Mistakes: Tree-like Self-Play for Secure Code LLMs" (available on arXiv) propose a new framework called Tree-like Self-Play (TSP) that reframes secure code generation as a fine-grained sequential decision process. Instead of blindly maximizing likelihood, TSP constructs a decision tree where the model explores branching trajectories—generating both secure "golden paths" and vulnerable variants. By treating code generation as a self-play game, the model learns to strictly discriminate against its own localized errors, providing a dense, on-policy learning signal that forces self-correction precisely at the critical decision nodes where vulnerabilities typically emerge.

Measured Performance Gains

In Python security benchmarks, TSP boosted CodeLlama-7B's pass rate (SPR@1) to 75.8%, significantly outperforming SFT (57.0%) and unstructured self-play baselines. The table below summarizes the key results:

Method Pass Rate (SPR@1) on Python Security Benchmark
Tree-like Self-Play (TSP) 75.8%
Supervised Fine-Tuning (SFT) 57.0%
Unstructured self-play baseline Not reported explicitly (below TSP)

Crucially, TSP induces robust out-of-distribution generalization: the model not only reduces vulnerabilities in unseen categories (CWEs) by 24.5% but also successfully transfers security principles learned from C/C++ to diverse languages, including Python, Go, and JavaScript. This suggests that TSP does not merely memorize patches, but internalizes abstract, language-agnostic security logic.

How Tree-like Self-Play Works

Unlike standard methods that optimize at the sequence level, TSP treats code generation as a tree-like exploration of decision nodes. The model generates multiple variants at each step—some secure, some vulnerable—and learns to steer toward the secure path based on feedback from its own mistakes. This creates a dense training signal that pinpoints exactly where the model's decisions lead to security flaws, enabling precise correction. The approach is model-agnostic and can be applied to any code-generation LLM.

Implications for Enterprise Code Security

For enterprise technology decision-makers, the TSP framework offers a path to more reliable AI coding assistants. By reducing vulnerabilities by nearly a quarter in unseen categories and transferring security knowledge across languages, TSP could help organisations shrink the security debt introduced by AI-generated code. While the research is preliminary and has not yet been peer-reviewed, the results suggest that fine-grained self-play methods could become a best practice for aligning code LLMs with security requirements. Procurement teams evaluating AI coding tools should consider whether vendors employ similar token-level security alignment, as coarse-grained methods may leave critical flaws undetected.

The paper is authored by Chen, Wenqi; Zhang, Ziyan; Wang, Bin; Liu, Lin; Hengheng; Zhengsu and was published on arXiv on June 2, 2026.


Sources:

Keep Reading

Recommended Stories

Reinforcement-Aware Knowledge Distillation Boosts LLM Reasoning Efficiency Technology

Reinforcement-Aware Knowledge Distillation Boosts LLM Reasoning Efficiency

Researchers propose RL-aware distillation (RLAD) to address distribution mismatch and objective interference in knowledge distillation for LLM reasoning. The method uses Trust Region Ratio Distillation (TRRD) to selectively imitate teacher policies during reinforcement learning. RLAD outperforms offline distillation, standard GRPO, and KL-based on-policy distillation across logic and math benchmarks.

June 21, 2026
Haiku to Opus in Just 10 bits: LLMs Unlock Large Compression Gains Technology

Haiku to Opus in Just 10 bits: LLMs Unlock Large Compression Gains

A new arXiv paper presents methods for compressing LLM-generated text, achieving over 100x reduction in data transfer compared to prior techniques. Lossless compression via domain-adapted LoRA adapters doubles efficiency, while an interactive Question-Asking protocol recovers up to 72% of the capability gap between small and large models using only 10 binary questions.

June 16, 2026
LLM Jaggedness Unlocks Scientific Creativity: New Benchmark Reveals Uneven AI Capabilities Can Be Harnessed for Innovation Technology

LLM Jaggedness Unlocks Scientific Creativity: New Benchmark Reveals Uneven AI Capabilities Can Be Harnessed for Innovation

A new arXiv paper introduces SciAidanBench, a benchmark for measuring the scientific creativity of large language models. The research finds that LLM capabilities are jagged—uneven across tasks and domains—but that this jaggedness can be harnessed through ensemble methods to produce superior scientific ideas.

June 16, 2026
New Research Reveals Truthfulness Preserved Across LLM Lineages, Enabling Better Hallucination Control Technology

New Research Reveals Truthfulness Preserved Across LLM Lineages, Enabling Better Hallucination Control

A new paper from researchers shows that truthfulness-related attention heads are preserved across generations of large language models, even after instruction tuning or multimodal adaptation. The authors propose TruthProbe, a soft-gating strategy that amplifies these heads to reduce hallucinations, with improvements on HaluEval, POPE, and CHAIR benchmarks.

June 16, 2026