Contract Consensus for Parallel Multi-File Code Repair

Language-model coding agents are good at fixing a bug in one place and bad at changes that span many files. When a fix requires renaming a parameter, changing a return type, or reshaping a data structure that several modules share, the agent has to keep every edit consistent with every other edit. Sequential agents lose track as context grows. Parallel teams of agents, one per file, drift apart once the shared interface starts moving. Distributed optimization solved a structurally similar problem long ago. Large problems are split into subproblems that run concurrently, each keeps a local copy of the variables it shares with its neighbours, and a coordination step repeatedly pushes those copies into agreement. Only the disagreement is communicated, not the whole problem.

We propose to carry this pattern into repository-level repair as a concrete mechanism. Worker agents fix separate clusters of code in parallel. The shared variable is an explicit, machine-checkable interface contract: function signatures, types, raised exceptions, and example input/output pairs at the boundaries between clusters. A coordinator revises the contract round by round, using only executable evidence such as type checks, import resolution, and test outcomes. It never uses agent votes. The claim is that on issues whose fix spans several coupled files, iterative contract consensus resolves more issues than either an upfront plan or a single sequential agent at the same token budget, and it does so in less wall-clock time.

Core Claim

Current multi-agent repair coordinates in one of three ways, and each fails differently.

MAGIS (Tao et al.) assigns one developer agent per file after a single natural-language "kick-off meeting". It reports 25.33% on SWE-bench Lite. Its authors state that it struggles when an issue requires sweeping changes across a dozen or more files, because agents cannot reconcile interfaces that shift during refinement.

SynFix (SynFix authors) is sequential. After an edit, it walks the one-hop neighbours of each changed entity and asks the model whether they need synchronized updates. It reports 52.33% on Lite and 55.8% on Verified with GPT-4o.

Adversarial Review (Qiu and Gill) shows that unconstrained agent discussion produces "false consensus", where agents agree on wrong fixes under conversational pressure. It fixes this with evidence-cited disagreement over a frozen, single artifact.

None of these systems keeps a persistent, checkable object that parallel workers must agree on and that is allowed to change as the fix is discovered. Our contribution is that object and the loop that updates it.

The analogy to consensus ADMM (the alternating direction method of multipliers, a splitting method in which subproblems solve locally and a dual "price" penalizes disagreement between local copies) supplies the design, not a convergence proof. Saravanos et al. give each robot copies of its neighbours' trajectories and exchange only with graph neighbours. Moehle et al. keep a feasible primal policy at every iteration, which permits early stopping with a known-good solution.

We borrow three pieces from this literature. The first is local copies of the shared interface held by each worker. The second is a residual that measures disagreement. The third is a persistent per-interface record of past violations that plays the role of the price, and is routed only to the workers who own that interface.

Written as the abstract problem we are approximating, let $x_i$ be the patch to code cluster $i$ and $f_i(x_i)$ its local failure measure (failing assigned tests, type errors). Let $z$ be the shared contract and $A_i(x_i)$ the interface that patch $x_i$ actually implements or assumes. Then

$$\min_{x_1,\dots,x_n,\,z}\ \sum_i f_i(x_i) \quad \text{subject to} \quad A_i(x_i) = z_{N(i)} \text{ for every cluster } i,$$

where $z_{N(i)}$ is the part of the contract touching cluster $i$. The consensus residual at a round is the number of boundary points where $A_i(x_i)$ and $z$ disagree, as detected by static checks and recorded runtime calls. Nothing here is convex or differentiable. The equation fixes vocabulary and tells us what to measure, namely whether this residual actually falls across rounds.

Research Program

The system has four parts.

Decomposition. We build a repository dependency graph with the line-level tree-sitter indexer from ozyyshr/RepoGraph. RepoGraph (Ouyang et al.) uses this graph only as static retrieval context. We use it to partition. After localization, we cluster the candidate edit set by coupling density so that edges cut by the partition are few. Each cut edge becomes a contract entry. This follows the logic of Narayanan et al., where decomposition pays off when subproblems are much cheaper than the whole. It differs from MAGIS by cutting along coupling rather than along file boundaries. Unlike RepoGraph, the graph is rebuilt after every merged round so that it reflects applied patches.

Workers. Each worker receives its cluster, the current contract slice, and only the failing tests whose coverage traces touch its cluster. It returns a patch plus any proposed contract amendments, each stated as a signature or type change with a justification tied to a test or traceback. Routing tests by coverage is a direct response to the context-distraction finding of Jimenez et al..

Coordinator. This step is deterministic, not a language model. It merges the patches and runs a type checker, import and arity checks, and the assigned and regression tests. It computes the per-interface residual. It accepts an amendment only if applying it lowers the total count of executable violations. Two conflicting amendments are both tested and the one with fewer violations wins. Because acceptance never depends on agents agreeing, the false-consensus failure of Qiu and Gill cannot occur at this step. Violations and rejected amendments accumulate in a per-interface ledger, our analogue of the dual price, which is fed back to the owners on the next round.

Last-green checkpoint. A round is committed only if regression failures do not increase. This follows Moehle's feasible-iterate idea and the rollback guards of Fang et al.. It directly targets the over-editing that Qiu and Gill report, and it lets us stop at any round with a patch that is no worse than the previous committed state.

The analysis side asks three questions:

  1. Does the residual decrease across rounds, or does it oscillate the way linearized non-convex ADMM can?
  2. Does the ledger change worker behaviour, measured by how often workers re-propose rejected amendments?
  3. How do gains scale with the number of coupled clusters?

The plateau that Yan et al. report for sequential compiler feedback (DSR rising from 48.57% to 52.57% over three rounds, then stalling) gives a reference shape. The hypothesis is that splitting feedback by cluster postpones that plateau on multi-file issues.

Baselines

All baselines use the same underlying model, the same localization output, the same sandbox, and a matched total token budget per issue. Each gets the same small prompt-tuning budget on a held-out slice of SWE-bench-train.

Naive reference. A single agent receives the localized files and the issue, generates a patch, and gets up to three rounds of test feedback. This is where the Yan et al. plateau predicts a ceiling.

Strongest existing method: SynFix. It is the strongest published competitor on exactly this question: dependency-aware propagation of edits across coupled code, with 52.33% on SWE-bench Lite and 55.8% on Verified as reported by SynFix authors using GPT-4o. It is also cheap, at $0.56 per issue. We will re-run it with our model, since the file does not say whether code is available and a reimplementation from the paper may be necessary. Adversarial Review's 75.2% on Verified comes from a different model setup and is not directly comparable, so we will re-run it under matched conditions rather than quote it.

Structured parallel alternative: MAGIS-style parallelism. Per-file workers coordinate through one upfront natural-language plan, plus a QA loop. MAGIS reports 25.33% on Lite (Tao et al.).

Unstructured parallel sampling: best-of-N. We draw N independent single-agent attempts at the same total token count and choose among them by the same test and type checks our coordinator uses.

Key ablations. The first uses a frozen contract: the contract is written once upfront and never revised. The second removes the ledger: violations from the current round are reported, but no history is kept. The third replaces coordinator acceptance with worker voting.

Beating SynFix means a statistically significant resolve-rate gain on the multi-file stratum, measured with a paired test over issues, at equal or lower tokens, with no loss on the single-file stratum. Beating the frozen-contract ablation is what shows that iterative consensus, rather than contract-first planning, is the active ingredient.

Why not just…?

Why not just use one long-context agent with a dependency graph, as SynFix does? This is the most serious threat. On SWE-bench most gold patches touch a single file, and there sequential propagation has nothing to lose. We expect no aggregate advantage there and do not claim one. The claim is limited to issues whose gold patch touches three or more files.

That claim rests on two gaps in SynFix's design. The first is that SynFix checks only one-hop neighbours sequentially, so a signature change that ripples two hops is invisible to it. The second is the context-distraction evidence of Jimenez et al., which suggests a single context degrades as the coupled set grows. If SynFix matches us on the multi-file stratum, the idea fails, and the stratified comparison will show it.

Why not just write the interfaces first and then fill in the files in parallel? This is the frozen-contract ablation, and it is plausible that it captures most of the benefit. If the correct interface change is evident from the issue text, planning is enough. Iteration should matter only when the right contract is discovered through test failures during the fix, the regime where MAGIS reportedly breaks down.

We will measure how often the final accepted contract differs from the initial one. We will also report gains separately for issues where it does. If the frozen contract ties the full system, we will report the method as contract-first decomposition and drop the consensus claim.

Why not just sample many full patches in parallel and pick one that passes the tests? Best-of-N uses parallel compute without coordination. On the independent-scenario heuristic, Moehle et al. prove only a K-suboptimality bound, which hints at why uncoordinated parallelism can waste compute on coupled problems. That bound concerns their linear program, not code, and is not evidence here.

For multi-file fixes, the probability that one sample gets every coupled edit right should fall roughly multiplicatively with the number of clusters, since each must independently be correct. Consensus instead lets correct pieces from different workers combine. The matched-token comparison, plotted against cluster count, tests exactly this prediction.

Why not just let the agents debate until they agree? Qiu and Gill already show that larger unconstrained teams do worse than a constrained three-agent protocol. On LiveCodeBench, the five-agent MARS baseline reached 82% against 87% for Adversarial Review. They attribute this to false consensus. The voting ablation tests whether evidence-based acceptance, rather than parallelism itself, drives our result.

Proposed Experiments

The primary benchmark is SWE-bench Verified and Lite, stratified by the number of files and of cross-file dependency edges in the gold patch. Because the high-coupling stratum in those sets is likely small, we will add a larger multi-file set filtered from SWE-bench Full and SWE-bench-train (the 19,000-instance training split), keeping issues whose gold patch touches three or more files and whose tests pass after the fix. No reported result found on Lacuna for resolve rate stratified by number of files changed, so all stratified numbers will be produced by us for every baseline.

Metrics are:

  • resolve rate;
  • regression-test pass rate on untouched tests;
  • tokens per issue;
  • wall-clock latency with workers running concurrently;
  • rounds to zero residual;
  • the fraction of issues whose contract changed during repair.

As a secondary, non-Python check of the header-coupling case POLO leaves to a single generator (Bai et al.), we will run the method on the six-project C/C++ performance suite. There the shared data-structure definitions in header files form the contract, and measured speedup under -O3 is the objective.

Four outcomes would settle the question:

  1. The gain over SynFix and best-of-N must grow with cluster count and be near zero on single-file issues.
  2. The full system must beat the frozen-contract ablation specifically on issues whose contract changed.
  3. The residual must fall across rounds on most issues rather than oscillate. If it oscillates, we will test damping by capping the amendments accepted per round.
  4. The last-green checkpoint must drive regressions on previously passing tests to at or below the naive baseline.

If the first two do not hold, the parallel-consensus idea is not buying anything beyond good dependency-aware sequential repair, and we will say so.