← Mohnish Behera

Repair Loop

A weekend project, September 2026 · code

Repair Loop asks a language model to fix a failing test, then lets something the model cannot touch decide whether the fix is right.

Why

A model asked to fix a failing test can make that test pass without fixing the bug, for example by special-casing the input the test uses. I wanted a loop where that does not count as success.

How it works

Reproduce the failing test Diagnose the cause Plan the fix Write two patches Check the diff is safe Run tests in a sandbox Critic and QA review Accepted patch rejected: evidence goes back, up to 3 rounds
Shaded steps run on GitHub Actions inside Docker. The rest run where the loop is started.
  1. Reproduce. Before any model runs, the public tests are run on the untouched code. If they pass, there is nothing to repair and the loop stops.
  2. Diagnose and plan. One model reads the failure output and a snapshot of the repository and names the likely cause. A second turns that into a short plan.
  3. Write patches. Two fixers work in parallel from the same plan with different instructions: one aims for the smallest root-cause fix, the other for a defensive one. Each returns a unified diff.
  4. Check the diff. Plain code rejects a diff that edits tests, touches a file outside the case's allowlist, renames a file, contains binary data or a symlink, or is too large (40 KB, 800 changed lines or 12 files).
  5. Run it somewhere else. The diff is sent to a GitHub Actions workflow. The runner checks it again, applies it to a clean copy of the case, and runs the tests in a Docker container with no network, a read-only filesystem, no Linux capabilities, a non-root user, and limits on CPU, memory and processes. Hidden tests run only if the public ones pass.
  6. Review. A critic model reads the patch next to the test results. If the tests passed and the critic accepts, a QA model makes the final call.
  7. Try again. If nothing is accepted, the last two critiques and test results go into the context and the loop starts over from diagnosis, for up to three rounds.

Each run has budgets (by default 24 model calls, 6 candidate patches and a $10 cost cap) and saves a checkpoint after every stage, so a stopped run can resume. No model is trained. Whatever improves between rounds comes from the evidence added to the prompt.

Choices I made

The benchmark

The repository includes 185 small Python projects, each with a bug, a public test that fails, and hidden regression tests. For 170 of them, the test suite checks that a reference fix passes both sets. For 159, it also checks that a shallow fix passes the public test and still fails the hidden ones.

A shallow fix looks like this. The public test checks one address, and this version handles exactly that address:

def canonical(address):
    if address == "[email protected]":
        return "[email protected]"
    return address.lower()

What happened when I ran it

I have one overnight run: one model, 12 cases, all four variants. It is not a result I would defend, and the table shows why.

VariantSolvedWhat stopped the rest
Single pass8 of 124 runs hit a budget limit
Retry only8 of 124 runs hit a budget limit
Diagnose, then fix6 of 126 runs hit a budget limit
Full team0 of 12Every run failed on GitHub errors (HTTP 500 and 502)

So the full loop, which is the configuration the project exists to test, has no result yet. The plumbing works: 273 verification jobs ran on GitHub Actions that weekend. The measurement does not exist.

What I would do next

Limits