Debugging a Flaky Test Suite With an AI Coding Assistant: What It Caught and What It Missed

A screen showing lines of source code in an editor

Image: MikeRun, CC BY-SA 4.0, via Wikimedia Commons.

Two published engineering write-ups of using an AI coding assistant against a real flaky test suite agree on the same pattern: the assistant is genuinely good at the part humans find tedious — running a suspect test hundreds of times and proposing a fix for each failure — and genuinely unreliable at knowing which of its own fixes are real versus cosmetic. Both teams shipped working results they were willing to write up publicly, with real before-and-after numbers attached rather than a vague endorsement. Neither team removed the human from the loop; the human’s job moved from writing fixes to judging which of the AI’s fixes were worth keeping.

Case One: A Quarantined Test Group, Run Overnight in Batches

A Rails team at thoughtbot had a group of tests tagged :flaky and quarantined out of CI for years — that group alone was failing 60 percent of CI runs before the team tried fixing it with an AI coding assistant. They ran the quarantined group repeatedly in Claude Code overnight, starting at five runs per batch and escalating to ten, fifty, then one hundred runs once the obvious failures stopped appearing, with the model keeping a markdown progress file across the session and explicit instructions not to declare success prematurely. Three weeks later, including roughly two weeks of human cleanup after the initial overnight run, the group was back in CI running at 0 percent failures on the main branch.

Case Two: A Standing Weekly Triage Pipeline

RavenDB runs a different scale of problem: over 32,000 tests, executed tens of millions of times a month across continuous CI, at a reliability the team estimates around 99.999 percent — which still produces roughly 10 to 20 flaky failures every week simply from the volume of runs. Instead of a one-time overnight push, the team built a standing pipeline: failures are collected weekly, copy-pasted to Claude for triage and an attempted fix, and the result becomes an issue containing either a working fix or a written summary of what Claude found, which an engineer then reviews before it merges. The author estimates the triage work would otherwise have taken a developer one to two weeks, though he is explicit that this is his own estimate, not a measured figure, and the article does not report what share of Claude’s proposed fixes were ultimately accepted.

What It Actually Caught, Reliably

Both teams report the assistant finding real, non-obvious causes, not just suppressing symptoms. RavenDB’s standout example was a test “waiting on the wrong resource” — code that looked correct, where the test passed almost every time only because the asserted value happened to already be set by the time the wait condition cleared, a timing coincidence rather than a correctness guarantee. Thoughtbot’s team reports the same shape of finding across many of their quarantined tests, once the noise was filtered out: a genuine race condition or ordering assumption that had been silently tolerated for years specifically because it failed rarely enough that nobody prioritized root-causing it.

What It Got Wrong, in Both Cases

The failure modes both teams describe are strikingly similar given how different the two codebases are.

  • Surface patches instead of root causes. RavenDB’s author describes some fixes as surface-level, addressing the symptom in the test rather than the underlying timing issue.
  • Noise mixed in with real fixes. Thoughtbot found unnecessary added sleeps, needless scope changes, and irrelevant tweaks bundled alongside the one useful fix per test, which had to be manually separated out.
  • Out-of-scope changes. RavenDB’s review process specifically had to catch and discard changes the model made that had nothing to do with the flaky test it was asked to fix.
  • Risk of cargo-cult patterns. Thoughtbot’s team notes explicitly that without the cleanup pass, the accepted fixes would have encouraged copying a pattern, such as an added sleep, that looks like a fix but hides the real problem, spreading a bad habit through the codebase instead of removing it.

The Human Review Time Didn’t Disappear — It Moved

Neither case study claims the AI assistant reduced the need for an experienced engineer; both are explicit that it changed what the engineer spends time on. Thoughtbot’s author credits over a decade of Rails and RSpec experience as essential to turning Claude’s raw output into something sustainable, and spent roughly two weeks separating coincidental improvements from real ones, re-running tests to prove which changes actually mattered, and unifying similar fixes across the suite. RavenDB’s workflow builds the same judgment step directly into the pipeline, as a standing review stage rather than a one-time cleanup, specifically because the model’s fixes still need an engineer to decide which ones are worth merging every single week.

A Workflow Worth Copying, Not Just the Headline Result

Stripped of the specific numbers, both case studies converge on the same four-step shape, which generalizes past Rails and past either specific vendor’s test framework.

  1. Isolate the suspect set first. Both teams worked from a pre-identified group — a tagged quarantine list or a weekly collection of CI failures — rather than turning the assistant loose on the entire suite at once.
  2. Run repeatedly, escalating batch size. Thoughtbot’s five-to-one-hundred escalation exists specifically to build confidence that a fix held under increasing pressure, not just that it passed once.
  3. Require a durable record of reasoning, not just a diff. Thoughtbot’s markdown progress file and RavenDB’s issue-with-summary both give a human reviewer something to evaluate besides the code change itself — the model’s own account of what it tried and why.
  4. Treat every proposed fix as a candidate, not a merge. The review step is where both teams’ real engineering judgment gets applied, and it is the step that would be unsafe to skip even though it is the most tempting one to skip once the diff looks plausible.

That review step is the same discipline teams already apply to AI-generated changes elsewhere in the pipeline — the same caution behind an AI-generated GitHub Actions workflow checklist or a set of structured AI code-review prompts run across security, correctness, and test gaps. A flaky-test fix is a smaller, more contained version of the same underlying question: does a confident-looking, passing change actually address what it claims to, or does it just make today’s symptom go away. Writing a clear record of what changed and why, the same discipline covered in our guide to commit messages and pull request descriptions a model can actually use, is what lets next month’s reviewer tell the difference between this week’s real fix and a sleep statement someone will have to find and remove again later.

Neither article reports a case where the AI assistant found nothing useful at all, or made the suite measurably worse overall — which is itself worth flagging rather than assuming away. Both are published by teams motivated to share a success story, and the quieter failure mode both still describe — fixes that look done but are not, bundled in with the ones that are — is exactly the kind of result that would be easy to under-report even in an honest write-up, simply because the plausible-looking bad fixes are harder to notice than an outright crash.

A Starting Checklist for Trying This on Your Own Suite

Before pointing an AI coding assistant at a flaky suite, both case studies suggest the same preparation pays off regardless of language or framework.

StepWhy both teams did it
Tag or collect the specific failing tests first, rather than running against the whole suiteIsolating the suspect set is what made batch escalation and triage feasible at all; an untargeted run has no clear stopping point
Ask for a written record of what was tried and why, not just a diffThis is what let a human reviewer, days or weeks later, judge a fix without re-deriving the reasoning from scratch
Start with a small batch and escalate only once it stops finding new failuresThoughtbot’s five-to-one-hundred escalation specifically exists to build confidence under increasing pressure, not just a single pass
Budget real human review time, not zeroBoth teams spent one to several weeks of engineer time on review and cleanup; treating that time as optional is where the cargo-cult risk comes from
Review for root cause vs. symptom specifically, as its own checkNeither team’s assistant distinguished the two reliably on its own — a sleep statement that makes a test pass is not the same as a fix, and nothing in a passing test run tells you which one you got

The two case studies differ enormously in scale — a one-time overnight push against a quarantined group versus a standing weekly pipeline against tens of millions of monthly test runs — but neither team describes the AI assistant as something that worked unattended. The consistent lesson across both is narrower and more useful than “AI can fix flaky tests”: it can generate and test many candidate fixes far faster than a person can, which is genuinely valuable, and it still needs a person who already understands the codebase to tell a real fix from a plausible-looking one.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top