RETRIES HIDE THE BUG

A pass on the second try is still a failure

L216 MINTESTING
PREDICT

Your CI retries a failed test up to three times and counts any pass as a pass. A test exercises a race in your checkout code that fails about four runs in ten. How often does a build containing that bug go green?

A retry asks the same question again and reports only the best answer. For a deterministic bug that does nothing. For a race, a timeout or a shared resource, it turns “fails sometimes” into “passes”, and the failed attempts disappear. That is the opposite of what a flaky test needs, which is a record that it flaked.

The honest policy keeps retries and keeps the evidence. It records every attempt, treats a pass on retry as a signal, fails a vanishing assertion because it may be your product, and quarantines a repeating infrastructure flake with an owner and a deadline. The same idea sits behind retries in production code: a retry is only safe when something notices it happened.

▶ SIMULATION
CI RUNNER
policy: silent retry, up to 3
builds: 0
THE PRODUCT
checkout_stock has a real race: yes
builds deployed over a race nobody was told about: 0
THE TEAM SEES
flaky tests on the dashboard: 0
tests that actually needed a retry: 0
last—
✓ a build never goes green over a product race that nobody was told about✓ the flaky count the team sees equals the tests that needed a retry✓ a test that never fails is never flagged
SCHEDULE
01[CI]policy: retry a failed test up to 3 times; any pass is a pass; nothing is recorded
02[CI]a build runs the three tests, retrying failures
03[CI]a build runs the three tests, retrying failures
04[CI]a build runs the three tests, retrying failures
05[CI]a build runs the three tests, retrying failures
06[CI]a build runs the three tests, retrying failures
07[CI]a build runs the three tests, retrying failures
08[CI]a build runs the three tests, retrying failures
09[CI]report
Start of auto-retry, nothing recorded scenario. 9 steps.
# the runner
retry_failed_tests: 3        # any pass is a pass
# no record of the failed attempts
# the dashboard counts tests that failed all 3 times: 0
# a real race passes on attempt 2 and ships

Compare the dashboard’s flaky count with the number of tests that actually needed a retry. In the first scenario they never meet.

BREAK IT NOT YET

The suite has been quiet for three nights under the auto-retry policy. Add one event before a build. Make a build go green over a real product race that nobody is told about.

GOAL: a build deploys over a product race, unflagged

FIX IT NOT YET

Write decide(history, ctx) for one test. history is that test's builds, oldest first; each build is an array of attempts, in order, { ok, kind } (kind is 'assertion' or 'infra' on a failure). ctx is { owner, today }. Return { verdict, flagged, owner?, deadline? }. The latest build decides. All attempts failed: 'fail', not flagged. Passed first time: 'pass', not flagged. Passed only on a retry: flagged, and if any earlier attempt failed an assertion the verdict is 'fail', because a retry does not erase a product bug. Otherwise 'pass', unless three or more of the last 10 builds (this one included) passed only on a retry: then 'quarantine' with owner: ctx.owner and deadline: ctx.today + 14.

Mental model:

A retry is a measurement, not a repair. Keep the failed attempts, because a pass on the second try is information about the first. A test that only passes on retry is a signal, and anything you put in quarantine needs an owner and a date, or it stays there for good.

IN PRODUCTION

Any CI with a retry flag: Jest's jest.retryTimes, pytest-rerunfailures, Gradle's test retry plugin, GitHub Actions re-run buttons, Buildkite and CircleCI automatic retries. The safe settings record each retry and report tests that passed only on retry as their own category. Quarantine lists, with an owner and an expiry, replace skip annotations that nobody revisits. Slack's write-up above describes a suppression system that disables a test after a failure and opens a ticket for its owner.

IN INTERVIEWS

“Our CI retries failures three times. Is that a problem?” Say it is fine for infrastructure noise and dangerous when it is silent. Explain why a race passes on retry, then describe the fix: record every attempt, flag a pass on retry, fail on a vanishing assertion until someone has looked, and quarantine with an owner and a deadline so the flaky count goes down instead of up.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: Eventual Consistency in Assertions →