Regression Testing and Quality Gates for ML

A renamed field cut a classifier's recall from 0.90 to 0.78, and every test stayed green. One detector misses it for weeks. Another fires within the hour.

Pick a detector, then press Ship the rename. Watch when its alarm fires and count the violations that slip through first. Then we build, piece by piece, the statistical gate, the tolerance window, drift and data checks, the canary, the tail gate, and a way to grade the gate itself.

You need recall and a confidence interval (see Metric Design and The Statistics of Evaluation) and a little Python. We build the rest from zero.

Catch a silent regression

Illustrative scenario: 500 violating uploads a day, recall 0.90 before the rename and 0.78 after. The detection delays (an hour, a day, three weeks) are typical orders, not measurements.

Chapter 0

Green the Whole Way Down

Follow a regression that no test sees, and measure how loud it was

A video platform runs a classifier that flags violating uploads. It catches 90 of every 100 violations: its recall (the share of true positives it finds) is 0.90. On a Tuesday, another team renames the field audio_transcript to asr_text.

The feature code still asks for the old name and gets nothing. It fills the gap with zeros for the 40% of uploads that have speech. Nothing crashes. Every request returns HTTP 200. Every unit test passes, because the code runs fine on the wrong data.

A regression is any change that makes the system worse for users, with or without a code change. On the 60% of uploads that keep the transcript, recall stays 0.90. On the 40% that lose it, recall falls to 0.60. The dashboard shows the traffic-weighted blend:

blended recall = 0.60 × 0.90 + 0.40 × 0.60 = 0.54 + 0.24 = 0.78

At 500 violations a day, misses rise from 50 to 110. Over three weeks that is 60 × 21 = 1,260 extra violating videos online. Was the drop loud enough to see in one day? Label 500 positives a day and measure recall. The standard error is the typical size of the day-to-day wobble in that measured rate.

Say it aloud

S-E equals the square root of p times one minus p, over n.

SE
S-E the standard error: how far one day's measured recall typically lands from the true recall.
√
the square root of turns a variance back into a distance in recall units.
p
p the true rate, here the healthy recall 0.90.
n
n the number of labeled positives in one day's sample.
In plain words

Multiply p by one minus p. Divide by n. Take the square root. Then divide the drop by SE to see how many wobbles deep it is.

With numbers

With the made-up incident: p = 0.90, n = 500. SE = √(0.09 / 500) = 0.0134. The drop 0.12 is 0.12 / 0.0134 = 8.9 standard errors. One day of labels would have shown it.

See how far apart the two days sit

Blue is the spread of a healthy day's measured recall. Orange is a broken day. Pink is the alarm line, 3 standard errors below 0.90. Shrink the affected share and the labeled sample until the bells overlap.

40%
500

Recall on the affected slice is fixed at 0.60. The bells use the normal approximation to the binomial.

The failure. Symptom: users complain while uptime, latency and CI stay green. Measure: compute the quality metric on a small labeled slice every day. Fix: watch the quantity that fails, not only the quantity that is easy to watch.

Real teams meet this too. In September 2025 Anthropic described three infrastructure bugs that degraded some Claude responses from August into September. Its evaluations "simply didn't capture the degradation users were reporting".

The road

  1. Five surfaces: where a model rots, and the test pyramid that guards each place.
  2. The paired gate: ship or block on an interval, not on two numbers.
  3. Run-to-run noise: tolerance windows that do not flake.
  4. Drift: watch the inputs while labels are late. PSI and KS.
  5. Data checks: is this data legal? Bands from binomial noise.
  6. Shadow and canary: test on live traffic, roll back by rule.
  7. The tail: p99, fan-out and cost.
  8. Grade the gate: the gate is a classifier with its own precision and recall.
  9. Defense in depth: layers multiply only if they fail independently.
  10. Field guide: terms, numbers, code and links.
The rename caused zero crashes and zero error logs. Why did recall still fall 12 points?

Chapter 1

Five Places a Model Rots

Map each regression surface to the test layer that can see it

The rename was a data regression. Data is one of five regression surfaces: places where behavior can change. Only one of them shows up as a diff in your repository.

SurfaceHow it goes wrongLayer that sees it
Codea library bump changes image resizing from bilinear to nearestunit and integration tests
Dataa vendor sends feet in place of metersdata checks, live monitors
Modela retrain drops 3 points on non-English uploadsgolden-set gate
Infraa quantized build drifts from the checkpointintegration on real serving, canary
Prompta system prompt edit breaks output parsing for 3% of casesgolden-set gate, live monitors

The ML test pyramid stacks five layers: unit tests at the bottom, then data tests, model tests, integration tests, and online tests at the top. The bottom layers are exact and run on every commit in seconds. The top layers are statistical and need samples, time or live traffic.

Switch layers off, watch escapes climb

Each bar is the chance the suite catches a regression on that surface. Switch a layer off and see which bars fall. Press Run 100 releases to drop real regressions through.

Illustrative catch rates per layer and surface, chosen so the full suite catches code 0.9, model 0.8, data 0.7, infra 0.6 and prompt 0.5.

With made-up numbers: 100 releases a quarter, 8% carry a real regression, spread evenly over the five surfaces. The miss rates are 0.1, 0.2, 0.3, 0.4 and 0.5, so the average miss is 1.5 / 5 = 0.30. Expected escapes: 8 × 0.30 = 2.4 a quarter. Raise prompt coverage to 0.8 and the average miss becomes 0.24, so escapes fall to 1.92. The weakest layer sets the escape rate.

The failure. Symptom: the team adds unit tests after every incident and incidents continue. Measure: tag each past incident by surface. Fix: spend on the surface with the highest miss rate, usually data or prompt.

A dependency bump changes image resizing from bilinear to nearest-neighbor. Your unit tests pass. Which layer most likely catches it?

Chapter 2

The Paired Gate

Decide ship or block from the interval of the difference, using only the examples where the two models disagree

The candidate scores 84.7% on the golden set. The baseline scores 86.2%. Ship or block? You cannot answer without the noise. A golden set is a fixed, versioned, labeled set that every release must pass. Keep two kinds: a sampled set drawn at random from traffic, for the statistics, and a curated set of past incidents, as zero-tolerance tripwires.

Run both models on the same n examples. You get two arrays of right-or-wrong, each of shape (n,). Count the disagreements: call b the examples the baseline gets right and the candidate gets wrong, and c the reverse. Examples both get right, or both get wrong, carry no news about which is better.

Say it aloud

d equals c minus b, over n; and S-E equals the square root of b plus c, over n.

d
d the measured difference: candidate accuracy minus baseline accuracy.
c
c examples only the candidate gets right.
b
b examples only the baseline gets right.
n
n the size of the golden set.
SE
S-E the standard error of d.
√
the square root of only the disagreements add noise, so only b plus c sits under it.
In plain words

Subtract b from c and divide by n to get d. Take the square root of b plus c and divide by n to get SE. The interval is d plus or minus 1.96 times SE. Block if its lower end is below minus delta, the largest drop you accept.

With numbers

With made-up counts: n = 1,000, b = 40, c = 25. d = −15 / 1,000 = −0.015. SE = √65 / 1,000 = 0.0081. Interval: −0.015 ± 0.0158 = [−0.031, +0.001]. With delta 0.01, the lower end −0.031 is below −0.01, so block.

Gate on the interval

Each run is one paired evaluation: teal dot, purple interval. Pink is the block line at minus delta. Set the true difference to 0, then shrink n and watch good releases get blocked.

1,000
0.00
1.00

Simulated with a disagreement rate of 6.5%. Each run draws b and c at random, so tallies vary by a few points.

How big must n be? To pass a truly equal candidate 80% of the time, delta must be at least (1.96 + 0.84) standard errors wide:

n = (1.96 + 0.84)² × pdis / δ² = 7.85 × 0.065 / 0.0001 = 5,102

Here pdis is the share of examples where the models disagree and δ (delta) is the margin, 0.01. A 1,000-example set passes an equal candidate only about 24% of the time.

The failure. Symptom: the gate blocks most releases, good or bad. Measure: the interval width, 3.92 × SE, against delta. Fix: grow the set toward the n above. Version it by hash, refresh it from traffic, and never add examples chosen because the candidate fails them.

A candidate's paired difference is −0.4 points, 95% interval [−1.8, +1.0]. The margin delta is 1 point. What does the gate do?

Chapter 3

Run It Twice, Get Two Numbers

Measure run-to-run noise and set the tolerance window from it

The gate blocked a release on Tuesday. Someone pressed retry, and it passed on Wednesday. Same model, same set, same code. The number moved because the evaluation itself is noisy.

SourceWhat moves
Training seedinitial weights, data order and dropout, so a retrain is a different model
GPU arithmeticthe order of a sum changes its last bits, and the order depends on the batch
Samplingtemperature above 0 draws a different output per run
Harnessunpinned data order, timeouts, a judge model that its provider updates

Temperature 0 does not fix the GPU row. In September 2025, Thinking Machines Lab sent one prompt 1,000 times at temperature 0 and got 80 different completions. The cause was batch size: the server load changes it, and kernels sum in a different order for each size.

Run the same model again and again

The candidate equals the baseline. Teal dots are single runs; the orange line is their mean, with its purple band. Pink edges mark the window. Press Run 10 and count the runs outside.

1.4
0.5

Each run draws a score from a bell curve around a true 81.0. The flake rates in the read-out are exact for that bell curve.

Run the artifact k times. The mean of k runs wobbles less than one run. Name the run-to-run standard deviation s and the standard error you want SE*.

Say it aloud

k equals s over S-E star, squared.

k
k the number of evaluation runs to average. Round up.
s
s the measured standard deviation between runs of one artifact.
SE*
S-E star the target standard error for the mean of the runs.
In plain words

The mean of k runs has standard error s over the square root of k. Divide s by SE-star and square it: that is the k that reaches the target.

With numbers

With made-up runs 0.812, 0.798, 0.805, 0.821, 0.784: mean 0.804, s = 0.0141. For SE* = 0.005: k = (0.0141 / 0.005)² = 7.9, so 8 runs.

Those five runs give the interval 0.804 ± 2.776 × 0.0063 = [0.787, 0.821]. The baseline, 0.810, sits inside. Yet the single run 0.784 looks like a 2.6-point regression.

The failure. Symptom: blocks that pass on retry. Measure: the retry-pass rate, and s from 5 to 10 reruns. A window of ±0.5 against s = 1.4 flags 72% of equal runs. Fix: pin what you can, set the window from s, and gate on the mean of k runs.

A single-run gate has a window of ±0.5 points. The measured run-to-run sd is 1.4 points. What happens?

Chapter 4

Watch the Inputs While Labels Are Late

Score how far today's data moved from the baseline, and know what drift cannot see

A fraud label arrives when the chargeback does, weeks later. The inputs arrive now. Drift detection compares today's input distribution with a frozen baseline, so an alarm can come weeks before the labels. It sees some kinds of drift and not others.

DriftWhat changesInput monitor sees it?
Covariatethe inputs, p(x): a campaign brings younger usersyes
Priorthe label mix, p(y): violations double in an electionpartly
Conceptthe meaning, p(y | x): fraudsters adaptno; only labels show it

The Population Stability Index (PSI) scores one feature. Cut the baseline into 10 bins that each hold 10% of it. Call the baseline share in bin i ei (expected) and today's share ai (actual).

Say it aloud

P-S-I equals the sum over i of a-i minus e-i, times the natural log of a-i over e-i.

PSI
P-S-I the drift score for one feature, 0 when nothing moved.
Σi
the sum over i add one term for each of the 10 bins.
ai
a-i today's share of rows in bin i.
ei
e-i the baseline share in bin i, here 0.10.
ln
the natural log of positive when the bin grew, negative when it shrank, so every term is 0 or more.
In plain words

For each bin, take today's share minus the baseline share. Multiply by the log of their ratio. Add the 10 terms. Rank the terms to see which bins moved.

With numbers

With made-up shares 0.06, 0.07, 0.09, 0.10, 0.11, 0.12, 0.13, 0.12, 0.11, 0.09: bin 1 adds (−0.04) × ln 0.6 = 0.0204, bin 2 adds 0.0107. All ten sum to PSI = 0.050. Bins 1 and 2 give 62% of it.

Move the live data, read three verdicts

Blue outlines are the baseline deciles. Orange bars are today. Teal bars below are each bin's PSI term. Shift and spread the live data, then press Replay incident.

0.25
1.00

Baseline is a bell curve. The incident sets 40% of values to zero, as the rename did. PSI and KS are exact for these shapes, not sampled.

The rule of thumb says PSI under 0.10 is stable and over 0.25 is a large shift. The Kolmogorov-Smirnov (KS) statistic D is the largest gap between the two cumulative shares; here D = 0.08. With 5,000 rows a side, the 5% critical value is 1.358 × √(2/5,000) = 0.027. KS calls the shift certain; PSI calls it stable. KS measures detectability and PSI measures size, so at scale, gate on D or PSI, not on the p-value.

The failure. Symptom: 400 features, a flood of alerts, and the real incident had none. Measure: each feature's own week-to-week PSI history. Fix: alert on multiples of that history, rank by PSI times feature importance, and add a labeled slice for concept drift.

Fraudsters adapt: patterns that were legitimate are now fraud. Feature distributions barely move. What catches it?

Chapter 5

Is This Data Even Legal?

Write expectations for every batch, and set each tolerance from sampling noise

Drift asks whether a distribution moved. Data validation asks a blunter question first: does this batch break a rule? It is unit testing for data: a list of expectations that runs on every batch. A null-rate check would have caught the rename in the first batch.

ExpectationExample of a violation
Schemaa column is missing or renamed
Rangedistances 3.28 times too large after a feet-for-meters swap
Null ratea feature that is 2% null is 27% null today
Freshnessthe server still reads yesterday's partition
Volumea dedup bug halves the row count
Cross-fieldend_time comes before start_time

A null rate is a measured rate, so it wobbles. A rule like "fail above 2%" fires on about half of healthy batches. Score today's rate against its own noise. Call the baseline null rate p, the batch size n, and today's null rate r.

Say it aloud

z equals r minus p, over the square root of p times one minus p, over n.

z
z how many standard errors today's rate sits above the baseline.
r
r today's measured null rate.
p
p the historical null rate, here 0.02.
√
the square root of the standard error of a rate, as in Chapter 0.
n
n the number of rows in the batch.
In plain words

Subtract p from r. Divide by the standard error of a rate with p and n. If z passes the tolerance, say 3, raise the alarm.

With numbers

With a made-up batch: 137 nulls in n = 5,000, so r = 0.0274. The standard error is √(0.02 × 0.98 / 5,000) = 0.00198. z = 0.0074 / 0.00198 = 3.74, past 3: page.

Set the band, count the false pages

The blue bell is the null count of healthy batches. The purple band is the tolerance. Orange is today's count. Then raise the number of checks and watch the noise pages add up.

137
3.0
200

Batch of 5,000 rows, baseline null rate 2%. False alarms assume healthy, independent checks with two-sided bands.

Each two-sided 3σ check fires on noise with chance 0.0027. Run 200 of them and you expect 200 × 0.0027 = 0.54 noise pages a day. Page at 4σ (chance 0.000063) and send 3σ hits to a daily digest: 200 checks then make one noise page every 79 days.

Run the same expectations in three places:

  1. At ingestion: quarantine the bad batch and serve the last good one.
  2. Before training: refuse to train on a corrupt snapshot.
  3. At serving: check each request and fall back if a feature is bad.

The failure. Symptom: on-call ignores data pages. Measure: noise pages per week, summed over all checks. Fix: tier the bands, give every check an owner, and give every skipped check an expiry date.

You run 200 data checks a day, each with a two-sided 3σ band. On healthy data, about how many noise pages come each week?

Chapter 6

Shadow, Then Canary

Test the candidate on live traffic, size the canary, and write the rollback rule first

Offline gates miss four things. Only live traffic shows them:

  1. a serving build that differs from the evaluated checkpoint;
  2. online features computed by different code;
  3. traffic the golden set never held;
  4. how users react.

Shadow mode sends a copy of live requests to the candidate and logs its answers without serving them. It shows crashes, latency under real load and the share of predictions that change. It cannot show user reactions. A canary serves the candidate to a small random slice of users, in stages such as 1%, 5%, 25%, 100%. Split by user, not by request, so one user's session stays in one arm.

How long must the canary run? Call the baseline conversion p1, the conversion after the drop you must catch p2, and their gap Δ.

Say it aloud

n equals z-alpha plus z-beta, squared, times p-one q-one plus p-two q-two, over delta squared.

n
n users needed in each arm, canary and control.
zα + zβ
z-alpha plus z-beta 1.645 for a one-sided 5% false alarm, plus 0.842 for 80% power.
p1q1 + p2q2
p-one q-one plus p-two q-two the noise of each arm, where q is one minus p.
Δ
delta the drop to catch, p-one minus p-two.
In plain words

Add the two z values and square them. Multiply by the summed noise of the two arms. Divide by delta squared. Halve delta and n grows four times.

With numbers

With made-up traffic: p1 = 0.080, p2 = 0.072, Δ = 0.008. n = 6.18 × 0.1404 / 0.000064 = 13,565 per arm. A 5% canary of 200,000 daily users gets 10,000 a day: 1.4 days.

Run a canary, wait for the band

The orange line is the measured canary minus control; the purple band is its 95% interval. On the decision day the canary rolls back if the whole band sits below zero. An error spike rolls it back at once. Make the canary small.

5%
−10%
1.0×

Illustrative: 200,000 users a day, baseline conversion 8%, a matched control slice the same size as the canary, baseline errors 10 per 10,000 requests.

Errors are fast. Expect 10 errors in the first 10,000 canary requests and see 50: z = (50 − 10) / √10 = 12.6. Roll back by rule, with no meeting. Write every rollback rule before the canary starts, so nobody argues during the incident.

The failure. Symptom: a config push takes down a fleet at once. In July 2024 a CrowdStrike content update passed a validator with a logic error and reached about 8.5 million Windows devices without staging. Measure: does every artifact go through stages? Fix: canary config and data like code.

A 5% canary has run 3 hours. Conversion shows −0.4 points, interval [−2.1, +1.3]. What is the right read?

Chapter 7

Gate the Tail, Not the Mean

Read latency as a distribution, and see how fan-out turns a rare slow call into a common one

A model can be more accurate and still be a regression, because it answers in 900 ms instead of 40. Say 98% of requests take 40 ms and 2% take 900 ms. The mean is 57.2 ms, well under a 100 ms target. One user in fifty still waits almost a second.

A percentile is the value below which a given share of requests falls. The p99 is the latency that 99% of requests beat. Sort the sample; the nearest-rank p-th percentile is the value at position ⌈p/100 × n⌉.

Drag the slow mode, watch p99 move

Orange is the mean, teal the p50, p95 and p99, pink the target. Raise the slow share: the mean barely moves while p99 jumps. Then raise the fan-out.

2%
900 ms
100 ms
1

Illustrative mixture: a fast hump near 40 ms and a slow hump at the chosen latency, on a log axis. Percentiles are exact for the mixture.

A request that fans out to k backends waits for the slowest. Call the chance that one backend is slow q.

Say it aloud

P-slow equals one minus, one minus q, to the k.

Pslow
P-slow the chance the whole request waits on at least one slow backend.
q
q the chance one backend is slower than its own p99, so 0.01.
k
to the k multiply by itself once per backend, k backends in parallel.
In plain words

One minus q is the chance one backend is fast. Raise it to the k: all k are fast. One minus that is the chance at least one is slow.

With numbers

q = 0.01, k = 10: 0.9910 = 0.904, so Pslow = 0.096. A backend's p99 becomes the frontend's p90.

Take a made-up sample of 20 latencies from 12 to 120 ms. The nearest-rank p95 is the 19th value, 58 ms; the p99 is the 20th, 120 ms. NumPy's default interpolates and gives 61.1 ms and 108.2 ms. Pin the definition (method="inverted_cdf" is nearest rank).

Cost is the third budget. A prompt edit that raises answers from 180 to 240 tokens, at a made-up $15 per million output tokens and 2 million requests a day, adds $1,800 a day. Gate the output length too.

The failure. Symptom: the latency gate flips verdicts after a library upgrade. Measure: rerun the gate on stored latencies with both versions. Fix: pin the percentile method, the load profile and the hardware, and set the band from repeat runs.

A request waits on 10 backends in parallel. Each is slower than its own p99 1% of the time, independently. What share of requests hit at least one slow backend?

Chapter 8

Grade the Gate

Treat the gate as a classifier over releases, and find the only move that improves both of its errors

Every release is truly good or truly regressed, and you cannot see which. The gate passes or blocks it. That is a 2 × 2 table, with "regressed" as the positive class.

Gate blocksGate passes
Truly regressedtrue positive: a savefalse negative: an incident
Truly goodfalse positive: lost timetrue negative

Gate recall is the share of regressions it blocks. Gate precision is the share of blocks that were right. Precision depends on how rare regressions are. Call the gate's detection rate r, its false-block rate f, and the share of releases that truly regress π.

Say it aloud

Precision equals r pi, over r pi plus f times one minus pi.

precision
precision the share of blocked releases that truly regressed.
r
r the gate's recall: the chance it blocks a real regression.
π
pi the base rate: the share of releases that truly regress.
f
f the false-block rate: the chance it blocks a good release.
In plain words

r times pi is the share of releases that are correct blocks. f times one minus pi is the share that are wrong blocks. Precision is the correct blocks over all blocks.

With numbers

With made-up rates r = 0.9, f = 0.10, π = 0.05: precision = 0.045 / (0.045 + 0.095) = 0.32. Two of every three blocks are wrong, from a good gate.

The gate sees a measured difference, not the truth. Good releases measure near 0; regressed ones near −2 points. Noise smears both into overlapping bells. A threshold on the overlap trades one error for the other. Only a smaller noise, a bigger golden set, pulls the bells apart.

Run a quarter through the gate

Green bell: good releases. Red bell: regressed. Pink line: block below it. Press Run a quarter. Lower the base rate and watch precision fall; then raise n, not the strictness, to rescue it.

−1.0
2,000
20%

Illustrative: a regression is a true drop of 2 points; noise sd is 100 × √(0.065/n) points; an incident costs $100k and a wrong block $5k.

Take made-up gates, 100 releases and 20 regressions. Gate A catches 0.75 and false-blocks 0.10: 15 saves, 5 incidents and 8 wrong blocks; precision 0.65, cost $540k. Gate B catches 0.90 and false-blocks 0.25: 18 saves, 2 incidents, 20 wrong blocks; precision 0.47, cost $300k. At $20k per incident both cost $140k. The prices choose the threshold.

The failure. Symptom: many blocks and still some incidents. Measure: each quarter, count escapes from incident reviews and overturned blocks from retries. Fix: if both errors are high, cut noise (n, runs, soak time) before moving the threshold.

The gate blocked 30 releases; 9 were real regressions. 2 regressions shipped. What are its precision and recall?

Chapter 9

Layers Multiply, If They Fail Independently

Compute the escape rate of a stack, and see what shared blind spots do to it

A data regression must pass three layers to reach users. Validation misses it half the time, the offline gate a quarter of the time, the canary 30% of the time. If the misses are independent, multiply them:

escape = missvalid × missoffline × misscanary = 0.5 × 0.25 × 0.30 = 0.0375

Here each miss is the chance one layer lets the regression through. Of 100 regressions, 50 pass validation, 12.5 pass the gate and 3.75 reach users.

Stack the layers

Each bar is how many of 100 regressions are still alive after a layer. Switch layers off. Then switch Correlated on: the canary now shares the gate's blind spots.

Illustrative miss rates 0.5, 0.25 and 0.30. Correlated sets the canary's miss to 0.60 for regressions the gate already missed.

Now say the canary watches the same metric as the gate on similar traffic. A regression the gate missed slips past the canary 60% of the time, not 30%. The escape becomes 0.5 × 0.25 × 0.60 = 0.075, twice as high, with the same boxes on the diagram.

LevelWhat the team has
0tests on code only
1a golden set, compared by eye
2paired gates with margins and measured run noise
3data validation and drift monitors in production
4canaries with pre-registered automatic rollback
5the gate audited by its own precision and recall

The failure. Symptom: incidents of one kind keep escaping a "five-layer" stack. Measure: for each regression class, list the layers that can see it. Fix: make each layer watch a different signal: inputs, distributions, offline quality, live behavior.

Two teams run three layers with miss rates 0.5, 0.25 and 0.30. Team A's layers watch inputs, offline quality and live behavior. Team B's all gate on one golden-set metric. Whose 3.75% can you trust?

Chapter 10

Field Guide

Keep the terms, the numbers, the checks and the code in one place

Treat every noisy measurement as a distribution. Bound the downside, write the decision rule before you look, and audit the gate like any other classifier.

ToolFormulaNumber from this page
Rate SE√(p(1 − p)/n)0.0134 at p = 0.90, n = 500
Paired gated = (c − b)/n, SE = √(b + c)/n[−0.031, +0.001]: block at delta 0.01
Golden-set size(1.96 + 0.84)² pdis / δ²5,102 for a 1-point margin
Runs needed(s / SE*)²8 runs for s = 0.0141, SE* = 0.005
PSIΣ (a − e) ln(a/e)0.050; the incident 0.73
KS Dlargest gap of the cumulative shares0.08 against 0.027 critical
Null-rate z(r − p) / √(p(1 − p)/n)3.74; 0.54 noise pages a day at 200 checks
Canary n(zα + zβ)²(p1q1 + p2q2)/Δ²13,565 per arm, 1.4 days at 5%
Fan-out1 − (1 − q)k0.096 at q = 0.01, k = 10
Gate precisionrπ / (rπ + f(1 − π))0.32 at π = 0.05
Stack escapeproduct of misses, if independent3.75%; 7.5% when correlated

Checklist before a gate goes live

  1. Each regression surface has a layer that can see it.
  2. Version the golden set by hash, refresh it from traffic, and keep it out of training.
  3. Measure run-to-run noise and set the window from it.
  4. The set is large enough that delta is wider than (1.96 + 0.84) standard errors.
  5. Every rate check has a noise band, and the whole system has a false-alarm budget.
  6. Write the rollback rules before the canary starts.
  7. Latency gates pin the percentile method and the load profile.
  8. Each quarter, count escapes and overturned blocks.

The core in code

pythonimport numpy as np
from scipy.stats import norm

def paired_gate(base_ok, cand_ok, delta=0.01, z=1.96):
    base_ok, cand_ok = np.asarray(base_ok, bool), np.asarray(cand_ok, bool)   # shape (n,)
    n = base_ok.size
    b = np.sum(base_ok & ~cand_ok)            # only the baseline is right
    c = np.sum(cand_ok & ~base_ok)            # only the candidate is right
    d, se = (c - b) / n, np.sqrt(b + c) / n
    return d, (d - z * se, d + z * se), "BLOCK" if d - z * se < -delta else "PASS"

def psi(e, a, eps=1e-6):
    e, a = np.clip(e, eps, None), np.clip(a, eps, None)
    terms = (a - e) * np.log(a / e)               # rank these to find the bins that moved
    return terms.sum(), terms

def null_rate_z(nulls, rows, p):
    return (nulls / rows - p) / np.sqrt(p * (1 - p) / rows)

def canary_n(p1, p2, alpha=0.05, power=0.8):
    z = norm.ppf(1 - alpha) + norm.ppf(power)
    return int(np.ceil(z**2 * (p1*(1-p1) + p2*(1-p2)) / (p1 - p2)**2))

print(null_rate_z(137, 5000, 0.02))     # 3.74
print(canary_n(0.080, 0.072))           # 13565
print(1 - 0.99**10)                   # 0.0956
print(np.percentile([12,14,15,15,16,17,18,18,19,20,21,22,23,25,27,30,34,41,58,120],
                    [95, 99], method="inverted_cdf"))   # [58 120], nearest rank

Where it sits

Wall you hitWhat it looks likeWhere to go
Too many checksnoise pages every daymultiple-testing corrections in eval statistics
Slow canariesdays to see a 10% dropvariance reduction in experiment design
A judge model driftsscores move with no releasegenerative evaluation
Release plumbinghow to do blue/green and flagsTesting and Deployment
The takeaway. A gate is a classifier over releases. Its errors come from noise, so shrink the noise first, then let the costs pick the threshold.

Keep going

AI Evaluation · CS 336: Evaluation · CS 329Z: Evaluation Fundamentals · Testing and Deployment

Sources for the real incidents: Anthropic, A postmortem of three recent issues (September 2025); Horace He and Thinking Machines Lab, Defeating Nondeterminism in LLM Inference (September 2025); CrowdStrike, Channel File 291 root cause analysis (August 2024); Microsoft, Helping our customers through the CrowdStrike outage (July 2024).

Now press Present or Teach and explain from memory: the paired gate, why the window comes from measured noise, what drift cannot see, and why precision falls when regressions are rare. Then go back to the hero and say why the null-rate check beats the labeled slice by a day.

Regression Testing and Quality Gates for ML
The evaluation family · Back to Gleams