Manuscript Offprint

arXiv:2610.10242

TestGRAD: Evolving Test Suites via Failure Pattern Momentum for SWE-Agent Ensemble

Pengfei He, Jiayuan Zhou, Shaowei Wang, Ruiqi Pan

Abstract

SWE-agent ensembles improve issue resolution by combining candidate patches from different agents with complementary strengths. The central problem is therefore test-based selection: generate tests, execute candidate patches, and identify the best patch. We formulate this process as test-space optimization: evolving an executable repository test suite until it distinguishes competing patches. Existing test-generation methods are limited optimizers. They usually lack an explicit loss for ensemble selection, optimize through incomplete directions that mostly create new tests or delete old ones, and perform one-off generation without feedback from repeated failures.

Inspired by gradient descent with momentum, we introduce TestGRAD, a framework for automatic test optimization. TestGRAD centers on three concepts. Differential loss gives the optimizer an explicit execution-defined target: useful tests should separate candidate patches by behavior. Full CRUD gradients expand the update direction from merely creating or deleting tests to reading existing test infrastructure, creating new tests, updating stale assertions, and deleting only obsolete tests. Failure Pattern Momentum mines frequent failure sequences from memory, allowing the optimizer to avoid repeated non-discriminative directions while compressing the failure-history context. On SWE-bench Verified, TestGRAD achieves 84.2% Pass@1 with a 4-agent ensemble, outperforming the strongest baseline (80.6%) by an absolute improvement of 3.6 percentage points, while compressing failure-history context by over 100×.

Introduction

Software engineering (SWE) agents autonomously resolve repository issues by localizing faults, generating patches, and validating fixes in a live coding environment (Jimenez et al. 2023; Lingxi Authors 2025). Different agents exhibit complementary strengths: an agent that fails on one issue may still produce the best patch for another. A practical way to exploit this diversity is parallel ensembling, where multiple SWE agents generate candidate patches and a selector chooses the final patch (Se and Vert 2025).

The selector must be grounded in behavior. A natural but weak approach is to ask an LLM judge to compare candidate patches and select the most plausible fix (Augment Code 2025; Zhang et al. 2025). Without execution evidence, however, the judge sees surface plausibility rather than repository behavior and can be sensitive to presentation order (Wang et al. 2023; Zheng et al. 2024). The key to SWE-agent ensembling is therefore test-based selection: generate tests, execute every candidate patch, and use the resulting behavior to identify the correct patch.

This view turns ensemble selection into test-space optimization: the optimized object is the repository test suite, and the objective is to evolve it for better selection. This is difficult for three reasons. First, the loss is not obvious. A test that simply passes or fails is not necessarily useful for selection; even patches that pass benchmark tests can remain behaviorally divergent from developer fixes (Wang, Pradel, and Liu 2026). Second, the update direction cannot be limited to creating new tests. Useful repository tests often require reading fixtures and conventions, updating stale assertions, and deleting only confirmed obsolete tests (Mündler et al. 2025). Third, test generation is rarely solved in one step: when an attempted test is non-discriminative, the next attempt should use that failure as optimization signal rather than restart from scratch.

Inspired by gradient descent with momentum in neural networks (Polyak 1964; Sutskever et al. 2013), we introduce TestGRAD, a framework that models test-suite evolution as gradient-descent-like optimization in test space. Table 1 summarizes the analogy. A test suite is the parameter state, differential execution is the loss, CRUD edits are gradient directions, frequent failure sequences are momentum, support is the retention weight, and the LLM agent is the optimizer. In the forward pass, TestGRAD executes the current test suite on candidate patches and observes whether their behaviors differ. In the backward pass, the LLM optimizer uses this execution-defined signal and mined failure momentum to produce the next CRUD test update. The design has three components.

① Differential loss. TestGRAD makes the optimization target explicit: a useful test suite should separate candidate patches by behavior. We define the loss by execution. If the current test suite contains a differential test, meaning at least one test passes on some candidate patches and fails on others, the loss reaches zero. Otherwise, the loss remains nonzero and the failed update is used to guide the next iteration. This differs from pass-count selection (Xia et al. 2025; Gao

∗^{*}Corresponding author.

et al. 2025), which simply chooses the patch that passes the most tests. Differential loss instead searches for behavioral contrast among candidates rather than merely verifying the intended fix. It prunes candidates that are indistinguishable under the current tests and discourages selection based on a single weak pass/fail signal.

② Full CRUD gradient. TESTGRAD treats test-suite evolution as a full CRUD update rather than a Create/Delete-only pipeline. Existing test-generation methods (Xia et al. 2025; Gao et al. 2025) mainly create a new test from the issue and, at most, delete conflicting tests by name matching. This partial direction is insufficient for repository tests, which often depend on existing fixtures, setup routines, imports, assertion helpers, and tests whose expected values must be revised after the fix.

TESTGRAD therefore exposes all four directions as the test-space gradient. Read extracts repository-specific testing knowledge for reuse. Create adds new discriminative tests. Update revises stale assertions or test bodies whose expected behavior changes with the fix. Delete removes only tests confirmed obsolete. This full direction avoids shallow standalone tests, preserves high-signal tests that only need assertion updates, and prevents a correct patch from being rejected simply because an old assertion was left unchanged.

③ Failure Pattern Momentum. In numerical optimization, momentum accumulates consistent gradient information across steps and helps avoid oscillation or repeated dead ends. TESTGRAD uses an analogous mechanism for test updates. When a CRUD update produces a non-discriminative suite, the failed update is written into failure memory. TESTGRAD then mines maximal frequent failure sequences from this memory. These sequences form Failure Pattern Momentum: compact evidence of directions that have repeatedly failed. The next LLM optimizer step receives this momentum and can move away from recurring non-discriminative regions of the test-suite space. Compared with summarizing failures using another LLM call (Shinn et al. 2023) or feeding raw test-execution feedback back to the generator (Huang et al. 2023), this design is deterministic, faithful to observed failures, and compresses context by over 100×100 \times.

On SWE-bench Verified (500 instances) (SWE-bench 2025), TESTGRAD achieves 84.2% Pass@1 with a 4-agent ensemble using Minimax-m2.7, outperforming the next-best baseline (TRAE, 80.6%) by an absolute improvement of 3.6 percentage points and the single-agent baseline by 5.0 percentage points. Gains are consistent across all three base LLMs. Ablations confirm the contribution of each component: removing Read drops Pass@1 by 3.0%, removing Update by 2.4%, replacing differential loss with pass-count selection by 3.4%, removing Failure Pattern Momentum by 1.6%, and removing iterative optimization entirely by 9.2%. Contributions:

① We formulate SWE-agent ensemble selection as test-space optimization over executable repository test suites.

② We instantiate this optimization with differential execution loss and full CRUD test-suite gradients.

③ We introduce Failure Pattern Momentum, which mines

Table 1: Role-level analogy between gradient descent with momentum and test-space optimization. A one-step CRUD edit plays the role of an instantaneous gradient, whereas a high-support recurring failed edit sequence plays the role of momentum carried across attempts.

Gradient Descent with MomentumTESTGRAD
</> Parameter state. Current parameter vector θt\theta_t.</> Test suite state. Current candidate test suite yty_t.
Objective. Loss function L(θt)\mathcal{L}(\theta_t).Objective. Differential loss L(yt)\mathcal{L}(y_t) measuring whether the current test suite has produced a differential outcome.
Retention strength. β∈[0,1]\beta \in [0,1] controls how much of the previous velocity is retained.Support-based retention.The β=MinSupport threshold\beta = \text{MinSupport threshold} defines the minimum frequency a sequence must satisfy. Lowering this threshold retains more sequences and gives momentum broader influence.
Momentum. β∇t−1\beta \nabla_{t-1}. The accumulated direction from previous steps.Momentum analogue.mt=Mineβ(M)m_t = \text{Mine}_{\beta}(M). A persistent test update distilled from recurring failure sequences in memory MM, after the latest failed update has been appended.
Update with Momentum.∇t=β∇t−1+(1−β)∂L∂θt\nabla_t = \beta \nabla_{t-1} + (1 - \beta) \frac{\partial \mathcal{L}}{\partial \theta_t}.Combines instantaneous gradient with momentum to suppress noisy one-step gradients and reinforce consistent directions.Gradient analogue.∇TestGrad=Optimizer(L,yt,mt)\nabla_{\text{TestGrad}} = \text{Optimizer}(\mathcal{L}, y_t, m_t).Combines current feedback with momentum to suppress one-off noisy edits and reinforce consistent test-improvement directions.
State update. θt+1=θt−η∇t\theta_{t+1} = \theta_t - \eta \nabla_t.Test update.yt+1=yt+∇TestGrady_{t+1} = y_t + \nabla_{\text{TestGrad}}, where ∇TestGrad\nabla_{\text{TestGrad}} is a combination of CRUD operations on the original test suite.

frequent failure sequences from memory to guide iterative test evolution while compressing context by over 100×100\times .

④ TESTGRAD achieves 84.2% Pass@1 on SWE-bench Verified with a 4-agent ensemble.

References (24)