GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
RecentarXiv preprint

ContextBench: A Benchmark for Context Retrieval in Coding Agents

1,136 real issues with expert-traced gold code, so you can score what a coding agent read, not only whether its patch passed. The retrieval scores did not rank agents the way solve rates did.

Breakdown by FDE Interviews · 11 min read · Updated

About the original · 2026
AUTHORS
Li, Zhu, Zhang, Feng, et al.
FROM
Nanjing University, University College London
PUBLISHED
Feb 2026 · arXiv preprint
CITED BY
33Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 19% of this breakdown.

01

The paper in one minute

Coding agents are judged by whether their patch passes the tests. That hides how they got there. An agent may stumble on a fix after reading the wrong files, or read exactly the right function and still write a broken patch. Han Li, He Ye, Zhaoyang Chu and colleagues at Nanjing University and University College London built ContextBench to score the middle of the process: what code the agent retrieved.

They pooled 4,497 tasks from SWE-bench Verified, Multi-SWE-bench, SWE-PolyBench and SWE-bench Pro. After deduplication and a difficulty filter (tasks few agents solve, with patches touching many, scattered files), 1,136 tasks from 66 repositories in eight languages remained. For each one, expert annotators traced the code the reference fix depends on (calls, inheritance, data flow) into a compact gold context. A gold context counts as sufficient if GPT-5, given only that code, produces a test-passing patch in at least one of five tries; failures get up to two more annotation rounds.

At evaluation time, every file and line range the agent reads is logged, and before submitting, the agent must declare the code it used. Both are mapped with tree-sitter to files, definition-level blocks (functions, classes) and lines, and compared with gold: recall, precision and F1, plus how early gold is found, how often the agent re-reads, and how much gold it saw but left out of its declaration.

The authors report three headline findings. Elaborate scaffolds did not retrieve better than a bash-only baseline, which they call coding agents' Bitter Lesson. Models favored recall over precision. And agents often saw the right code and then dropped it.

THE IDEA, VISUALLY
BUILDING THE GOLD CONTEXTS 4,497 tasks from 4 SWE benchmarks 3,100 after ID and embedding dedup 1,500 hard: unsolved, many files, dispersed 1,136 annotated, 66 repos, 8 languages Gold = code an expert traced from the fix, kept compact. Sufficient if GPT-5, given only that code, passes the tests in 1 of 5 tries; otherwise two more annotation rounds. SCORING ONE RUN Every read file + line range Explored union of reads Declared agent's own list vs gold, at file, block (function/class) and line level: recall, precision, F1 of the declared context; efficiency = how early gold is found; redundancy = re-reads; usage drop = gold seen but not declared. The declared context is the agent's own answer to a prompt, not a trace of what its patch used. FIVE AGENTS, GPT-5 (TABLE 2) line F1 Pass@1 mini-SWE-agent 0.312 0.472 Agentless 0.376 0.452 SWE-agent 0.208 0.490 OpenHands 0.130 0.490 Prometheus 0.231 0.512 Pass@1 axis starts at 0.40; rank correlation with line F1 −0.67 LINE RECALL VS PRECISION, MINI-SWE-AGENT (TABLE 3) GPT-5 R 0.606 P 0.301 Claude Sonnet 4.5 R 0.588 P 0.374 Gemini 2.5 Pro R 0.313 P 0.529 Devstral 2 R 0.404 P 0.485 GOLD SEEN BUT NOT DECLARED (TABLE 5) GPT-5 0.179 Claude Sonnet 4.5 0.196 Gemini 2.5 Pro 0.431 Devstral 2 0.435
ContextBench attaches expert-traced gold code to 1,136 issues and scores every file and line an agent reads. Its retrieval metrics separate models well but rank agent scaffolds almost opposite to their solve rates, and two of four models favored precision over recall despite the paper's headline.
Research notes: the problem, approach and results
1,136

issue-resolution tasks from 66 repositories in 8 languages, with 522,115 lines of gold context

≤ 0.344

line-level context F1 for every model tested on the 500-task Lite subset

0.43 vs 0.18

share of already-seen gold code missing from the declared context, Gemini 2.5 Pro and Devstral 2 against GPT-5

THE PROBLEM

SWE-bench-style benchmarks score only the final patch. A passing patch can come from trial and error or test overfitting, and a failing one gives no hint whether the agent never found the right code or found it and then ignored it.

THE IDEA

Take hard tasks from four issue-resolution benchmarks, have experts trace the code each fix depends on into a compact gold context, check it is sufficient by asking GPT-5 to patch from it alone, then record every region an agent reads and compare with gold at file, block and line level.

THE RESULT

Across five agents on GPT-5, the simple mini-SWE-agent had the best retrieval scores but was fourth of five on Pass@1. Across four models, line-level F1 stayed at or below 0.344, Claude Sonnet 4.5 led on Pass@1 (0.530), and Gemini 2.5 Pro and Devstral 2 dropped about 43% of gold code they had already seen.

02

Why it matters to an FDE

When a customer's coding agent fails on their monorepo, the first question is whether it found the right code. ContextBench gives that question a method.

Separate finding from fixing. Log every read, compare with the code a human says matters, and you know whether to work on search (indexes, tools, repository maps) or on reasoning and patch generation.

Watch the gap between seen and used. Two models in this paper lost over 40% of relevant code they had already read. That points to context management, not search.

Retrieval scores are not outcomes. The best-retrieving scaffold was fourth of five on solve rate. Use retrieval metrics to diagnose a given agent, and keep the end-to-end test suite as the measure of success.

Building gold contexts is expensive. About 40 minutes of expert time per issue. For a customer, 30 to 50 annotated issues from their own repository is a realistic diagnostic set.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦2 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    Construction, metrics, the main tables and misreadings to avoid

    Free account
  2. 04How it works

    Task selection, annotation and verification, context tracing, and the metric definitions

    Premium
  3. 05The numbers that matter

    The agent comparison, the model comparison, retrieval patterns, dynamics and robustness

    Premium
  4. 06Try it yourself

    Compute every ContextBench metric on a toy trajectory, then check the paper's tables

    Premium
  5. 07Where it breaks

    Self-reported context, the gold-context assumptions, internal inconsistencies and coverage

    Premium
  6. 08Using it on a deployment

    Building a retrieval diagnostic for a customer's coding agent

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →