Coding agents that fix real software bugs now come in two styles. Cheap pipelines run once: they find the likely file, write a few candidate patches, and pick one. Expensive systems loop: tests and patches are revised against each other, and reviewer agents argue before any edit is made. The expensive loops resolve more issues, but they spend that compute on every issue, including the many that the cheap pipeline already solves. This proposal builds a router that decides, issue by issue, whether to stop after the cheap pass or pay for the loop. Its signal comes from an idea in capsule networks: let several cheap candidate patches "vote", and measure whether they agree. Agreement is judged by how the patches behave when the code is run, not by how their text looks. When the votes agree, accept the cheap answer. When they split, send the issue to the expensive loop.
The bet is specific. Capsule networks are image and code models in which small units send predictions to larger units and form connections where the predictions agree. That literature learned two things. Iterative agreement helps, but it plateaus and costs latency. A single pass can often approximate the result of many iterations. We claim both lessons carry over to agentic code repair. The thing to predict is not "is the cheap patch correct?" but "will the expensive loop fix what the cheap pass got wrong?" Disagreement measured in execution behavior should predict that marginal gain better than issue-text difficulty or a simple did-the-tests-pass check.
Where the two directions meet
In capsule networks, routing-by-agreement (Sabour et al.) runs a small loop inside every forward pass. Lower-level parts vote for higher-level wholes, and connections strengthen where votes cluster. The overhead literature shows this loop is the bottleneck. STAR-Caps replaces it with a single-pass straight-through gate and scales capsules to ImageNet. Inverted dot-product attention routing makes the iterations cheap and parallel. Scalable Modular Network reports that four agreement iterations improve compositional generalization over zero iterations, but add about 17% inference time and show diminishing returns. We take a design constraint from this work rather than a method. Agreement is a useful routing signal, but routing must cost much less than the computation it gates, or it eats its own savings.
Code repair shows the same shape one level up. Agentless is a feed-forward pipeline of localization, search-and-replace repair, and patch validation. It reaches 32.00% on SWE-bench Lite at $0.70 per issue. Iterative systems go higher. InfCode co-evolves tests and patches and reports 40.33% on SWE-bench Lite with DeepSeek-V3 and 79.4% on SWE-bench Verified with Claude 4.5 Sonnet. Adversarial Review forces structured reviewer–critic consensus before edits and reports 75.2% on Verified against a 71.6% zero-shot baseline. It also uses 4.5 times more tokens, notes that review loops cause over-editing, and explicitly leaves "Adaptive AR" as future work.
Self-debugging gains saturate after one round on CodeTransOcean: 48.57% rises to 52.57% after three rounds, with most of the gain in the first. Together these results motivate the proposal. Iteration helps only a minority of inputs, and nobody routes to that minority.
The closest existing router is progress-gated dual-process routing (DPR). DPR switches an embodied agent from fast tactical edits to slow replanning after five low-progress steps, judged by a language model acting as evaluator. It reports large gains on ALFWorld over compute-matched Self-Refine, Tree of Thoughts, and LATS. We differ from DPR in three ways. First, we route between whole repair systems, not between modes inside one agent. Second, our gate reads execution behavior from a ground-truth oracle rather than a judge's progress score. Third, we train the gate to predict the benefit of escalating rather than firing on stalls. MAGIS also routes, assigning file-level subtasks to developer agents, but its plan is fixed at kickoff and every issue gets the same review loop.
Core Claim
Take $k$ cheap candidate patches for one issue. Run each against a shared pool of tests: the repository's existing regression tests plus reproduction tests generated from the issue. Group candidates whose pass/fail and output signatures match into behavioral clusters. We claim the structure of these clusters predicts the escalation gain much better than issue-text features do. The relevant structure is the share of candidates in the largest cluster, the number of clusters, and whether the largest cluster passes the reproduction tests.
The escalation gain is defined as
$$g(x) = \Pr[\text{expensive loop resolves } x] - \Pr[\text{cheap pass resolves } x],$$
where $x$ is an issue.
Low agreement can mean two different things. The candidates may be exploring genuinely different root causes, which is the multi-site, symptom-versus-cause regime that FaultLoc shows agents handle badly. Or the cheap pass may be confused in a way more iteration also cannot fix. Separating these two cases, so the router does not escalate hopeless issues, is what makes the router more than a confidence threshold.
Research Program
We first build a shared harness. Agentless serves as the cheap tier, with its $k$ samples exposed. InfCode serves as the expensive tier, with Adversarial Review as a second expensive tier. All of them run with one fixed backbone model. We use DeepSeek-V3, because InfCode reports a SWE-bench Lite number with it, so we can check our reproduction against that number. Fixing the backbone matters because the per-issue costs in the file come from different models and cannot be compared directly.
We then log, for every issue in SWE-bench-train and the evaluation sets, the cheap-tier behavioral clusters, the cheap outcome, and the expensive outcome. These logs give direct labels for $g(x)$.
The router is a small gradient-boosted or logistic model. Its inputs are the agreement features plus inexpensive context: the number of files localized, the size of the patch diff, and the issue length. It is trained on SWE-bench-train outcomes only.
Following the capsule overhead lesson, we also test an amortized single-pass variant. This router predicts escalation from the first two candidates and the localization output alone, the way STAR-Caps approximates an iterative routing loop with one pass. It tells us how much of the agreement computation itself can be skipped.
All reported costs include the router's own sampling and test execution.
Baselines
The do-nothing reference is the cheap tier alone. This is Agentless with its own reranking and regression-test selection, which already uses its samples to pick a patch. It fixes the floor on resolution and on cost, and any router must sit on a better resolution-versus-cost curve than simply running more Agentless samples. The cited reference point is 32.00% on SWE-bench Lite at $0.70 per issue (Agentless), but we compare against our same-backbone rerun.
The strongest existing method is always escalating to InfCode. It is the strongest reported system in the file: 40.33% on SWE-bench Lite with DeepSeek-V3 and 79.4% on Verified with Claude 4.5 Sonnet (InfCode). It defines the accuracy ceiling the router must approach. Beating it means one of two things. Either the router matches its resolution rate within the 95% confidence interval from bootstrapping over issues, at no more than half its token cost. Or the router exceeds it at equal cost. The second outcome could happen because skipping the loop on easy issues avoids the over-editing that review loops cause. Always escalating to Adversarial Review is a second ceiling on Verified, where it reports 75.2%.
Three routers isolate the key ingredient. Each is trained on the same SWE-bench-train logs and tuned with the same budget: an equal grid over thresholds and an equal number of feature-selection trials.
The first is a test-pass early-exit router. It escalates whenever the cheap tier's chosen patch fails the generated reproduction tests.
The second is an issue-text difficulty classifier. It uses issue length, the number of files localized, and diff size, which captures the MAGIS finding that success falls as the number of modified files grows.
The third is a random router whose escalation rate matches our router's, which gives the cost-matched chance line.
The decisive ablation compares three versions of our router: agreement features alone, context features alone, and both together. If agreement adds nothing over context and test-pass features, the central claim fails.
Why not just…?
Why not just stop when the reproduction tests pass? This is the most serious competitor. Execution is already the ground-truth oracle, so test-pass gating may capture most of the signal. Its weakness is that generated reproduction tests are written by the same model that wrote the patch. A symptom patch can pass a test that only checks the crash site, which is exactly the failure FaultLoc documents. Agreement can catch cases where several candidates pass the tests but behave differently from one another. We treat test-pass gating as a full baseline. We also report the subset where it accepts but candidates disagree, and check how often the expensive loop resolves those issues. If that subset is small, we will report that test-pass gating is sufficient.
Why not just cap the loop at one or three rounds for every issue? CodeTransOcean's saturation curve and DPR's gains over compute-matched Self-Refine both suggest that uniform caps waste compute on issues that never needed iteration. We nonetheless run InfCode capped at one and at three rounds for every issue as additional points on the cost curve. A router that cannot beat the best fixed cap on that curve has no reason to exist.
Why not just predict difficulty from the issue text, with no extra sampling? This router costs almost nothing, and sampling $k$ candidates does cost something. However, the cheap tier already samples candidates, so the agreement features come nearly for free. Static difficulty also cannot tell "hard but fixable by iteration" apart from "hard and hopeless". The three-way ablation decides this directly.
Why not just use a stronger model in a single pass? In the file, raw scale does not substitute for structure. Qwen3.5-27B beats the much larger Kimi K2.5 on FaultLoc, and DPR's gain is similar at 8B and at frontier scale. We do not test model scaling, and we say so. The router is orthogonal to the choice of backbone.
Proposed Experiments
The main evaluation runs on SWE-bench Lite (300 issues) and SWE-bench Verified (500 issues). For each system we report the resolution rate, total tokens, and dollar cost under one backbone, and we plot the full resolution-versus-cost curve by sweeping the router threshold. As a secondary over-editing metric, we report the fraction of resolved patches that touch functions outside the gold patch. LiveCodeBench serves as a cheap development testbed, using Adversarial Review as the expensive tier; it reports 87% there against 77% zero-shot.
The first decisive check is predictive. For each feature set, we measure how well it identifies issues where the cheap tier fails and the expensive tier succeeds, using the area under the ROC curve on held-out issues. Agreement must beat context and test-pass features by a margin that holds across bootstrap resamples.
The second decisive check is the Pareto test described under Baselines.
The third is diagnostic. On FaultLoc's 900 C/C++ memory-safety bugs, we test whether low agreement among candidate localizations concentrates on multi-site bugs. On these bugs, FaultLoc reports Hunk Recall falling from 55.8% to 24.3% for GPT-5.3-Codex. A positive result would show that disagreement tracks root-cause ambiguity, not just noise.
A negative result on the first check, with agreement adding nothing over test-pass gating, would be informative on its own. It would mean the execution oracle already captures what agreement measures, and that adaptive routing for code repair needs only a pass/fail threshold.
References
- Dynamic Routing Between Capsules
- STAR-Caps: Capsule Networks with Straight-Through Attentive Routing
- Capsules with Inverted Dot-Product Attention Routing
- Scalable Modular Network: A Framework for Adaptive Learning via Agreement Routing
- Agentless: Demystifying LLM-based Software Engineering Agents
- InfCode: Adversarial Iterative Refinement of Tests and Patches for Reliable Software Issue Resolution
- Adversarial Review: Structured Disagreement for Grounded Agentic Code Review
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- Within-Episode Failure Recovery in LLM Agents via Progress-Gated Dual-Process Routing
- MAGIS: LLM-Based Multi-Agent Framework for GitHub Issue Resolution
- FaultLoc: Evaluating Coding Agents For Fault Localization