Parts 1 and 2 were about why a test passes on your machine and fails in CI. Twelve causes so far, most of them from your comments.

This part is about what happens next. Most teams answer a flaky test with a retry. The retry passes, the build goes green, and the cause stays in the suite.

So first the twelve causes, sorted. Then four CI rules that stop "passed on retry" from becoming normal.

The 12 causes in 9 buckets

Bucket What it looks like First fix
1. Brittle selectors Breaks when a class or layout changes Role and label locators
2. Timing Slower runner, checks that don't wait Web-first assertions, no isVisible() checks
3. Flake noise Retries hide the real cause Treat "flaky" as a failure (below)
4. Shared data Parallel workers, leftover state, no ORDER BY Each test creates its own data
5. Dependency drift CI resolves a different version npm ci, committed lockfile
6. The network VPN, proxy, live third-party APIs Mock or record and replay
7. Pipeline config CI=true changes defaults, shallow clones Read your config with CI set
8. Time, locale, order UTC runners, readdir order Pin timezone and locale, sort lists
9. Ownership Nobody looks first, quarantine never ends An owner and an end date (below)

Each bucket needs a different fix. Naming the bucket first saves you from fixing the wrong thing.

Why retries hide the cause

The config that npm init playwright generates has this:

retries: process.env.CI ? 2 : 0, 

So locally a flaky test fails and you see it. In CI it fails, retries, passes, and the run exits green. The report marks it "flaky", but nobody reads the report of a green build.

Retries are fine. Retries with no rule around them are where flakiness piles up.

Rule 1: "passed on retry" fails the run

Playwright has a flag for exactly this:

// playwright.config.ts export default defineConfig({ retries: process.env.CI ? 2 : 0, failOnFlakyTests: !!process.env.CI, }); 

Or on the command line: npx playwright test --fail-on-flaky-tests. The CLI flag has been around since 1.45; the config option came in 1.52.

With it on, a test that only passes on retry fails the run. You still get the retry, so you still get the trace from the second attempt. You just don't get a green tick for it.

On a suite with years of old flakiness, this is too strict on day one. That's what rule 2 is for.

Rule 2: quarantine old flakiness, with an owner and an end date

A reader on Reddit suggested a split I like: new flakiness blocks the PR, old flakiness keeps running but doesn't block.

Tag the known flaky tests:

test('order total includes delivery', { tag: '@quarantine', annotation: { type: 'quarantine', description: 'owner: payments team, until 2026-12-16' }, }, async ({ page }) => { // ... }); 

Then run two jobs:

# Blocking job: everything except quarantined tests, flaky fails the run npx playwright test --grep-invert @quarantine --fail-on-flaky-tests # Non-blocking job: quarantined tests still run and report npx playwright test --grep @quarantine 

Any new flakiness is yours to fix right away. The quarantined tests keep their history while someone works on them.

The annotation is the important part. A quarantine without an owner and a date is just a slower way of deleting the test. When the date passes, someone decides: fix it, rewrite it, or delete it on purpose. A small check in CI that fails when a date has passed keeps that honest.

Rule 3: prove a new test before it merges

Most flakiness is easier to catch on the day the test is written. Run the tests you changed many times before they merge:

npx playwright test --only-changed=origin/main --repeat-each=15 

--only-changed (Playwright 1.46+) runs the test files changed against origin/main, plus any test files that import a changed file. --repeat-each=15 runs each of them 15 times. It needs the git history, so use fetch-depth: 0 on checkout. Yes, the shallow clone from part 2 again. A test that can't pass 15 times in a row on a CI runner isn't ready, and you find out before it lands on everyone else.

Rule 4: cheap evidence on every failure, heavy evidence on retry

I asked on r/cicd what people save from a failed CI run. The best answer split it by cost.

Cheap, on every failure: the log with the random seed at the top, tool versions, the runner image version, timezone and locale.

Heavy, only when it matters: traces, video, database dumps. trace: 'on-first-retry' already does this for traces: no trace on the first attempt, a full one on the retry.

Another reader added the one that explains most "passes locally" failures: dump the resolved dependency tree and the runner image next to the logs, then diff them against a passing run.

- name: Record the environment if: failure() run: | mkdir -p env npm ls --all > env/deps.txt || true echo "$ImageOS $ImageVersion" > env/runner.txt - uses: actions/upload-artifact@v4 if: failure() with: name: failed-run-env path: env/ retention-days: 7 

ImageOS and ImageVersion are set on GitHub-hosted runners. On your own image, record its digest instead.

On retention: shorter than you think. GitHub keeps artifacts for 90 days by default. Seven is plenty for something you'll look at this week. And treat artifacts as if they could hold real data: log the seed so you can regenerate the data instead of storing it.

Where AI fits

The deps.txt diff is a good job for an AI assistant. Paste the dependency tree from a green run and a red run, and it will find the one package that moved faster than you will. It can't guess that diff without the files, so rule 4 comes first.

Over to you

Does your team fail the build on flaky tests, or let them through with a retry? And if you quarantine, what stops the quarantine list growing forever?

Thank you to the Reddit readers whose answers shaped rules 2 and 4.

I'm building Locator League, browser-based Playwright challenges where your test runs for real. The first CI challenge, Fix the Flaky Test, is free with an account.