Scout-Grep Mini:
Half the Model,
None of the Blindness
Matching 4B code search quality in 2.0-second multi-turn retrieval via on-policy distillation and TreeDeCA
Published Nov 17, 2026 · 15 min read
In agentic software engineering, generating code rarely dominates end-to-end latency anymore. Frontier models can plan refactors, synthesize patches, and iterate against test suites faster than humans can review them. What slows an agent down, increasingly, is everything that happens before the first line is edited: navigating large repositories to find the exact files and lines that matter.
Offloading retrieval from the main reasoning model to a specialized search subagent keeps noise out of the main context window, but it concentrates the wait time inside multi-turn search latency. A single code search is not one model call—it is a sequential loop of five or six calls where each grep and file read depends on the last. Every hundred milliseconds added to a forward pass multiplies across the entire loop, and every slice of per-turn overhead we shave off immediately speeds up interactive coding and high-volume agent rollouts.
Today we are sharing how we shrank Scout-Grep in half—from four billion to two billion parameters. Built on Qwen3.5-2B, Scout-Grep mini cuts model weights from 9 GB to 4.4 GB, reduces average multi-turn search latency by 37%, and drops median end-to-end deployment latency on a single B200 from 3.4 seconds to 2.0 seconds—running unquantized and without speculative decoding. On the 50 held-out tasks of ContextBench Verified, it matches our 4B Scout-Grep model point for point (0.411 for both, up from 0.127 on the untuned base model).
Getting a half-size model there required solving a problem that affects anyone training small multi-turn tool agents: standard reinforcement learning raised recall by spamming cheap filename searches while destroying precision. To fix it without hand-patching rewards, we introduce TreeDeCA (Tree-aware Decision-token Credit Assignment), a parameter-free self-distillation objective that assigns credit first to the right turn via tree rollouts, and then to the exact high-entropy tokens where tool decisions are made.
Fig. 01Half the parameters, the same quality, 37% faster search
1.Why code search compounds latency
Scout-Grep exists because of a simple division of labor: a frontier model should spend its compute budget reasoning over code and writing patches, while a small, fast specialist locates the relevant context first. Because one search chains five or six sequential tool turns, per-turn inference speed dominates user-perceived latency and agent rollout throughput.
Cutting the parameter count in half shrinks the memory footprint from roughly 9 GB to 4.4 GB and immediately unlocks 37% faster multi-turn execution under identical serving conditions—dropping median production latency from 3.4 seconds to 2.0 seconds on a dedicated B200.
The catch is that the untuned base model can barely perform multi-turn repository navigation. While it can emit syntactically valid tool calls, across our 50 held-out evaluation tasks it locates just 18% of ground-truth files and 3% of ground-truth lines (0.127 ). Shrinking the model without losing search quality meant answering a fundamental training question: how do you transfer multi-step investigative judgment into a half-size policy when trajectory-level rewards are too coarse to guide it?
2.Inside our three-stage training recipe
No single training objective bridges the gap from 0.127 to 0.411. Imitation alone stalls on recall; reinforcement learning alone hacks the tool interface. Our recipe separates the problem into three stages—teaching search habits, enforcing outcome accountability, and sharpening per-token credit assignment:
| Stage | Method | Why it matters | Training scale |
|---|---|---|---|
| 1 | On-policy distillation + corrective SFT | Teach the 4B teacher’s search habits on the student’s own states; eliminate tool syntax errors | 16 updates (92 tasks) + 1 corrective round |
| 2 | Reinforcement learning (GSPO) | Push the policy to optimize end-to-end search recall against real outcomes | 44 updates (699 tasks) |
| 3 | TreeDeCA (proposed) | Route outcome credit to specific turns and high-entropy decision tokens | 60 updates (461 tasks) |
Every stage runs directly against real repositories checked out at exact commits—the model executes live grep and file-read calls, and raw tool outputs stream straight into context. Nothing is simulated or cached offline. We keep the exact reward function from our 4B Scout-Grep post, with strict zero-overlap separation between all training tasks and the 50 held-out evaluation tasks.
Fig. 02Three stages from 0.127 to 0.411
3.Stage 1: On-policy distillation builds habits
3.1Learning from the student’s own mistakes
The most obvious way to compress a 4B agent to half its size is supervised fine-tuning (SFT) on the teacher’s search logs. It completely fails. Teacher logs only show trajectories where navigation went smoothly. As soon as the smaller student searches independently, it wanders into states the teacher never visited—a weak regex, a noisy directory listing, an irrelevant file—where offline demonstrations offer zero recovery signal. When we tested SFT on 1,353 teacher turns, search quality did not budge and repetitive generation got worse.
On-policy distillation flips the loop. The student rolls out full multi-turn searches on its own. We pass those exact student-generated trajectories—mistakes included—to a frozen 4B teacher (alternating between two 4B teachers across tasks) and compute token-level distributions over every token the student produced. Rather than answering “How would a 4B model solve this from scratch?”, the teacher answers “Given the mess you just walked into, what should you do next?”
Because tool outputs are masked as observations and the student resamples fresh trajectories after every step, learning is remarkably sample-efficient: 16 updates across 92 tasks (~120K output tokens) are enough to transform the model’s behavior.
| Model | Search quality (F0.5) | File precision | File recall | Line precision | Line recall |
|---|---|---|---|---|---|
Base model (Qwen3.5-2B) | 0.127 | 0.228 | 0.181 | 0.153 | 0.033 |
| After on-policy distillation | 0.315 | 0.550 | 0.461 | 0.385 | 0.081 |
Search quality jumps +18.9 points (paired 95% CI: +13.7 to +24.0), improving 41 out of 50 tasks. More importantly, the student absorbs the teacher’s investigative discipline: 71% of its grep calls inspect matching line contents directly, and 67% of the files it cites in its final answer are files it actually opened and read.
3.2Repairing tool syntax before RL
Even after distillation, the smaller model exhibits brittle tool formatting—most commonly duplicating parameter keys inside a single call. Each malformed call burns an entire turn and injects error tracebacks into context; left unaddressed, formatting failures drown out task rewards during subsequent RL.
Rather than mixing generic SFT data, we applied Harness Adaptation via Corrective SFT, correcting errors strictly inside the states the student naturally reaches:
- Train only on the student’s own rollouts where format failures actually surface.
- Truncate at the first malformed call so downstream error messages never contaminate supervision.
- Supervise the full repaired tool call alongside valid calls to preserve structural fluency.
A single corrective round cut development-set format errors from 45 to 6. It also surfaced an insight that became central to Stage 3: inside a 150-token tool turn, almost everything is deterministic syntax—only a handful of decision tokens govern what the agent actually does.
3.3Where imitation hits a recall ceiling
At 0.315 , the distilled student is precise when it answers, but it stops short—recovering just 8.1% of ground-truth lines. Matching a teacher’s local token distribution teaches plausible next steps, not exhaustive coverage. To care about missing files, the policy has to optimize against end-to-end search outcomes directly.
4.Stage 2: Outcome RL trades reading for recall
To push coverage up, we ran outcome-driven reinforcement learning (GSPO) across 699 tasks, sampling 8 rollouts per task. We kept the exact 4B reward structure: 55% on final-answer accuracy and completeness, 35% on encountering ground-truth evidence during search, and 10% on tool-budget efficiency.
On surface recall metrics, RL worked exactly as intended—file recall jumped +15 points and line recall +18 points. Yet overall search quality stalled completely:
| Stage | Search quality (F0.5) | File precision | File recall | Line precision | Line recall |
|---|---|---|---|---|---|
| After distillation | 0.315 | 0.550 | 0.461 | 0.385 | 0.081 |
| After RL (GSPO) | 0.294 | 0.418 | 0.606 | 0.269 | 0.257 |
Precision collapsed by roughly the same margin recall gained, leaving net quality flat (−0.022, 95% CI: −0.068 to +0.023). Inspecting all 200 evaluation trajectories revealed a striking behavioral regression:
| Per-search behavior (mean) | After distillation | After RL (GSPO) |
|---|---|---|
| Total tool calls | 12.0 | 25.0 |
Share of grep calls inspecting line content | 71% | 5% |
| Duplicate calls identical to an earlier call | 0.8 | 8.4 |
| Files cited in final answer | 2.5 | 5.2 |
| Share of cited files actually read | 67% | 46% |
RL bought recall by casting a wider net, not by reading code. Tool calls more than doubled, duplicate calls surged tenfold, and 92% of grep calls switched to filename-only mode (only 5% inspected matching lines, with the remaining 3% using match counts). Instead of opening files to verify logic, the student policy sprayed filename queries and padded its final citations with broad line ranges.
This is a fundamental lesson for small tool-using agents: the failure isn’t a broken reward function—it’s coarse credit assignment. Reading code and reasoning over context is cognitively expensive for a small model; spraying filename searches is cheap. When a single scalar score is broadcast uniformly across 25 tool calls, the optimizer reinforces whatever low-effort habit correlates with hitting more ground-truth lines. Rather than playing whack-a-mole with reward penalties, we built a learning signal that pinpoints which turn and which token caused the outcome.
5.Stage 3: Credit at decision tokens
5.1Two scales of credit blur
Multi-turn tool RL suffers from credit assignment blur at two distinct scales:
- Across turns: A trajectory spans five or six turns and a dozen tool calls before receiving a single terminal reward. Standard group-relative methods (GRPO, GSPO) broadcast identical advantage to every turn—rewarding wasted searches inside winning rollouts and penalizing smart reads inside losing ones.
- Within a turn: Even once you isolate a pivotal turn, 100–200 of its tokens are zero-uncertainty protocol scaffolding (
<tool_call>,<function=grep>, parameter names, closing tags). Actual search strategy is decided at a tiny fraction of positions: the brief natural-language plan right before a tag (e.g., choosing “Let’s read…” vs. “Let’s search…”), theoutput_modeflag (contentvs.files_with_matches), the query string, or the line range.
The filename-spamming pathology from Stage 2 lives entirely at this second level: out of hundreds of tokens in a turn, a single token after output_mode determines whether the model inspects code or flies blind.
5.2Isolating pivotal turns with rollout trees
TreeOPSD (Zou et al., 2026) solves the first level by organizing rollouts into a trajectory tree. For each task, we sample root trajectories and branch alternate rollouts directly from intermediate turns—replaying shared prefixes verbatim so diverging actions from the exact same state can be compared head-to-head.
Backing terminal rewards up from the leaves gives each turn an advantage estimate , which maps to a bounded Bernoulli target :
Because the gradient vanishes once the turn’s log-probability shift reaches , repeated updates on the same batch remain stable without runaway drift. However, letting denote the log-probability change at token across a turn of length , TreeOPSD aggregates tokens uniformly:
Turn credit stops at the turn boundary—diluting gradient signal equally across XML tags and genuine search decisions.
5.3Weighting decision tokens by frozen entropy
Why do two branches from the exact same prefix end in radically different rewards? Because at a handful of uncertain positions, sampling forked onto different paths. In single-turn reasoning, Wang et al. (2025) showed that high predictive entropy cleanly identifies these “forking tokens”—and in our own 4B measurements, over half of all generated tokens had entropy below 0.01 nats.
TreeDeCA (Tree-aware Decision-token Credit Assignment) embeds this directly into tree self-distillation: the tree routes credit to the turn, and frozen sampling-time entropy routes credit to the decision tokens inside it. Letting denote token ’s predictive entropy recorded at rollout time (detached and frozen before optimization) and denote total turn entropy, we replace uniform token counting with entropy weighting while keeping and untouched:
| Component | TreeOPSD (uniform) | TreeDeCA (entropy-weighted) |
|---|---|---|
| Within-turn shift | ||
| Turn weight |
Taking the token-level gradient makes the mechanism transparent:
Boilerplate syntax tokens with receive virtually zero gradient update; optimization concentrates automatically on the exact tokens where the policy hesitated between actions.
Practically, TreeDeCA adds one line of bookkeeping (recording frozen rollout entropies ) while preserving three clean properties:
- Exact backward compatibility: Under uniform token entropy, TreeDeCA reduces identically to TreeOPSD.
- Bounded updates: Per-turn gradients still vanish at and reverse beyond it, preventing multi-epoch overshoot.
- Zero new hyperparameters: Scaling all entropies by a constant cancels out in both and . Unlike hard top-% token clipping—or teacher-entropy reweighting such as UECR-GRPO, which requires an external teacher forward pass—TreeDeCA uses continuous weights derived purely from the student’s own rollout uncertainty.
Fig. 03One 73-token turn: 10 decision tokens receive 77% of the credit
greps scores 0.09, whereas reading the target file scores 0.37. Right: across the 73 tokens of the file-read turn, 51 have entropy below 0.01. TreeOPSD gives the top 10 decision tokens just 14% of the turn’s update; TreeDeCA routes 77% of the credit directly to them.Across 36 sampled trajectories (~23,000 generated tokens), 71% of tokens have entropy below 0.01, while the top 10% hold 68% of total entropy. That uncertainty lands squarely on genuine decisions: the opening token of a search pattern averages 1.48 nats, the output_mode value averages 0.34 nats (versus a median near zero), and another spike appears in the brief pre-tool sentence where the model commits to reading versus searching before emitting a single XML tag.
5.4Results: Doubling the gain in head-to-head runs
We ran a strict apples-to-apples comparison between our implementation of TreeOPSD and TreeDeCA—starting from the exact same post-RL checkpoint (0.294), on the same 461 tasks, with identical learning rates, tree topology (4 root trajectories per task, each spawning 2 branches for 12 trajectories total), 15 rounds / 60 updates, and identical compute (~2 hours 40 minutes on a single H200, with zero objective-specific tuning):
| Checkpoint | Search quality (95% CI) | File precision | File recall | Line precision | Line recall |
|---|---|---|---|---|---|
| Post-RL starting point | 0.294 (0.240–0.346) | 0.418 | 0.606 | 0.269 | 0.257 |
| + TreeOPSD (uniform tokens) | 0.351 (0.292–0.406) | 0.552 | 0.537 | 0.280 | 0.219 |
| + TreeDeCA (entropy-weighted) | 0.411 (0.344–0.474) | 0.623 | 0.580 | 0.385 | 0.248 |
TreeDeCA doubles the improvement over TreeOPSD (+11.8 points vs. +5.8 points; paired difference +6.0 points, 95% CI: +2.6 to +9.2, winning on 33 of 50 tasks vs. 13 losses). Just as telling is how each method raises precision: TreeOPSD sacrifices 7 points of file recall by simply reporting fewer files, whereas TreeDeCA boosts file precision by +21 points and line precision by +12 points without any statistically significant drop in recall.
5.5Restoring read-before-cite discipline
Behavioral telemetry across the 200 evaluation rollouts shows why token-level credit makes the difference:
| Per-search behavior (mean over 200) | Post-Distill | Post-RL | TreeOPSD | TreeDeCA | 4B Scout-Grep |
|---|---|---|---|---|---|
| Tool calls | 12.0 | 25.0 | 11.7 | 14.6 | 10.4 |
| File reads | 2.2 | 2.1 | 0.6 | 2.9 | 2.7 |
| Searches reading zero files | 17% | 13% | 56% | 3% | 5% |
grep calls inspecting content | 71% | 5% | 8% | 38% | 48% |
| Cited files actually read | 67% | 46% | 28% | 81% | 74% |
Fig. 04TreeDeCA restores the 4B teacher’s investigative style
Both tree methods prune away RL’s redundant tool spam, cutting call volume by 40–50%. Beyond that, their behaviors diverge sharply:
- TreeOPSD does less of everything—including reading. Under uniform token credit, the easiest way to avoid bad outcomes is conservatism: in 56% of searches it never opens a file at all, and only 28% of its cited files were ever read.
- TreeDeCA reads first, then answers. It opens files in 97% of searches, inspects matching line content in 38% of
grepcalls, and actually reads 81% of the files it cites—exceeding even the deployed 4B model. Concentrating gradient updates on decision tokens directly rewired the choices between “search again vs. read” and “filenames vs. content.”
6.4B search quality in two seconds
To benchmark models on a level playing field, we locked the Quick Search harness—same prompt, read-only tools, and turn budget across 50 held-out tasks (4 rollouts per task, failures scored as zero)—and ran all checkpoints unquantized without speculative decoding under high concurrent load:
| Model | Parameters | Search quality (95% CI) | File precision | File recall | Line precision | Line recall | Mean time |
|---|---|---|---|---|---|---|---|
Base model (Qwen3.5-2B) | 2 billion | 0.127 (0.088–0.171) | 0.228 | 0.181 | 0.153 | 0.033 | 8.0 s |
| Scout-Grep mini | 2 billion | 0.411 (0.344–0.474) | 0.623 | 0.580 | 0.385 | 0.248 | 9.6 s |
| Scout-Grep (deployed) | 4 billion | 0.411 (0.354–0.465) | 0.555 | 0.646 | 0.421 | 0.274 | 15.3 s |
| Scout-Grep (experimental, undeployed) | 4 billion | 0.474 (0.401–0.541) | 0.645 | 0.630 | 0.458 | 0.386 | 27.4 s |
(Note: Absolute scores differ from our earlier 4B blog post because all models here are evaluated on the updated Quick Search environment.)
- Exact quality parity with deployed 4B: The paired difference between Scout-Grep mini and 4B Scout-Grep is −0.001 (95% CI: ±0.040), with complementary precision-recall profiles (+6.8 points higher file precision on mini; +6.6 points higher file recall on 4B).
- 37% faster under matched load: Without any serving-layer tricks, swapping the 4B model for mini drops mean search time from 15.3 s to 9.6 s.
- 2.0-second median in production conditions, with a simpler serving stack: Replicating our previous post’s single-stream B200 deployment benchmark (co-located client, 50 held-out tasks run twice), Scout-Grep mini hits a 2.0-second median end-to-end search latency (p95 under 5 seconds):
| Deployed configuration | Serving stack | Median end-to-end search |
|---|---|---|
| Scout-Grep (4 billion) | Quantized + speculative-decoding draft model | 3.4 s |
| Scout-Grep mini (2 billion) | Unquantized, no draft model | 2.0 s |
Eliminating both quantization and draft-model orchestration makes production serving dramatically simpler while cutting median latency by over a second. (The current Quick Search harness also uses five calls per search rather than six, though total generated tokens per search remain roughly unchanged.)
Clear headroom remains at larger compute budgets. Pushing the 4B model further yielded an undeployed experimental checkpoint at 0.474 (+6.2 points over mini, driven by +14 points in line recall)—but at 27.4 seconds per search, nearly 3× slower than mini, it crosses the latency ceiling for interactive retrieval. It stands instead as a concrete target for future distillation.
7.Where models stall and next steps
Cutting our search model in half taught us that distillation, outcome RL, and fine-grained credit assignment solve distinct failure modes—and exposed three clear boundaries we are tackling next:
- Entropy consumption caps training horizon: Because TreeDeCA concentrates updates on uncertain decision tokens, mean output entropy drops from 0.43 to 0.29 over 60 updates (whereas TreeOPSD stays flat around 0.42). Scaling TreeDeCA to much longer runs will require explicit entropy regularization. Theoretically, weighting by entropy also trades away exact alignment with the initial on-tree policy-gradient direction in exchange for preserving bounded targets.
- Single-seed pre-registered comparison: Due to rollout cost, TreeOPSD and TreeDeCA were each trained once with pre-committed final-checkpoint evaluation on our 50-task regression suite, where both the +6.0-point paired gain and behavioral shifts are large and statistically significant.
- Learning when to stop early: Like our 4B models, Scout-Grep mini exhausts its allocated turn budget until prompted to summarize. Teaching the policy to terminate as soon as evidence is sufficient is an immediate lever to push sub-2-second searches even lower.
When code retrieval runs in two seconds on a two-billion-parameter model without losing accuracy, repository search stops competing with reasoning for GPU memory and latency—freeing frontier coding agents to spend their context and compute on the engineering problems that actually require them.