Post-Training Scaling for Code and Security Capabilities: How RL and Long-Horizon Environments Drive Improvement
Post-training scaling has become a key lever for improving large language models in code generation and security tasks. This article explains how increasing reinforcement learning compute and environment interaction—while keeping the base model fixed—can boost reasoning and task execution. It covers long-horizon environments for multi-step practice, automated verifiers for reward calculation, and the infrastructure needed to run extended training cycles.
Large language models acquire their capabilities in two main phases. Pre-training enables the model to learn linguistic and world knowledge, while post-training shapes the model to align with user intent, reason, and complete concrete tasks. Post-training typically includes supervised fine-tuning, preference optimization, and reinforcement learning (RL).
This article focuses on a specific definition of post-training scaling. The base model’s parameter count, activation ratio, and network architecture remain unchanged, and no re-pretraining is performed. Under this constraint, additional compute and data are invested into post-training, and the resulting changes in model capability are observed. This setup functions as a set of controlled experiments: the base model stays fixed while the compute and environment interaction scale in the RL stage.
It is important to note that these experiments isolate the contribution of reinforcement learning alone. Other post-training techniques, such as supervised fine-tuning and preference optimization, also affect outcomes. Therefore, the gains from RL should not be attributed to post-training as a whole.
A useful way to think about this: pre-training equips the model with broad knowledge, while post-training via RL teaches it to perform tasks. Once the base model reaches a certain size, additional pre-training data yields diminishing returns. Redirecting resources toward RL with environment interaction may then accelerate improvements in reasoning and task execution.
Long-Horizon Environments: Practice on Multi-Step Tasks
Real-world software development and system operations are rarely single-turn question-and-answer exchanges. An engineer first observes the current state, then forms a plan, executes commands, reads error messages, and iterates on fixes. Long-horizon environments provide training platforms that simulate these multi-step interaction scenarios. They include task descriptions, file system states, an executable terminal, and feedback that approximates real-world conditions.
Scaling the environment mainly means increasing task diversity and complexity. For example, the same type of problem can be practiced across different project structures, dependency versions, and failure modes. By repeatedly trying and failing in these environments, the model learns to maintain context across steps, localize errors, and correct them—rather than memorizing answers to specific questions.
Building these environments is costly. It requires manual task design, reproducible container setup, and test data preparation. Fidelity is also limited, as simulated environments differ from production systems. In practice, environments should be layered by task difficulty, with complexity increasing gradually, and a holdout set of environments kept aside for evaluation.
Automated Verifiers: Where Rewards Come From
Reinforcement learning relies on reward signals to update the policy. In code and security domains, manual scoring is expensive and hard to standardize, so automated verifiers handle most reward computation. A verifier typically combines two components: rule-based hard checks and model-based quality assessment.
The following pseudocode illustrates how the two parts are combined:
# Constant definitionsBASE_REWARD = 1.0 # Full reward when all tests passNEGATIVE_PENALTY = -1.0 # Penalty for compile failure or test tamperingQUALITY_WEIGHT = 0.2 # Weight for model scoring, kept small to avoid dominating trainingdef auto_verifier(task, model_action, env_feedback):# 1. Rule check: compile failure yields a negative rewardif not check_compile(env_feedback):return NEGATIVE_PENALTY# 2. Check whether tests were modified: test files are mounted read-onlyif not check_tests_unmodified(env_feedback):return NEGATIVE_PENALTY# 3. Test pass rate in [0, 1], using hidden test casespass_rate = run_unit_tests(env_feedback, task.hidden_tests)rule_reward = BASE_REWARD * pass_rate# 4. Model scoring: clipped to [0, 1], used only as a low-weight supplementquality = min(max(model_critic(task.spec, model_action), 0.0), 1.0)return rule_reward + QUALITY_WEIGHT * quality
The design has three key points. First, compile failures and test tampering both incur negative rewards, preventing the model from gaming the system by outputting invalid code or modifying assertions. Second, tests are split into public and hidden sets; hidden tests measure generalization and reduce overfitting to public cases. Third, model scoring is clipped to a fixed range and assigned a small weight, preventing critic bias from dominating the training direction.
Verifiers also have clear limitations. Tests only cover behaviors that have been written down; a high pass rate does not guarantee the absence of defects. Model-based scoring may carry biases that reward superficially clean but technically flawed code. Therefore, periodic human review with sampling, along with tracking the agreement rate between verifier judgments and human judgments, is recommended. If the agreement rate declines, the verifier should be corrected before continuing training.
Infrastructure: Supporting Long-Running Training Cycles
Post-training scaling places high demands on engineering infrastructure. A single training cycle can last weeks or even months, processing large volumes of environment interaction data. Issues in compute scheduling, memory management, or communication efficiency can slow down the entire pipeline.
A common industry approach is the asynchronous distributed architecture. Environment simulation, model inference, and gradient updates run in separate resource pools, communicating through queues. Inference does not wait for training, and training does not wait for environments to finish, reducing idle GPU time.
For memory optimization, activation recomputation and state replay are widely used. Activation recomputation recalculates some intermediate results during backpropagation, trading extra compute for memory headroom—useful when memory is tight but compute is available. State replay reuses historical trajectories to improve sample efficiency. Both have trade-offs. Recomputation increases training time, and overly stale replayed data can cause policy drift. Throughput, per-GPU memory usage, and overall training stability should be tested before deploying these techniques at scale.
