TL;DR
Most coding benchmarks ask a model to write a short, self-contained function. Real software work means finding a bug in a large project and fixing it across several files. SWE-bench collects 2,294 real GitHub issues from 12 popular Python projects, pairs each with the pull request that fixed it and the tests that prove the fix, and scores a model by whether its generated patch makes those tests pass. When the paper was written, the best model resolved about 2 percent of the issues.
Builds on: Retrieval-Augmented Generation, BM25, Unit Testing, Fine-Tuning · Leads to: repository-level coding evaluations and agent systems that are scored by running the project's own tests
Why it mattered
Language models were being sold as coding assistants, yet the benchmarks used to measure them were small and clean. A model could look strong by writing a function from a docstring and still fail on a real bug report in a large codebase. SWE-bench made that gap measurable. It also made the task continually renewable: new issues can be collected from any Python repository, so a model can be tested on problems created after its training data ends.
Later coding agents and leaderboards adopted the same design: give the model a repository and an issue, and check the result with the project's tests. The paper also released a training set and two fine-tuned open models, which showed what open systems could and could not do on the task.
The problem
Think about what a real bug fix needs. An issue is often a long report, about 195 words on average in SWE-bench, with a stack trace or a code snippet. The codebase is large: an average task has about 3,010 non-test files and 438,000 lines of code. The fix is usually small, with a gold patch changing about 33 lines in 1.7 files, but finding those lines is the hard part.
A patch is a text file in the standard diff format that says which lines to delete and which to add. A pull request is a proposed set of changes to a repository, usually with discussion and tests attached. A fail-to-pass test is one that fails on the old code and passes after the fix. A pass-to-pass test passes both before and after, and guards against breaking existing behaviour.
The benchmark needed three things: tasks hard enough to stump current models, a way to verify answers without a human, and a source of tasks that did not run out. Self-contained coding benchmarks had the second property but not the first or third.
How it works
Think of SWE-bench as two parts: a pipeline that builds task instances from GitHub history, and an evaluation that runs a model's patch against the tests. Here is the construction pipeline, which is the part that decides what the benchmark measures.
flowchart LR A["Stage I: 12 popular Python repos, about 90,000 pull requests"] --> B["Stage II: keep merged PRs that fix an issue and change test files"] B --> C["Stage III: run the tests before and after; keep PRs with at least one fail-to-pass test"] C --> D["2,294 task instances"] D --> E["Model gets issue text and codebase, returns a patch"] E --> F["Apply patch, run tests, count as resolved only if all pass"]
-
Collect pull requests. The authors start from about 90,000 pull requests in 12 popular Python repositories. Popular projects tend to have clear contribution rules, better tests and better maintenance.
-
Filter by attributes. A candidate must be merged, must resolve a GitHub issue, and must change the test files. The test change is a sign that a contributor checked whether the issue was fixed.
-
Filter by execution. The tests from the pull request are run on the code before and after the change. The instance is kept only if at least one test goes from failing to passing, and if the environment installs and runs without errors. This leaves 2,294 instances.
-
Give the model the task. The model receives the issue text and a snapshot of the repository at the commit before the fix. It must return a patch.
-
Apply the patch. The standard
patchprogram applies the model's diff to the snapshot. If it does not apply, the attempt fails. -
Run the tests. The fail-to-pass tests must now pass, and the pass-to-pass tests must still pass. Only then is the issue counted as resolved.
-
Report the rate. The metric is the percentage of the 2,294 instances that are resolved.
Worked examples
Setting: Claude 2, the headline model of the paper's first evaluation, resolved 1.96 percent of the 2,294 instances.
- Convert the percentage to a fraction: .
- Multiply by the number of instances: .
- Round to a whole number of instances: about 45.
- Check: , which is 1.96 percent.
- Interpretation: the model solved about 45 of the 2,294 problems, so the test is far from solved.
Answer: about 45 instances.
Setting: Claude 2 with BM25 retrieval resolves 1.96 percent; with an oracle that supplies exactly the files the gold patch edits, it resolves 4.8 percent. The paper reports 110 solved instances for Claude 2 with the oracle.
- Check the oracle figure: , or 4.8 percent. This matches the paper.
- The ratio of the two rates is .
- The oracle is not realistic, since a real engineer may not know which files to change in advance.
- Interpretation: most of the gap is in finding the right files. Better retrieval would help, but even with perfect file choice the model solves only about 5 percent.
Answer: the oracle roughly doubles the resolution rate, to about 4.8 percent, and the ceiling from retrieval alone is limited.
Setting: the Sphinx napoleon issue, sphinx-doc__sphinx-8713, in which the documentation of "Other Parameters" is formatted wrongly when a configuration flag is set. The model receives the issue and the full text of the files the gold patch edits, which is the oracle setting.
- The model finds the right function, the one that parses the "Other Parameters" section.
- Its patch makes that function behave as if the flag were always set, so the other branch breaks.
- The patch does not pass the tests that check the issue, so the instance is not resolved, even though the model edited the correct place.
- Interpretation: finding the right location is not enough. The patch must respect the whole logic of the function, which the tests check.
Try it: in the oracle setting Claude 2 resolves 110 instances and SWE-Llama 13b resolves 91. How many fewer does SWE-Llama 13b resolve, and what is the percentage gap between the two rates? Answer: 19 fewer instances; the rates are and , a gap of about 0.83 percentage points.
The math
Let be the number of task instances. For instance , let be the event that the generated patch applies cleanly, the event that all fail-to-pass tests pass, and the event that all pass-to-pass tests still pass. The instance is resolved when all three hold.
The resolution rate of a model is
where is 1 when the condition holds and 0 otherwise.
Step 3 in symbols: the three conditions
The three conditions are strict. A patch that applies but fails a fail-to-pass test scores zero. A patch that fixes the issue but breaks a pass-to-pass test also scores zero. So the metric rewards correct and non-breaking changes together. This is the standard idea from Unit Testing, applied to a whole repository.
Step 5 in symbols: why the patch format matters
Let the model output a patch with lines added and lines removed. The paper reports that models usually produce much shorter patches than gold ones. For Claude 2 in the oracle setting, the average is about 19.6 changed lines, against about 39.1 for the average gold patch. Shorter patches are less likely to be wrong in a large edit, but they also tend to miss the extra changes that the gold patch makes to keep the code consistent.
Step 4 in symbols: the retrieval budget
Let be the context budget in tokens and let be the token count of a file . Retrieval chooses a set of files such that , ranked by a score such as BM25. The codebase is so large that most files cannot fit, so the choice of decides what the model can see.
Results
Main results (Table 5). With BM25 retrieval, Claude 2 resolved 1.97 percent of SWE-bench, and Claude 3 Opus resolved 3.79 percent. GPT-4-turbo resolved 1.31 percent, ChatGPT-3.5 0.17 percent, and SWE-Llama 13b 0.70 percent. On the smaller SWE-bench Lite subset, Claude 3 Opus reached 4.33 percent. Across the full benchmark, models' patches applied at rates from about 26 to 54 percent (Table 5), so many attempts failed before the tests ran.
Oracle retrieval (Appendix Table 18). With the files edited by the gold patch supplied, Claude 2 resolved 4.8 percent. In the oracle-collapsed setting, which keeps only the edited lines plus 15 lines of buffer, GPT-4 rose from 1.3 to 3.4 percent and Claude 2 from 4.8 to 5.9 percent.
Context length. Claude 2's performance drops as the total context length grows. The authors suggest that models see much code unrelated to the issue and struggle to find the lines that need editing.
Fine-tuned models. The SWE-Llama models were fine-tuned on about 19,000 issue-patch pairs from 37 other repositories, with LoRA on the attention layers and sequences over 30,000 tokens removed. With BM25 context they did poorly, since they were trained to edit every file given to them, while in BM25 most files should be left alone.
Date and contamination. For most models, performance on issues from before and after 2023 differed little. The authors take this as evidence that models were not simply recalling later versions of the repository. The exception was GPT-4, which was tested on a random 25 percent subset because of cost.
Limits. The benchmark covers only Python, from 12 repositories, and only text issues, while many issues contain images. For example, 32 percent of matplotlib issues include embedded images, which text-only models cannot read. The authors note that the oracle setting is unrealistic, and that the best open model fine-tuned by them is far behind the proprietary models. The paper notes that a model may find a valid fix that differs from the reference patch; the tests can only confirm the behaviour they check, so such fixes are judged by those tests alone.
Misreadings to avoid
It is tempting to think that a model that writes correct functions can fix repository bugs. In fact the paper shows that the two tasks differ: finding the right code in a large repository and making a change that keeps the rest of the code working is much harder.
It is tempting to think that a low score means the model cannot write code. In fact most failures were patches that did not apply or did not pass the tests, and the models' patches were often shorter than the gold ones. The score measures end-to-end resolution, not coding skill in isolation.
It is tempting to think that the oracle setting is the true ceiling. In fact it shows only a partial upper bound on retrieval, since the gold files do not always contain all the context needed to fix the bug.
Use SWE-bench to measure end-to-end repository work, and read the per-repository and per-context breakdowns, not only the headline rate. Do not use it to judge single-function generation, where simpler benchmarks are cheaper and more direct.
Reading guide
Read the paper in this order, with the lessons it needs at each step:
- Section 1, Introduction. Needs Language Model for the setting and Unit Testing for the verification idea.
- Section 2, Benchmark construction and task formulation. Needs Version Control for pull requests, commits and patches, and Unit Testing for fail-to-pass and pass-to-pass tests.
- Section 3, SWE-Llama. Needs Fine-Tuning for the training procedure and LoRA for the parameter-efficient update. The base models are from LLaMA.
- Section 4, Experimental setup. Needs BM25 and TF-IDF for the retrieval baselines, Retrieval-Augmented Generation for the idea of supplying retrieved context, and Bi-Encoder for the dense retrieval the authors rejected.
- Section 5, Results. Needs Transformer for the context-length discussion and the table definitions above.
Chain of ideas in this lesson: real bug fixes live in large repositories; a benchmark can score them automatically by running the project's tests; the construction pipeline keeps only pull requests with real fail-to-pass tests; models fail mostly on finding the right code and on producing patches that apply and keep the rest working.
Check yourself
QuestionA benchmark has 500 instances and a model resolves 35 of them. What is the resolution rate, to one decimal place?Show answer
The rate is , or 7.0 percent.
QuestionWhy does the SWE-bench metric require the pass-to-pass tests to still pass, not only the fail-to-pass tests?Show answer
A fail-to-pass test shows that the issue is fixed, but a patch could fix it while breaking other behaviour. The pass-to-pass tests guard against that, so the metric rewards a fix that is also safe. Without them, a model could game the benchmark by making the target test pass in a way that breaks the rest of the project.
QuestionIn the oracle setting Claude 2 resolves 110 instances, and in the BM25 setting it resolves about 45. What does the gap suggest?Show answer
The gap of about 65 instances shows that much of the difficulty comes from finding the right files in the codebase. Even with the right files, the model resolves only 110 of 2,294, so the task is also hard once the context is given.
QuestionApplied scenario: a company wants to test a coding assistant on its own internal repositories. It uses the SWE-bench method. What must it prepare, and what risk should it watch for?Show answer
It needs issues that have tests linking the old and fixed behaviour, which means fail-to-pass tests from its own merged pull requests, and a way to install the project so the tests run. The risk is that its codebase may be in the training data of the model being tested, so it should check the date of the issues against the model's training cutoff, as the paper does.
Sources
- Jimenez, Yang, Wettig, Yao, Pei, Press, Narasimhan (2023), SWE-bench: Can Language Models Resolve Real-World GitHub Issues?, arXiv:2310.06770. https://arxiv.org/abs/2310.06770
- DOI for the same paper: https://doi.org/10.48550/arXiv.2310.06770