Engineering Diaries · CI/CD
§
CI/CDTestingDeveloper Experience

One Green Rerun Proves Almost Nothing. What 20 Green Runs Taught Me About Flaky Tests.

A single rerun turns a failed test green, but it does not tell you whether the test is flaky, how often it fails, or what else fails beside it. The 20-run scoring pipeline I use to turn intermittent CI failures into an ordered engineering queue.

01 · The misleading green build

A rerun is a recovery action, not a diagnosis

A failed CI job went green on its second attempt. Everyone moved on. That is a perfectly reasonable way to keep a release moving, but it is not evidence that the test was fine. It only tells us that the failure did not repeat that one time.

I have seen teams treat the green rerun as a verdict: a test was flaky, the failure is uninteresting, retry the job and close the tab. That behaviour quietly changes the meaning of a green build. It becomes proof that somebody was patient enough to click again, not proof that the change is safe.

The useful question is not, did it pass after a rerun? It is: how often does it fail when the commit is known good, and what does it fail alongside? Those are different questions and they need different evidence.

A test that fails once in twenty clean runs and a test that fails nineteen times are both flaky. They are not the same operational problem.

That distinction is why I built a detection run that starts from a known-green commit rather than from an unlucky pull request. The goal was not to create a clever flake score. The goal was to give engineers enough signal to decide whether to fix, quarantine, group, or simply stop blaming the latest code change.

02 · Control the experiment

Start with a commit that already earned your trust

Flakiness is easy to mismeasure because normal CI runs contain real code changes. If a test fails on a pull request, there are at least two plausible explanations: the change broke it, or the test is intermittent. Re-running the same commit reduces uncertainty, but it still does not separate a rare product failure from an unstable test unless the commit is independently known good.

Our reference point was a commit whose full suite had completed successfully. We ran that unchanged revision twenty times, using the same test command and recording every individual result. Twenty is not a magic number. It is a practical budget: enough samples to reveal repeat offenders without turning the detector into the largest user of CI capacity.

Control

Keep the commit, command, runtime family, and result parser stable. Record the environment and attempt number too, because a pattern tied to one runner image is a different problem from random test behaviour.

This setup does not prove a test will never fail in production. It makes a narrower claim: on an unchanged, previously green revision, this test produced inconsistent outcomes. That is an actionable and defensible claim.

03 · Measure per test

Count failures before you invent a severity label

The first score was deliberately boring:

flake-score.ts
const score = (failures: number, runs: number) =>\n  Math.round((failures / runs) * 100);

A test that fails 3 out of 20 runs has a 15% observed failure rate in that sample. Calling that a 15% chance of failure everywhere would overstate it. The sample is small and the execution environment matters. But it is still much more informative than the binary label flaky.

0/20
No signal in sample
1/20
Investigate if costly
5/20
High-confidence priority
20/20
Probably not intermittent

That last category matters. If a test fails on every supposedly green replay, do not hide it in a flaky-test queue. It may be an environmental regression, expired fixture, or broken assumption that deserves an ordinary incident path.

04 · Find the shared failure

A list of test names is rarely the unit of repair

The first version of any flake dashboard tends to become a long list of red test names. It looks precise and is often useless. Engineers repair shared causes: a mock server that starts late, a global clock that leaks, a browser session that is reused, or a fixture that another test mutates.

So the pipeline also aggregates results by module and suite. If six tests from one module appear in the same failing attempts, the priority is not six individual tickets. It is one investigation into the shared boundary.

Observed patternLikely next question
One isolated test fails across attemptsIs its assertion time-sensitive or order-dependent?
Several tests in one module fail togetherWhat setup, mock, or resource do they share?
Many unrelated modules fail on one attemptWas the runner, network, or test service unhealthy?

This grouping also prevents a bad incentive. Without it, a team can improve the dashboard by splitting one unstable suite into smaller test names. The count rises while the engineering problem stays exactly where it was.

05 · Make it operational

The report has to reach the people who can act on it

A CSV attached to a weekly email is technically a detection system. It is not one engineers will use. Our pipeline published the test and module scores to Datadog, a small S3-backed dashboard, and Slack. Each surface had a distinct job.

  • Datadog showed trends and made it possible to correlate spikes with runner changes or deployment windows.
  • The dashboard let owners inspect the exact attempts behind a score instead of trusting an aggregate.
  • Slack made newly prominent failures visible where the team was already discussing broken builds.

There is an important restraint here: do not page people for every intermittent test. Alerts become background noise quickly. The useful notification is a change in behaviour: a new repeat offender, a sharp increase, or a module whose instability is now blocking a meaningful part of the pipeline.

Design for investigationEvery score should link back to the individual attempts, test output, commit, and owning module. A ranking without evidence simply moves the argument from the CI log to a dashboard.
06 · Avoid false certainty

Twenty runs create a signal. They do not create a probability law.

Repeated runs have blind spots. If all twenty execute during a quiet period, they may miss the contention that happens when the queue is full. If every attempt lands on the same runner shape, they may miss platform-specific behaviour. And if the test only flakes after a particular state transition, replaying a clean commit may never hit it.

That is why the score needs context rather than theatre. Include run timestamps, runner metadata where available, and failure excerpts. Treat a low score as a lead, not a license to ignore a real failure. Treat a high score as a triage priority, not proof of root cause.

The right confidence statement is modest: this test was inconsistent under these repeatable conditions. Modest statements survive scrutiny and still help teams make faster decisions.

There is a parallel trap in quarantining. Quarantine can protect delivery while a repair is being built. It should have an owner, a reason, an expiry, and a visible cost. Otherwise it becomes a polite way to delete coverage without saying so.

07 · A repair order

Fix the failures that damage trust first

I would not sort a backlog only by flake percentage. A test that fails 2 out of 20 times on an expensive, frequently changed checkout path can cost more than a peripheral test that fails 8 times. The useful priority combines instability with blast radius.

Repeat runs
Score + cluster
Owner triage
Repair or expiry

In practice, start with failures that either block merges repeatedly, affect a shared suite, or make engineers rerun builds as habit. Then look for the repair with the largest shared payoff: isolate test data, await a real readiness signal, remove global state, or split a resource that should never have been shared.

The target is not a graph at zero forever. Real systems change. The target is a pipeline whose failures mean something again.

08 · The verdict

Make green mean that the code passed, not that someone retried it

Flaky tests are often framed as a test-framework annoyance. They are a reliability problem in the delivery system. Every unexplained red build asks an engineer to spend attention deciding whether to investigate, rerun, or gamble. Over time, that teaches the whole team to ignore the signal CI was meant to provide.

A known-green commit run twenty times is not sophisticated science. That is exactly why it works as a starting point. It replaces a vague label with observed behaviour, groups failures around causes rather than names, and puts the evidence where owners can act on it.

If you are beginning from scratch, do three things: choose one known-green revision, collect individual test outcomes across a fixed set of repeats, and publish the raw attempts next to the score. Do that before buying a new testing platform or adding another automatic rerun.

A green build should be a statement about the software, not an archaeological record of how many times the team had to ask it.
Written by Divyansh Singh. Views expressed are the author's own. Published October 2026. All code examples have been tested and verified.