---
title: Health Status
description: How Mergify decides whether a test is healthy, flaky, or broken, and what moves it from one state to another.
---

Every test is in one of three states: **healthy**, **flaky**, or **broken**.
Mergify tracks a test per repository, branch, pipeline, job, and test name, so
the same test can be healthy on one branch and flaky on another.

Mergify reads a test's runs one at a time, in the order they finished, and
ignores skipped runs. Each run can move the test at most one step, and a run
that matches none of the arrows below leaves the test where it is. A test
that stops running keeps its state for 90 days, then reads as healthy again,
with no run left to back the verdict.

```dot class="flow" title="Test health states: a failure makes a test unhealthy, a streak of clean passes brings it back"
digraph {
  splines="ortho";
  nodesep=0.2;
  ranksep=0.4;

  // Each edge label is a node of its own: orthogonal routing cannot place
  // edge labels, so the label sits on the edge it names.
  node [shape=plaintext, fontsize=11, margin="0.12,0.04", width=0, height=0, class="chrome"];
  failure [label="failure"];
  few_clean [label="a few\nclean passes"];
  evidence_from_healthy [label="flaky\nevidence"];
  long_clean [label="a longer\nstreak of clean\npasses over\nseveral days"];
  evidence_from_broken [label="flaky evidence"];
  fail_streak [label="fails on several\ncommits in a row"];

  node [shape=box, fontsize=14, margin="0.24,0.15", height=0.42];
  healthy [label="Healthy", shape=oval, class="merged"];
  broken [label="Broken", class="failed"];
  flaky [label="Flaky", class="flagged"];

  // Invisible edges keep the labels in the same order as the states they join.
  { rank=same; failure -> few_clean -> evidence_from_healthy -> long_clean [style=invis]; }
  { rank=same; broken -> evidence_from_broken -> flaky [style=invis]; }

  // Edges leading up are written top-down with dir=back, so they do not
  // pull the healthy state below the others.
  healthy -> failure [arrowhead=none];
  failure -> broken;
  healthy -> few_clean [dir=back];
  few_clean -> broken [arrowhead=none];
  healthy -> evidence_from_healthy [arrowhead=none];
  evidence_from_healthy -> flaky;
  healthy -> long_clean [dir=back];
  long_clean -> flaky [arrowhead=none];
  broken -> evidence_from_broken [arrowhead=none, constraint=false];
  evidence_from_broken -> flaky [constraint=false];
  broken -> fail_streak [dir=back];
  flaky -> fail_streak [arrowhead=none];
}
```

## Flaky evidence

A failure alone does not make a test flaky. Mergify needs evidence that the
outcome does not follow from the code, and any of these counts:

- **Same commit, different result**: the test both passed and failed on the
  same commit.

- **Marked flaky**: your test framework reported the run as flaky, even if it
  passed.

- **Intermittent failure**: the test fails on a new commit after passing since
  its last failure, and that last failure is recent. This holds even if the
  test recovered in between, so a test that keeps failing now and then ends up
  flaky, not broken.

A **clean pass** is a passing run with no flaky evidence. Any failure, or any
run with flaky evidence, restarts the streak of clean passes.

A flaky test takes longer to recover than a broken one. A broken test that
starts passing has most likely been fixed, while a flaky test can pass for a
while before failing again, so Mergify waits for a longer streak spread over
time before calling it healthy.

## Example

> **Figure:** A few clean passes end a broken stretch; a flaky one ends only after a longer streak spread over several days. Reruns of e5 keep it flaky: a pass and a failure on one commit is flaky evidence, not a recovery. In the runs, green passed and red failed.
>
> Timeline of one test, run by run, with its health below. It fails on commit a1, with nothing pointing to flakiness: broken. It passes cleanly on the next few commits: healthy again. Two days later it fails on e5, after passing since its recent failure on a1: flaky. A rerun of e5 fails again and the test stays flaky, since reruns of one commit count once toward a failing streak. Another rerun of e5 passes: the same commit gave both results, so it is still flaky. It then passes cleanly on new commits, many times over several days, and goes back to healthy.

## Fixing a flaky or broken test with AI

Click a flaky or broken test on the [Detection](/test-engine/detection) page:
under its health, **Fix with AI** hands it to your coding agent, whether the
test is [active, quarantined, or skipped](/test-engine/test-states).

Pick an agent to open it with the prompt filled in, or click **Copy Prompt** to
paste it into any other. The prompt carries the test's recent failures and health
history, and asks for a fix that fits its health:

- **Flaky**: find what makes the outcome change on the same code and remove it,
  without retries or sleeps.

- **Broken**: find the change that broke the test and fix the cause, in the code
  or in the test.

Either way, the prompt tells the agent not to delete or skip the test.

## Related pages

- [Detection](/test-engine/detection) lists your tests by state and helps you
  decide which ones to fix first.

- [Test States](/test-engine/test-states#when-mergify-quarantines-a-test-itself) explains when
  Mergify quarantines a test based on its state.
