CodeMonkeys: Scaling Test-Time Compute for Software Engineering

Ryan Ehrlich, Bradley C. A. Brown, Jordan Juravsky, Ronald Clark, Christopher Ré, Azalia MirhoseiniarXiv 2025

Abstract

Scaling test-time compute is a promising axis for improving LLM capabilities. However, test-time compute can be scaled in a variety of ways, and effectively combining different approaches remains an active area of research. Here, we explore this problem in the context of solving real-world GitHub issues from the SWE-bench dataset. Our system, named CodeMonkeys, allows models to iteratively edit a codebase by jointly generating and running a testing script alongside their draft edit. We sample many of these multi-turn trajectories for every issue to generate a collection of candidate edits. This approach lets us scale "serial" test-time compute by increasing the number of iterations per trajectory and "parallel" test-time compute by increasing the number of trajectories per problem. With parallel scaling, we can amortize up-front costs across multiple downstream samples, allowing us to identify relevant codebase context using the simple method of letting an LLM read every file. In order to select between candidate edits, we combine voting using model-generated tests with a final multi-turn trajectory dedicated to selection. Overall, CodeMonkeys resolves 57.4% of issues from SWE-bench Verified using a budget of approximately 2300 USD. Our selection method can also be used to combine candidates from different sources. Selecting over an ensemble of edits from existing top SWE-bench Verified submissions obtains a score of 66.2% and outperforms the best member of the ensemble on its own.

Introduction

While Large Language Models (LLMs) are increasingly capable at coding, training ever-larger models is becoming prohibitively expensive. A promising alternative is "test-time compute"—allocating more computational resources during inference to allow a model to "think" longer or explore multiple solution paths.

Applying this concept to real-world software engineering is challenging. GitHub issues involve massive codebases that often exceed standard context windows. Furthermore, generating numerous candidate solutions is only useful if the system can reliably identify which fix actually addresses the bug without introducing regressions. CodeMonkeys addresses these challenges by scaling both "serial" (iterative reasoning) and "parallel" (multiple attempts) compute, while introducing a robust selection mechanism to identify the optimal fix.

Methodology

The CodeMonkeys system architecture is divided into three distinct stages: context retrieval, candidate generation, and final selection.

Context Retrieval

To manage the computational cost of processing large repositories, CodeMonkeys employs a two-tier retrieval strategy. First, a relatively "cheap" local model (Qwen2.5-Coder-32B) scans every file in the repository to identify potentially relevant code. Subsequently, a "frontier" model (Claude 3.5 Sonnet) ranks these identified files to ensure the most critical context fits within a 128k token window.

Figure 1: The multi-stage context retrieval process identifies relevant files from the codebase.

Generation via State Machines

The generation phase utilizes parallel state machines to produce candidate edits. The process begins with a "Testing State Machine" that focuses on writing a reproduction test script designed to fail on the current bug. Once a test is established, an "Editing State Machine" uses that test as a guide to iteratively modify the codebase. The model refines its code based on execution feedback until the reproduction test passes, effectively scaling serial compute through multi-turn iterations.

Figure 2: Parallel state machines for generating tests and edits.

Selection

To pick the best fix from multiple parallel attempts, the system employs "Majority Voting with Tests." Every generated test is executed against every generated edit. In cases where a clear winner does not emerge, a specialized "Selection State Machine" is triggered. This machine generates new tests specifically designed to differentiate between the top candidates, ensuring the final selection is robust.

Evaluation and Results

The system was evaluated on SWE-bench Verified, a human-validated subset of 500 instances from the SWE-bench dataset. This benchmark ensures that issue descriptions are clear and evaluation tests are reliable, providing a high-fidelity measure of model performance.

CodeMonkeys achieved a success rate of 57.4% on SWE-bench Verified. The total cost for the benchmark run was approximately $2,300 USD, with the majority of the budget allocated to the iterative editing phase. Notably, the "Barrel of Monkeys" ensemble—which combines CodeMonkeys' results with those from four other top-tier agents—reached a score of 66.2%, placing it near the top of the global leaderboard.

Discussion and Key Insights

Several key insights emerged from the development of CodeMonkeys:

  • Amortizing Context Costs: By generating many parallel samples, the high initial cost of a full-repository scan is spread across many attempts, making a "read everything" approach economically viable (representing only ~15% of the total budget).
  • The Serial-Parallel Frontier: There exists a trade-off between the number of attempts and the number of iterations per attempt. The researchers found a frontier where different allocations of compute result in similar solution coverage.
  • The Selection Gap: A significant gap exists between "coverage" (the 69.8% probability that a correct solution exists in the pool) and the final "score" (57.4%). This indicates that identifying the correct solution remains a harder problem than generating it.
  • Model-Agnostic Selection: The success of the "Barrel of Monkeys" ensemble demonstrates that the selection logic can effectively combine diverse candidate solutions from different underlying models and agents.

Limitations and Future Work

Despite its success, CodeMonkeys has limitations. Context retrieval still fails to find necessary files in 7.4% of cases. Future improvements could involve leveraging a repository's existing unit test suite to better filter out regressions. Additionally, increasing diversity in generation—perhaps by informing models of previous failed attempts—could further improve coverage and overall performance.

Summary updated

BibTeX
@misc{ehrlich2025codemonkeys,
  author = {Ryan Ehrlich and Bradley C. A. Brown and Jordan Juravsky and Ronald Clark and Christopher Ré and Azalia Mirhoseini},
  title = {{CodeMonkeys: Scaling Test-Time Compute for Software Engineering}},
  year = {2025},
  eprint = {2501.14723},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.14723},
}
Figure