# KAT-Coder-V2.5: training a coding model to live inside a repository

> Satyajit Ghana — Head of Engineering @ Inkers Technology
> canonical: https://ai.thesatyajit.com/articles/kat-coder-agentic-training
> date: 2026-07-10
> tags: llm, agents, reinforcement-learning, code-generation, explainer
A "coding model" usually means a next-token predictor you paste a function stub into. **KAT-Coder-V2.5**, from the Kwaipilot / Kuaishou team, is trained for a different job: to *act* — to open a real repository, run its tests, read the failures, edit files, and iterate until the tests pass, across dozens of turns. Once that's the target, the model stops being the hard part. The hard part is manufacturing enough **precisely specified, executable, objectively verifiable** tasks to train on, and building an RL loop that survives long, sparse-reward trajectories. This report is mostly about that manufacturing stack. It pairs with our pieces on [agent harnesses](/articles/agent-harness) and on [near-frontier code RL](/articles/swe-1-7); KAT-Coder is a full-stack answer to the same question those raise.

The one idea to leave with: **an autonomous coding agent is an environment-and-data problem before it is a modeling problem.** Everything below — AutoBuilder, the data flywheel, harness randomization, the asymmetric critic, multi-teacher distillation — exists to feed a policy verifiable practice inside realistic scaffolds, without letting it overfit any single one.

<Figure
  src="/articles/kat-coder-agentic-training/fig2.png"
  alt="Two-row pipeline diagram. Top row, 'Environment Scaling Engine': repo artifacts (repositories, issues, pull requests, commits) feed task mining (code patch and test patch into problem statement, requirements, interface constraints), a clarity check funnel, AutoBuilder (build-and-verify agent, config script, dependencies, clean checkout, sandbox execution), verification (parsed outputs, >90% tests collected, reproducible pass-to-pass/fail-to-pass), producing 100K+ environments across 12 languages at a 16.5%-to-57.2% success rate. Bottom row, 'Data Scaling Flywheel': rollout trajectories (failed, near-miss, passing) go through hint-boosted rollout (success 0% to 20%), hint-free replay, process filtering (exploration, localization, fidelity, minimality, verification, honesty), and harness robustness (randomized interfaces and injected perturbations). A right-hand column lists the outputs: precise tasks, executable envs, validation tests, verified patches, robust trajectories, reward signals, harness-invariant behavior."
  caption="The agentic software-engineering data pipeline: an Environment Scaling Engine turns real repositories into verifiable sandboxes, and a Data Scaling Flywheel turns raw rollouts into high-value training signals (Huang et al., 2026, Figure 2)."
/>

## AutoBuilder: turning real repos into verifiable sandboxes

The raw material is public repositories, but an issue title and a merged PR are not a task. Two problems have to be solved. First, **task mining**: raw issue/PR text is ambiguous and often misaligned with what actually got merged, so AutoBuilder regenerates a structured spec from the *golden patch* and *test patch* — a **problem statement** (from the golden patch), **requirements** (from the test patch), and **interface constraints** (from both) — then runs a clarity check to ensure it's self-contained.

Second, **environment construction**: a build agent writes a configuration script and a separate verification agent runs it in an isolated sandbox, accepting the environment only when it can collect **>90% of the expected tests** with reproducible fail-to-pass and pass-to-pass outcomes (exit codes and log-scraping are explicitly rejected as too easy to fool). Combining base images, language templates, and retrievable build recipes, this reaches a **57.2% environment-construction success rate** (up from a 16.5% starting point) and yields **>100,000 verifiable environments across 12 languages**. That corpus of executable tasks is the substrate everything else trains on.

## The data flywheel: recovering near-misses without leaking hints

Verifiable environments are necessary but not sufficient: on genuinely hard tasks the model's raw pass rate is near zero, so rollouts produce no learning signal. KAT-Coder's answer is a two-stage recovery loop. First, inject **process-level hints** to lift near-misses over the line, raising the pass rate from ~0% to **~20%**. But a trajectory that only succeeds *because it was handed a hint* teaches the model to expect hints it won't have at deployment — so the second stage **replays the same tasks hint-free** and keeps only the trajectories that still recover. The final data carries no hint leakage and stays faithful to the original distribution. Drag the hint strength and step the stages:

<DataFlywheel />

What survives then passes a **process-score filter** that scores each trajectory on exploration, localization, pre-edit reasoning, specification fidelity, repository conventions, patch minimality, verification quality, recovery, and honesty — down-weighting exploitative or unstable behavior even when the tests happen to pass. A parallel **harness-robustness** step randomizes tool names, argument conventions, and output formats and injects realistic perturbations (missing dependencies, transient failures, truncated outputs, noisy logs), so trajectories don't encode a single scaffold's quirks.

## KwaiClawEnv: general agentic tool use

Repository work isn't the only skill. **KwaiClawEnv** is a three-layer pipeline that manufactures general tool-use trajectories: a **Service layer** builds callable capabilities from human-authored Skills and LLM-generated Services (>90% generation success from open-source community Skills), a **Task layer** expands real task seeds into variants with configurable difficulty and tool-chain length, and an **Eval layer** converts rollouts into SFT-ready samples and feeds quality signals back upstream. It yields **>100,000 high-quality instances** with an **average of 15 tool calls** per task and the longest **exceeding 100 steps** — genuinely long-horizon agentic data, validated through a three-stage checker (service reachability, task-schema legality, sandboxed execution) and two-layer filtering (hard rules plus LLM-as-judge).

## Reinforcement learning, hardened for long horizons

### Harness randomization

An agentic policy trained inside one fixed scaffold overfits the *surface* of that scaffold, not the task. The report names three failure modes: **format overfitting** (anchoring to one action format, so parsing breaks when the protocol changes), **context-structure overfitting** (depending on how history is concatenated), and **control-flow overfitting** (relying on a fixed reflection/stop schedule). The fix is to train across many harnesses that vary along three axes — tool-invocation protocol, context management, and control flow — spanning **white-box** harnesses (like mini-swe-agent: simple, uncompressed, clean signal) and **black-box** production harnesses (Claude Code, Codex, OpenClaw, OpenHands: with compression and context reorganization). Flip the axes and watch the rendered action change while the task — and its reward — stay put:

<HarnessRandomizer />

Underneath, the sandbox itself had to be hardened: container-image and environment-variable bugs meant **~16% of trajectories** initially failed for reasons unrelated to the model. Fixing disk pressure (95% → 60% usage) and timeouts drove sandbox-related failures to **below 2%**, and invalid-rollout rates from 6–7% to under 1%.

### Asymmetric PPO with a hindsight critic

Long-horizon tasks are sparse-reward: the signal lands only at the end, when the tests pass or fail. That makes the critic's job — estimating the value of an intermediate state — brutally high-variance, and a noisy value function means a noisy advantage, which destabilizes training. KAT-Coder's move is an **asymmetric actor–critic**: the actor sees only the normal harness state $s_t$ (so it behaves identically in training and deployment), while the critic is given a *privileged* **hindsight context** $c_t$ — the eventual reward, test outcomes, coverage signals, patch-level diffs, trajectory statistics, and subsequent turns. Scrub the turn and toggle hindsight to see the value estimate tighten:

<HindsightCritic />

Concretely, the standard clipped PPO objective is optimized:

$$
\mathcal{J}_{\mathrm{PPO}}(\theta)=\mathbb{E}_{q,\,o}\left[\frac{1}{|o|}\sum_{t=1}^{|o|}\min\!\left(r_t\hat{A}_t,\ \mathrm{clip}(r_t,1-\epsilon,1+\epsilon)\hat{A}_t\right)\right], \quad r_t=\frac{\pi_\theta(a_t\mid s_t)}{\pi'(a_t\mid s_t)},
$$

with advantages from GAE, $\hat{A}_t=\sum_{l=0}^{T-t-1}(\gamma\lambda)^l\delta_{t+l}$ and $\delta_t=r_t+\gamma V'(s_{t+1})-V'(s_t)$. The asymmetry is entirely in the value function: the critic conditions on the hindsight context, so its regression target uses $V_\psi(s_t,c_t)$ rather than $V_\psi(s_t)$:

$$
\mathcal{L}_{\mathrm{critic}}^{\mathrm{asym}}(\psi)=\mathbb{E}_{(s_t,c_t,R_t)}\left[\left(V(s_t,c_t;\psi)-R_t\right)^2\right].
$$

Because $c_t$ contains information the actor can't see, the value estimate is far less of a blind guess — lowering advantage variance without ever contaminating the deployed policy. Reward itself is a two-part framework: a **rule-based** reward with a core task score (all fail-to-pass *and* pass-to-pass tests must pass for full credit), eight behavioral constraints (duplication, garbled output, tool-call accuracy and placement, redundant calls, parallelism, debug-artifact cleanup), and failure-path incentives (file-search $F_2$, unit-test pass rate); plus a **model-based** generative reward model scoring fault diagnosis, post-fix validation, and execution strategy. The reported SWE training curve rises stably throughout.

<Figure
  src="/articles/kat-coder-agentic-training/fig3.png"
  alt="Architecture diagram of the RL training infrastructure. A top row labelled 'any agent harness' shows Claude Code, Codex CLI, OpenHands, mini swe-agent, and SWE-agent. They connect to 'Kwai Env', a dashed box containing a Gateway Server (middleware speaking Anthropic, OpenAI Chat, and OpenAI Responses protocols) linked to an Environment Module with Sandbox and Container, and an Experience Buffer. On the left, a Rollout Engine (N workers) exchanges token-in/token-out with the gateway and receives weight sync from a Train Engine (M workers), which is fed request-level samples from the experience buffer."
  caption="The agentic RL infrastructure: a gateway server lets any agent harness drive sandboxed environments over multiple protocols, while rollout and train engines exchange trajectories and synced weights (Huang et al., 2026, Figure 4)."
/>

### Multi-Teacher On-Policy Distillation

Rather than run five separate RL specialists and hope they compose, KAT-Coder fuses them with **Multi-Teacher On-Policy Distillation (MOPD)**: the student generates on-policy, and for each domain $d$ its distribution is pulled toward that domain's expert teacher $\pi_{T_d}$ under a reverse-KL objective —

$$
\mathcal{L}_{\mathrm{MOPD}}(\theta)=\mathbb{E}_{(x,d)}\,\mathbb{E}_{y\sim\pi_\theta(\cdot\mid x)}\left[\sum_{t=1}^{|y|}w_t\,\mathrm{KL}\!\left(\pi_\theta(\cdot\mid x,y_{<t})\,\middle\|\,\pi_{T_d}(\cdot\mid x,y_{<t})\right)\right],
$$

fusing five experts — agentic software engineering, general agentic reasoning, terminal use, web coding, and general knowledge — into one model without the usual "see-saw" of gains in one domain costing another. Two stabilizers make on-policy distillation behave: an **off-policy cold start** (ordinary teacher-forced cross-entropy on teacher samples) to bootstrap before going on-policy, and **drift-aware dynamic truncation** that measures the top-$k$ overlap $\rho_t=|\mathcal{T}_t^k\cap\mathcal{S}_t^k|/k$ between teacher and student predictions and truncates where they diverge too far.

## The numbers

Evaluated under a unified Claude Code harness against a panel of frontier models (GLM-5.1, GLM-5.2, Kimi-K2.6, and Opus 4.8), KAT-Coder-V2.5 posts the **top score on PinchBench (94.9)** and ranks **second only to Opus 4.8** on repository-level SWE — SWE-Bench Pro **65.2** (Opus 4.8 leads at 69.2) and the team's own KAT Code Bench **53.1** (Opus 4.8 57.3):

<BenchBars
  title="Agentic coding benchmarks — KAT-Coder-V2.5 vs frontier panel (%)"
  unit="%"
  bars={[
    { label: "PinchBench (Avg)", value: 94.9, highlight: true },
    { label: "Opus 4.8 · Pinch", value: 93.5 },
    { label: "SWE-Bench Pro", value: 65.2, highlight: true },
    { label: "Opus 4.8 · SWE-Pro", value: 69.2 },
    { label: "KAT Code Bench", value: 53.1, highlight: true },
    { label: "Opus 4.8 · KAT-Code", value: 57.3 },
  ]}
/>

The picture is not uniform. On tool-use and repo-level SWE, KAT-Coder is at or near the frontier; on **Terminal-Bench 2.1 it scores 60.7** — behind GLM-5.2 (77.9), Kimi-K2.6 (73.0), and Opus 4.8 (84.6) — and on **SciCode 50.3**, behind GLM-5.2 (50.5) and both Kimi-K2.6 and Opus 4.8 (53.5). On KAT Claw Bench it reaches 85.5, with GLM-5.2 (86.8) and Opus 4.8 (90.7) ahead. The efficiency of the *training stack* — not inference — is the story; the paper reports no wall-clock or cost comparison against the frontier panel.

<Figure
  src="/articles/kat-coder-agentic-training/fig1.png"
  alt="Six grouped bar charts, one per benchmark (SWE-Bench Pro, KAT Code Bench, PinchBench, KAT Claw Bench, Terminal-Bench 2.1, SciCode). Each chart plots KAT-Coder-V2.5 in green against GLM-5.1, GLM-5.2, Kimi-K2.6, and Opus 4.8 in grey. KAT-Coder leads on PinchBench and is second on SWE-Bench Pro and KAT Code Bench, but trails on Terminal-Bench 2.1 and SciCode."
  caption="KAT-Coder-V2.5 (green) against a frontier panel across six SWE and agent benchmarks: leading on PinchBench, second on repository-level SWE, and behind on terminal and scientific coding (Huang et al., 2026, Figure 1)."
/>

<Callout type="warn">
Honest caveats. **The panel and two of the six benchmarks are author-chosen.** KAT Code Bench and KAT Claw Bench are the team's *own* new benchmarks; the comparison excludes other open agentic-coding methods and reports no ablations isolating what each component (harness randomization vs. the hindsight critic vs. MOPD) actually contributes — the "16% → &lt;2%" sandbox and "0% → ~20%" hint numbers are engineering deltas, not controlled ablations. The wins are **real but scoped**: first on PinchBench, second on SWE-Bench Pro, but **behind every panel model on Terminal-Bench 2.1 and behind three of four on SciCode** — the report itself flags terminal and scientific tasks as open weaknesses. The whole stack (AutoBuilder, KwaiClawEnv, the benchmarks) is internal infrastructure, so transfer to non-standard or closed repositories is unproven, and long-horizon credit assignment is "partially addressed" but still called a challenge.
</Callout>

## The take

KAT-Coder-V2.5 is best read not as a model but as a **recipe for the surrounding machine**. Its most transferable ideas are architectural in the systems sense: verify environments by actually collecting tests (not scraping logs), recover near-misses with hints and then *strip the hints* so the data stays honest, randomize the harness so the policy learns the task instead of the scaffold, and hand the critic — but never the actor — a view of the future to tame sparse-reward variance. Set against [rollout-stability work like Routing Replay](/articles/rollout-routing-replay) and [cheaper frontier RL](/articles/frontier-rl-cheaper), the throughline is the same: at long horizons, most of the win is in the plumbing, not the loss function. Whether the fixed recipe generalizes past the team's own repositories and benchmarks — and closes the terminal and scientific gaps — is the open question; but as an account of what it takes to make a coding model *live inside a repository*, it's unusually complete.

---

*Built on the [KAT-Coder-V2.5 Technical Report](https://arxiv.org/abs/2607.05471) (Huang, Li, Xu et al.; Kwaipilot / Kuaishou, 2026). All benchmark values are quoted from the paper's Table 4 (unified Claude Code harness); the interactive diagrams are illustrations of the mechanism, not measured traces. PinchBench averages are the paper's, retrieved from pinchbench.com on 2026-07-02.*
