How context building affects generated code
The same coding tasks, the same model and eight ways of building its context, from no repository at all to an agent that explores with tools. 440 final-round runs: thinking on, a cold prefix cache before every run, one sample per configuration.
Pass rate by context level
Every bar is one configuration over its tasks (27 runs = the 20 tasks, 7 of them on both repos; L0 and L1-L2 run each task once, on its smallest repo). PASS: a valid answer and every hidden test passes. FAIL: a valid answer, a hidden test fails. Grey: no accepted answer, or the output limit was hit. Hatched (n/a): tasks the level doesn't run, so every bar is on the same scale.
| Configuration | Runs | PASS | Reuse | Repo tests kept | Judge rank | Input | Output | Seconds |
|---|---|---|---|---|---|---|---|---|
| L0 | 2 | 1 | – | 1/1 | 0.27 | 1.1k | 21.2k | 545 |
| L1 | 20 | 6 | 0/10 | 6/6 | 0.63 | 1.2k | 9.9k | 266 |
| L1 +hint | 20 | 7 | 2/8 | 6/7 | 0.63 | 1.3k | 8.5k | 225 |
| L2 | 20 | 10 | 4/10 | 10/10 | 0.47 | 2.2k | 6.1k | 151 |
| L3 | 27 | 23 | 12/12 | 23/23 | 0.26 | 41.7k | 4.9k | 148 |
| L4 bm25 | 27 | 21 | 12/13 | 21/21 | 0.25 | 2.4k | 5.6k | 120 |
| L4 embed | 27 | 19 | 9/13 | 19/19 | 0.26 | 2.0k | 7.2k | 172 |
| L5 bm25 task_vs_code | 27 | 18 | 9/13 | 18/18 | 0.38 | 2.5k | 7.7k | 191 |
| L5 bm25 model_queries | 27 | 21 | 10/13 | 20/21 | 0.29 | 3.4k | 6.2k | 162 |
| L5 embed task_vs_code | 27 | 22 | 10/12 | 21/22 | 0.26 | 2.2k | 7.1k | 160 |
| L5 embed task_vs_code +hint | 27 | 19 | 11/13 | 19/19 | 0.28 | 2.2k | 7.0k | 160 |
| L5 embed model_queries | 27 | 21 | 10/13 | 21/21 | 0.33 | 3.4k | 9.3k | 220 |
| L6 | 27 | 19 | 13/13 | 19/19 | 0.36 | 9.7k | 6.2k | 169 |
| L6+docs | 27 | 20 | 13/13 | 20/20 | 0.38 | 11.5k | 4.7k | 116 |
| L7 grep | 27 | 25 | 12/12 | 25/25 | 0.24 | 22.5k | 3.8k | 94 |
| L7 hybrid | 27 | 25 | 12/12 | 25/25 | 0.26 | 21.6k | 3.6k | 93 |
| L7 rich | 27 | 21 | 12/12 | 21/21 | 0.30 | 26.9k | 4.9k | 127 |
| L7 selective | 27 | 24 | 12/12 | 23/24 | 0.23 | 31.4k | 3.9k | 116 |
Reuse: reuse tasks where the hidden spy saw the needed helper called. Repo tests kept: passing runs whose patch also keeps the repository's own test suite green. Judge rank: mean share of the other candidate patches the blind judge ranked above this configuration's patches (0 = always best, lower is better). Input, output, seconds: medians per run.
What the model saw of the helper decides whether it reuses it
| Needed helper in context as | Reused, thinking on | Reused, thinking off |
|---|---|---|
| full source | 122/124 (98%) | 114/125 (91%) |
| a call site | 12/14 (86%) | 8/11 (73%) |
| signature only | 26/26 (100%) | 5/20 (25%) |
| not seen | 3/40 (8%) | 1/32 (3%) |
With the full source in context the helper is almost always used. With thinking on, a bare signature (the L6 repository map) is enough too; with thinking off it mostly wasn't, the model asked to look first instead of answering. When the helper isn't in the context at all, the model writes its own version.
What we expected and what happened
| Expectation | Verdict | Evidence (final round) |
|---|---|---|
| Reuse depends on whether the helper's code is visible. | held | Full source 122/124, signature 26/26, not seen 3/40. |
| An agent with tools matches the whole repo at a fraction of the input. | held | L7 grep 25/27 vs L3 23/27; median fresh input per run 15k vs 42k. |
| Model-written search queries beat changing the search engine. | partly | With BM25, model queries 21/27 vs task text 18/27; with embeddings the task text did as well (22/27). |
| A repository map of signatures is enough to write the change. | with thinking | L6 19/27 with thinking, 6/54 without (thinking off, the model asked to see code instead of answering). |
| Thinking matters most when the context is thin. | held | Largest gains at L6 (6 → 39) and L1 (6 → 13); smallest at L3 (21 → 23). |
| Richer agent tools and a self-managed working set help. | not on repo M | rich 21/27, selective 24/27 vs grep 25/27; M's files are small, so there's little to save (repo L tests this next). |
| Documentation drift (the trap) is caught only by levels that show and check the helper's body. | held | Reused and fixed only at L4 and L7; the signature-only levels (L6) trusted the docs. |
Thinking on vs thinking off
The same 440 configurations with and without thinking. Thinking costs about 12× the output tokens (665 → 7,701 per run). What it buys is mostly answers that work at all: with thinking off a third of the runs produced no usable code or code that doesn't import. Those failures are exactly the ones a harness that runs tests would catch and could retry. The silently wrong answers, whose repo tests pass, are as common either way. Only tests that cover the behaviour catch those.
| Outcome | Thinking off | Thinking on |
|---|---|---|
| PASS | 212 (48%) | 322 (73%) |
| No usable answer (any harness notices) | 84 (19%) | 4 (1%) |
| Code doesn't import (any test run catches it) | 63 (14%) | 26 (6%) |
| Wrong; the repo's own tests fail (a test loop would flag it) | 9 (2%) | 12 (3%) |
| Wrong; the repo's own tests pass (silent) | 72 (16%) | 76 (17%) |
| Level | PASS, off | PASS, on | Change |
|---|---|---|---|
| L0 | 0/2 | 1/2 | +1 |
| L1 | 6/40 | 13/40 | +7 |
| L2 | 7/20 | 10/20 | +3 |
| L3 | 21/27 | 23/27 | +2 |
| L4 | 30/54 | 40/54 | +10 |
| L5 | 75/135 | 101/135 | +26 |
| L6 | 6/54 | 39/54 | +33 |
| L7 | 67/108 | 95/108 | +28 |
No level could run code, so nothing told the model it was wrong. With a test loop, thinking off would likely close part of the gap, at the cost of retries. Latency isn't compared here: the thinking-off round ran 4 requests at a time on a warm cache.
Latency
Final round only: one request at a time, cold prefix cache, FP8 (vLLM, TP=2, kv auto, MTP speculative decoding: 4 draft tokens).
| Level | <1 min | 1-3 min | 3-10 min | >10 min | Median s | Minutes per PASS |
|---|---|---|---|---|---|---|
| L0 | 0 | 0 | 1 | 1 | 545 | 18.2 |
| L1 | 5 | 10 | 17 | 8 | 257 | 17.5 |
| L2 | 5 | 6 | 8 | 1 | 151 | 7.5 |
| L3 | 4 | 13 | 10 | 0 | 148 | 3.1 |
| L4 | 12 | 17 | 22 | 3 | 164 | 4.6 |
| L5 | 29 | 42 | 61 | 3 | 169 | 4.8 |
| L6 | 7 | 24 | 21 | 2 | 140 | 4.3 |
| L7 | 29 | 53 | 24 | 2 | 110 | 2.6 |
Minutes per PASS: all time spent at that level divided by its passing runs. Thin-context levels think longest (L1 runs often think for 10k+ tokens); the agent is the fastest per pass.
Cost
| Level | Input / run | Cached / run | Output / run | Tokens per PASS | $ per 100 PASS, open-weights host | $ per 100 PASS, frontier API |
|---|---|---|---|---|---|---|
| L0 | 1.1k | 0.0k | 21.2k | 44.6k | $3.44 | $64.26 |
| L1 | 1.3k | 0.0k | 12.9k | 43.5k | $3.25 | $60.60 |
| L2 | 1.9k | 0.0k | 8.4k | 20.7k | $1.43 | $26.44 |
| L3 | 31.6k | 0.0k | 5.4k | 43.5k | $1.25 | $20.69 |
| L4 | 2.1k | 0.0k | 7.9k | 13.5k | $0.91 | $16.80 |
| L5 | 2.7k | 0.0k | 8.3k | 14.8k | $0.96 | $17.80 |
| L6 | 8.3k | 0.0k | 7.2k | 21.5k | $1.03 | $18.40 |
| L7 | 26.8k | 11.3k | 5.3k | 36.6k | $1.10 | $18.27 |
Illustrative prices, not quotes: open-weights host: $0.20 input / $0.80 output per million tokens; frontier API: $3.00 input / $15.00 output per million tokens. Cached input is counted at the full price here; with prompt caching the agent's repeated prefixes (the "cached" column) would cost less.
Richer tools and a self-managed working set
| L7 variant | PASS | Reuse | Input | Cached | Tool calls | Seconds |
|---|---|---|---|---|---|---|
| grep | 25/27 | 12/12 | 22.5k | 7.2k | 13 | 94 |
| hybrid | 25/27 | 12/12 | 21.6k | 7.2k | 12 | 93 |
| rich | 21/27 | 12/12 | 26.9k | 11.3k | 11 | 127 |
| selective | 24/27 | 12/12 | 31.4k | 14.3k | 11 | 116 |
grep and hybrid: grep, file reads, references (hybrid adds semantic search).
rich: the same tools, richer (search hits with source, line ranges, read a function by name).
selective: rich plus drop, which removes earlier results from the conversation. On repo M the richer
tools didn't help: the files are small, so reading whole files is cheap, and the model rarely used
read_symbol (14 calls against 246 file reads). With thinking on,
18 of 27 selective runs dropped something, but the context saved was small:
4,734 tokens dropped and 8,670 input tokens avoided in total, about
1.0% of selective's input. Repo L (169k tokens, files and functions hundreds of lines
long) is built to give these tools something to do.
Judged code quality
A blind judge (agy, rubric v2) compared all candidate patches of a task side by side, without knowing how any was made. Its correctness score agrees with the tests almost everywhere: 114 failing runs got a low score and none a high one; 307 passing runs got a high one. The 15 passing runs it scored low are where the hidden tests miss something.
| Judge: correctness 4-5 | Judge: 1-3 | |
|---|---|---|
| Hidden tests pass | 307 | 15 |
| Hidden tests fail | 0 | 114 |
Patch coverage: of 322 passing patches, 6 had less than 80% of their changed statements run by the hidden tests. 4 passing patches broke the repository's own tests (the regression check). No run, at any level, added tests of its own: the prompt never asks for tests (0 runs did).
How the model fails
Trusted the documentation
trap-001: format_weight documents
"lb" but returns kg. The repository map showed only the signature and docstring; the patch called it with "lb".
Reused and fixed it
The agent read the helper, saw the missing branch,
fixed packaging.py and reused it from the label code.
Right fix, unrelated edit
Fixed the helper correctly, then gave a dataclass field a default for no reason; the module no longer imports.
L3 · trap-001 · MCorrupted output
Correct fix, but duplicated tokens garbled a line
(format_weight(weight_g(weight_g, …): a syntax error. Seen in about 2% of final-round answers.
Passed, but broke the repo
Hidden tests pass, the repository's own tests don't. 4 such runs in the final round.
L1 +hint · reuse-004
L5 bm25 model_queries · convention-003
L5 embed task_vs_code · convention-003
Thought past the output limit
With no context at all, the model reasoned until it hit the 32k output limit and never wrote the code.
L0 · control-001Used dead code
The patch imports from the old, unused common/
package (named like the canonical place). 2 final-round runs.
L5 bm25 model_queries · reuse-001
L5 embed model_queries · reuse-001
How sure we are
- One model, one sample per configuration. Repeats in the development round flipped about 1 run in 5, roughly ±3 per 13 runs of a configuration: small differences between configurations are noise.
- One synthetic repository (two sizes) written for the experiment; real repositories are messier. Repo L, larger and older, comes next.
- One trap task. The judge is an LLM; its scores agree with the tests but it can share the model's blind spots.
- No level could run code. Agents with a test loop would recover some failures (see Thinking on vs off).