ealeng

Episode 59 of 61 · Self-improving systems

Regression tests and flaky alarms: why hiding noisy tests made it worse

A QA agent runs 195 tests against an AI assistant every night and raises an alarm when quality drops. With nothing changed, its paired-test alarm went off 9 times in 60 simulated nights; leaving out the flaky tests made it 37. Comparing each test with its own pass rate brought it to almost none (4 false alarms in 200 two-month replays) and still caught every real breakage. The price: a 2-point drop slips by.

Lab 18 · Autonomous Systems12 min read
Video transcript8:13

0:00Cold open

0:01

I built a QA agent. QA means quality assurance: checking that something still works.

0:07

My agent is meant to run our AI assistant through a hundred and ninety-five tests, every night.

0:14

If too many tests start failing, it raises an alarm.

0:19

To test it, I replayed two months of nights from recorded runs. Nothing about the assistant changed.

0:26

The alarm still went off nine times, on average.

0:31

Some tests pass in one run and fail in the next. So I left those out, to calm the alarm down.

0:38

Then it went off thirty-seven times.

0:42

Hiding the noisy tests made the alarm noisier. Why?

0:48Intro

0:49

Hands-on AI engineering: autonomous AI, part three.

0:54

Today: a QA agent that notices when quality drops, without crying wolf.

1:00Meet Nadia

1:02

I’m Nadia, an AI engineer at Quill Academy, a made-up online course site.

1:08

Our assistant answers learners’ questions from nine short articles.

1:14

In part one, I grew a suite of a hundred and ninety-five tests, mostly from questions by simulated users.

1:22

Each test asks the assistant a question. It passes when the answer is right and cites its source.

1:29

The QA agent is built to run them every night, with nobody watching, and decide whether to raise the alarm.

1:38

Every run here is a real, recorded run of the assistant.

1:43

The breakages are planted on purpose. And the two months of nights are simulated, by mixing those recorded runs.

1:5201 · Normal noise

1:53

First: what does a normal run look like? I ran the unchanged assistant six times.

2:00

It passed between a hundred and seventy-four and a hundred and eighty-four tests.

2:06

Nothing changed between those runs. AI models just don’t answer exactly the same way every time.

2:14

So the pass rate wobbles by about five percentage points on its own.

2:20

Like a bathroom scale that reads a little different every time you step on it.

2:26

Forty-nine tests passed in some runs and failed in others.

2:31

They’re called flaky tests: the amber squares.

2:3602 · Planted changes

2:37

Next, I changed the assistant on purpose, in six ways, and ran each version three times.

2:44

Here’s how it answers. It searches an index of article passages, takes the top three, and writes an answer that cites one.

2:54

One change was an older, cheaper model. It scored almost five points higher. Not every change is a step back.

3:02

Scrambling three percent of the index cost about two points. That’s inside the normal wobble: the shaded band.

3:11

Scrambling more of the index, or taking one passage instead of three, cost seven to fifteen points.

3:19

And a prompt that drops citations cost almost seventy.

3:2403 · Alarm rules

3:26

So when should the agent raise the alarm? An alarm when nothing changed is a false alarm: crying wolf.

3:34

I replayed each rule two hundred times, over two simulated months, built by mixing three real runs of the unchanged assistant. Then I counted the false alarms.

3:46

The simplest rule: alarm when the score falls three points below its usual score. About two false alarms in two months.

3:55

A smarter-sounding rule is the paired test. It looks at each test on its own.

4:01

First, it builds a reference: what each test did in most of three early runs.

4:08

Each night, it checks every test against its reference. Did it go down, from pass to fail? Or up?

4:15

If far more went down than up, more than chance would give, it raises the alarm.

4:22

That rule: nine false alarms in two months.

4:26

Leave out the twenty-five tests that flipped in those three early runs, and it’s thirty-seven.

4:33

All three rules caught every real breakage, usually within about half a day. The difference is how often they cry wolf.

4:4304 · Why

4:44

Here’s why. The reference turns every test into a sure pass or a sure fail.

4:50

Almost all of them, a hundred and eighty-six, are sure passes.

4:56

Yet a test that passed all three early runs still fails now and then: about one run in eighteen.

5:03

So on any night, many more tests can slip down than climb up.

5:08

In the worst of three more runs of the unchanged assistant: fifteen down, three up. The paired test called that worse, and raised the alarm.

5:19

Now leave out the flaky tests. What’s left did the same thing in all three early runs, and almost all of those passed.

5:27

Almost all of those can only go one way: down. Fourteen to one.

5:34

It’s like picking the students who aced three quizzes in a row. On the fourth, some slip.

5:40

Not because they got worse. Luck helped pick them. That’s called regression to the mean. It has nothing to do with regression testing.

5:5005 · The fix

5:52

The fix: compare each test with its own pass rate, instead of a sure pass or fail.

5:58

A test with a perfect record still gets a small chance to fail. A flaky test gets a bigger one.

6:06

Add those chances up, and you get the failures to expect in a normal run: about fifteen.

6:13

The alarm only fires well above that: past about twenty-six failed tests.

6:19

Unchanged runs land below the line.

6:23

Real breakages land far above it.

6:27

Replayed over two months: four false alarms in two hundred replays. Almost none.

6:34

And it still caught every real breakage, usually within about half a day.

6:40

The price: the two-point change lands below the line, too. The older rules caught it most of the time.

6:48

This one caught it only eight percent of the time within a week. That’s what not crying wolf costs.

6:5606 · What it says

6:57

An alarm should also say what broke. Mine lists the tests that newly fail, and how they fail.

7:04

The prompt that drops citations: a hundred and forty-one tests, every one missing its citation.

7:12

That points straight at the prompt.

7:15

The scrambled index: thirty-nine tests, most of them refused to answer.

7:21

Search taking one passage: thirty-four, about half of them refused.

7:27

Those two look the same in the report. Telling them apart takes a look at the index itself. That’s part four.

7:36Back to Nadia

7:37

So, why did hiding the noisy tests make the alarm noisier?

7:42

Because the tests I kept were picked for passing. From there, most could only slip.

7:49

Now I measure the noise first, and compare each test with its own pass rate.

7:55

I keep the flaky tests in.

7:58

And when the alarm fires, it tells me which tests failed, and how.

8:04Summary

8:05

Measure the noise before you trust a drop.

8:08

Then compare each test with itself.Nadia: Quiet nights again.

Key takeaways

  • ✓Measure the noise first. Six runs of the unchanged assistant passed 174 to 184 of 195 tests (89.2–94.4%): about 5 points of wobble with nothing changed. 49 tests passed in some runs and failed in others. A drop smaller than that wobble can't be seen from one run.
  • ✓Not every change is a drop. Of six planted changes, an older, cheaper model (gpt-4o-mini) scored 4.8 points higher. Scrambling 3% of the search index cost 1.9 points, inside the wobble. Real breakages cost 6.8 to 68.7 points; a prompt that drops citations cost the most.
  • ✓A paired test against a fixed reference cries wolf. The reference is each test's majority result in three early runs, which turns every test into a sure pass (186) or a sure fail (9). On an unchanged night, many more can slip down than climb up: run 5 had 15 down and 3 up (p = 0.0075). Replayed over 60 nights, 9 false alarms.
  • ✓Leaving out the flaky tests made it worse: 37 false alarms. The 170 kept did the same thing in all three early runs, and 164 of them passed, so almost all can only go down (14 to 1 on run 5). A test that passed three times in a row still failed about one later run in 18. That's regression to the mean, which has nothing to do with regression testing.
  • ✓The fix: compare each test with its own pass rate, pulled toward the suite's average because three runs is few (3 of 3 → 96%, 2 of 3 → 79%, 0 of 3 → 46%). Expected failures on a normal night: about 15; the alarm fires past about 26. 4 false alarms in 200 two-month replays, every real breakage caught (median 11 hours). The price: the 2-point change was caught only 8% of the time within a week.
  • ✓An alarm should say what broke. The no-citation prompt: 141 newly failing tests, every one 'no citation', which points at the prompt. The scrambled index (39, mostly refused) and one-passage search (34, about half refused) look alike in the report; telling them apart needs a look at the index itself.

A QA agent runs the assistant through its tests every night, with nobody watching, and raises an alarm when quality drops. The hard part isn't catching a broken assistant. It's not crying wolf when nothing changed, because AI answers vary from run to run. This chapter measures that noise, replays two months of alarms for each rule, and shows why hiding the noisy tests made the alarm noisier.

The source is Lab 18 (Autonomous Systems), script 03_qa_agent.py, recorded in October 2026; the video uses that recorded run, no new calls. The course site, Quill Academy, and its people are made up. Every run of the suite is a real recorded run: gpt-5.4-nano answers, gpt-5.4-mini grades. The breakages are planted on purpose, and the two months of nights are simulated by mixing those real runs. The 195 tests are the suite chapter 57 grew from simulated users' questions. Script 03's hourly rules and its report table go beyond the video; they're in "Also in the lab" below.

The QA agent

The assistant answers learners' questions from nine short articles: it searches an index of article passages, takes the top three, and writes an answer that cites one. Each of the 195 tests asks a question, and passes when the grader says the answer is right and it cites its source (or it correctly declines). The agent's job, every night:

  1. Run all 195 tests.
  2. Apply an alarm rule to tonight's results.
  3. If it fires, say which tests newly fail, and how.

A nightly run of the full suite costs about 5 cents. But testing a rule for real would take two months of nights per rule and per change, and one two-month run says little about how often a rule cries wolf. So the lab ran the suite for real a few times per version and replayed 60 nights 200 times from those runs: each night, every test's result is drawn from one of its real runs. Rules are set from runs 1–3 of the unchanged assistant, and their false alarms are counted on runs 4–6, so the noise they're tested on is noise they weren't tuned on.

Normal noise

The unchanged assistant, run six times, passed 174, 184, 181, 180, 174 and 179 tests: 89.2% to 94.4%, 91.6% on average. Nothing changed between those runs. Models just don't answer exactly the same way every time, so the score wobbles by about 5 points on its own, like a bathroom scale that reads a little differently every time you step on it.

49 of the 195 tests passed in some runs and failed in others. These are flaky tests.

Planted changes

Then the lab changed the assistant six ways and ran each version three times:

Change Pass rate vs. unchanged
Unchanged (6 runs) 91.6% (89.2–94.4%)
Older, cheaper model (gpt-4o-mini) 96.4% +4.8
3% of the index scrambled 89.7% −1.9
10% of the index scrambled 84.8% −6.8
Search takes 1 passage, not 3 80.2% −11.5
30% of the index scrambled 76.2% −15.4
A concise prompt that drops citations 22.9% −68.7

Two lessons before any alarm rule. Not every change is a drop: the older model scored higher. And a small drop hides in the wobble: 1.9 points sits inside the unchanged runs' own range. The real breakages cost 7 to 69 points.

Three alarm rules

An alarm when nothing changed is a false alarm. Each rule was replayed 200 times over 60 nights of the unchanged assistant:

Rule (nightly, all 195 tests) False alarms in 60 nights Caught the 2-point change within a week
Score more than 3 points below its usual 2.3 87%
Paired test 9.0 96%
Paired test, flaky tests left out 37.4 100%
Each test vs. its own pass rate 0.02 (4 in 200 replays) 8%

All four caught every real breakage (10% and 30% scrambled, one passage, no citations) in every replay, with a median delay of 11 hours. The difference is how often they cry wolf.

The paired test (McNemar's test, the one used to compare two methods in chapter 54) sounds like the smarter rule, because it looks at each test on its own:

  • First it builds a reference: what each test did in most of the three early runs.
  • Each night, it checks every test against its reference: did it go down (pass to fail) or up (fail to pass)?
  • If far more went down than up, more than chance would give (p < 0.01), it raises the alarm.

Pick a night and see what each rule does. Start with unchanged run 5, then tick "leave out":

Try it · One night, three alarm rulesLab 18 · script 03 · real runs of the 195-test suite
Night:
reference: pass reference: fail went down (pass → fail) went up (fail → pass) flipped in runs 1–3
Can slip · can climb
186 · 9
Went down · up
15 · 3
Failed tonight
21 of 195
Pass rate
89.2%
RuleTonightAlarm?
Score more than 3 points below its usual 92.1%89.2%no
Paired test: more down than up, p < 0.0115 vs 3, p = 0.008yes
Each test vs its own pass rate: more than 25.7 failures (expected 15.3)21 failedno

Nothing changed tonight, so any alarm here is a false alarm. Every test the reference calls a pass can only go down; only the 9 it calls a fail can go up.

Why the paired test cried wolf

The reference turns every test into a sure pass or a sure fail: 186 sure passes and 9 sure fails. But a test that passed all three early runs still fails now and then: about one later run in 18 (5.7%). So on any night, many more tests can slip down than climb up, with nothing changed.

On unchanged run 5, the worst of the three later runs: 15 down, 3 up, p = 0.0075. The paired test called that worse and raised the alarm.

Now leave out the 25 tests that flipped in the three early runs. What's left did the same thing in all three runs, and 164 of the 170 passed. Almost all of them can only go one way: down. Run 5 becomes 14 to 1, and run 6, 8 to 0, fires too. Over 60 nights, 37 false alarms. And the "stable" tests weren't: 24 of the 170 flipped in a later run.

It's like picking the students who aced three quizzes in a row. On the fourth, some slip, not because they got worse, but because luck helped pick them. That's called regression to the mean. It has nothing to do with regression testing.

Pick the aces from runs 1–3, then watch them on the unchanged runs 4–6:

Try it · Pick the aces, then watch themLab 18 · script 03 · real unchanged runs, 195 tests
Step:
Watch:
passed every run 1–3 failed at least one of runs 1–3 not picked
Tests watched
164 of 195
Pass rate, runs 1–3
100.0%
Pass rate, runs 4–6
?

These 164 tests aced all three early runs: 100% by construction. That is how they were picked.

McNemar's test itself isn't the problem. It fits when both sides are single runs measured the same way: two versions, each run once on the same tests. The bias comes from treating a majority vote of noisy runs as the truth: that removes the noise from one side only.

The fix: compare each test with itself

Give each test its own pass rate instead of a sure pass or fail. Three runs is few, so each rate is pulled toward the suite's average: (passes + 3 × average) / 6.

Passed in runs 1–3 Its pass rate
3 of 3 96%
2 of 3 79%
0 of 3 46%

A test with a perfect record still gets a small chance to fail; a flaky test gets a bigger one. Add up each test's chance to fail and you get the failures to expect on a normal night: about 15. The alarm fires only well above that: past expected + 3 standard deviations, about 26 failed tests.

Try it · Where to draw the lineLab 18 · script 03 · failed tests per real run
Unchanged, runs 1–3 (set the rules)
Unchanged, runs 4–6
Older model (score went up)
Index 3% scrambled
Index 10% scrambled
Search: 1 passage, not 3
Index 30% scrambled
Prompt drops citations
149–151 →
01020304050

failed tests of 195 · dashed: expected on a normal run (15.3) · red: the alarm line

Unchanged runs over
0 of 3
2-point change over
0 of 3
Real breakages over
12 of 12

Lower the line and the 2-point change starts to cross it, but so do unchanged runs. At 1 SD (18.8 failures), two of the 2-point change’s runs cross (19 and 24 failed), and so does unchanged run 5 (21). The real breakages sit far past any sensible line. The runs are real; the lab’s false-alarm counts come from replaying 60 nights mixed from runs 4–6, 200 times.

  • The unchanged runs 4–6 failed 15, 21 and 16: all below the line.
  • Every run of the real breakages is above it: 29–31 (10% scrambled), 37–41 (one passage), 46–47 (30% scrambled), 149–151 (no citations).
  • Replayed over two months: 4 false alarms in 200 replays. It still caught every real breakage, with a median delay of 11 hours.

The price: the 2-point change failed 19, 24 and 17 tests, under the line too. This rule caught it only 8% of the time within a week; the older rules caught it most of the time, the same rules that fire on nothing. That's what not crying wolf costs.

What the alarm says

An alarm should also say what broke. The agent lists the tests that newly fail (passed in the baseline, fail now), grouped by how they fail:

Change Newly failing How they fail
Prompt drops citations 141 all 141 "no citation"
30% of the index scrambled 39 25 refused, 7 no citation, 7 wrong
Search takes 1 passage 34 18 refused, 13 no citation, 3 wrong

"No citation" across every article points straight at the prompt. But the scrambled index and one-passage search look alike: mostly refusals, spread over many articles. Telling those two apart takes a look at the index itself, which is chapter 60.

Also in the lab

These parts of script 03 aren't in the video. From the lab's README and result files (the same October 2026 run):

  • Running more often. Every 6 hours with the per-test rule: 0.1 false alarms in 60 days, real breakages caught in a median 3 hours, and the 2-point change 30% of the time within a week, at $0.22 a day instead of $0.05.
  • Small hourly samples. Every hour on 20 random tests, the 3-point threshold false-alarmed 369 times in 60 days: 20 tests are far noisier than 195.
  • CUSUM (cumulative sum) adds up "failures beyond expected" over time and alarms past a level. Set to one false alarm per 60 days on runs 1–3, it gave 4.8 on runs 4–6: noise estimated from three runs is too optimistic.
  • The 2-point change, alarmed. 3% scrambled: 12 newly failing in its first run, 6 no citation, 4 refused, 2 wrong. The older model: 3 newly failing and 3 newly passing.
  • Building it. The lab's first per-test rates used (passes + 1) / (runs + 2), which puts a 3-of-3 test at 80% and expected twice the real failures; it caught nothing. Pulling toward the suite's average keeps the expected count right.

What to do

  • Measure the noise first. Run the unchanged system several times and look at the spread before you decide what a drop is.
  • Keep the flaky tests in. Leaving them out doesn't remove noise; it picks tests that can only get worse.
  • Compare each test with its own pass rate, pulled toward the average when you have few runs, and alarm on more failures than expected.
  • Set the rule on some runs and check its false alarms on others.
  • Decide what size of drop you need to catch. Smaller drops need more tests or more runs, not a twitchier line.
  • Make the alarm say what broke: the newly failing tests, and how they fail.

Caveats

  • Simulated nights. There are 6 real runs of the unchanged assistant and 3 per change. Each two-month replay mixes those runs test by test, which assumes a test's result one night doesn't depend on another's.
  • Few runs. Each test's rate comes from three runs, and the false alarms from three more. With more baseline runs, the rates (and the paired test's reference) would be better.
  • An AI grader. A pass is gpt-5.4-mini saying the answer is right; the grader's own wobble is part of the noise measured here.
  • One suite, one assistant. 195 tests and a made-up course site. Other systems wobble more or less; measure yours.
  • Planted breakages. Real breakages may be gradual, or hit a few tests hard; a rule that sums failures across the suite sees those later.

The checklist

  1. Run the unchanged system several times and record the pass-rate range and the flaky tests.
  2. Never turn a majority vote of noisy runs into a fixed pass/fail reference for a paired test.
  3. Give each test a pass rate, and compute the failures to expect on a normal night.
  4. Set the alarm line from calibration runs, and count false alarms on held-out runs.
  5. Replay the rule against planted breakages to see what it catches and how fast.
  6. List newly failing tests with how they fail in every alarm.
  7. Write down the smallest drop the rule can catch, so nobody assumes it catches everything.

Practice: three alarm rules in code

Build the paired test's reference, count down and up, compute McNemar's p-value, then the per-test pass rates and the alarm line. The tests use the real pass/fail results of all 24 runs and expect the lab's numbers: 186 sure passes, 25 flaky, 15 vs 3 on run 5 (14 vs 1 without the flaky tests), one slip in 18, 96/79/46%, about 15 expected and a line at 25.7, quiet on unchanged nights and loud on every real breakage.

Try it · Practice in PythonRuns in your browser · ⌘/Ctrl + Enter to run
qa_practice.py77 lines

Quiz

Try it · Check your understanding0 of 6 answered
  1. 1.Six runs of the unchanged assistant passed 174 to 184 of the 195 tests. What does that mean for an alarm?

  2. 2.Swapping in the older, cheaper gpt-4o-mini model scored 4.8 points higher. What should a drop alarm do?

  3. 3.Why does the paired test fire on an unchanged night?

  4. 4.Leaving out the 25 tests that flipped in the three early runs took false alarms from 9 to 37. Why?

  5. 5.How does the per-test rule decide whether tonight is bad?

  6. 6.What does the per-test rule give up for almost no false alarms?

Check your understanding

Try each question before opening its answer.

Your nightly suite dropped 2 points. What do you check before paging anyone?

The unchanged system's own run-to-run spread, and which tests flipped. Here the unchanged assistant ranged from 89.2% to 94.4%, so 2 points on 195 tests (about four tests) is well inside the noise.

Why can a paired test against a majority-vote reference fire when nothing changed?

The reference calls 186 tests sure passes and 9 sure fails, but a test that passed three early runs still fails about one later run in 18. Down can outnumber up by chance: 15 to 3 on unchanged run 5, p = 0.0075, under the 0.01 cutoff.

Why did leaving out the flaky tests make the false alarms go up, from 9 to 37?

The tests kept were picked for doing the same thing three times, and 164 of 170 had passed every time. Picked for passing, they can mostly only slip: 14 down, 1 up on run 5. That's regression to the mean.

How does comparing each test with its own pass rate avoid that?

No test is treated as a sure thing: a 3-of-3 test is expected to fail 4% of the time, a 2-of-3 test 21%. Summed up, a normal night is expected to fail about 15 tests, and the alarm waits for more than about 26. Unchanged runs failed 15, 21 and 16.

What does the per-test rule miss, and what would you do about it?

Small drops: the 2-point change failed 19, 24 and 17 tests, under the line, and was caught 8% of the time within a week. If drops that size matter, run more tests or more often (every 6 hours caught it 30% of the time), rather than lowering the line into the noise.

Two alarms both say "about 35 tests newly failing, mostly refused, spread across many articles". What can you conclude?

Search is probably returning the wrong passages, but not why. In the lab, a scrambled index and search taking one passage instead of three looked just like that; telling them apart needs a look at the index itself. A wave of "no citation", by contrast, points straight at the prompt.

Next up: Chapter 60, self-healing RAG: the QA agent says search broke, so the system checks its own index and repairs it. The repair was broken too.

Learning something useful?

New labs, articles, and videos on evaluating and testing AI systems come out regularly. Follow along so you don't miss the next one.