Fix failed CI builds automatically
When a build fails, an automation reads the logs and the code, decides whether the cause is a real bug, a flaky test, or the environment, and opens a pull request with the fix if the fix is safe. If it isn't – the fix would mean disabling a test, loosening an assertion, or hiding an error – the automation reports what fails and why instead, naming the test, the code path, and the evidence.
You build it from the Fix Failed CI template. It works best on the builds of a branch that should always be green, such as main or a nightly build.
Before you start
The agent has to build the project and run the failing tests to prove its fix. If your build needs specific tools, services, or secrets, create an environment configuration for the repository first.
For GitHub, the build runs in GitHub Actions. For GitLab, it runs in GitLab CI/CD. For other CI systems, see Use it with GitLab or another CI system.
Set up the automation
Create an automation that fixes failed builds
On the Automations page, click New Automation. In Instructions, click Use Template and select Fix Failed CI under By Air.
Select the repository, or the environment configuration you created for it.
In Triggers, add . Click Show filters on the trigger row, and in the Workflow field, enter the name of the workflow that builds and tests the project. Without the filter, any failed workflow starts a run, including deployments and scheduled jobs. The filter matches part of the name, ignoring case, so
CIalso matchesCI Deploy– enter enough of the name to tell them apart.
To react to one job instead of the whole workflow, use and enter the job name.
In the trigger's checkout selector, select the branch the fix should be based on, and set the change handling to Create a PR. The run checks out this branch, not the branch whose build failed; the failed run's details, including its branch, reach the agent as the run's context.
Add the guard rails from Keep it to the builds that matter to the end of the instructions.
To hear about a run that reported a cause instead of opening a pull request, add a webhook notification that posts every run's summary to a Slack channel. Failed runs are emailed to you without any setup.
Click Create.
Keep it to the builds that matter
A failed workflow fires the trigger on any branch – the trigger has no branch filter – and a run that timed out or failed to start counts as a failure too. Two things keep the automation from spending credits on failures nobody wants fixed:
Ignore other branches – failures on feature branches are usually work in progress, and the pull request the automation opens runs the same workflow. If that build fails too, it would start another run. Tell the agent to stop early:
Act only on failures on the main branch. For a failure on any other branch, do nothing and say so in one line.Don't repeat the same diagnosis – if
mainstays red, every new commit fails the same way:Before you start, check the open pull requests. If one already fixes this failure, stop and link it.
Use it with GitLab or another CI system
GitLab CI/CD – use or , and Create an MR as the change handling – see GitLab events.
TeamCity, Jenkins, or any other CI – add a Webhook trigger instead, and make the build call the webhook when it fails. Send the build URL, the branch, and the end of the build log in the JSON payload: the payload becomes the run's context, so the agent can work without access to your CI server. See Incoming webhooks.