Skip to main content

🩺 flake-doctor

Find the flaky tests hiding in your CI history.
Then prove what causes them, and that the fix works.

CI License: MIT Python 3.9+ No dependencies pytest

flake-doctor scan finding 7 flaky tests in aiohttp's CI history

A real scan of aiohttp's last 30 days of CI, replayed. Numbers and messages are from the actual run.

Quick start · How it works · Real results · Diagnose a test · FAQ


Every team with CI has tests that fail for no reason. Someone clicks Re-run, it goes green, and the flaky test lives on to waste the next person's afternoon. Nobody keeps a list of which tests do this, but your CI history already does: every time a job failed and then passed on the same commit, a test flaked.

flake-doctor reads that history, tells you which pytest tests are flaky and what they cost you, then helps you diagnose and fix each one with evidence instead of sleep() and retries.

🚀 Quick start

Command line: scan any repo you can read
pipx install git+https://github.com/ChiragPatankar/flake-doctor   # PyPI release coming: pipx install flake-doctor
export GITHUB_TOKEN=...                                            # or `gh auth login`, or ~/.config/flake-doctor/token
flake-doctor scan owner/repo                                       # or run it inside a clone and omit owner/repo
Option What it does
--days 60 how far back to look (default 30)
--workflow tests only workflows whose name or file matches
--branch main only runs on one branch
--format markdown|json, --output FILE report format and destination (--json-output/--markdown-output for extra copies)
--max-logs 400 download budget; logs that can prove flakiness are read first
--scan-passing also read passing logs, to catch tests pytest-rerunfailures quietly retried
--all also list failures that look real rather than flaky
--fail-on-flaky exit 1 if anything flaky is found (for CI gates)

Job logs are cached in ~/.cache/flake-doctor, so a repeat scan only downloads what's new.

GitHub Action: a "Flaky test report" issue that updates itself
# .github/workflows/flaky-tests.yml
name: Flaky test report
on:
  schedule:
    - cron: "0 6 * * 1"     # every Monday
  workflow_dispatch:

permissions:
  actions: read
  issues: write

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: ChiragPatankar/flake-doctor@v0
        with:
          days: 30
          workflow: tests     # optional: only your test workflow(s)

The report also goes to the job summary. Outputs: flaky-count, suspect-count, report (JSON path). Set fail-on-flaky: true to fail the job when flaky tests are found, or create-issue: false to skip the issue.

Claude Code plugin: let Claude find, fix and verify them
/plugin marketplace add ChiragPatankar/flake-doctor
/plugin install flake-doctor@flake-doctor

Then ask things like "CI keeps going red, which tests are flaky?" or "test_checkout fails on CI but never locally, fix it." The skill scans the CI history, measures before touching code, finds the mechanism (with a deterministic reproduction where it can), fixes the cause rather than adding retries, and reruns enough times to make "it passed" mean something.

🔍 How it works

flowchart LR
    H[("GitHub Actions<br>runs + job logs")] --> S["<b>flake-doctor scan</b>"]
    S --> F["🔴 <b>flaky</b><br>failed, then passed<br>on the same commit"]
    S --> P["🟠 <b>suspect</b><br>fails on many branches<br>while CI mostly passes"]
    S --> X["⚪ hidden<br>real failures, breakages,<br>lint / infra"]
    F --> R["<b>flake-doctor run</b><br>alone · shuffled · under load"]
    P --> R
    R -->|order-dependent| PO["<b>flake-doctor polluter</b><br>bisects to the leaking test"]
    R -->|intrinsic| HI["<b>flake-doctor hints</b><br>clock · sleep · random · sets · globals"]
    PO --> FIX["fix the cause<br>+ rerun to prove it"]
    HI --> FIX
Verdict Evidence required
🔴 flaky the same job (workflow + job name + matrix) passed on the same commit after the test failed, or pytest-rerunfailures had to retry it
🟠 suspect failed on 3+ commits across 2+ branches, and the workflow passed at least half its runs around those failures
⚪ hidden anything else: failures on one branch (probably a real bug), failures while CI was red everywhere (a breakage, e.g. a new dependency release), and failed jobs with no pytest failures at all

📊 Results on real projects

30 days of GitHub Actions history (19 Sep to 19 Oct 2026), default settings:

Project Runs scanned Failed jobs Flaky tests What they were
pydantic 1,241 1,144 7 4 date tests that fail whenever CI runs across midnight UTC, plus 3 in third-party suites it runs
aiohttp 4,180 (25 days) 610 7 keep-alive and read timeouts hitting connection resets, a WebSocket heartbeat test, a timing assertion
fastapi 3,119 257 0 correctly not flagged: 29 "everywhere" failures were a dependency breakage
pandas 2,836 (7 days) 500 0 the jobs that passed on retry failed for infrastructure reasons (HTTP 500s, build errors)
The pydantic bug: a test that only fails after midnight

In tests/test_datetime.py, date.today() is evaluated inside @pytest.mark.parametrize, which runs when tests are collected, not when they run (simplified):

@pytest.mark.parametrize('value', (date.today(), date.today() + timedelta(1), '2064-06-01'))
def test_past_date_validation_fails(value, past_date_type):
    with pytest.raises(ValidationError):   # "today" must not count as a past date
        ...

A macOS job collected tests on 10 October and ran them after midnight UTC. By then "today" was yesterday, so PastDate accepted it:

value = datetime.date(2026, 10, 10)
E       Failed: DID NOT RAISE ValidationError

The re-run passed 50 minutes later. It's the kind of failure nobody investigates, because it only ever happens to someone else's job, late at night.

Most red CI isn't flaky tests

Across these four projects, the large majority of failed jobs were lint, type checks, docs builds, bots and infrastructure. flake-doctor reports those separately ("failed jobs without pytest failures" and "jobs that failed and then passed on the same commit") so they don't drown out the tests.

A first 30-day scan of a busy repository takes a few minutes and about 1,000 API requests, mostly log downloads. Repeat scans reuse the cache and take 20 to 90 requests.

🧪 Diagnose one test locally

Once you know which test is flaky, find out why. Real output from examples/warehouse, a 176-test project with a buried bug:

$ flake-doctor run "tests/test_checkout.py::test_order_total[standard]"

Isolated runs: 0/10 failed (0%)

Shuffled-suite runs: 13/20 failed (65%)
   13x  AssertionError: assert 104.29 == 129.11
  tests that change the outcome when they run before it:
    +1.00  tests/test_promotions.py::test_flash_sale_price[WID-100S-20]  (failed 13/13 when before, 0/7 when after)

Verdict: ORDER-DEPENDENT
  Passes alone but fails in some suite orders: another test leaks state into it.
  Next: flake-doctor polluter 'tests/test_checkout.py::test_order_total[standard]' --seed 868885 --scope tests

One parametrized promotions test mutates a dict returned by an lru_cache, silently repricing the product for every later test (and, in production, for every later customer).

Command What you get
flake-doctor run <test> failure rate alone and in shuffled suite order, grouped failure messages, tests that correlate with failure, a verdict, and how many clean runs it takes to trust a fix. --stress loads every CPU core like a crowded CI runner; --json saves before/after results.
flake-doctor polluter <test> --seed N the exact test that breaks it when run first, plus a two-test reproduction command
flake-doctor hints <test> suspicious lines in the test and the code it imports: sleeps, real clocks, unseeded randomness, set/filesystem ordering, unrestored globals and env vars, network calls, fixed ports and paths

causes.md is a practical guide to each kind of flakiness, the right fix, and the "fixes" that only hide it.

❓ FAQ

Do I need a token? What can it access?

GitHub requires authentication to download job logs, even for public repos. Read access to the repository's Actions is enough; Issues write is only needed for --issue. Without a token, scan still lists the jobs that failed and then passed on the same commit, which needs no logs.

Is my code or data sent anywhere?

No. flake-doctor only talks to the GitHub API, and only reads (except --issue, which writes one issue). Your token is never forwarded to the storage host GitHub redirects log downloads to, and logs are cached locally in ~/.cache/flake-doctor.

Which test frameworks and CI systems are supported?

pytest on GitHub Actions. Test names come from pytest's FAILED/ERROR summary, xdist progress lines, -v output, pytest-pretty's failure table, or pytest's own failure sections, so it works whatever summary plugin you use. Retries are attributed to tests from RERUN lines (needs -v or -rR). The job-level report works for any language.

My project never re-runs jobs. Will it find anything?

Fewer confirmed flakes, yes. Push and pull-request runs of the same commit still count as a same-commit pass, and "suspects" still surface. Logs expire after 90 days by default, so very old failures can't be attributed.

Why not just add retries?

Retries make the symptom rarer and leave the cause in place. Sometimes the cause is a real bug: the pydantic test above is fine, but the warehouse example's polluter would charge real customers the wrong price. flake-doctor helps you find the cause and prove it's fixed.

How much does a scan cost in API requests?

About one request per 100 runs, one per failed or re-run run, and one per job log read. Big test matrices can fail dozens of jobs at once, so logs are budgeted (--max-logs): jobs with a same-commit pass first, then at most two matrix siblings per run, newest first.

Does the Claude Code skill actually help? (benchmarks)

evals/ holds the benchmark: realistic requests run by Claude with and without the skill against examples/flaky-zoo and the harder examples/warehouse, graded by scripts that rerun each fixed test 60 to 200 times and check the product code directly.

The honest result: on small, readable codebases a strong model fixes these flakes without the skill too. The skill made verification more rigorous (fixes checked with 50+ reruns: 3/3 with the skill vs 1/3 without), but the outcome-changing part is finding flaky tests in the first place, which needs CI history no model can see by reading code. That's why scan is the core of this project.

🗺️ Roadmap

  • PyPI release
  • JUnit XML artifacts as an alternative to log parsing
  • Jest/Vitest and Go test output
  • GitLab CI
  • PR comments when a failure matches a known flaky test

🤝 Contributing

Issues and PRs welcome, especially CI log excerpts the parser gets wrong. See CONTRIBUTING.md.

License

MIT

Metadata

Release files for flake-doctor 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake-doctor 0.1.0
File Size Uploaded Provenance Actions
flake_doctor-0.1.0.tar.gz 48.5 kB With provenance Details for flake_doctor-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake-doctor 0.1.0
File Interpreter ABI Platform Actions
flake_doctor-0.1.0-py3-none-any.whl Python 3 none any Details for flake_doctor-0.1.0-py3-none-any.whl

Total release size: 87.6 kB

Release files / flake_doctor-0.1.0.tar.gz

Download URL flake_doctor-0.1.0.tar.gz
Size 48.5 kB
Tags Source
SHA-256 checksum
How to use checksums
52e339d724a2cd19a0043c294d57ab54b5b6cc57075ad6b0d3c21e0e31131f1c
BLAKE2b-256 checksum
How to use checksums
77199eca0fb9b9ee69f419df95af79b405f400f15b6b8d86371d5953e7a94887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / flake_doctor-0.1.0-py3-none-any.whl

Download URL flake_doctor-0.1.0-py3-none-any.whl
Size 39.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4581f3bf15e05e8505ba627b297c2b53e5ef0195653102b438ba6eddebee367
BLAKE2b-256 checksum
How to use checksums
fe7895650db5c42db1e30600ddfa940d4b7748ee485a7a4699d39d53529ecad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for flake-doctor 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flake_doctor-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page