> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peak.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-healing CI

> Fix failing pull request CI with a small, verified commit.

> [!NOTE]
>
> Self-healing CI is in beta. It runs on Peak's own repositories only.

When a pull request's job fails on a Peak runner, Peak finds the cause.
If the pull request's code caused it, Peak fixes it, re-runs the failing command, and pushes one small commit to the pull request branch.
Peak repeats until CI is green.

## Before you start

* Sign in to Peak as an Admin.
* Run the pull request's jobs on Peak runners.

## Turn it on

1. Open [Self-healing CI](https://app.peak.inc/autofix).
2. Choose Turn on.
3. Choose All repositories, or Choose repositories and check each one.
4. Choose Turn on.

Expect Auto-push on each repository you chose.
Expect no new GitHub permission and no new install.

## Choose a mode

Set Mode beside each repository.

| Mode | What Peak does |
| - | - |
| Auto-push | Pushes each verified fix to the pull request branch |
| Suggest only | Puts the fix in the pull request comment for you to apply |
| Off | Nothing |

## Check what Peak changes

Peak pushes a fix only when all of these are true.

* The failing command failed before the fix and passed after it, in an isolated VM at the same commit.
* The fix changes the code the pull request touched, or a file named in the failure.
* The fix changes at most 10 files and 300 lines.
* The pull request is open, comes from the same repository, and still has the commit that failed.

Peak never does these.

* Write to the default branch.
* Force-push, rebase, or merge.
* Touch pull requests from forks.
* Change CI definitions, such as workflow files.
* Change lint, type, or test settings.
* Delete or skip tests, or weaken an assertion.
* Add sleeps, retries, or longer timeouts.
* Add lint or type suppressions.
* Hide errors, such as with an empty catch.
* Change environment or credential files, or binary files.

Peak suggests these instead of pushing them.

* A change to an expected value in a test
* A snapshot update
* A dependency pin or downgrade
* A change that undoes part of your pull request

## Read the pull request comment

Expect one Peak comment on the pull request.
Peak edits it as it works.

| Section | What it lists |
| - | - |
| Fixes | Each commit, the job, the cause, and the green run that proves it |
| Flaky, retried once, not changed | Tests that fail now and then, with how often |
| Not fixed here | Failures that also fail on your base branch, and failures that need a secret or a setting |
| Suggested, not pushed | Fixes that need your call, with the patch |
| Stopped | The limit Peak reached, and what it tried |

Peak re-runs a flaky job once.
Peak never changes code for a flaky test.

## Recognize Peak's commits

Each Peak commit is by `peak-runners[bot]`, signed by GitHub, and ends with a `Peak-Autofix:` line.
Branches that require signed commits accept it.

## Pull before you push

A Peak commit puts the pull request branch ahead of your copy.
Pull before your next push.

```bash theme={null}
git pull --rebase
```

## Revert a fix

Revert the commit like any other.

```bash theme={null}
git revert <sha>
```

Expect Peak never to push that fix to that pull request again.

## Stop Peak on a pull request

Add this label to the pull request.

```text theme={null}
no-autofix
```

Expect no new Peak commits on that pull request.

## Apply a suggested fix

1. Open the pull request comment.
2. Under Suggested, not pushed, choose Apply.
3. Check the patch.
4. Choose Apply.

You need push access to the repository on GitHub.
Peak checks it with your own GitHub sign-in.
If Peak asks, choose Connect GitHub, then open the link again.
Peak then pushes the fix to the pull request branch.

## Check the limits

| Limit | Value |
| - | - |
| Fix commits per pull request | 3 a day |
| Failed attempts in a row | 2, then Peak stops on that pull request |
| One fix | 20 minutes |
| Spend per repository | 10 USD a day |
| Spend per workspace | 25 USD a day |

Check fixes pushed, fixes kept at merge, time saved, and cost for the last 30 days on [Self-healing CI](https://app.peak.inc/autofix).

## Use the API and MCP server

| Method | Path | Scope |
| - | - | - |
| GET | /api/v1/autofix/sessions | runs:read |
| GET | /api/v1/autofix/sessions/SESSION\_ID | runs:read |
| PATCH | /api/v1/autofix/repositories/GITHUB\_REPOSITORY\_ID | runners:write |

Send a mode to set it: auto, suggest, or off.

```json theme={null}
{ "mode": "suggest" }
```

Agents connected to the [MCP server](https://docs.peak.inc/mcp-server.md) get these read-only tools.

| Tool | Use it to |
| - | - |
| list\_autofixes | List fixes, newest first. |
| get\_autofix | Read one fix with its patch and failed jobs. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.