The CI Retry Flag: What ‘–retries 2’ Actually Measures

A Green Build That Wasn’t

On 14 March 2024, a pull request against a payments service went green after two failed attempts. The CI log showed the same test, test_settlement_reconciliation, failing on attempt one with a timeout against a stub ledger, then passing on attempt two. The build status was a single word: passed. The ticket that followed said the test was flaky and had been retried. The release went out. What the build status did not say — and what the retry flag was never designed to say — is that the suite had not passed on first execution, and that the failure had been re-rolled rather than explained.

This is the artifact under examination: a retry count in CI configuration, whether expressed as --retries 2, retries: 2, or a retry: block. The question is not whether retries are useful. They are. The question is what a green build containing retried tests actually measures, and whether the release owner reading that green knows which quantity they are looking at.

What the Instrument Actually Does

The mechanics are documented and consistent across the major runners. Cypress states plainly that retries are off by default and must be enabled: “By default, tests do not retry when they fail. You need to enable test retries in your configuration to use this feature” (Cypress docs). With two retries configured, Cypress runs a failing test up to two additional times, for three total attempts, before marking it failed. Playwright is the same in spirit: “By default failing tests are not retried” (Playwright docs).

The important part is not the count. It is the categorization. Playwright documents three outcomes: “passed” for tests that passed on the first run, “flaky” for tests that failed on the first run but passed when retried, and “failed” for tests that failed on the first run and failed all retries. Cypress similarly surfaces a Flaky filter and a Flaky badge in its Cloud reporting, and records each attempt with screenshots suffixed by attempt number.

So the retry flag does not, by itself, manufacture a lie. It produces a different category. The defect appears one layer up, when the build status collapses “flaky” and “passed” into the same green check. That collapse is a reporting decision, not a property of the flag.

Job-level retries behave differently again. GitLab’s retry keyword is documented as controlling “when and how many times a job can be auto-retried in case of a failure” (GitLab CI/CD YAML reference). That is a coarser instrument: it re-runs the whole job, not the failing test, and the resulting green says even less about which test was unstable.

Three Instruments Wearing One Name

A retry count is asked to do three incompatible jobs, and conflating them is where release decisions go wrong.

As a flake detector, a retry is weak. GitHub’s engineering write-up on reducing flaky builds is explicit about the limits of rerun-based detection: “certain types of flaky tests couldn’t be detected with this approach, such as a time-based flaky test. (If your test failed because it was a leap year, rerunning it two minutes later won’t help.)” GitHub also reports that its two initial approaches — same-code-different-result across builds, and retrying failed tests within a build — “were only able to identify 25 percent of the flaky failures, counting on developers to find the rest” (GitHub Engineering, 2020). A retry that passes is evidence that the test is non-deterministic under some condition. It is not evidence about which condition.

As a build-unblocking mechanism, the retry is effective and that is why it spreads. Gradle’s engineering blog states the rule of thumb directly: “by simply rerunning the failed test one more time, the test failures due to flakiness can be reduced by 90%” (Gradle blog, 2022). That is a real productivity gain. It is also a statement about failure frequency, not about failure cause.

As a suppression mechanism, the retry is the weakest of the three and the most dangerous to leave unlabeled. Microsoft’s CloudBuild, as described in the lifecycle study, “automatically retries the test once by default, and if the retry passes, then the test is considered flaky and the build continues” (Lam et al., ICSE 2020). The build continues. That is suppression with a detection label attached. Microsoft’s own Flakes system goes further and suppresses known flaky failures for 30 days by default, explicitly “to discourage developers from fully relying on suppressions.” The 30-day window is a design admission that suppression without expiry becomes permanent.

Retry Is Not Quarantine

Martin Fowler’s 2011 essay on non-determinism remains the clearest statement of the distinction. He defines a non-deterministic test as one that “passes sometimes and fails sometimes, without any noticeable change in the code, tests, or environment” (Fowler). His prescription is quarantine: “If you have non-deterministic tests keep them in a different test suite to your healthy tests.” The purpose is legibility — so that the healthy suite’s signal stays readable.

Retry does the opposite. It keeps the unstable test inside the blocking suite and re-rolls the outcome. A team that uses retries as a substitute for quarantine ends up with neither a clean signal nor a tracked work item. Fowler warns that quarantined tests “keep getting thrown into quarantine and forgotten, which means your bug detection system is eroding.” A retried test that passes is worse than a quarantined one in this respect: it never enters the quarantine list at all, so there is nothing to forget and nothing to review.

This is the actual defect. Not the flag. The substitution of retry for quarantine, and the absence of any artifact that records the substitution.

What a Passing Retry Cannot Prove

Three claims are routinely smuggled into a green build that contains retried tests, and none of them is supported by the retry.

It does not prove the failure was environmental. A passing retry is consistent with a race condition, a time-zone assumption, a shared-state leak from a prior test, or a genuine intermittent bug in production code. The Microsoft RootFinder paper states the risk directly: “Ignoring flaky test failures can be dangerous since a rerun test that passes might hide a real bug in the production code” (Lam et al., ISSTA 2019).

It does not prove the test is correct. A test that asserts the wrong thing can still be flaky, and a retry that passes tells you nothing about whether the assertion was ever meaningful.

It does not prove the code is correct. This is the claim release owners most need to resist. The Microsoft lifecycle study found “several cases where developers claim they ‘fixed’ a flaky test but our empirical experiments show that their changes do not fix or reduce these tests’ frequency of flaky-test failures.” The same epistemic trap applies one level down: a passing retry is a claim of a fix that has not been verified. The developer who sees green and moves on has accepted an unverified claim.

The Steelman: Retries Keep the Pipeline Honest

The strongest case for the retry flag is not that it hides flakes. It is that without it, teams do something worse: they ignore red builds entirely. Fowler’s warning is that “once you start ignoring a regression test failure, then that test is useless and you might as well throw it away.” A retry that passes keeps the failure visible in the run record — Playwright’s flaky category, Cypress’s attempt screenshots — while preventing a single unstable test from blocking every merge. That is a defensible trade.

GitHub’s numbers support the productivity argument. Before their flaky-test management system, “1 in 11 commits had at least one red build caused by a flaky test, or about 9 percent of commits.” After, the rate dropped below half a percent. That improvement came from a broader system — detection, impact scoring, issue assignment — not from retries alone, and GitHub is careful to say so. But the retry was a component of it.

The steelman holds only under one condition: the retried pass must remain visible as its own category. Where the build status collapses it into green, the steelman collapses with it. The flag is defensible; the dashboard that hides the flag’s output is not.

What to Instrument Alongside the Flag

The recommendation is not to remove the retry. It is to make the retried pass legible as a distinct quantity, and to attach a policy to it. Four design questions a release owner can put to the team this week:

  1. Is the retried pass surfaced per test, or only per build? Playwright and Cypress already emit the category. If the CI dashboard shows only pass/fail, the category is being discarded before anyone reads it. The first fix is a reporting fix, not a configuration fix.
  2. What is the retry rate per test, not the retry count per build? A build-level count of two retries tells you nothing about which test is unstable. A per-test retry rate over a rolling window tells you which test to quarantine, fix, or delete. The count without the rate is a number without a referent.
  3. What happens when a test’s retry rate crosses a threshold? Gradle’s approach is instructive: too-flaky tests are quarantined into a nightly job, reviewed weekly, and fixed on a dedicated fix-it day when the total exceeds a threshold. The threshold is a policy decision, not a research finding. The point is that a threshold exists and triggers an action other than another retry.
  4. Does the release record distinguish first-attempt passes from retried passes? If the release notes or the deploy gate say “all tests passed” without qualification, the release owner is reading a collapsed quantity. The fix is a line in the release template, not a new tool.

The Operational Recommendation

One change a senior practitioner can make immediately, without touching the retry configuration: add a first-attempt pass rate to the release gate, alongside the overall pass rate. The overall rate is what the retry flag produces. The first-attempt rate is what the suite would have produced without it. The gap between the two is the flake load the retry is absorbing, expressed as a single number that a release owner can read in the same glance as the green check.

This is not a new metric and it is not a research finding. It is the same information Playwright already categorizes as “flaky” versus “passed,” aggregated to the level where the release decision is actually made. The retry flag is not dishonest by itself. It becomes dishonest when the build status is the only artifact anyone reads. Making the retried pass visible as its own category — in the dashboard, in the release record, and in the gate — is the smallest change that keeps the green honest.

FAQ

Does --retries 2 mean the same thing in every CI system?

No. The literal flag varies. Cypress and Playwright configure retries in their own config files and categorize retried passes separately. GitLab’s retry keyword re-runs the whole job, not the failing test. GitHub Actions does not document a test-level retry flag in its workflow syntax; retries there are typically implemented by re-running the job or by the test runner’s own configuration. The pattern is common; the semantics are not interchangeable.

Is a retried pass evidence that the test is flaky?

It is evidence that the test is non-deterministic under some condition. It is not evidence about which condition, and it does not distinguish a race condition from a time-zone assumption from a shared-state leak. GitHub’s write-up notes that rerun-based detection misses entire classes of flake, such as time-based failures.

Should we remove the retry flag?

Not necessarily. Removing it without replacing it with quarantine and per-test retry-rate reporting tends to produce the outcome Fowler warns about: teams start ignoring red builds. The flag is a reasonable build-unblocking mechanism. The problem is the reporting layer that hides what it did.

How is this different from quarantine?

Quarantine removes a test from the blocking suite so the remaining signal stays clean, and creates a tracked work item. Retry keeps the test in the blocking suite and re-rolls the outcome. A team that uses retry as a substitute for quarantine has neither a clean signal nor a tracked item.

Related Post