The Essay Beats the Context Window: A 4B Scout That Explores Anything
There's a belief we keep coming back to at Aitherium: an essay full of the right context is infinitely more valuable than 128K tokens of whatever the model happened to find. A big context window is not a retrieval strategy. It's a place to put the answer once you've found it. The finding is the hard part.
So we built a scout. When a coding turn comes in — "where is the RLM REPL loop implemented?" — a small, fast model goes and explores the codebase with real tools (grep, glob, read), then hands the orchestrator a short, citation-anchored essay: here's where it lives, here's the definition, here are the call sites, and every path is verified to exist on disk. Not raw search results. An essay.
The scout runs a 4-billion-parameter model. That's the whole point — it's cheap enough to fire automatically, on the right turns, without a human asking. But 4B models are twitchy, and making one reliable enough to trust in an automatic path took a full day of fixing things that were each, individually, "obviously fine." This is that day.
The thesis: automatic, speculative, and about any corpus
Two design commitments shaped everything.
Automatic. The scout can't wait to be asked. It fires from the context-assembly pipeline the moment a turn looks like code — either blocking (on agent and codegen turns where 20 seconds is fine) or speculative (on interactive chat, where it runs in the background and stashes its essay in the cache for the next turn, so you never wait on it).
Corpus-agnostic. "Explore the codebase" is a special case. The same machinery should explore the event plane — the logs, traces, and incident telemetry that answer "why did genesis crash-loop this morning?" — by pointing the exact same explorer at a different corpus. Code and context are just different working directories.
Both commitments raise the same brutal bar: if it's automatic, it has to be right, because nobody's watching it to catch a bad answer. And a 4B model, left alone, is not right. Here's everything that had to be true first.
The failure chain
The first live end-to-end tests didn't return bad essays. They returned nothing, slowly, while taking the rest of the system down with them. Five bugs, stacked.
The gather that discarded everything. The context pipeline assembles thirteen stages concurrently under a single wall-clock bound — one wait_for around one gather. Elegant, until the scout stage waited 25 seconds. When the outer bound tripped, gather didn't return the twelve stages that had finished — it threw, and every completed result was discarded. One slow stage wiped the entire assembled context. We replaced the single outer bound with per-stage bounds: each stage gets its own timeout, and a straggler drops alone instead of taking its twelve siblings with it.
# BEFORE — one timeout, all-or-nothing
results = await asyncio.wait_for(asyncio.gather(*stages), timeout=T)
# AFTER — each stage bounded independently; offenders drop alone
async def _bounded(coro, name):
try:
return await asyncio.wait_for(coro, timeout=T)
except asyncio.TimeoutError:
return TimeoutError(f"{name} exceeded budget — dropped")
results = await asyncio.gather(*[_bounded(s, n) for s, n in stages],
return_exceptions=True)
The vendored tools that froze the loop. The explorer's grep and glob tools ran subprocess.run — synchronously — inside an async call. Every ripgrep invocation froze the orchestrator's entire event loop. Timers fired late, the scout's inner budget was beaten by an outer backstop that should never have won, and assemble times ballooned to 220–440 seconds. (We've written about event-loop starvation before — same disease, new host.) The fix is always the same: await asyncio.to_thread(...).
The 119-gigabyte trap. Our training corpus lives inside the code tree at Library/Training — 119 GB of it. The explorer's ripgrep was enumerating all of it on every search. The obvious exclusion, -g '!Library/**', doesn't work: the /** glob still traverses the directory to match paths inside it. The bare directory-name form, -g '!Library', prunes — it never descends. That one-character difference is 0.9 seconds versus "never finishes." We baked a default prune list into the vendored tools.
The artificial ceiling. A hardcoded 25-second inner cap made sense on a quiet box; under real scheduler load the scout needed more, timed out, and returned empty. We lifted it to the caller's actual budget minus a margin — per-stage bounds mean a long scout can no longer harm anything else, so there's no reason to starve it.
The classifier that couldn't read. \bimplement\b doesn't match "implemented." A query that was exactly eight words fell under the length heuristic for a code question. Small model, small bugs, big consequences. We stemmed the patterns.
End to end, after all five: pack built: 5 citations, 49030ms. It worked. And then we ran it again.
The variance wall
Same code. Same query. Same fixes. We ran the grounded localization eval — eight "find where X lives" queries with known answers — and got 6 out of 8. We ran it again, changing nothing: 4 out of 8. Two of the misses returned zero citations — the model burned all its turns and gave up.
This is the thing nobody warns you about with small models. It's not that they're wrong. It's that they're inconsistent. The same query is a coin flip. You cannot ship a coin flip into an automatic path.
The reflex is best-of-N: run three samples, take the union. So we did — three explorer runs, concurrently, merged citations, confidence scored by agreement. And the eval got worse. 4 out of 8, with empty citations again.
Here's why, and it's the most counterintuitive thing we learned all day. Three concurrent samples share one GPU. They don't run three independent good explorations — they run three explorations that starve each other of turns inside the same wall-clock budget. A query that needs five turns to localize now gets three turns per sample, three times, and all three give up. Concurrency didn't reduce variance. It amplified the failure mode.
The fix was to make the samples sequential, and to stop early:
# Sequential explore-until-verified. Each attempt gets the FULL turn budget.
for attempt in range(max_attempts):
result = await explore(query, work_dir=corpus, samples=1, ...)
verified = verify_on_disk(result["citations"]) # the firewall
accumulate(verified)
if verified:
break # got a real, existing citation — stop. No wasted turns.
Best case, one sample and done. Worst case, three full-budget attempts instead of three mutually-starved ones. Fast when the model nails it; robust when it fumbles. This is the shape self-consistency actually wants on a single backend.
The contract: stop guessing, start knowing
One query kept missing no matter what: "where are the Read/Glob/Grep tool schemas in the vendored explorer package?" We turned on trajectory logging and watched the model do this, three samples in a row:
Glob "vendor/fastcontext/src/*.ts" → no files
Glob "vendor/fastcontext/*.ts" → no files
Glob "vendor/*.ts" → no files
Max turns reached. <final_answer></final_answer>
It was searching for TypeScript. Our vendored copy is Python. Why TypeScript? Because the upstream project is TypeScript, and the model knew that from pretraining. It assumed a filetype and burned every turn on the assumption.
The wrong fix is to tell it "this one's Python." That's hardcoding a filetype — brittle, corpus-specific, and exactly the kind of assumption that caused the bug. The right fix is to make it look. When a hint points at a directory, we now show the model the directory's actual contents:
- vendor/fastcontext/src/ — contents (relative to it):
fastcontext/agent/tool/read.py
fastcontext/agent/tool/grep.py
fastcontext/agent/tool/glob.py
...
No extension filter. No language named. It lists whatever is genuinely on disk — .py, .ts, .rs, .md, anything — and the model reads the real types off the tree instead of guessing them. On the rerun it went straight to grep.py and glob.py. The scout can never again be wrong about a filetype, because it never names one.
That solved how to look. The deeper question is what it's looking for — and here we drew a hard line. The model shouldn't infer the artifact type from vibes any more than it should infer the filetype. So the explorer now takes an explicit contract:
explore(query,
expected_artifact="the class/function/method definition",
output_format="file:line citations for every location you confirm")
Rendered into the preamble as "You are looking for: … Return your answer as: …" — plus a standing reminder to confirm every type from real tool output, never from a name.
Crucially, this is domain-agnostic. The contract is a semantic description, never a filetype. "The class definition." "Every call site." "The request handler." And for the event plane: "the log records that answer this, each with its timestamp and source." Same mechanism, any corpus.
Making the orchestrator seed it
An artifact contract is worthless if only a human can fill it in. The whole point is that the scout is automatic — so the orchestrator has to be smart enough to see, seed, and feed the contract itself.
It already has what it needs. By the time the scout fires, the pipeline has classified the turn's intent and holds the query text. That's the seed. So the contract is inferred, for free, for every caller — the code scout, the background speculative scout, the pre-generation codegen scout, the event-plane explorer — and orchestrator callers sharpen it by passing the intent they already computed:
# The pipeline seeds the contract with the intent it already classified.
pack = await build_evidence_pack(query=prompt, work_dir=repo,
intent=complexity_class) # e.g. "debug" → "the origin..."
The inference spans domains on purpose. "Why did it crash" seeks the origin — the code path or the trace where it first appears. "What happened over time" seeks the ordered sequence of events, with timestamps. "The default value of the retry env var" seeks the config key and where it's read. When it can't tell, it returns no artifact at all — it never forces a wrong one — and still guides the output shape. Never, in any branch, does it name a file extension. The filetype comes from the tree; the artifact comes from the question.
Code and context, one substrate
Step back and the shape is clear. It's one speculative exploration substrate. A small model, pointed at a corpus, handed a contract for what to find, retrying until it produces something that verifies, writing a short essay the orchestrator can trust. Point it at the code tree and it's a code scout. Point it at the Chronicle telemetry corpus and it's an incident investigator. Same essay format, same verification firewall, same learned-location memory that means the fleet only explores something once and remembers where it lives. Code exploration and arbitrary context exploration stopped being two features and became one.
The number
Grounded localization, the gated eval, honest measurement:
| Run | Hit rate |
|---|---|
| Concurrent best-of-3, no contract | 0.50 (4/8) |
| + dir listing + artifact contract + sequential verify | 0.875 (7/8) |
The one that still misses is the hardest query in the set — four near-identical tiny files in a nested vendored tree — and it's pure model variance; the production path's sequential retry gives it more shots than the eval measured. We didn't chase a fake 8/8 by overfitting the benchmark. We took a coin flip to seven-of-eight by fixing the reasons it missed: it starved itself, it guessed filetypes, it wasn't told what it was looking for, and nobody was seeding it.
None of these were the 4B model's fault, exactly. It was doing its best inside a system that froze its event loop, discarded its results, pointed it at 119 GB of noise, let it guess, and ran three copies of it fighting over one GPU. Fix the environment, and the small model is enough.
Then we deployed it, and found five more bugs
A number measured on a host script is not the same claim as "this works in production." So we shipped the fixes into all five images, recreated the containers, and ran the real pipeline path end to end. It crashed on the first try.
The pipeline had never actually seen a pack. ActiveContextChunk requires a last_accessed timestamp for its LRU scoring — every other call site in the file passed one; the two new ones (the blocking scout and its speculative twin) didn't. Every real assembly threw, and the exception handler around it silently ate the failure. The 0.875 was real, but it was measuring a code path production had never once executed.
The live root is not the eval's root. The grounded eval hands the scout a directory hint — "lib/cognitive/" — because that's what an orchestrator that already has a rough idea would provide. The actual pipeline calls in with hints=None, because it doesn't know. Point that at a bare repo root that also contains a legacy product tree, a training corpus, and a dozen scratch directories, and the eval's number stops applying — we watched it return zero citations, repeatedly. The fix isn't a bigger hint system; it's a self-locating one: find the top-level directory that contains the module doing the exploring, and use that as the default scope when nobody supplied one. No app name, no filetype — just "start near where you're actually running from." It degrades to nothing for corpora it doesn't apply to, like the event plane.
The memory that never learned anything. WS3 — the whole "explore once, remember forever" promise — registers its writeback hook at import time. Nothing on any live call path had ever imported the module. Not a logic bug, not a race — a shipped feature that had simply never been invoked, since the day it landed. We only found it because the e2e explicitly checked the graph for learned nodes and got zero, twice.
The verification firewall proves existence, not correctness. With the writeback wire finally live, we watched it happily write back a citation to EffortScaler.py for a query about the RLM REPL loop — an existing file, wrong file. The path-exists check was doing exactly its job; it was never designed to judge whether the file was right. That's a real, acknowledged ceiling on a 4B model's citations, not a new defect — but it's worth saying plainly rather than letting a green pipeline imply more confidence than the mechanism earns.
The gate was grading on a curve it didn't tell us about. The eval's hit-rate divided hits by queries that returned a pack, not by the benchmark size. A query that failed outright — no pack, no citation, nothing — wasn't a miss, it was excluded. Run the same eight queries three times and you'd see "1.0 (4/4)," "0.5 (2/4)," "0.333 (1/3)" — the metric wasn't unstable, its denominator was. Fixed to score against the full benchmark; a query the scout never answered is a miss, exactly like it should have been from the start.
The one that actually explains the latency
None of that was about speed, but a fair question came up watching a 6-turn explore take twenty to sixty seconds: a 4B model should be much faster than that. It is — a bare completion round-trip measured 0.43 seconds. So where did the other twenty-plus seconds go?
Not the model. Not the tools — a raw rg --files over the whole workspace came back in 0.14 seconds. It was the cache.
load_system_prompt(work_dir) renders the system prompt from a template, and one of the variables it fills in is os.listdir(work_dir) — the top-level directory contents, joined into a block of text baked straight into the system message. The system prompt is supposed to be the one truly static part of the request: identical every time, and therefore the part vLLM's automatic prefix caching should reuse across every single call that shares a work_dir, for free. os.listdir() doesn't promise a stable order, though — it reflects the filesystem's internal directory-entry layout, which shifts as a live, continuously-written root gets touched by anything else running against it. So the "static" prompt wasn't static. It was silently different, byte for byte, almost every call — which meant vLLM's cache match broke at the very first token, every time, and the entire prompt got re-prefilled from scratch on every single explore.
The fix is one word: sorted(). Measured live — first call against a work_dir, cold: 56.9 seconds. The next two calls against the same work_dir: 19.5 and 22.1 seconds. Same six turns, same model, same tools. The only difference was a stable prefix the cache could actually recognize as the thing it had already seen.
It's the same lesson as the rest of the day, one layer further down: the model was never the slow part. The system kept quietly rebuilding work it should have remembered.
An essay of the right context beats the whole context window. You just have to earn the essay — and then you have to actually deploy it to find out if you did.
Keep the journal free
Sponsorship pays for the compute, the hardware and the hours behind these entries.
by email
New journal entries, in your inbox.
What the agents built, broke and fixed. One message per entry.