---
title: "WarpGrep: Fast, Parallel Code Retrieval with RL"
url: "https://www.morphllm.com/blog/fast-context-rl-retrieval"
description: "How we trained WarpGrep, a fast context model specialized in doing the dirty work of code search, using highly parallel code retrieval that matches frontier coding models while taking 5x less time"
date: "2026-01-08"
author: ["Dhruv Bhatia","Dat Quoc","Tejas Bhakta"]
---
# WarpGrep: Fast, Parallel Code Retrieval with RL

![Breadth + Depth](/breadth.jpeg)

<div align="center" style={{ fontSize: '1.05em', color: '#555', marginTop: '-1.2rem' }}>
  <em>Why Morph's Parallel Agentic Search is Better than Sequential Search</em>
</div>

## Semantic search gives you a map when you need a scout

If you've watched a coding agent work for any length of time you've seen it happen. It knows precisely what it wants. It just can't find where that thing lives, and it'll happily spend a third of its turns and a good chunk of its token budget wandering the tree looking.

The reflex is to reach for semantic search. You embed the codebase, embed the query, and take the nearest neighbors back. That's a decent way to get breadth out of a single call, since you're pattern-matching against the whole repo at once. But it's causally blind. It will not explain why function X calls function Y, and it has no idea how a request travels from the API handler down into the database, because those relationships aren't in the geometry it's searching.

Which is fine when the question is "what exists and roughly where." A lot of the questions aren't that. "Where's the auth middleware that checks JWT expiration" is a question you answer by following a trail, taking a guess, checking it, and doubling back when the guess was wrong. A map won't do that for you. You want something closer to a scout.

There's a second problem with going semantic-only, and it's the one that quietly wrecks output quality. The retrieved files are all almost right, so the model's working memory clogs with near-misses, its answers get mushier, and latency creeps up the whole time. Every file you pull in is more tokens and, worse, more attention spent, and at inference time attention is fixed. You can't buy more of it. So the context window ends up being the thing everything else depends on, and keeping it clean is most of the job.

## Breadth in space, depth in time

WarpGrep is the small sub-agent we built for that job. It does one thing, which is find the exact code fast enough that the main model never stops working to go rummage.

An embedding lookup ranks the whole repo once and hands back the top of the list. WarpGrep keeps reasoning while it retrieves, and that's the entire difference between the two. It can put up to 8 tool calls in the air inside one turn, so you don't wait on a single embedding query to resolve. You've got several guesses outstanding at the same instant. A grep here, a glob there, a directory listing, none of them blocking the others.

Give it 4 turns of that and it can chase something across the codebase. Turn one it hits the handler. Turn two it traces what the handler calls into. Turn three it spots that both of those route through the same utility. Turn four it comes back with the line ranges nailed down. No similarity score anywhere in there. It's pulling a thread: the auth check is here, so where does the token get minted, go find out.

## Why a sub-agent beats the main model doing it

When you read a function you use it and then you forget it, and that forgetting is doing real work. The model doesn't forget. Whatever it opened is still in the context window right up until the run ends, still weighing on attention. This is the thing that trips people up when they first watch a strong model flail. It'll untangle a genuinely nasty bug and, in the same trajectory, half-drown itself in the twenty loosely-related files it read to get there.

Stick a retriever in front of it and most of that goes away. The main agent sees the files that survived the search and none of the twenty that got opened and thrown out. It's faster too, since an 8B model firing searches in parallel beats Claude picking through the repo one call at a time, and those search tokens landed on the retriever's bill instead of eating into the reasoning you're paying for.

Only one thing in this whole setup is genuinely scarce. It's the main model's context window, and everything above exists to keep from spending it.

## How we built it

### Dataset creation

The seed was SWE-Bench-style data, and we gathered a few hundred more real repos around it. Every query we rewrote into "how / where / what" phrasing, since that's what forces a multi-hop search out of the agent. A literal query just resolves to one string match and the agent learns nothing from it. Then came the part that mattered most, which was stratifying the repos hard enough that no one kind of problem could dominate the signal. Sizes went from 200 files up past 10k. The languages were TypeScript/JavaScript, Python, Go, and Rust. Queries ranged over symbol lookup, behavior tracing, routing and config, and cross-file data flow, and difficulty climbed from single-file cases up to multi-file ones that need tight line-range precision.

Ground truth is a set of `(file, [start, end])` spans. We salted in hard negatives so the reward would actually pay for precision, near-miss files and off-by-N line windows that look right until you check them. And every repo got version-locked, so a label still points at the same code weeks after we wrote it down.

The objective is weighted F1 with β=0.5, scored jointly over file retrieval and line-range retrieval. Precision carries the weight on purpose. If the agent misses a file, the main model can go back for it. If the agent buries the main model in junk, that context is already spent.

### Training: the RL loop

The policy emits tool calls. The environment returns tool outputs. The terminal reward is weighted F1 against ground truth. Run that loop long enough and the agent picks up four habits:

- Spend all 8 parallel calls per turn, and make the guesses different from each other
- Kill dead ends fast to save the 4-turn budget
- Stop once the next call stops buying anything, at a threshold it learned rather than one we set
- Return tight line ranges, not whole files

One result surprised us. Cap the output length and the agent starts writing cleverer greps, but total performance drops. Plain F1 with line-based relevance got us a working MVP. Getting the last nine of reliability took a lot more care in shaping the reward.

## Making RL compute-efficient

RL is a compute hog to begin with, and tool-use trajectories make it worse than usual, because every single step has to run real code before you're allowed to score it. Getting the efficiency back took a handful of tricks.

### The base setup

Here's the naive version. You run inference on the GPUs, grade what comes out, push a weight update from the scores and logprobs, and go around again. What kills you is the switch itself. Every GPU is constantly flipping between training and inference, and they end up sitting idle more than they compute.

### Split the resources

So don't make them flip. Inference gets its own GPUs, the rollouters, and they generate flat out and never stop. Training gets a separate pool that just drains a queue of finished samples. Once nothing changes modes, the rollouters stop pausing and so do the trainers.

### Stream mini-batches

There's also no reason to wait around for a whole batch. Each rollout goes to the trainer the instant it lands. It's an improvement, but the sync barrier is still there underneath it. The trainer keeps blocking until it has enough samples, and then, right when the weights sync, it's the rollouter's turn to wait.

### Controlled staleness

Idle rollouter GPUs are exactly what we're trying to avoid, so here's the trade we made: let the training data go a little stale. The rollouter runs straight through several gradient steps rather than syncing every batch, and importance sampling covers the drift its data picks up along the way. Above a staleness threshold of zero, a rollouter puts out `trigger_parameter_sync_step × ppo_mini_batch_size` samples before a sync fires. Clip the importance weights at 5 per token and variance stays in line. The one number worth watching is effective sample size, and it barely budged; it held near 0.99 even with staleness cranked up to 0.5. So we bought 1.6× throughput for almost nothing, and whatever it cost in sample efficiency stayed below what we could measure.

Long sequences are the next wall. Nothing syncs until the slowest rollout in the batch finishes, and that tail is brutal. Prefill-heavy workloads like ours got off easier than decode-heavy ones would, though not by much, so our first fix was `sleep()` and `resume()` in vLLM. A worker due for a sync no longer had to discard its half-finished sequences; it kept the KV cache, took the weights, resumed. On the long sequences that was worth 2.35×.

The version we actually ship, PipelineRL, drops the pause entirely. Weight deltas travel over NCCL into workers that never once stop decoding, and no GPU-second goes to waste. The cost lands in the loss. A worker keeps generating right through a weight swap, so one sequence comes out half from step t and half from step t+k. Its first hundred tokens were sampled by the old policy. Its tail by the new one. Treat that as a single policy and the loss reads the seam as a decision the model made and rewards it, which gives you garbage gradients. Token-level importance weighting with a discount is what fixes it, the discount trusting those early stale tokens a little less than the tail.

## Results

![WarpGrep Benchmarks](/compare.png)

| Metric | WarpGrep | SWE Grep | Claude Haiku | Gemini Flash |
|--------|----------|----------|--------------|--------------|
| **F1 Score** | **0.73** | 0.72 | 0.72 | 0.66 |
| **Avg Steps** | **3.8** | 3.7 | 12.4 | 10.8 |

WarpGrep lands **0.73 F1** in **3.8 steps**. Claude Haiku takes 12.4 steps to reach the same neighborhood; Gemini Flash takes 10.8. About a third of the steps for the same answer.

The edge holds up in big repos. Past 1,000 files the speed gap stays, complex multi-file questions still finish inside the 4-turn budget, and because the main agent only ever sees the relevant slices, the prompts downstream of it stay short.

On long-horizon tasks we measured a **40% speedup** in end-to-end completion and a **70% reduction in context rot**, the slow decay you get when irrelevant context piles up across a run.

---

**Related reading:**
- Cognition's SWE-Grep: [cognition.ai/blog/swe-grep](https://cognition.ai/blog/swe-grep)
- Efficient RL with staleness: [arxiv.org/pdf/2509.19128](https://arxiv.org/pdf/2509.19128)

---

We're hiring for a variety of roles. [DM us](https://x.com/morphllm) if you're interested in working on RL problems.
We're not trying to compete on the frontier. We build specialized models for code operations that make codegen agents more productive.
