Failure Rate Stable, Flake Frequency Rising: Agent-Era Fix
Failure rate is the number most teams watch, and when it holds steady for weeks it looks like good news. But it can stay flat while the suite gets steadily less reliable, because retries absorb flaky failures before they reach the final verdict. A test that fails on the first attempt and passes on the second adds nothing to failure rate, yet it costs a rerun, delays a merge, and teaches engineers to distrust red builds.
Agentic quality engineering widens this gap. Coding agents that open pull requests often re-run failed checks automatically or add retry decorators to get to green, which keeps failure rate flat and pushes flake frequency up where nobody looks. Suites also include more tests that call a model; if those get retried until they pass, their real pass rate disappears too.
This article explains why the two metrics diverge, how to capture attempt-level data and query flake rate in ClickHouse, how to set a flake budget enforced as a CI gate, and where the instrumentation usually breaks.
Learn Python, Behave, GitHub Copilot, APIs, and CI/CD by building a real framework you can finish in a weekend.
Flake Rate vs. Failure Rate: Two Different Clocks
Failure rate is the ratio of test runs that end in a final failure state — after all retry attempts are exhausted. Flake rate (sometimes called flake frequency) counts how often a test produces a non-deterministic result on any attempt, regardless of the final outcome. A test with a 40% flake rate can have a 0% failure rate if your retry count is high enough. These are not two views of the same metric — they have different denominators, different latencies, and different implications for developer trust.
Where failure rate fits in your test architecture is at the gate: it's the signal that blocks a merge or pages an on-call. Flake rate lives upstream of that gate, in the execution layer. Tracking it belongs on the same dashboard as first-attempt pass rate and failure signatures — because first-attempt pass rate is exactly what flake rate erodes. If you're only watching final-state metrics, you're watching a lagging indicator that retries have already sanitized.
Instrumenting Flake Rate and Defining a Flake Budget
The first step is separating first-attempt outcomes from final outcomes in your results store. Most JUnit XML parsers and CI integrations only write the final state. You need attempt-level rows. In GitHub Actions, set continue-on-error and capture each attempt's exit code, or use Pytest with pytest-rerunfailures and a custom plugin that writes per-attempt results to a structured log. Once you have attempt-level data in ClickHouse or BigQuery, flake rate is a straightforward query:
-- ClickHouse: flake rate per test over the last 14 days
SELECT
test_name,
countIf(attempt = 1 AND status = 'failed') AS first_attempt_failures,
countIf(attempt > 1 AND status = 'passed') AS recovered_on_retry,
round(
recovered_on_retry / nullIf(first_attempt_failures, 0) * 100, 2
) AS flake_rate_pct
FROM test_attempts
WHERE run_ts >= now() - INTERVAL 14 DAY
GROUP BY test_name
HAVING first_attempt_failures > 5
ORDER BY flake_rate_pct DESC
LIMIT 30;
This surfaces tests that are frequently recovering on retry — your highest-signal flake candidates. The HAVING first_attempt_failures > 5 filter eliminates statistical noise from rarely-run tests. Pair this with a Grafana time-series panel tracking flake_rate_pct over rolling 7-day windows; a rising slope on that panel while failure rate flatlines is the exact divergence pattern this article describes. Linking each flaky test to its retry log lines in Loki shortens triage, because the engineer starts from the first failing attempt.
Defining a Flake Budget
A flake budget is an explicit ceiling on acceptable flake rate — expressed either as a percentage of test executions or as an absolute retry count per pipeline run. It functions identically to an error budget in SRE: once consumed, new flaky tests are blocked from merge until the budget is restored. A reasonable starting point is a suite-wide flake budget of 2% of first-attempt executions per week, with a per-test cap of 15% flake rate before that test is quarantined. These numbers are not universal — calibrate against your retry cost and developer interrupt rate.
# GitHub Actions: fail the pipeline when flake budget is exceeded
- name: Check flake budget
run: |
python scripts/flake_budget_check.py \
--results-path ./test-results/ \
--budget-pct 2.0 \
--per-test-cap 15.0 \
--window-days 7
env:
CLICKHOUSE_DSN: ${{ secrets.CLICKHOUSE_DSN }}
The Python script queries the attempt-level table, computes suite-wide and per-test flake rates for the rolling window, and exits non-zero if either threshold is breached. This makes the flake budget a hard gate — not a dashboard someone checks on Fridays. Note that fixing a high-flake test can temporarily spike your apparent failure rate as retries no longer rescue it; that pattern is well-documented and failure rate often rises immediately after a flake is fixed for exactly this reason.
Where Flake Instrumentation Breaks Down in Practice
The most common mistake is configuring retries at the CI level (a retry wrapper action in GitHub Actions, or Buildkite's automatic job retries) without capturing attempt-level data. The retry happens, the pipeline goes green, and the attempt record is never written anywhere. You end up with a failure rate that looks healthy and zero visibility into flake frequency — the worst possible combination. Fix this before you build any dashboard: instrument at the test runner level, not the CI job level, so every attempt is a row.
The second mistake is treating flake rate as a team-level vanity metric rather than a per-test SLO. Aggregating flake rate across a 4,000-test suite produces a number that's almost always small enough to ignore, even when 20 tests are each flaking 30% of the time. Flake budgets only work when they're enforced at the test identity level. Similarly, teams that track duration variance alongside flake rate catch environmental instability — slow DNS, saturated test databases — that manifests as flakiness before it manifests as failure.
Keeping agent retries and model-calling tests visible
Attempt-level data only helps if every attempt is recorded, including the ones an agent triggers. Two sources of hidden retries are now common: an agent re-running a failed workflow until it passes, and an agent adding a retry decorator or marker to a test in the same pull request that changes it. Both keep failure rate flat while flake frequency rises.
- Record who triggered each run. Store the run attempt number and the actor (person or bot account) next to each attempt row. A climbing share of second attempts triggered by an agent is an early flake signal.
- Count retry additions. Flag pull requests that add
@pytest.mark.flaky, a--rerunsoption or a framework retry setting, and report them weekly. Each one is a flake budget withdrawal that should be approved by a person. - Write the rule down. A repository instruction file such as
.github/copilot-instructions.mdcan say that agents must not add retries or re-run failed checks more than once without reporting the failure in the pull request.
Model-calling tests need the opposite treatment. Retrying them until they pass turns a pass rate into a meaningless green, so run them in their own job without retries, N times each, and report the share of passing runs against a threshold:
SELECT test_name,
round(countIf(status = 'passed') / count() * 100, 1) AS pass_rate_pct,
count() AS runs
FROM test_attempts
WHERE kind = 'llm' AND run_ts >= now() - INTERVAL 14 DAY
GROUP BY test_name
ORDER BY pass_rate_pct ASC;
Keep that table off the flake budget. Their variance is expected; a falling pass rate is a regression signal for the prompt or model, not a flake. The retry count article goes deeper on how retries inflate the numbers.
Myths That Let Flakiness Hide Behind Stable Failure Rate
Myth 1: A stable failure rate means the suite is healthy. Failure rate is a final-state metric. Retries filter out flaky failures before they reach it. A suite running at 3% failure rate with a 12% flake rate is not healthy — it's fragile and expensive. The stable failure rate is a measurement artifact of your retry configuration, not a signal about code quality. This same dynamic appears when coverage shrinks quietly; failure rate can look stable even as test coverage is shrinking, masking a completely different class of risk.
Myth 2: Quarantining flaky tests solves the flakiness problem. Quarantine is a triage tool, not a fix. Tests in quarantine stop contributing to failure rate and stop consuming flake budget — which means the underlying non-determinism is now invisible, not resolved. Teams that quarantine without a mandatory remediation SLA (e.g., fix or delete within 10 business days) accumulate quarantine debt until the quarantine list is longer than the active suite. Track quarantine age as a first-class metric, alert when a test has been quarantined more than 14 days, and count quarantined tests in your flake budget denominator so the budget reflects true suite health.
The failure rate / flake rate divergence is not a monitoring gap you patch with a new dashboard — it's a measurement philosophy problem. Start by writing attempt-level data from your test runner, build the ClickHouse or BigQuery query above, and set an explicit flake budget with a hard gate in CI. Once flake frequency is a first-class signal with teeth, the stable-failure-rate illusion stops being a source of false confidence. From there, audit your retry configuration: every retry that isn't logged is a flake that never happened, officially.
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.