Module: L1-M06 · Duration: ~180 min (estimate, including the independent exercise) · Previous: L04 · Next: Module exercises, then L1-M07
1. Introduction
The comparison in L04 tells you which cases changed. It does not tell you why. A case labelled REGRESSION can be a product defect, but it can also be an oracle that is too strict, a wrong expectation, or just a timeout. Sending all of them to the developers as "bugs" wastes everybody's time and destroys trust in the test suite.
This lesson teaches triage: classifying each result by its cause, based on evidence, before reporting. It also teaches how to write a regression report that the person deciding on the release can read.
2. Learning objectives
- Define a flaky test, and distinguish a case that was already unstable from a new regression.
- Apply the seven-class triage process, in the right order, based on evidence.
- Read failure samples to distinguish a product defect from an oracle defect.
- Write a regression report with the configuration, the results by case, the human verdicts and a release recommendation.
- Choose the right treatment for a flaky test (not "rerun until green").
3. Prerequisites and tools
4. Concepts
4.1 Flaky tests
Luo et al. (FSE 2014) write: "some tests—often called flaky tests—have non-deterministic outcomes" [R1]. Google's blog post (2016) defines a flaky test as a test "that exhibits both a passing and a failing result with the same code", reports "about 1.5% of all test runs reporting a 'flaky' result", and "about 84% of the transitions we observe from pass to fail involve a flaky test!" [R2]. For ordinary software, the leading causes in Luo's study are Async Wait (45%), Concurrency (20%) and Test Order Dependency (12%), among the 161 commits analysed [R1].
An LLM feature has one more, inherent cause: the output itself changes (L01). So the question is not "is it flaky?" but "was this case already unstable in the baseline?". If it was, its occasional failures in the new version are not caused by the change.
Everyday example. The traffic light at a crossroads has been flickering since last month. Today it still flickers, after the city updated the control software. You cannot blame the new software, because the light was like this before; but it still has to be reported and fixed, because people meet it every day.
Good vs bad. Q-HOTLINE in demo §8.1: baseline 80%, candidate 86%, p = 0.595, and the new version still has failing answers.
| Weak conclusion | Good conclusion | |
|---|---|---|
| Wording | "The new version makes Q-HOTLINE fail: regression" | "Q-HOTLINE was already unstable in the baseline (80%); no significant change (p = 0.595). PRE_EXISTING_FLAKY, not caused by the change. Still recorded, because customers get the wrong '24/7' answer" |
| Why | Blames the change for a problem that was already there | Separates the old problem from the new one, and does not forget the old one |
4.2 The seven triage classes
| Class | Meaning | Evidence needed |
|---|---|---|
ENVIRONMENT |
The failure is a timeout or an infrastructure error, not an answer | The number of environment errors; the answers that were returned did not change significantly |
DATA_DEFECT |
The case's expectation is wrong | Fails on both sides; the expectation contradicts the source |
ORACLE_DEFECT |
The answer is correct but the oracle rejects it | The failure sample is correct according to the source |
PRODUCT_REGRESSION |
The new version really is worse | A significant change; the failure sample is wrong according to the source |
PRE_EXISTING_FLAKY |
Already unstable before, not caused by the change | The baseline already had an intermediate rate; no significant change |
IMPROVEMENT |
The new version is better | A significant change in the good direction |
NO_CHANGE |
No change seen | No significant change and no other sign |
The order matters. Check the environment and the expectations first, because they invalidate every other
conclusion. suggest() in the lab does exactly that: environment errors are marked ENV: on every case with
a high error rate, even when the main class is another one. For a
REGRESSION, always read the failure samples before calling it a product defect.
Everyday example. A motorbike will not start. A good mechanic first checks whether there is petrol (the environment) and whether the right key is in (the expectation), and only then opens the engine (a product defect). Opening the engine first and then finding the tank empty wastes the whole morning.
Worked example. Give suggest() four hand-made rows, one situation each. Save the following as try_l05.py in
the lab folder, run python try_l05.py, then delete the file:
from lab import triage
rows = {
"timeouts only": dict(base_rate=1.00, cand_rate=1.00, change="NO_SIGNIFICANT_CHANGE", cand_errors=8),
"worse + errors": dict(base_rate=1.00, cand_rate=0.40, change="REGRESSION", cand_errors=8),
"fails both": dict(base_rate=0.00, cand_rate=0.00, change="NO_SIGNIFICANT_CHANGE", cand_errors=0),
"was unstable": dict(base_rate=0.80, cand_rate=0.86, change="NO_SIGNIFICANT_CHANGE", cand_errors=0),
}
for name, row in rows.items():
cls, why = triage.suggest({"case": name, "p_value": 0.5, "base_errors": 0, **row}, runs_per_case=50)
print(f"{name:15} -> {cls}: {why}")
Output (copied from a real run on Python 3.14.6 and 3.12.3, Linux, 2026-11-06; both versions gave identical output):
timeouts only -> ENVIRONMENT: ENV: 8/50 runs errored; answers that did come back show no significant change
worse + errors -> PRODUCT_REGRESSION: ENV: 8/50 runs errored; significantly worse: read failure samples (could be an ORACLE_DEFECT)
fails both -> DATA_DEFECT: fails in both runs: check the expectation against its source first
was unstable -> PRE_EXISTING_FLAKY: baseline already unstable (80%); no significant change
- timeouts only: 8/50 runs errored (16%, above the 5% threshold), and the answers did not change: the main class is ENVIRONMENT.
- worse + errors: also 8/50 errors, but the answers got clearly worse. The main class is PRODUCT_REGRESSION, and
the reason still starts with
ENV:: environment errors are flagged, not dropped. - fails both: 0% on both sides. The DATA_DEFECT rule comes before every other rule: check the expectation against its source first.
- was unstable: baseline 80%, inside the 10%-90% band, no significant change: PRE_EXISTING_FLAKY.
4.3 The machine suggests, a person decides
lab/triage.py suggests a class with simple rules. It does not know whether an answer is correct according to
the policy. For example: a REGRESSION whose failure sample is a correct answer worded differently is really an
ORACLE_DEFECT. Only a person who reads the samples and the source can decide. That is why the report has an empty
Human verdict column.
Anthropic's documentation ranks grading methods by reliability and cost: grading with code is "Fastest and most reliable, extremely scalable, but also lacks nuance", while grading by humans is "Most flexible and high quality, but slow and expensive" [R3]. Triage is where that nuance is needed, but only for the few cases that the machine has filtered out.
Everyday example. The thermal scanner at a building's entrance flags someone as feverish. The guard does not isolate them at once; a nurse checks again with a thermometer and then decides. The machine filters fast, a person decides.
Good vs bad. The "opening hours" case in situation 1 (§7): 100% down to 0%, suggested class PRODUCT_REGRESSION.
| Weak verdict | Good verdict | |
|---|---|---|
| Wording | Copies the suggested class: "PRODUCT_REGRESSION" | Reads the failure sample "Cửa hàng mở từ 8h đến 22h" (the opening hours, written with "h" for hours), opens the policy: the answer is right. Verdict ORACLE_DEFECT, with the failure sample and the policy section quoted as the reason |
| Consequence | Developers spend time fixing a product that is not broken | The team fixes the oracle, records why, and rebuilds the baseline (L03) |
4.4 Handling a flaky test
- Do not "rerun until green": that is pass@k (L02) and it hides defects.
- Do: measure the true rate (L02); set a gate by risk; if a high-risk case is unstable, that is a product defect (customers run into it), not a defect of the test.
- Quarantine a test only when someone owns it and there is a deadline for fixing it, and the report still lists it.
Everyday example. A fire alarm often goes off by mistake. Taking the battery out is the worst fix: nobody will know about a real fire. The right way is to log the false alarms, give one person the job of fixing it with a deadline, and meanwhile still have someone check.
Good vs bad.
| Situation | Weak practice | Good practice |
|---|---|---|
| A test that often fails on CI | Add @pytest.mark.skip, no owner, no deadline |
Quarantine with an owner and a deadline; the report still lists the case with its true pass rate |
| A high-risk case passes only 70% | Call it a "flaky test" and rerun until green | Report it as a product defect: customers get a wrong answer about 30% of the time |
4.5 The regression report
A report that is usable for a release decision has:
- the configuration of both sides, the dataset fingerprint, the number of runs, the seed or time, the statistical test and α;
- a table by case: rates, confidence interval, p-value, environment errors, suggested class, human verdict and reason;
- failure samples for every labelled case;
- a recommendation: release, release with conditions, or block, with a reason based on risk.
Everyday example. A doctor reads the test results and writes a conclusion the family can understand: "can go home, check-up in 1 week, come back at once if the fever returns". Nobody wants a stack of test results without a conclusion.
Good vs bad. The recommendation part of a report (fictional):
| Weak recommendation | Good recommendation | |
|---|---|---|
| Wording | "2 cases changed, could the team take a look." | "Release with conditions. The 'exchange fee' case (low risk) is a PRODUCT_REGRESSION: 96% down to 70%, p < 0.001, the failure samples state the wrong fee; owner: Lan, fixed in next week's patch. No high-risk case changed significantly. The candidate has 8% timeouts: reported to the infrastructure team, rerun before the patch." |
| Why | No decision, no evidence, nobody knows what to do | A decision, evidence, risk, an owner and a deadline |
5. Technical deep dive
5.1 triage.suggest(row, runs_per_case)
First, a side without any valid run → ENVIRONMENT (an incident). If environment errors are > 5%, the reason of every class starts with ENV: k/N runs errored. Then the
rules, in order: fails on both sides (≤ 10%, with at least 10 valid runs on each side) → DATA_DEFECT; REGRESSION → PRODUCT_REGRESSION (with a reminder to read
the samples); IMPROVEMENT; baseline within the band 10%-90% → PRE_EXISTING_FLAKY; only environment errors →
ENVIRONMENT; otherwise NO_CHANGE.
These thresholds are the lab's choices, not a standard. A real project tunes them by risk. A rate right at the edge of the band (10% or 90%) can change class between two runs: read the figure, not only the label.
5.2 report.render(base, candidate, rows)
Creates Markdown with the configuration section, the table by case and the failure samples. The report states "no correction for multiple cases" explicitly (L04 section 4.4).
6. The QA perspective
- Order of work: environment → expectations and source → significant change → read the samples → verdict → recommendation.
- What can go wrong: sending every REGRESSION to the developers without reading the samples; editing an oracle to get "green" without recording it; counting timeouts as regressions; calling a case that was already unstable a regression; giving no recommendation.
- Severity: a PRODUCT_REGRESSION in a high-risk case blocks the release; ORACLE_DEFECT and DATA_DEFECT need the test to be fixed and the baseline rebuilt (L03), and do not block the release; ENVIRONMENT needs a rerun once the environment is stable.
7. Real-world scenarios
Scenario 1 (fictional): a regression that turns out to be the oracle. After a model change, the "opening hours" case drops from 100% to 0%. The failure sample: "Cửa hàng mở từ 8h đến 22h" (the shop's opening hours, written in the short "h" form). The oracle only accepts "8 giờ" (the hour followed by the Vietnamese word for o'clock). This is an ORACLE_DEFECT: fix the oracle (and record the reason), rebuild the baseline on the new dataset, run again.
Scenario 2 (fictional): a "defect" caused by the network. Last night's report has 12/12 cases dropping slightly. The environment-error column shows about 15% timeouts in every case. The real answers did not change. Verdict: ENVIRONMENT; recommend a rerun, do not block the release for quality reasons, but tell the infrastructure team about the timeout rate.
8. Hands-on tutorial
8.1 Running the demo
python -m lab.demo l05
Output (copied from a real run, 2026-10-31):
# faq-v1 -> faq-v2
- Baseline: `faq-v1@sim-2026-09/sample`, 50 runs/case, seed 1
- Candidate: `faq-v2@sim-2026-09/sample`, 50 runs/case, seed 2
- Dataset fingerprint: `14026646ef678dee` (same for both runs)
- Test: Fisher exact, two-sided, alpha 0.05, per case, no correction for multiple cases
| Case | Baseline | Candidate (95% CI) | p | Errors (cand) | Suggested class | Reason | Human verdict |
|---|---|---|---|---|---|---|---|
| Q-ADDR | 100% | 100% (93%-100%) | 1.000 | 0/50 | NO_CHANGE | no significant change | |
| Q-CANCEL | 68% | 100% (93%-100%) | 0.000 | 0/50 | IMPROVEMENT | significantly better | |
| Q-COD | 96% | 96% (87%-99%) | 1.000 | 0/50 | NO_CHANGE | no significant change | |
| Q-FREE-RETURN | 84% | 80% (67%-89%) | 0.795 | 0/50 | PRE_EXISTING_FLAKY | baseline already unstable (84%); no significant change | |
| Q-HOTLINE | 80% | 86% (74%-93%) | 0.595 | 0/50 | PRE_EXISTING_FLAKY | baseline already unstable (80%); no significant change | |
| Q-REFUND | 100% | 92% (81%-97%) | 0.117 | 0/50 | NO_CHANGE | no significant change | |
| Q-SHIP | 98% | 40% (28%-54%) | 0.000 | 0/50 | PRODUCT_REGRESSION | significantly worse: read failure samples (could be an ORACLE_DEFECT) | |
| Q-WARRANTY | 100% | 100% (93%-100%) | 1.000 | 0/50 | NO_CHANGE | no significant change | |
## Failure samples (candidate)
- Q-COD run 17: "ShopEasy chỉ nhận thanh toán bằng thẻ." -> missing fact ['khi nhận hàng', 'COD']; forbidden 'chỉ nhận'
- Q-COD run 32: "ShopEasy chỉ nhận thanh toán bằng thẻ." -> missing fact ['khi nhận hàng', 'COD']; forbidden 'chỉ nhận'
- Q-FREE-RETURN run 0: "Hàng bị lỗi được đổi trả miễn phí vận chuyển. Bạn chỉ cần chụp ảnh sản phẩm. Sau đó gửi yêu cầu trong ứng dụng. Nhân viên sẽ liên hệ. Bạn nhận mã vận đơn qua email." -> 5 sentences > 2
- Q-FREE-RETURN run 6: "Hàng bị lỗi được đổi trả miễn phí vận chuyển. Bạn chỉ cần chụp ảnh sản phẩm. Sau đó gửi yêu cầu trong ứng dụng. Nhân viên sẽ liên hệ. Bạn nhận mã vận đơn qua email." -> 5 sentences > 2
- Q-HOTLINE run 0: "Tổng đài hỗ trợ 24/7." -> missing fact ['8 giờ']; missing fact ['22 giờ']; forbidden '24/7'
- Q-HOTLINE run 12: "Tổng đài hỗ trợ 24/7." -> missing fact ['8 giờ']; missing fact ['22 giờ']; forbidden '24/7'
- Q-REFUND run 9: "Bạn được đổi trả trong 30 ngày." -> missing fact ['kể từ ngày nhận hàng', 'từ khi nhận hàng']
- Q-REFUND run 20: "Bạn được đổi trả trong 30 ngày." -> missing fact ['kể từ ngày nhận hàng', 'từ khi nhận hàng']
- Q-SHIP run 2: "Đơn hàng được giao trong 1-2 ngày làm việc." -> missing fact ['3-5 ngày']; forbidden '1-2 ngày'
- Q-SHIP run 3: "Đơn hàng được giao trong 1-2 ngày làm việc." -> missing fact ['3-5 ngày']; forbidden '1-2 ngày'
In English: the failure samples are the lab's Vietnamese answers: Q-COD says that only card payment is accepted; Q-FREE-RETURN gives the free return of defective goods followed by further steps (photo, request in the app, staff contact, tracking code by email); Q-HOTLINE says that support is around the clock; Q-REFUND gives the return period without saying where it starts; Q-SHIP gives a delivery time shorter than the policy.
Reading the output:
- Q-SHIP is suggested as PRODUCT_REGRESSION. The failure sample says "1-2 ngày" (days), while policy §2 says 3-5 working days: this is a real product defect.
- Q-HOTLINE and Q-FREE-RETURN are suggested as PRE_EXISTING_FLAKY: the baseline was already unstable.
- Q-REFUND drops from 100% to 92% but is NO_CHANGE (p = 0.117). For a high-risk case, your verdict can be "NO_CHANGE, but run more once following the rule for running more (L02 section 4.3) before the release".
8.2 Running the tests
python -m pytest tests/test_l05_triage.py -v
8.3 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Every case is ENVIRONMENT | A high error rate in every case | This is a finding in its own right; report it, then rerun once the environment is stable |
| No failure samples for a case | The case never failed | Normal; samples exist only for cases with fails |
9. Independent exercise
Problem: Write the verdicts for the report faq-v1 -> faq-v2.
Requirements: complete exercises/test_l05_verdicts.py:
- For every case in the report in section 8.1, record a class from
triage.CLASSESand a reason (at least 5 words) that quotes evidence: rates, p-value, failure samples, or a policy section. - Write a release recommendation (3-5 sentences) for
faq-v2.
Test data: the output of python -m lab.demo l05; data/policy.md.
Deliverable: the test file and the release recommendation.
Acceptance criteria: the test passes; every verdict that differs from the suggested class has a reason saying why; the recommendation mentions the risk of each labelled case.
Hint: the suggested class is a starting point, not the answer.
9.1 Extra exercise: from verdicts to a release recommendation
Time: 15-30 minutes. File: exercises/test_l05_extra_release.py.
Problem: The human verdicts are in. The last step of the report is the recommendation (§4.5): release, release with conditions, or block, with a list of what needs doing. The file's docstring states the team's release rule for this exercise (a lab convention, written from §4.4, §4.5 and §6).
Requirements:
- Run
python -m pytest exercises/test_l05_extra_release.py. Untouched, 6 tests fail with a message starting withFailed: TODO. - Write
recommend(verdicts, risk): return the decision and the list of actions, following the rule in the docstring. - Run again until you get
6 passed. Write one sentence: why is thehigh-risk-flakyexample CONDITIONAL, whileimprovement-and-low-risk-flakyis RELEASE?
Acceptance criteria: 6 tests pass; the answer to step 3 says that an unstable high-risk case is a problem customers meet (§4.4), while a low-risk one does not hold the decision back.
Hint: build the list of actions first, then decide; sorted() on a list of tuples sorts by case id.
9.2 Real-world scenario: the regression report of an e-wallet (fictional)
The e-wallet "Ví Sen" (fictional) has a support chatbot. The team has just changed the prompt and run a comparison with 50 runs per case. Policy excerpt (in English here; the failure samples below quote the Vietnamese answers):
- §1 Transfers between two wallets: free.
- §2 Withdrawals to a bank: a fee of 3.300 đồng each time.
- §3 Top-up limit: at most 100 million đồng per month.
- §4 Locking the wallet when the phone is lost: call the hotline or go to the Security section of the app.
- §5 Refunds for failed transactions: within 3 working days.
Report (Fisher, α = 0.05, no correction for multiple cases):
| Case | Risk | Baseline | Candidate | p | Errors (cand) | Suggested class |
|---|---|---|---|---|---|---|
| W-TRANSFER | medium | 100% | 100% | 1.000 | 0/50 | NO_CHANGE |
| W-WITHDRAW | high | 98% | 52% | 0.000 | 0/50 | PRODUCT_REGRESSION |
| W-LIMIT | low | 100% | 0% | 0.000 | 0/50 | PRODUCT_REGRESSION |
| W-LOCK | high | 100% | 100% | 1.000 | 9/50 | ENVIRONMENT |
| W-REFUND | medium | 0% | 0% | 1.000 | 0/50 | DATA_DEFECT |
| W-GREETING | low | 82% | 78% | 0.803 | 0/50 | PRE_EXISTING_FLAKY |
Failure samples (candidate):
- W-WITHDRAW: "Rút tiền về ngân hàng hoàn toàn miễn phí." The oracle reports: missing
3.300. - W-LIMIT: "Bạn được nạp tối đa 100.000.000 đồng mỗi tháng." The oracle reports: missing
100 triệu. - W-REFUND: "Giao dịch lỗi được hoàn tiền trong 3 ngày làm việc." The oracle reports: missing
24 giờ. - W-GREETING: "Chào bạn!" The oracle reports: missing
Ví Sen.
Your task (45-60 minutes):
- Write a verdict for each case: a class from
triage.CLASSESand a reason that cites evidence (rates, p-value, failure samples, policy section). Every verdict that differs from the suggested class must say why. - For each case that needs fixing, write down what has to be done and who should do it (developers, the dataset author, the infrastructure team).
- Write a release recommendation of 3-5 sentences, following §4.5.
A good answer has:
- Each case has a verdict and a reason that cites specific evidence, not just the suggested class copied
- Every labelled case has its failure samples checked against the right policy section before the conclusion
- Environment errors reported on their own, and weighed by the risk of the case they affect
- A list of actions that separates product fixes, test or data fixes, and infrastructure work
- A recommendation with a clear decision, a reason based on risk, and the conditions for release
10. Knowledge check
0/19 done · Results are kept in this browser only.
P02 · True or false
P03 · Short answer
Why must the environment and the expectations be checked first?
P04 · Short answer
Name two right ways and one wrong way to handle a flaky test.
P05 · Essay
(Scenario) A report has 2 PRODUCT_REGRESSIONs (one high-risk, one low-risk), 1 ORACLE_DEFECT and 10% timeouts. Write the release recommendation.
P06 · Put in order
P08 · Multiple choice
P09 · Spot the bug
The excerpt below is copied from suggest() in lab/triage.py, with one line modified. Find the bug.
valid = min(row.get("base_valid", min_valid), row.get("cand_valid", min_valid))
if (rb <= stable_fail or rc <= stable_fail) and valid >= min_valid:
return out("DATA_DEFECT", "fails in both runs: check the expectation against its source first")
if row["change"] == "REGRESSION":
return out("PRODUCT_REGRESSION", "significantly worse: read failure samples (could be an ORACLE_DEFECT)")P10 · Recall
Lesson: L1-M06-L04P11 · Match
P12 · Select all that apply
P13 · True or false
P15 · True or false
P16 · Multiple choice
P17 · Apply now
In code-labs/l1-m06, do the extra exercise of §9.1 in exercises/test_l05_extra_release.py, then run python -m pytest exercises/test_l05_extra_release.py.
P18 · Match
P19 · True or false
11. Summary
- Concepts: flaky tests; already unstable versus a new regression; the seven triage classes and their order; the machine suggests, a person decides; handling a flaky test; the content of a regression report.
- Skills: evidence-based triage; reading failure samples; writing verdicts and a release recommendation.
- Pitfalls: sending every REGRESSION to the developers; rerunning until green; editing an oracle without recording it; no recommendation.
- You can now: turn a comparison result into a defensible release decision.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | An Empirical Analysis of Flaky Tests (Luo, Hariri, Eloussi, Marinov), FSE 2014, DOI 10.1145/2635868.2635920 | ACM (authors' PDF) | https://mir.cs.illinois.edu/marinov/publications/LuoETAL14FlakyTestsAnalysis.pdf | 2026-10-31 | Definition; the three leading groups of causes (§3.1) |
| R2 | Flaky Tests at Google and How We Mitigate Them (John Micco), 2016 | Google Testing Blog | https://testing.googleblog.com/2016/05/flaky-tests-at-google-and-how-we.html | 2026-10-31 | Definition; 1.5% of test runs; 84% of pass-to-fail transitions |
| R3 | Define success criteria and build evaluations | Anthropic | https://platform.claude.com/docs/en/test-and-evaluate/develop-tests | 2026-10-31 | Comparison of grading by code, by humans and by an LLM |
Key terms (English ↔ Vietnamese)
| English | Tiếng Việt |
|---|---|
| Triage | Phân loại theo nguyên nhân |
| Flaky test | Test lúc pass lúc fail với cùng code |
| Oracle defect / data defect | Lỗi của oracle / lỗi của kỳ vọng trong dữ liệu |
| Quarantine | Tạm cách ly một test |
| Release recommendation | Đề xuất release |