Taming Flaky Regressions and Sharpening Failure Classification
System DesignModel answerLast updated
Design an acceptance strategy for non-deterministic test output, then build a classification scheme that goes beyond pass/fail to drive precise triage.
Context
You are a QA engineer responsible for a regression suite that runs nightly against a complex software system. Some components — rendering pipelines, numerical solvers, ML inference paths — produce outputs that legitimately vary run to run even when the software is working correctly. Your current setup flags any deviation from a golden reference as a failure, drowning the team in noise and eroding trust in the suite.
Your tech lead has asked you to fix two things before the next release cycle.
Part 1 — Handle Valid Output Variation Without Hiding Real Bugs
Some test failures are not bugs: floating-point results shift across hardware, image encoders produce slightly different file sizes, timing metrics fluctuate under load. A naive golden-file comparison rejects all of it.
Describe a principled approach to accepting a range of valid outputs while keeping the suite sensitive to genuine regressions.
Your answer should address:
- How you define and document an acceptance rule (tolerance band, set of allowed values, statistical threshold, etc.) so that it is traceable to a specification or measured baseline rather than chosen arbitrarily.
- How you distinguish a real product defect from a test environment problem, a flaky dependency, or measurement noise — and what evidence you collect to tell them apart.
- How changes to the acceptance oracle are reviewed and controlled so that someone cannot quietly widen a tolerance to make a failing test green.
Part 2 — Replace Pass/Fail With a Structured Outcome Model
A binary pass/fail label loses information. A crash in a core subsystem and a cosmetic rendering glitch on an unsupported peripheral both show up as "FAIL," yet they demand completely different responses.
Design a classification scheme for observed test outcomes that supports faster, more accurate triage.
Your answer should address:
- The dimensions you would record for each failure: what happened, why you think it happened, how severe the impact is, and how confident you are in that diagnosis.
- How product impact (who is affected, under what conditions) and reproducibility (consistent, intermittent, environment-specific) feed into prioritization.
- What you do with failures that resist diagnosis — how you avoid prematurely marking them as benign while still keeping the queue manageable.
What a Strong Answer Looks Like
- A concrete acceptance-rule design that reduces noise without simply relaxing assertions or retrying until green.
- Explicit separation of test category (what the test is for) from outcome classification (what actually happened).
- A triage path with traceable decisions, clear ownership, and no silent suppression of unresolved issues.
Hints
Hint 1
For Part 1, ask yourself: what is the source of truth for 'valid'? A tolerance pulled from thin air is just as dangerous as no tolerance at all — anchor it to a spec, a physics constraint, or a statistically derived baseline from known-good runs.
Hint 2
For the oracle change-control problem, think about how production code changes are governed: code review, approval gates, audit logs. Apply the same discipline to your acceptance criteria.
Hint 3
For Part 2, think in separate columns: outcome (what the test reported), suspected cause (product bug vs. environment vs. test), severity (blast radius for a real user), and confidence (how sure are you of the cause). A crash with 100% reproduction rate and a timing flap that appears 5% of the time need completely different queues.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1 — Principled Acceptance of Valid Output Variation
Anchor tolerances to something real
The most common mistake is picking a tolerance like "±2%" because it makes the noise go away. That is just moving the goal post. Every acceptance rule should be traceable to one of three sources:
- A written specification. If the standard says output luminance must be within 1 nit of target, the test tolerance is 1 nit — no negotiation.
- A physics or mathematical bound. Floating-point accumulation error on a 32-bit path has a calculable upper bound. Use it.
- A statistical baseline from known-good runs. Run the component 50–100 times on a known-good build, measure the distribution of outputs, and set the threshold at mean ± 3σ (or a chosen percentile). Document the sample size and the build SHA used. This makes "valid variation" an empirical fact, not an opinion.
For outputs where none of the above applies — and that is a legitimate situation — the correct answer is to escalate to the owning team for a specification, not to invent a number.
Distinguishing defects from noise
When a result lands outside the acceptance band, the failure could be:
| Root cause | Evidence |
|---|---|
| Product regression | Consistently reproducible, correlates with a recent commit, affects multiple related tests |
| Test environment problem | Fails on one agent only, passes after re-image, depends on load from co-located jobs |
| Flaky dependency | Third-party service timeout, network jitter, external resource unavailable |
| Measurement noise | Only seen when system is under unusual load, no correlation to any code change |
Collecting this evidence is not optional — it is what separates a useful failure from a noise event. Instrument your test harness to record: the executing agent, system resource utilization during the run, relevant environment variables, and the nearest code changes on the branch. Without that metadata, triage is guesswork.
Change control for the acceptance oracle
Acceptance rules are part of the test specification. Treat them like production code:
- Store tolerance definitions in version control alongside the tests, not in a spreadsheet or a config file with no history.
- Require a pull request and at least one approval from the owning team (not just the QA team) to widen any tolerance.
- On any change, require the PR to include a justification (spec reference, updated baseline data, or a documented engineering decision) and a re-run of the affected tests against the previous golden build to confirm the old failures were in fact noise.
- Log every change with a timestamp and author so that if a metric quietly degrades over several releases, you can trace back exactly when the tolerance was relaxed and why.
The goal is that no one can silently make a test easier to pass without leaving an auditable trail.
Part 2 — A Structured Outcome Model
Four dimensions, not one
Replace the single PASS/FAIL label with four recorded fields per failure:
- Observed outcome — what the test infrastructure reported: crash, assertion mismatch, timeout, setup error, unexpected output. This is objective and requires no interpretation.
- Suspected cause — your best hypothesis: product defect, test infrastructure problem, environment issue, known intermittent. Mark it explicitly as a hypothesis; it can be revised.
- Severity — the realistic impact on a user if the suspected cause is correct: blocks core functionality for all users, degrades a non-critical feature, affects an unsupported configuration, cosmetic only.
- Confidence — how sure you are of the suspected cause, on a simple scale (high / medium / low / unknown). A crash that reproduces 100% of the time on a clean machine warrants high confidence. A 5%-rate timeout warrants low.
These four fields together drive triage far more efficiently than pass/fail, because reviewers can immediately sort by severity × confidence and focus investigation where it matters.
Product impact and reproducibility as triage inputs
Two factors should govern queue priority above almost everything else:
- Impact: a defect that crashes the main workflow for all users on supported hardware is a release blocker regardless of how recently the code changed. A rendering anomaly visible only on an EOL peripheral with specific driver versions is not.
- Reproducibility: a consistent failure on a clean environment is almost certainly a product defect. An intermittent failure needs a minimum reproduction threshold (e.g., "fails in at least 3 of 10 independent runs") before it enters the product bug queue. Below that threshold it goes to a monitored watch list with an automated re-run policy.
Do not conflate the category of a test with the nature of its failure. A performance regression test that crashes is not a performance issue — it is a stability issue that happened to surface in a performance test. The failure type, not the test type, determines the queue.
Handling failures that resist diagnosis
The dangerous anti-pattern is "we can't reproduce it, so mark it low priority and move on." That silently discards real data. Instead:
- Assign every unresolved failure a minimum hold period (e.g., 72 hours or three nightly runs) before it can be closed as environment noise.
- During that period, run the test in isolation on a clean, dedicated environment. Remove co-located job interference as a variable.
- If it still fails intermittently, file a tracked item with severity = unknown and confidence = low, and assign it an owner. It cannot be closed without a documented root cause.
- Aggregate intermittent failures across runs. A test that fails 8% of the time over 200 runs is not noise — it is a latent bug with a statistical signature. Tools that track flakiness rate over time will surface these patterns that any single run review would miss.
Common mistakes to avoid
- Widening tolerances instead of investigating — this hides defects behind a moving standard.
- Treating all test failures as product bugs — environment and tooling issues waste engineering time on the wrong queue.
- Closing unresolved intermittents as "probably fine" — intermittents often precede consistent failures after a future change removes the timing slack that was masking the bug.
- Letting the test category determine triage priority instead of the failure type and impact — a flaky unit test and a flaky end-to-end test are not equally urgent just because one is "higher level."