SWE-bench

A model reads a real GitHub issue and edits a real repository. The repository’s own tests decide if the issue is resolved. In the first results, the best score with file retrieval was 1.96%.

Learn what one task contains, what “resolved” checks, and why 2,294 real tasks scored so low.

Pick a candidate patch below. The tests run. Watch the two kinds of test and the verdict. Beside it, the paper’s resolve rates for the same model with different retrieval.

You need a little Python and a feel for what a unit test is. We teach the rest.

Based on SWE-bench: Can Language Models Resolve Real-World GitHub Issues? (arXiv 2310.06770, ICLR 2024) by Carlos E. Jimenez, John Yang, Alexander Wettig, Shunyu Yao, Kexin Pei, Ofir Press and Karthik Narasimhan. It is the reading for the guest lecture on SWE-bench in Stanford CS 329Z, Engineering AI Agents (Mon Nov 16). The course posted no slides, so this lesson follows the paper. Every idea is re-taught here in our own words and devices.

Run a patch against the tests

Illustrative: the five patches, the second test name and the failed tests are invented to show the idea. The task is the paper’s example sympy-17022 (Figure 7); 51 is the paper’s median count of pass-to-pass tests (Section 2.3). The bars are printed rates: Tables 2, 5, 6 and 18 of arXiv 2310.06770. Table 5 prints Claude 2 as 1.97; the text and Table 2 print 1.96.

Chapter 0

Real Issues, Real Repositories

See why fixing one real issue is a different test from writing a short function

A maintainer opens the issue tracker. One issue says that lambdify prints an identity matrix as the letter I, so the numbers come out wrong. The maintainer finds the code printer, adds one method and adds one test. The pull request merges.

SWE-bench gives a model the same job. The model gets the issue text and a copy of the repository. It returns a patch: a file that lists lines to add and lines to remove. The paper collects 2,294 such tasks from 12 Python repositories.

One task instance holds an issue, a repository snapshot, a gold patch and tests. The gold patch is the human fix that the maintainers merged.

Earlier code benchmarksSWE-bench
Inputa short, self-contained probleman issue of 195 words and a repository of 3,010 files
Outputa few lines of codea patch; the gold patch edits 1.7 files, 3.0 functions, 32.8 lines
Checkerunit teststhe repository’s own unit tests

Find the fix

Each square is one non-test file of an average SWE-bench repository. Press the button to mark the files the gold patch edits.

Table 1 of the paper gives the means: 3,010 non-test files, 438K lines, 1.7 files and 32.8 lines in the gold patch. The grid and the two marked squares are a drawing, not a real repository.

Worked number: 32.8 lines to change, 438,000 lines to read. 32.8 ÷ 438,000 is 0.0075%. The model must find those lines before it can write them.

Failure. The patch looks tidy but edits a file the fix never needed. Measure it: list the files in the patch and the files in the gold patch. Fix it with better context. Chapter 5 shows how the paper chose files.

The road

  1. Build a task from a pull request: how 93,139 PRs become 2,294 tasks.
  2. Fail-to-pass and pass-to-pass: the two kinds of test.
  3. The harness: seven steps from patch to verdict.
  4. Six outcomes: why “not resolved” is not one thing.
  5. Finding the files: BM25 and oracle retrieval.
  6. The results tables: resolved against applies.
  7. Why patches fail: one case and four patterns.
  8. What the paper does not show: limits and a date check.
  9. Field guide: terms, numbers, a checklist, code.
What makes a SWE-bench task different from a short code problem?

Chapter 1

Build a Task from a Pull Request

Turn a merged fix into a question, an answer and a checker, three filters at a time

A merged pull request (PR) that links an issue and adds tests already holds a whole task. The issue is the question. The code change is the answer. The new tests are the checker. The authors only collect and filter.

  1. Scrape. Collect PRs from 12 popular Python repositories.
  2. Attribute filter. Keep a PR if it merged, resolves an issue, and edits test files.
  3. Execution filter. Install the repository and run the tests before and after the PR. Keep the PR only if at least one test goes from fail to pass.

Run the three filters

Press a stage. The bar shows the pull requests that survive up to that stage.

Counts are summed over the 12 repositories in Table 10 of the paper. The main text rounds the first number to about 90,000.

Worked number: 11,407 ÷ 93,139 is 12.2%, so the attribute filter keeps one PR in eight. 2,294 ÷ 11,407 is 20.1%, so the execution filter keeps one in five. Overall, 2.5% of the PRs become tasks.

The problem statement joins the issue titles, the issue text and the comments written before the PR’s first commit. The paper does this to keep the solution out of the prompt.

Failure. A test calls a function that only the gold patch creates, such as make_grid_v2. No issue names it, so no model could guess it. The paper removes these tasks. It checks the before-patch log for ImportError and AttributeError to find them.

Which condition makes the execution filter drop a candidate task?

Chapter 2

Fail-to-Pass and Pass-to-Pass

Run the tests twice and learn which tests prove the fix and which prove nothing broke

You fix a leaking tap. Two checks matter. Does the tap stop dripping? Does the rest of the house still have water? A fix that passes one check and fails the other is not a fix.

The harness runs the repository’s tests twice: before the gold patch and after it. Each test lands in one of four buckets. A fail-to-pass (F2P) test fails before and passes after. It proves the issue is fixed. A pass-to-pass (P2P) test passes both times. It proves old behavior survives.

Sort the tests

Choose a moment. After the gold patch, each test gets a bucket label.

Illustrative: eight tests with invented names. The paper keeps four buckets: fail-to-fail, fail-to-pass, pass-to-fail and pass-to-pass (Appendix A.3). The toy shows three.

The score judges a model patch on F2P and P2P together:

resolved
The score for one task. It is 1 or 0. There is no partial credit.
F2P ∪ P2P
All fail-to-pass tests and all pass-to-pass tests of this task. The median task has 51 extra tests (Section 2.3).
passes
A test that is missing from the log counts as a fail (Appendix A.4).
the model’s patch
The harness applies the patch together with the task’s test patch.

Worked number: a task has 2 F2P tests and 51 P2P tests, so 53 tests must pass. A patch that passes 52 scores 0. The metric of the paper is the share of the 2,294 tasks with score 1.

Failure. The patch looks right but the score is 0. The symptom is a P2P test that fails or never runs. Measure it: open the test log and list the status of every F2P and P2P name. Fix the patch so that no old behavior changes.

A patch makes every F2P test pass but breaks one P2P test. What is its score?

Chapter 3

The Harness: Seven Steps

Follow one model patch from a text file to a verdict, and see where it can die

The harness is the program that scores one patch. It starts from a clean repository each time, so one run cannot leak into the next. Here are its steps (Appendix A.4).

  1. Reset the repository and check out the base commit.
  2. Activate the task’s environment.
  3. Install the repository.
  4. Apply the test patch.
  5. Apply the model’s patch.
  6. If step 5 failed, repair the patch and apply it again.
  7. Run the tests and read the log.

Run the harness

Choose a patch, then press Next step. The log shows what the harness does.

The seven steps follow Appendix A.4. The three patches are invented. The repair (step 6) removes unneeded context lines and recomputes the header values.

Worked number: Claude 2 with BM25 files made 2,281 patches. 988 applied. That is 988 ÷ 2,294 = 43.07%, the “% Apply” of Table 5. The repair step rescued 302 of the 988, or 30.57% (Table 14).

Failure. The patch does not apply, so the score is 0 before any test runs. The symptom is a low apply rate. ChatGPT-3.5 with BM25 files applied 26.33% of its patches. Measure the apply rate beside the resolve rate. Fix it with format examples in the prompt, as the paper does.

At which step does a malformed patch get a second chance?

Chapter 4

Six Outcomes, Not Two

Split “not resolved” into six cases and see where each model’s patches land

A score of 0 hides a lot. One patch does nothing. Another fixes the issue and breaks three tests. Appendix C.5 sorts every patch that applied into six cases by two counts: how many F2P tests pass and how many P2P tests pass.

F2P tests that passAll P2P passSome P2P fail
AllResolvedBreaking Resolved
SomePartially ResolvedWork in Progress
NoneNo-OpRegression

Where the patches land

Choose a model. Bars show its patches that applied, split into the six outcomes.

Counts are Table 23 of the paper (oracle retrieval). *GPT-4 ran on a 25% random subset of 574 tasks. Table 23 lists 1,078 applied patches for Claude 2, while Table 14 lists 1,441 for oracle retrieval. The paper does not say why, so we use Table 23’s own rows.

Worked number: Claude 2 has 1,078 applied patches. 471 are No-Ops and 436 are Regressions, so 907 of 1,078 (84.1%) pass no F2P test. 110 are Resolved. 110 ÷ 2,294 is 4.80%.

Failure. Breaking Resolved: the patch fixes the issue and breaks a P2P test. Claude 2 has 26 of these. The harness counts them as failures. Measure it as the share of F2P-complete patches that lose some P2P test. Fix it by running the old tests before you submit.

A patch passes all F2P tests and fails two P2P tests. Which outcome is it?

Chapter 5

Finding the Files: BM25 and Oracle

Choose which files the model reads, and see why more context made the score drop

A repository has 438K lines, and a model reads far fewer. The paper’s baseline must pick files first. It uses BM25, a word-match score that ranks files by the rare words they share with the issue. It adds the top files until a token limit is full. The limits are 13k, 27k and 50k tokens.

For analysis, the paper adds an oracle setting. The oracle “retrieves” exactly the files that the gold patch edits. It is less realistic, because a real engineer does not know those files in advance.

More files in, fewer fixes out

Choose a context limit. The top bars show how many gold-patch files BM25 found. The last bar shows Claude 2’s resolve rate.

Recall: Table 3. Claude 2 resolve rate: Table 2 for BM25 and Table 18 for oracle. The resolve bar is full at 5%. Oracle recall is 100% by definition.

Worked number: from 13k to 50k tokens, average recall rises from 29.58% to 51.06%. Claude 2’s score falls from 1.96% to 1.22%. At 27k, BM25 finds all the oracle files for 39.83% of tasks and none of them for 100 − 51.27 = 48.73%.

Only some models can read this much. Table 4 gives the share of tasks whose oracle input fits. ChatGPT-3.5 (16,385 tokens) fits 58.1%. GPT-4 (32,768) fits 84.1%. Claude 2 (100,000) fits 96.4%.

Failure. The score falls as the context grows. The paper reads this as a localization problem: models are “simply ineffective at localizing problematic code”. Measure it by grouping tasks by input length (Figure 5). Fix it by cutting the context. The oracle-collapsed setting keeps only the edited lines plus 15 lines on each side. In Table 6 GPT-4 goes from 1.3% to 3.4%.

BM25 at 50k tokens finds more oracle files than at 13k. What happens to Claude 2’s resolve rate?

Chapter 6

The Results Tables

Read resolved and applies side by side for each model and each retrieval setting

The paper evaluates ChatGPT-3.5, GPT-4, Claude 2 and its own SWE-Llama. SWE-Llama is CodeLlama-Python (7b and 13b) fine-tuned with LoRA on 10,000 issue and PR pairs from 37 other repositories. The version 3 table adds Claude 3 Opus and GPT-4-turbo.

Two metrics matter. % Resolved is the score of Chapter 2. % Apply is the share of patches that applied.

Compare the models

Choose a setting and a metric. Models that the paper did not test in that setting are left out.

Printed values from Tables 5, 18 and 6 of arXiv 2310.06770. *GPT-4 in the oracle setting ran on a 25% random subset (574 tasks).

Worked number: with BM25 files, SWE-Llama 13b applies 53.62% of its patches and resolves 0.70%. 0.70 ÷ 53.62 is about 1.3 resolved per 100 applied patches.

Failure. You read the apply rate as skill. The symptom is a high apply rate with a tiny resolve rate. Measure resolved and applies together. The paper suspects that SWE-Llama, trained on oracle files, stumbles when BM25 gives it files that need no edit.

A model applies 50% of its patches and resolves 1%. What does that tell you?

Chapter 7

Why Patches Fail

Read one failed patch against the gold patch, then four patterns the paper finds

The paper studies task sphinx-8713. The issue: the napoleon_use_param setting should also change how the “Other Parameters” section prints. The input is 1,558 lines, or 20,882 tokens, in the oracle setting. The model edits the right function, _parse_other_parameters_section.

Gold patch against model patch

Switch between the two patches. The tests below are the ones the paper lists in Figure 6.

Patch lines are simplified from Figure 6 of the paper. The paper prints test results for the model patch only. The gold patch passes by construction, because Chapter 1’s filter requires it.

The model makes the function act as if the setting were always on. The gold patch checks the setting first. A test that builds the docs with the setting off catches the mistake at once.

PatternEvidenceWhere
Long context hurtsClaude 2 gets worse as the input growsFigure 5
Patches beat whole filesClaude 2 writing whole files: 2.2%. Writing patches: 4.8%Section 5
Short editsClaude 2: 19.6 lines. Gold patches: 44.1 linesTable 8
Images in issues32% of matplotlib issues, 10% of seaborn, 2% of allSection 5

Worked number: 19.6 ÷ 44.1 is 44%. Claude 2’s applied patches are less than half as long as the gold patches for the same tasks. The paper adds that models write “greedy” code that solves the problem as stated and ignores the style of the codebase.

Failure. The model fixes the symptom in the issue and misses the rule behind it. The test log shows this as a failed P2P or F2P test that checks a nearby setting. Fix it by running the old tests. The paper names execution feedback as promising, but its baselines do not use it.

Why did the model patch for sphinx-8713 fail, in the paper’s analysis?

Chapter 8

What the Paper Does Not Show

Read the paper’s own limits, then check one risk with a date split

The paper states three limits. All tasks are Python. The experiments are baselines: a retriever and a model, with no tools and no agent loop. And tests alone do not guarantee quality: model patches can be less comprehensive, less efficient or less readable than human ones.

One more risk is memory. The repositories are public, so a model may have seen the fixes. The paper splits tasks by date: issues created before 2023 and after.

Before 2023, after 2023

Pick a model to read its two numbers. All five pairs are drawn.

Table 7 of the paper, oracle retrieval. *GPT-4 ran on a 25% random subset, so its after-2023 zero rests on few tasks.

Worked number: Claude 2 scores 4.87% before 2023 and 4.23% after, a gap of 0.64 points. If it had memorized fixes, the older issues would score far higher. For four of five models the gap is small. GPT-4 is the exception, on the subset.

Failure. A model scores well on old issues and badly on new ones. Measure it with a date split like this one. Fix it with new tasks. The pipeline of Chapter 1 can make tasks from any PR after a model’s training date.

Our reading, not the paper’s: the tests come from the PR author and may not match every valid fix. Later work audits tasks and tests with that doubt in mind. See the Agentic Benchmark Checklist. Scores on this benchmark rose a great deal after this paper. We give no later numbers, because the paper does not.

What does the before and after 2023 split test?

Chapter 9

Field Guide

Keep the terms, the numbers, a checklist, the scoring code, and where to read next

SWE-bench turns merged GitHub fixes into 2,294 tasks. A model patch is resolved only if every fail-to-pass and every pass-to-pass test passes. The first baselines resolved under 5% with oracle files and under 4% with BM25.

The terms

TermPlain meaning
Task instancean issue, a repository snapshot, a gold patch and tests
Gold patchthe human fix from the merged PR
Test patchthe PR’s test edits, applied before the model’s patch
F2P testfails before the gold patch, passes after; proves the fix
P2P testpasses before and after; proves nothing broke
% Resolvedshare of tasks where every F2P and P2P test passes
% Applyshare of patches that applied
BM25word-match file ranking used as the baseline retriever
Oraclethe files the gold patch edits, given to the model
Oracle collapsedoracle files with unedited code folded away, except 15 lines around each edit
SWE-bench Litea 300-task subset, more self-contained, focused on bug fixes

The numbers to remember

NumberWhat it isWhere
2,294tasks from 12 Python repositoriesSection 2.1
93,139 → 11,407 → 2,294PRs crawled, converted, validatedTable 10
3,010 files, 438K linesmean size of a codebaseTable 1
1.7 files, 3.0 functions, 32.8 linesmean gold patchSection 2.3
9.1 and 120.8mean F2P tests and mean total testsTable 1
1.96%, 1.87%, 1.22%Claude 2 with BM25 at 13k, 27k, 50k tokensTable 2
4.80%Claude 2 with oracle filesTable 18
9.39%Claude 3 Opus with oracle collapsed filesTable 6
3.79%Claude 3 Opus with BM25 filesTable 5
19,000 and 10,000SWE-Llama training pairs collected, and kept under 30,000 tokensSection 3

A checklist before you trust a SWE-bench number

This list is our own summary, not the paper’s. Tick what a score you read has told you.

Check the score

Tick each item the report gives. The read-out says how much you can trust the number.

Our summary of the paper’s cautions. It is not a list from the paper.

The core as code

This is our sketch of the scoring in Python, not the authors’ code.

def resolved(task, model_patch):
    repo = checkout(task.repo, task.base_commit)       # steps 1 to 3
    repo.apply(task.test_patch)                        # step 4
    if not repo.apply(model_patch):                    # step 5
        model_patch = repair(model_patch)              # step 6: trim context, fix header
        if not repo.apply(model_patch):
            return 0                                   # no tests run
    status = run_tests(repo, task.test_files)          # step 7: {test name: "pass" | "fail"}
    must_pass = task.fail_to_pass + task.pass_to_pass
    return int(all(status.get(t) == "pass" for t in must_pass))   # a missing test is a fail

def resolve_rate(tasks, patches):
    return 100 * sum(resolved(t, patches[t.id]) for t in tasks) / len(tasks)

Where it sits

This lesson is the reading for the SWE-bench guest lecture in Stanford CS 329Z. No slides were posted. The course runs from what agentic systems are. The lecture on Evaluation Fundamentals and Benchmark Design gives the frame, and the Terminal-Bench lecture shows a benchmark of a different shape. The homework is the evaluation task.

Read next: SWE-smith makes training tasks of this shape in bulk. Terminal-Bench checks outcomes in a container. The Agentic Benchmark Checklist asks how to tell if a benchmark is valid.

Credit and sources

SWE-bench: Can Language Models Resolve Real-World GitHub Issues? was written by Carlos E. Jimenez, John Yang, Alexander Wettig, Shunyu Yao, Kexin Pei, Ofir Press and Karthik Narasimhan. The authors work at Princeton University, Princeton Language and Intelligence, and the University of Chicago. It appeared at ICLR 2024 and is arXiv 2310.06770; this lesson follows version 3. Read the original at arxiv.org/abs/2310.06770. Every number here comes from that paper unless a device says it is illustrative. Course credit: Stanford CS 329Z, Engineering AI Agents, taught by Diyi Yang, Michael Ryan and John Yang.

Resolved means every test passes, not that the patch looks right. Read a score with its retrieval setting, its apply rate and its date split. Then read a few patches.
Go back to the hero and run each patch again. Name the outcome in the Table 22 grid before you read the verdict.
Which statement matches the paper?
Based on “SWE-bench: Can Language Models Resolve Real-World GitHub Issues?” by Jimenez, Yang, Wettig, Yao, Pei, Press and Narasimhan (2024)
Read the paper · Back to Veanors