Code LLM Training Explained: SFT, RFT, and Agentic RL Behind AI Coding Assistants
This article examines whether the AI coding assistant market is truly saturated and argues that real competition lies in model and training capability rather than feature demos. It walks through the common three-stage paradigm for training high-quality code LLMs—Supervised Fine-Tuning (SFT), Rejection-sampling Fine-Tuning (RFT), and Agentic Reinforcement Learning (Agentic RL)—and explains the data design, multi-ground-truth verification, entropy-guided tree pruning, and heterogeneous scheduling behind each stage. It also covers the cloud-native infrastructure and security/compliance practices needed for large-scale training, and closes with a checklist of the metrics that separate durable differentiation from shallow, easily replicated surface features.
1. Is the AI Coding Assistant Space Already Crowded?
If you only count products, the space looks crowded: code completion, single-file generation, cross-file refactoring, terminal execution, and bug fixing all keep appearing, and leading vendors are shortening their iteration cycles. But if you shift the yardstick from “feature demos” to “training systems and model capability,” the competition is still in deep water.
More sensible criteria include: whether the model can understand repository-level context, whether it can reliably complete multi-turn tool calls, whether generated code passes compilation and tests, whether inference and training costs are controllable, whether cluster utilization is stable, and whether security and compliance requirements are met. In other words, the space doesn’t lack products that “can plug into some CLI tool”—it lacks code LLM training systems that are low-cost, highly stable, and continuously improvable.
2. How Do You Train a Code LLM? The Three-Stage Paradigm
The industry usually divides high-quality code LLM training into three stages: Supervised Fine-Tuning (SFT), Rejection-sampling Fine-Tuning (RFT), and Agentic Reinforcement Learning (Agentic RL). This isn’t a fixed, universal answer, but it is a common path. It relies on a few prerequisites: high-quality and compliant data, reliable verifiers, clearly defined evaluation sets, sufficient compute budget, and a rollback-capable training and data management process.
Around questions like “how to train a code LLM,” “SFT vs. RFT,” “how Agentic RL reduces cost,” and “common training failure causes,” the table below is a good starting point:
| Stage | Input | Output | Key Metrics | Common Failures | Troubleshooting Direction |
|---|---|---|---|---|---|
| SFT | Instructions, code snippets, task types, scenario tags | Foundational code understanding and generation | Compile pass rate, test pass rate, instruction-following rate | Data duplication, train/eval leakage, insufficient scenario coverage | Deduplication, leakage removal, syntax validation, task×scenario ratio |
| RFT | SFT model, prompts, multiple ground truths, verifier | Higher-quality training samples and stronger initialization | Positive-sample rate, verifier accuracy, pass@k | False negatives, verifier misjudgment, reward noise | Add more ground truths, supplement tests, calibrate thresholds |
| Agentic RL | Environment, tools, trajectories, rewards, scheduling resources | Agent policy capable of completing multi-step tasks | Task completion rate, bubble rate, GPU utilization, reward variance | Long-tail trajectory idling, reward drift, scheduling blockage | Entropy-guided pruning, heterogeneous scheduling, reward calibration |
The three stages are interlocking: SFT sets the capability foundation, RFT improves sample and initialization quality, and Agentic RL upgrades single-point generation into task-execution capability. Dirty data or unclean rewards from an earlier stage get amplified in later stages.
3. The SFT Stage: Two-Way Coverage of Tasks and Scenarios
The key to the SFT stage isn’t simply piling on lines of code—it’s two-way coverage built around real user tasks and common code scenarios. The task dimension can include code generation, code explanation, bug fixing, unit test generation, code translation, refactoring, code review, and documentation generation. The scenario dimension can include algorithm logic, web backends, data processing, scripting/ops, front-end interaction, concurrency and performance, database access, and test frameworks.
Data formats are usually kept structured and batch-loadable. For example:
{"instruction": "Add boundary checks to this function and explain them", "language": "python", "input": "def divide(a, b):\n return a / b", "output": "...", "task_type": "bug_fix", "scenario": "backend"}
Field meanings can be defined clearly: instruction is the user’s need; language is the target language; input is the input code or context; output is the expected output or reference implementation; task_type labels the task category; scenario labels the business or technical scenario; and if you use a conversation format, messages can express multi-turn context.
After the data format, you must add data-security and engineering-risk notes:
- De-identify training data: remove sensitive information such as usernames, emails, paths, IPs, keys, and tokens.
- When using private repository code, confirm the repository’s authorization scope and avoid unauthorized code entering the training set.
- Code-leak protection must cover data upload, caching, logs, checkpoints, and export.
- Credential management should rely on a key management service or environment isolation; never write real credentials into samples.
- Before training, estimate compute and storage costs and keep rollback points so that bad data doesn’t waste a long training run.
Key engineering points include: deduplication, isolation of the training set from the evaluation set, syntax-checkability, and unified output specifications. A little dirty data means paying multiples of the cost in the later RL stages.
4. The RFT Stage: Introduce Multiple Ground Truths to Improve Rollout Efficiency
The core idea of RFT (Rejection-sampling Fine-Tuning) is: sample multiple candidate outputs for the same prompt, use verifiable signals to filter the correct samples, and then feed them back for fine-tuning. Compared with a single ground truth, introducing multiple ground truths is more valuable—for example, multiple correct solutions, multiple reference test sets, multiple expected outputs, or multiple static-check rules.
Multiple ground truths bring three benefits:
- Higher positive-sample hit rate: many problems have more than one correct path, so a single ground truth easily misjudges a reasonable-but-different solution as negative.
- Better rollout efficiency: more accurate reward signals reduce invalid trajectories, so a limited sampling budget produces more effective gradients.
- Greater training stability: clearer positive/negative boundaries reduce oscillation caused by reward noise.
The following pseudocode makes k, ground_truths, threshold, verifier.pass_rate, the selection rule, and the empty-acceptance branch concretely executable:
class Verifier:def pass_rate(self, candidate, prompt, ground_truths):tests = ground_truths.get("tests", [])expected = ground_truths.get("expected_outputs", [])checks = ground_truths.get("static_checks", [])total = len(tests) + len(expected) + len(checks)if total == 0:return 0.0passed = 0for t in tests:if run_test(candidate, t):passed += 1for e in expected:if compare_output(candidate, prompt, e):passed += 1for c in checks:if run_static_check(candidate, c):passed += 1return passed / totalverifier = Verifier()k = 8 # Number of candidates sampled per promptthreshold = 0.75 # Candidate acceptance thresholddef quality_key(c, prompt, ground_truths):reward = verifier.pass_rate(c, prompt, ground_truths)static_penalty = c.get("static_issues", 999)length_penalty = len(c.get("code", ""))return (reward, -static_penalty, -length_penalty)for prompt in dataset:ground_truths = ground_truths_by_prompt[prompt.id]candidates = [model.sample(prompt) for _ in range(k)]rewards = [verifier.pass_rate(c, prompt, ground_truths) for c in candidates]accepted = [c for c, r in zip(candidates, rewards) if r >= threshold]if accepted:chosen = max(accepted, key=lambda c: quality_key(c, prompt, ground_truths))fine_tune_buffer.add((prompt, chosen))else:# When no candidate reaches the threshold, don't feed back for training directly;# instead increase k, add ground truths, escalate to manual review, or apply rule-based filtering.rejected_buffer.add((prompt, candidates, rewards))
The selection rule here is: first compare the verifier pass rate, then reduce the number of static-check issues, and finally prefer shorter output, so that overly long candidates or ones with static defects aren’t mistakenly chosen as high-quality samples. If accepted is empty, record the rejected samples and trigger data supplementation or threshold adjustment rather than forcing training.
This step lays the groundwork for Agentic RL: the higher the initialization quality and the cleaner the rewards, the less likely large-scale RL is to drift.
5. Agentic RL Scaling: The Key to Large-Scale Reinforcement Learning
Once you enter Agentic RL, the challenge shifts from “how to train” to “how to train efficiently on a cluster.” Agent training naturally has a long tail: within the same batch of tasks, some trajectories finish in a few steps while others need dozens of tool-call rounds. This length variance causes GPU idling—what’s commonly called “bubbles.”
5.1 Entropy-Guided Tree Pruning
A common approach is to compress massive rollout trajectories into a prefix tree: shared prefixes are stored once, avoiding repeated expansion. Nodes are then ranked to decide which are worth expanding further.
Entropy can be defined as follows: at node n, if the model’s normalized probability or sampling frequency for candidate action a is p(a|n), then the action-distribution entropy is:
H(n) = -Σ p(a|n) * log(p(a|n))
Visit probability can be defined as:
Q(n) = visit_count(n) / visit_count(root)
It’s important to stress: high entropy means high uncertainty, not necessarily high learning value. High-entropy nodes may simply reflect a model that hasn’t converged yet, or they may offer exploration gains; low-entropy nodes may already be converged, so continued sampling yields little. So you can’t look at entropy alone—you also need to combine visit probability, reward progress, and verifier pass rate.
A budget-allocation strategy can be:
- Prioritize expanding nodes that are “high entropy and high visit,” because they are both uncertain and on the critical path.
- Downweight, merge, or stop sampling “low entropy and already converged” nodes to avoid wasting compute.
- Reserve a portion of the budget for exploration to prevent over-greedy behavior from reducing diversity.
- Investigate nodes with persistently abnormal verifier pass rates separately, to avoid reward noise contaminating training.
Node selection can be written as:
def compute_entropy(n):probs = list(n.action_probs.values())return -sum(p * math.log(p + 1e-9) for p in probs if p > 0)def select_nodes(tree, budget, explore_ratio=0.2):root_visits = max(1, tree.root.visit_count)nodes = [n for n in tree.nodes if n.visit_count >= 2]if not nodes:return []max_entropy = max(compute_entropy(n) for n in nodes) or 1e-9for n in nodes:n.entropy = compute_entropy(n)n.visit_prob = n.visit_count / root_visitsn.score = (0.6 * (n.entropy / max_entropy)+ 0.3 * n.visit_prob+ 0.1 * n.progress_delta)explore_budget = max(0, min(budget, int(budget * explore_ratio)))main_budget = max(0, budget - explore_budget)converged = [n for n in nodes if n.entropy < 0.2 and n.reward_mean > 0.8]active = [n for n in nodes if n not in converged]chosen = sorted(active, key=lambda n: n.score, reverse=True)[:main_budget]explore = sorted(active, key=lambda n: n.entropy, reverse=True)[:explore_budget]return chosen + explore
This both controls sampling scale and preserves effective exploration, avoiding wasted budget on low-value paths.
5.2 Heterogeneous Scheduling and Logical Decoupling
An Agentic RL runtime usually consists of two parts: the training side handles model forward passes, backpropagation, and parameter updates; the agent side handles environment interaction, tool calls, and reward computation. Their compute profiles differ: the training side is GPU-heavy, while the agent side often involves a lot of I/O and CPU logic. If they are tightly coupled and run serially, they tend to wait on each other.
A better approach is to fully decouple training and agent logic and use heterogeneous resource scheduling: run the training flow and the rollout flow on separate, appropriate resource pools, exchanging data through queues or streaming pipelines. The goal is to reduce bubbles and raise cluster utilization. Actual results depend on the task long tail, communication bandwidth, scheduling isolation, and data supply. If there are too many long-tail tasks, message queues back up, network bandwidth is insufficient, or scheduling isolation is poorly designed, cluster utilization will drop even when the algorithm is correct.
At the engineering level, this relies on a reliable scheduling framework, data pipelines, and state management—the key link that turns a “theoretically correct RL algorithm” into “scalable industrial training.”
6. Cloud-Native Infrastructure and Security/Compliance Supporting Training
Large-scale code model training is inseparable from a robust foundation. General capabilities include: a container platform to host elastic GPU training and rollout tasks; object storage to hold massive corpora, checkpoints, and trajectory data; message queues or streaming pipelines to decouple the training side from the agent side; and logging, monitoring, and alerting to observe throughput, bubble rate, reward curves, and hardware utilization in real time.
On security and compliance, at minimum pay attention to the following:
- Least privilege: split training, inference, storage, and monitoring accounts by responsibility, and avoid long-term shared high-privilege access.
- Object storage encryption: enable encryption at rest and in transit for corpora, checkpoints, trajectories, and evaluation sets.
- Log redaction: redact sensitive fields in code snippets, user input, paths, tokens, and exception stack traces.
- Credential management: use short-lived credentials, key rotation, and audit logs, and never write credentials into code or samples.
- Monitoring and alert thresholds: set threshold alerts for GPU utilization, bubble rate, queue backlog, sudden reward changes, verifier pass rate, and task failure rate.
Together these capabilities ensure the stability and observability of long training runs, rather than relying on any single proprietary interface.
7. Where Is the Real Differentiation?
Back to the original question: is the AI coding assistant space too crowded? By product count, yes. But by technical depth, the competition focuses on a few hard metrics:
- Repository-level context understanding: can it go beyond single files to understand multi-file dependencies and project structure?
- Tool calling and task completion rate: is the multi-turn plan–execute–correct loop reliable?
- Breadth of language and framework coverage: is there deep support for mainstream ecosystems?
- Inference and training cost: are per-token cost, cluster utilization, and bubble rate controllable?
- Security and compliance: are the correctness and maintainability of generated code, and supply-chain risk, controllable?
This can be further organized into a checklist:
| Check Item | Key Metrics | Recommended Action |
|---|---|---|
| SFT data quality | Dedup rate, compile pass rate, scenario coverage, authorization status | Establish data cleaning, leakage removal, and compliance review |
| RFT verifier reliability | Test case coverage, false positive rate, false negative rate, threshold | Introduce multiple ground truths and static checks; calibrate periodically |
| Agentic RL bubble rate | Average wait time, long-tail trajectory share, queue length | Optimize scheduling, pruning, and data supply |
| Cluster utilization | GPU utilization, CPU utilization, scheduling isolation effect | Decouple training and agent sides; monitor bottlenecks |
| Tool call success rate | Single-step success rate, multi-step completion rate, correction rate | Add tool documentation, rollback, and retry strategies |
| Security & compliance | Data authorization, credential leaks, log redaction | Least privilege, encryption, auditing, and alerting |
What is truly crowded is homogeneous surface capability—the kind where you “plug in a CLI and it works”—while deep training systems, data engineering, reward design, and RL engineering capability remain scarce.
8. Summary
The competition in intelligent programming tools is essentially a competition in the efficiency and quality of code LLM training systems. SFT must solidify two-way coverage of tasks and scenarios; RFT must purify samples and raise rollout efficiency through multiple ground truths; and Agentic RL must use entropy-guided tree pruning to focus on high-value trajectories while relying on heterogeneous scheduling and logical decoupling to reduce bubbles and raise cluster utilization.
For product and engineering teams, rather than chasing surface-level integrations, it pays to invest effort in data quality, verifier reliability, reward design, distributed training efficiency, and security/compliance. Whoever can string SFT, RFT, and Agentic RL into a low-loss, highly stable, observable, rollback-capable industrial pipeline is more likely to build a sustained advantage in a seemingly crowded space.
