---
title: Recipe: Fix until tests pass · Agent Playground docs
description: Writes a function, runs the tests, fixes what failed and runs them again until they pass. What it does, when to use it, how to make it yours, and what a run costs.
url: https://www.quietrobot.ai/docs/playground/recipes/fix-until-pass
---

# Recipe: Fix until tests pass

Writes a function, runs the tests, fixes what failed and runs them again until they pass. What it does, when to use it, how to make it yours, and what a run costs.

Runs a project's tests, and when they fail, fixes the code and runs them again, until they pass or the loop limit is reached. It's the simplest useful loop, and the shape behind most "keep at it until it works" jobs.

| At a glance | |
|---|---|
| **Category** | Coding |
| **Shape** | A loop |
| **Plan** | Free and up |
| **Needs a Claude key** | No |
| **Limits it comes with** | 5 loops, 180 seconds, $0.05 |

```flow
{"title": "Fix until tests pass, as it is on the canvas.", "nodes": [["setup", "run", "Set up project"], ["write", "run", "Write code", "go back here"], ["test", "run", "Run tests"], ["fix", "run", "Fix failures"], ["save", "run", "Save result"]], "edges": [["setup", "write"], ["write", "test"], ["test", "fix", "Failed"], ["fix", "test"], ["test", "save", "Passed"]]}
```

<figure class="shot">
  <img class="art-light" src="/docs/playground/recipes/fix-until-pass-light.webp" alt="The Fix until tests pass recipe in the builder after a run, with each step's result on the canvas and the run's steps listed on the right." width="1440" height="900" loading="lazy">
  <img class="art-dark" src="/docs/playground/recipes/fix-until-pass-dark.webp" alt="" width="1440" height="900" loading="lazy">
  <figcaption>A real run of the recipe. The panel on the right lists every step with what it printed.</figcaption>
</figure>

## When to use it

* You have a check that says pass or fail (tests, a linter, a script that validates a file) and something that can make the next attempt better.
* You want an AI agent to keep fixing code until the tests are green, with a cap on how many tries it gets.
* You're learning the Playground: this is the recipe to start with.

## Run it

1. Open **Agent Playground** in the dashboard and find **Fix until tests pass** under **Start from a recipe**. In the builder, **Recipes** in the toolbar lists them too.
2. Choose **Use this recipe**. It becomes a flow of your own, so changing it never changes the recipe.
3. Choose **Simulate** to see the forecast, then **Run**.

**What you'll see:** **Run tests** fails three times, each time with fewer failures (`1 passed, 3 failed`, then `2 passed`, then `3 passed`), and passes on the fourth try. The panel groups the steps by **First pass**, **Loop 1**, **Loop 2** and **Loop 3**, and **Save result** packs the working code into `result.tgz`.

## Make it yours

1. Change **Set up project** to get your own code, for example `git clone https://github.com/you/app proj && cd proj && pip install -r requirements.txt`. For a private repository, save a token under **Policies → Secrets** first.
2. Change **Run tests** to your test command: `pytest -q`, `npm test`, `go test ./...`.
3. Replace **Fix failures** with an **Agent**. Set its **Goal** to `The tests in proj fail. Fix the code so they pass. Don't change the tests.`, use **Insert…** to add the output of **Run tests**, and set **Check that it worked** to your test command. You'll need [your Claude key](https://www.quietrobot.ai/docs/playground/ai-steps#add-your-claude-key).
4. Change **Save result** to whatever should happen with working code: package it, open a pull request, or add an [Approval](https://www.quietrobot.ai/docs/playground/tutorials/approvals-and-limits) first.
5. Open **Limits** and set **Loops** to how many tries you'd accept (3 to 5 is typical with an agent), and **Spend** to cover the agent's Claude use.

## What a run costs

These are the builder's own forecast for the recipe as it comes, with its limits, rounded. **Simulate** shows the same numbers for your version, and they change as you change the flow.

| | Typical | 1 in 10 runs | At most |
|---|---|---|---|
| **Sandbox time** | $0.0002 | $0.0004 | $0.0023 |
| **How long it takes** | 20 seconds | 35 seconds | 180 seconds |

A typical run uses $0.0002 of sandbox time, so about 4,000 runs cost $1, and every plan includes $5 of usage a month. **At most** is the most a run could cost with these limits: it stops at $0.05 or 180 seconds, whichever comes first.

## Related

* [Tutorial 3: Keep trying until it works](https://www.quietrobot.ai/docs/playground/tutorials/loops)
* [Agent fixes the failing test](https://www.quietrobot.ai/docs/playground/recipes/agent-fix-test)
* [Fix, review, ship](https://www.quietrobot.ai/docs/playground/recipes/fix-review-ship)
* [Coding recipes](https://www.quietrobot.ai/docs/playground/recipes/coding)
* [All recipes](https://www.quietrobot.ai/docs/playground/recipes)
