Abstract
Autonomous software-engineering agents must discover relevant repository context. This paper studies a local developer-agent workload in which exploration uses standard shell primitives—primarily git grep, POSIX find, and recursive regular expressions. In the benchmark's naive arm, these utilities return unranked lines and lead to full-file reads, increasing the context retained by a multi-turn loop. In the modeled loop, retained context is re-read on later turns, creating a measurable token-volume penalty while stable-prefix cache reuse remains provider- and API-dependent.
The architecture has four layers: lexical BM25 search, dense semantic expansion with a latency circuit breaker, bounded batch retrieval, and AST symbol extraction. The included five-scenario runner measures the first and third layers in its Arm A-versus-Arm B comparison. AST outline savings come from a separate public multi-trial report, so the paper does not attribute those AST figures to the five-scenario runner.
Across five canonical developer retrieval scenarios evaluated on a production codebase, the ranked-and-bounded comparison reduced estimated single-turn prompt context from 29,662 tokens to 11,746, a 60.40% direct reduction. Over the modeled 10-turn horizon, cumulative input reads fell from 296,620 to 117,460, a difference of 179,160 reads. The public QMD suite measured batch retrieval at 189.3ms versus 400.6ms for two serial fetches, while the public multi-trial report measured fleet MRR of 0.9062, Precision@1 of 81.2%, and a p50 search latency of 187.77ms. This paper reports local payload and retrieval measurements; it does not measure task success, provider API cache hits, or billed monetary savings.
Scope and questions
Thesis. Treating an autonomous coding agent as an interactive human shell can create context bloat when unranked search output is followed by full-file reads. In this workload, scored retrieval and bounded fetches reduced the measured discovery payload. The result is a local context-volume finding, not a claim about universal cost, reasoning, or task completion.
The study asks four bounded questions: what penalty a retained discovery dump creates over a multi-turn horizon; how local lexical and dense retrieval differ in latency and ranking; how AST outlines change source-inspection payloads; and how batch retrieval changes subprocess latency and output size.
The intended audience is AI systems architects, developer-tooling engineers, platform teams building MCP servers, and researchers designing software-engineering harnesses.
Retrieval architecture
- Lexical BM25 (
qmd search): Returns scored document identifiers and snippet anchors. BM25 uses term-frequency saturation and document-length normalization; the source paper gives the scoring formula and documented parameter values. - Dense semantic expansion (
qmd vsearch): Uses local quantizedEmbeddingGemma-300MandQwen3-Reranker-0.6B-Q8_0. The cited run measured 10.293 seconds, so the architecture invokes it only after lexical retrieval fails its threshold. - Bounded batch retrieval (
qmd multi-get -l 30): Fetches several targets in one call with a 30-line envelope around matched anchors. - AST outline (
ast-grep outline): Exposes source symbols before line-bounded reads. Its separate fixture report measured estimated savings of 93.3% for Python, 90.5% for agent-card YAML, and 94.5% for skill frontmatter.
The five-scenario comparison uses BM25 search and bounded multi-get. It does not execute ast-grep; the AST numbers are retained as a separate evidence line.
Benchmark setup
The canonical run used Windows 11 on AMD64 with Python 3.11.9, QMD 2.8.3, ast-grep 0.45.3, and Git 2.47+. It used a public Koality-Assured/ai-router checkout and a detached local QMD index. The runner makes no external network calls.
Five fixed scenarios cover worktree isolation, AST-grep configuration, STRIDE threat modeling, Confluence CQL synchronization, and agent cost-estimation benchmarks. Arm A runs git grep -i and reads every existing file in the scenario's fixed sample list. Arm B runs qmd search -n 5, takes up to three returned document identifiers, and fetches them with qmd multi-get -l 30.
The runner estimates tokens as ceil(characters / 3.8), estimating grep and file content separately for Arm A and search JSON and multi-get output separately for Arm B. These are workload estimates, not counts from a provider tokenizer.
Measured results
| Scenario | Arm A tokens | Arm B tokens | Reduction |
|---|---|---|---|
| Worktree isolation | 16,118 | 2,356 | 85.38% |
| AST-grep patterns | 3,804 | 2,940 | 22.71% |
| STRIDE threat model | 4,482 | 1,946 | 56.58% |
| Confluence CQL | 3,026 | 2,285 | 24.49% |
| Cost estimation | 2,232 | 2,219 | 0.58% |
| Aggregate | 29,662 | 11,746 | 60.40% |
The spread matters. The aggregate is a weighted workload total, not a per-query guarantee: the observed reduction ranges from 0.58% to 85.38%.
For the modeled 10-turn horizon, the runner multiplies each single-turn result by 10. That produces 296,620 versus 117,460 cumulative input reads, a difference of 179,160. It assumes the measured discovery payload remains present on every turn; it does not execute a live agent or model provider compaction.
| Primitive | Latency | What it shows |
|---|---|---|
git grep | 43.1ms | Fast flat matching without ranking. |
qmd search | 202.5ms | Scored lexical retrieval with structured snippets. |
qmd vsearch | 10.293s | Dense expansion and reranking with high local CPU overhead. |
multi-get | 189.3ms | 52.8% lower latency than two serial 400.6ms fetches in the cited run. |
The architecture therefore accepts some BM25 overhead to gain ranking and bounds, while using a circuit breaker before dense search. The paper does not claim that the layered path is the fastest wall-clock choice for every primitive.
Cache and worktree boundary
The benchmark does not send requests to commercial model APIs, observe cache hits, or measure billed cost. Anthropic, Google, and OpenAI document provider-specific cache controls, stable-prefix conditions, minimum lengths, and cached-token telemetry. Those sources establish what a provider can report, not what this local benchmark achieved.
Keeping the QMD index in a detached scratch/qmd-main worktree prevents local SQLite writes and index churn from dirtying the active development checkout. That is an operational hygiene invariant, not a measured token or cache result. A reproduction should record its source revision and index state.
Threats and limitations
- Dense-search latency was measured on one AMD64 CPU without AVX-512 or a dedicated GPU.
- The 3.8-character estimate varies across languages, identifiers, and indentation patterns.
- The five scenarios and sample-file lists are hand-specified, not a randomized repository sample.
- Arm A and Arm B compare captured payloads, not semantic answer quality or task success.
- The included runner does not invoke
ast-grep; AST savings come from a separate cited fixture report. - Provider billing, cache-hit rates, reasoning quality, and end-to-end agent performance remain unresolved.
- The included runner records one timing observation per scenario; the cited QMD reports have separate procedures and scope.
Conclusion and reproduction
For this public workload, ranked lexical retrieval plus line-bounded batch fetches reduced estimated discovery context by 60.40% in aggregate. The per-scenario results show why that number needs a workload label. The strongest conclusion is operational: bound search output, inspect code structure before reading broad source ranges, and keep mutable indexes out of active worktrees.
Reproduce the included comparison with:
python supporting/benchmark/run_benchmark.py \
--source-root /path/to/ai-router \
--out /path/to/output
The claim-to-evidence ledger, source log, and reproduction guide keep measured claims, primary-source facts, inferences, and unresolved questions separate.