Flake Rate After a Quarantine Sweep: The Math, Agents Too
The flake rate drops sharply the week after a quarantine sweep, and nobody shipped a fix. The dashboard looks healthier and the senior engineers are suspicious, because nothing changed in the test code. What changed is which tests are being counted. Confusing that with a reliability improvement is how a quarantine backlog turns into a deferred-fix liability that never gets repaid.
Agentic quality engineering makes sweeps cheaper and therefore more frequent. A coding agent can find every flaky test, add the quarantine marker and open the pull request in minutes. That is useful work, but it produces exactly the metric drop this article is about, and if the same agent is later asked to "improve the flake rate", quarantining is the shortest path to the target.
This article walks through the arithmetic behind the drop, a query that keeps active, total and quarantine rates side by side, a flake budget enforced in CI, and the misreadings that survive even in experienced teams.
Learn Node.js, Cucumber, GitHub Copilot, APIs, CI/CD, and modern automation by building a complete framework.
Flake Rate Meaning: What the Metric Is Actually Counting
Flake rate is the proportion of test runs that produce a non-deterministic result — a test that fails on one attempt and passes on a retry without any code change. The canonical formula is: (flaky runs) / (total runs) over a rolling window, typically 7 or 14 days. A test is counted as flaky if it exhibits at least one pass/fail alternation within a single commit SHA. Most tooling — ReportPortal, Buildkite Test Analytics, Datadog CI Visibility — computes this at the test-case level and then aggregates to a suite or pipeline level.
Where teams get tripped up is the aggregation. Suite-level flake rate is a weighted average across every active test. Remove 30 high-frequency flakers via quarantine and the numerator drops sharply, but so does the denominator's noise floor. The remaining tests look more stable not because they improved, but because the noisiest contributors are no longer in the pool. This is the same statistical artifact that causes flake rate averages to obscure your highest-risk tests — the aggregate masks per-test behavior entirely.
Instrumenting the Metric So the Drop Means Something
The first step is tracking quarantined tests as a separate population, not dropping them from your dataset. Store every run result — active or quarantined — and tag the quarantine state at query time. In PostgreSQL against a JUnit XML ingest pipeline:
-- Flake rate for ACTIVE tests only (what most dashboards show)
SELECT
DATE_TRUNC('day', run_at) AS day,
COUNT(*) FILTER (WHERE is_flaky = true AND quarantined = false)::float
/ NULLIF(COUNT(*) FILTER (WHERE quarantined = false), 0) AS active_flake_rate,
-- Flake rate including quarantined tests (the honest number)
COUNT(*) FILTER (WHERE is_flaky = true)::float
/ NULLIF(COUNT(*), 0) AS total_flake_rate,
-- Quarantine rate: what fraction of the suite is currently benched
COUNT(DISTINCT test_id) FILTER (WHERE quarantined = true)::float
/ NULLIF(COUNT(DISTINCT test_id), 0) AS quarantine_rate
FROM test_runs
WHERE run_at > NOW() - INTERVAL '14 days'
GROUP BY 1
ORDER BY 1;
Plot all three lines on the same Grafana panel. When active flake rate falls while quarantine rate rises, you're looking at a measurement artifact, not an engineering win. The total flake rate line stays flat or climbs — that's your ground truth. After a sweep, the typical shape is a sharp fall in the active line, a step up in quarantine rate, and a total line that barely moves. Route triage and reporting on the total line, not the active-only number.
The second instrument you need is a flake budget. A flake budget is a ceiling on the acceptable quarantine rate — typically 2–5% of the active suite — beyond which new quarantines require a corresponding fix commitment. Define it in your pipeline config so it enforces itself:
# .github/workflows/flake-budget-gate.yml
- name: Check flake budget
run: |
python scripts/flake_budget_check.py --budget-pct 3.0
env:
TESTRESULTS_DB_URL: ${{ secrets.TESTRESULTS_DB_URL }}
# scripts/flake_budget_check.py (Python 3.11+, psycopg2)
import sys, psycopg2, os
conn = psycopg2.connect(os.environ["TESTRESULTS_DB_URL"])
cur = conn.cursor()
cur.execute("""
SELECT
COUNT(*) FILTER (WHERE quarantined = true)::float / NULLIF(COUNT(*), 0) * 100
FROM (SELECT DISTINCT test_id, quarantined FROM test_runs
WHERE run_at > NOW() - INTERVAL '1 day') t
""")
rate = cur.fetchone()[0] or 0.0
budget = float(sys.argv[sys.argv.index("--budget-pct") + 1])
print(f"Quarantine rate: {rate:.2f}% | Budget: {budget:.2f}%")
if rate > budget:
sys.exit(1)
This gate fires when the quarantine backlog exceeds the budget, forcing the team to fix before quarantining more. It also means the week-after drop in flake rate triggers a budget check, not a celebration. Note that flake rate compounds across dependent pipeline stages, so three stages each at a 3% flake rate give close to a 9% chance that at least one of them flakes on a given pipeline run. Set budgets per stage, not just at the suite level.
Pitfalls That Survive Even Experienced Teams
Celebrating the drop without auditing the quarantine list. The most common mistake is treating a falling flake rate as a closed loop. Quarantined tests accumulate silently. Without a scheduled review cadence — weekly at minimum, wired to a Slack reminder or a PagerDuty escalation policy — the list grows until it represents 15–20% of the suite, at which point the active flake rate metric has lost most of its predictive value. The fix is mechanical: every quarantined test gets a JIRA ticket with a due date, and the budget gate blocks new quarantines when the backlog is over threshold.
Using a rolling average window that's too wide. A 30-day rolling window smooths over the sweep entirely, making the drop look gradual and organic. Teams running 7-day windows see the artifact clearly and can respond. Fourteen days is the practical maximum for a fast-shipping team; anything wider obscures the causal relationship between a sweep and the metric movement. If your observability stack is Datadog or Honeycomb, set the flake rate query window explicitly rather than relying on whatever range the dashboard happens to default to.
When an agent runs the sweep
Delegating a quarantine sweep to a coding agent is reasonable: finding tests that flipped on the same commit and adding a marker is mechanical. The risk is in what the agent is told to optimize. "Reduce the flake rate" is satisfied by quarantining; "reduce the total flake rate without raising the quarantine rate" is not. Give the agent the honest metric from the query above, not the active-only one.
Make each agent-run sweep produce a reviewable record rather than a silent metric change:
- One evidence line per test. The pull request lists each quarantined test with the commits where it both passed and failed, so the reviewer can see it is flaky rather than broken.
- A cause hypothesis at intake. The agent proposes the layer (test code, infrastructure, application race) and a person confirms or corrects it. That label drives the fix queue after the sweep.
- The budget check runs on the pull request. If the sweep would push the quarantine rate over budget, the gate fails before merge, and the team decides which fixes come first.
- Agent sweeps are annotated. Tag the merge commit so the Grafana panel shows a marker on the day the active flake rate drops. Anyone reading the chart later sees the cause.
Exclude model-calling tests from the sweep entirely. They fail some fraction of runs by design; quarantining them removes the only check on prompt and model regressions. Report them as pass rates over N runs in their own panel. The quarantine rate article explains how to price the backlog a sweep leaves behind.
What Most Teams Misread in the Post-Sweep Data
Myth: a lower flake rate means the suite is more reliable. Reliability is a function of signal fidelity — how confidently a red build predicts a real defect. Quarantining noisy tests improves signal fidelity only if the quarantined tests are also being fixed. If they're just hidden, you've traded false positives for false negatives: the suite looks clean while real regressions in quarantined areas go undetected. This is why failure rate often spikes after a flake is actually fixed — the test starts catching real bugs it was previously masking with noise.
Myth: flakiness is a test-code problem. A significant fraction of flakes originate in test infrastructure — container startup timing, shared database state, network timeouts in CI environments — not in the test logic itself. A quarantine sweep that doesn't categorize root cause by layer (test code vs. infrastructure vs. application race condition) will see the same tests re-flake after they're reinstated. Tag every quarantined test with a cause hypothesis at quarantine time; it takes 90 seconds and makes the fix prioritization queue dramatically more actionable than a flat list of test names.
The week-after drop is a measurement artifact until proven otherwise. Run the three-line query — active flake rate, total flake rate, quarantine rate — before drawing any conclusions. Set a flake budget with a hard gate in CI, categorize quarantine root causes at intake, and schedule a weekly review. If you're also seeing suite-level metric shifts after structural changes, the same denominator dynamics apply to flake rate resets after a suite refactor — worth reading alongside this one.
Note: This article is for informational purposes only and is not a substitute for professional advice. If you need guidance on specific situations described in this article, consider consulting a qualified professional.