Large-Codebase Coding-Agent Failure Patterns (Sourcegraph Five)¶
Five repeatable failure shapes coding agents exhibit once a codebase passes roughly 400,000 lines — recognise each by its transcript signature before shipping the patch.
The Sourcegraph CodeScaleBench study scored 1,281 agent runs across 40+ open-source repositories in 9 languages and isolated five recurring failure patterns (Sourcegraph, 2026-05). Each is a transcript signature a reviewer can spot before merge.
When this applies¶
Apply it only when all three hold (Sourcegraph, 2026-05): a codebase above ~400,000 LOC; a discovery-bound task where the agent must find which files to touch; and multi-file or cross-repo scope (a +0.209 F1 delta against +0.085 single-repo). Single-file edits and hand-curated lists bypass the patterns.
The five patterns¶
Each is a transcript signature paired with a remediation (Sourcegraph, 2026-05):
- Lost in the Codebase — the agent spends its timeout on
read/globchains with no edits. Fix: code search and indexing (+0.259 reward delta, 400K–2M LOC band). - Wrong File, Wrong Symbol — it picks the wrong symbol among dozens of similar matches. Fix: structural navigation (go-to-definition, find-references) resolves ambiguity that grep cannot.
- Partial Completion — it edits some files and misses others — overlapping premature completion but rooted in discovery failure, not verification skip. Fix: hybrid keyword, semantic, and structural retrieval, the most contested remediation (see below).
- Tool Thrashing — Sourcegraph saw 96 calls against an optimal of 5. The same signature surfaces in autocompact loops that refill context within a few turns of compaction (anthropics/claude-agent-sdk-python#958). Fix: task-aware retrieval.
- Context Overflow — it reads whole files, diluting signal even after finding the right ones — the infinite context anti-pattern triggered by discovery. Fix: fetch the function, type, and call site, not the file. All five remediations together: file recall 0.127 → 0.277, F1@5 0.099 → 0.262, 38% shorter runtime, 30% lower cost (CodeScaleBench).
Why it works¶
All five share one cause: the working set exceeds what context plus search can carry. Below ~400K LOC the model holds it implicitly; above it, discovery degrades. Code intelligence moves that indexing outside the model — precomputed import graphs, symbol tables, and reference chains let it retrieve rather than search (Sourcegraph, 2026-05). A 2026 study calls this the "Navigation Paradox": larger context windows do not remove the need for structural navigation, because architecturally critical but semantically distant files fall outside the model's attention without an index (Zylos Research, 2026-04).
When this backfires¶
- Semantic retrieval for Partial Completion is contested. Claude Code, Cursor, and Devin dropped vector-DB RAG for agentic search, which beat it on real code (SmartScope, 2026; MindStudio, 2026). Hybrid retrieval is one answer among several.
- Vendor-study framing. Sourcegraph sells the remediation; a strong agentic-search harness, of the kind Cursor and Devin adopted, may close the gap without indexing.
- Polyglot or build-broken repos. Structural navigation needs a working build — references degrade silently when compilation fails or no unified cross-language index exists.
- Task restructuring beats infrastructure. Per-repo PRs or scoping to one component often cost less than indexing a monorepo.
Example¶
A reviewer reads an agent transcript on a 1.2M LOC monorepo and observes:
[turn 7] glob "**/User*.java" → 287 matches
[turn 8] read User.java → 4.2 KB
[turn 9] read UserService.java → 8.7 KB
...
[turn 24] read UserMapper.java → 3.1 KB
[turn 25] edit UserService.java → patch landed
[turn 26] declare task complete
Three patterns are visible in one transcript:
- Lost in the Codebase at turns 7–24: 17 read calls without a single targeted lookup.
- Wrong File, Wrong Symbol at turn 25: the agent edited
UserServicewhenUserAccountService— also in the match set — was the change site for the bug report's "user account creation." - Partial Completion at turn 26: the service-layer patch missed the matching repository and controller; three subclasses still reference the old contract.
A reviewer who spots these signatures stops the PR. They either ask the agent to widen the change set or hand it find-references on the changed signature to enumerate the affected sites.
Key Takeaways¶
- The five patterns — Lost in the Codebase, Wrong File / Wrong Symbol, Partial Completion, Tool Thrashing, Context Overflow — are sourced from 1,281 agent runs across 40+ repos and surface as observable transcript signatures (Sourcegraph, 2026-05).
- The catalogue applies above ~400K LOC and to discovery-bound, multi-file tasks. Below that, standard tools suffice.
- The mechanism is shared: the agent's working set exceeds what context plus naive search can carry, so externalised indexing replaces failed implicit search.
- Code intelligence on the recommended band delivered +0.259 reward delta, file recall 0.127 → 0.277, and F1@5 0.099 → 0.262 (CodeScaleBench).
- The semantic-retrieval remediation for Partial Completion is contested — Claude Code, Cursor, and Devin dropped vector-DB RAG in favour of agentic search (SmartScope, 2026).
- Use the patterns as a transcript-review checklist; treat the specific Sourcegraph stack as one remediation among several.
Related¶
- Whole-Codebase Visibility as a Migration Prerequisite — the upstream scoping check that decides whether a migration needs whole-codebase visibility infrastructure to prevent the Partial Completion entry in this catalogue.
- Five-Failure-Layers Diagnostic — complementary layer-attribution ladder; this catalogue names behavioural symptoms, the diagnostic names the harness layer responsible.
- Premature Completion — verification-skip failure that overlaps with Partial Completion's transcript signature; root cause differs.
- The Infinite Context — the deliberate version of Context Overflow; same attention-dilution mechanism, different trigger.
- Refactoring Runaway — adjacent multi-file failure where the agent does too much rather than too little.
- Comprehension Debt — the human-side consequence of agents that ship partial completions through merge without the team noticing the gap.