Key takeaways
- ✓A mutant is one small automatic change to a line the PR adds, like `or` → `and` or a deleted statement. If CI turns red, the mutant is caught. If CI stays green, it survived: nothing protects that line, and only a reviewer could notice.
- ✓Mutants and planted bugs answer different questions. Mutants are cheap and crude, and measure what CI misses. Planted bugs are realistic, and measure what a reviewer finds. On a PR that adds a per-sync batch size (c20), CI caught all 12 mutants but not the planted bug, which is wrong only above the default batch size of 100, where the PR's test never looks.
- ✓Of 734 mutants in 68 correct PRs, the PR's own tests caught 555 (76%), the rest of CI 50 (7%), and 129 survived: 18% (95% interval 15–20%). Running a line isn't checking it.
- ✓The web app is the least protected: 33 of 84 mutants survive (39%), against 15% for the API and the worker. Its tests render a screen and check that some text appears, so a wrong number or a missing error still passes. Limits are weak everywhere: `n → n + 1` survives 40% of the time.
- ✓A deleted `conn.commit()` survived CI 6 times out of 7. The worker's tests write and read back through the same database connection, so they see their own unsaved change. One test that reads through a second connection would close the whole gap.
- ✓Not every survivor is a bug: an equivalent mutant changes nothing anyone could see. Of 52 survivors read by hand, 42 were real bugs, 6 equivalent and 4 unclear. So most of what CI lets through is a reviewer's job.
- ✓With 173 bugs, a reviewer who finds 60% gets a range of 53–67% (about ±7 points); one kind of bug alone, 11 of them, gives 35–85%. To tell a 60% reviewer from a 75% one 4 times in 5 takes a bit over 200 bugs; at 173 it works about 2 times in 3, and small gaps stay out of reach.
Chapter 1 built a test set for code reviewers: 250 pull requests (PRs, proposed changes) to Harbor, 173 of them with a planted bug, and every one passing CI (the automatic checks that run on each PR). This chapter asks two questions about that set. First: how much does CI miss in everything a PR adds? Second: are 173 bugs enough to measure a reviewer?
Both come from the same lab as Chapter 1, Lab 01 (The Review Testbed) in code-review-labs, but from its last two scripts: 03_what_ci_catches.py (mutation testing, from the recorded results/mutants.jsonl and results/survivor_labels.jsonl) and 04_corpus_budget.py (intervals and power, using stats.py). Chapter 1 covers the rest: healthy main, families, planted bugs, hidden tests and the answer key. Nothing here calls a model, and nobody reviews anything yet: the two "reviewers" at the end are made up for a simulation.
How the PRs are named. Each pull request has an id like c20-d1. The first part is the change: c20 is one feature, adding a per-sync batch size. (c changes come from the app's own history, n changes were written for the test set.) The second part is the version: -clean is the correct PR, and -d1, -d2 are copies of it with one planted bug each.
Harbor is a small app that copies customer records into tools like a CRM (the sales team's customer list). It has three parts: a GraphQL API in TypeScript, a web app with the screens, and a Python worker that sends the data.
What a mutant is
Change c20 adds one setting to a sync (one copy job, from a source table to a destination): how many records to send at a time, in each batch. This is the line that picks the batch size:
size = batch_size or BATCH_SIZES[destination.kind]
Use the sync's own setting, or, if it has none, the destination's default. For a CRM, that's 100.
A mutant is one small, automatic change to a line, for example or becomes and. With a setting of 4, Python's 4 and 100 gives the second value, 100, so the setting is ignored. Then CI runs. The PR's own test sets a batch size of 4 and expects batches of at most 4. It gets one big batch instead, so it fails. CI turns red: the mutant was caught.
If CI had stayed green, the mutant would have survived. Then nothing protects that line, and only a reviewer could notice.
Mutants or planted bugs?
Why use mutants, when the set already has planted bugs? Because they answer different questions.
| Mutants | Planted bugs | |
|---|---|---|
| Made by | a script, in seconds (734 of them) | agents writing each one, then a hidden test proving it |
| Look like | one small swap, like or for and, or a deleted line |
a realistic mistake |
| Measure | how much CI misses | what a reviewer finds |
The batch-size change shows why you need both. Its correct PR had 12 mutants (8 in the API, 4 in the worker), and its own tests caught all 12. Then the planted bug, c20-d1 (the same PR with bug 1 planted), changes the same line the way a person might get it wrong:
size = min(batch_size, BATCH_SIZES[destination.kind]) if batch_size else BATCH_SIZES[destination.kind]
The PR's test asks for 4: the minimum of 4 and 100 is 4. Correct, so CI stays green. A customer asks for 200: the minimum of 200 and 100 is 100. Wrong. It only goes wrong above the default, and the PR's tests never try that. Try each version:
Pick a version of the one line that chooses the batch size, then a customer's setting. CI runs the PR's own test, which sets a batch size of 4 and expects no batch above 4.
# worker/harbor_worker/destinations/__init__.py size = batch_size and BATCH_SIZES[kind]
With a setting, “and” returns the second value, the default, so the setting is ignored. At 4 the test gets one big batch and fails: the mutant is caught.
All 12 mutants of this PR: all caught by its own tests
- caught · ?? null → ?? undefined · api/src/repo/syncs.ts
- caught · n → n + 1 (MAX_BATCH_SIZE) · api/src/validation.ts
- caught · != → == · api/src/validation.ts
- caught · < → <= · api/src/validation.ts
- caught · > → >= · api/src/validation.ts
- caught · && → || · api/src/validation.ts
- caught · || → && · api/src/validation.ts
- caught · n → n + 1 (the minimum, 1) · api/src/validation.ts
- caught · or → and · worker/…/destinations/__init__.py
- caught · delete statement · worker/…/destinations/__init__.py
- caught · delete statement · worker/harbor_worker/models.py
- caught · delete statement · worker/harbor_worker/runner.py
The planted bug is not a mutant: no small automatic swap produces it. A hidden test, which tries a batch size above the default, proves it.
734 mutants: what CI caught
The lab's mutate.py made mutants in the lines that each correct PR adds: 734 of them in 68 PRs (bundles, which repeat other changes' code, are left out, and 4 more PRs have no line a mutant can touch). For each mutant, CI runs again: first the PR's own tests, then the rest of CI, stopping at the first failure. The rest of CI is every other check: the other parts' test suites, the type check (do the code's types fit together) and checks on generated code and database migrations.
| Outcome | Mutants | Share |
|---|---|---|
| Caught by the PR's own tests | 555 | 76% |
| Caught by the rest of CI | 50 | 7% (worker tests 29, type check 12, API tests 9) |
| Survived CI | 129 | 18% (95% interval 15–20%) |
Almost one in five. In 33 of the 68 PRs every mutant was caught. Each survivor is a change CI let through; if it were a real mistake, only a reviewer could catch it.
The PR's own tests cover the lines they add, so why does anything survive? Because running a line isn't checking it. A test can execute a line and never assert what it did.
Where CI is weakest
Mutants in the lines that 68 correct PRs add.
Survived: 129 of 734, 95% interval 15–20%. The rest of CI: worker tests 29, type check 12, API tests 9. Each mutant is one change, run through the PR's own tests first, then everything else, stopping at the first failure.
What survives most
- deleted conn.commit(): 6 of 7
- n → n + 1: 44/109 = 40%
- > → >=: 11/27 = 41%
- delete statement: 32/268 = 12%
Limits are where tests stop: a minimum of exactly 5, a reason of exactly the maximum length.
Are survivors real bugs? (read by hand)
42 bugs · 6 equivalent · 4 unclear, of 52
Of the 129 survivors, 52 were read. An equivalent mutant changes nothing anyone could see; unclear ones change behaviour only in a corner the spec doesn't decide.
| Part | Survived CI |
|---|---|
| API | 30/200 = 15% (11–21%) |
| Web app | 33/84 = 39% (30–50%) |
| Worker | 66/450 = 15% (12–18%) |
The web app is the least protected, more than twice the others. Its tests render a component to HTML and check that some text appears, so a wrong threshold, a missing error message or an unused state update often still renders something that passes.
Two other cuts from the same run. By PR size, XS 0 of 13, S 16%, M 21%, L 16%: no clear trend. By operator, n → n + 1 (44 of 109, 40%) and > → >= (11 of 27, 41%) survive most. Limits are where tests stop: a minimum of exactly 5, a reason of exactly the maximum length.
The missing save
One gap showed up again and again. Harbor keeps its data in a database, and a change only counts after a commit, the database's Save button. Change c19 forbids MIRROR mode (a sync that also deletes records) for email destinations. When an old sync like that runs, the worker marks the run as failed and then commits:
conn.execute(
"UPDATE sync_runs SET status = 'FAILED', finished_at = ?, error = ? WHERE id = ?",
(to_iso(now()), "MIRROR mode isn't available for EMAIL destinations", run["id"]),
)
conn.commit()
The mutant deletes conn.commit(). CI stays green. But in real use, if the worker stops next, that failed status is lost. Deleting a commit like this survived 6 times out of 7 across the corpus (the 7th, in c28, a PR that splits the worker's run loop into two functions, was caught by the worker tests).
Why do the tests miss it? The worker's tests write and read back through one database connection, so they see their own unsaved change, like reading your own draft before pressing Save. Two of the planted bugs sit in exactly this gap: c23-d2, where a run whose source table is missing is marked failed but never saved, so it stays RUNNING forever, and c28-d1, where a claimed run is never saved as RUNNING, so a second worker claims it too and sends the same records twice. The lab's suggested fix is one test that writes through one connection and reads through another: a single test closes the whole class.
Is every survivor a bug?
Not always. In c24, a PR that adds an optional description to syncs (at most 280 characters), a mutant turns a zero into a one:
if ((input.description?.trim().length ?? 1) > MAX_DESCRIPTION_LENGTH) {
A missing description now counts as one character long instead of zero. The limit is 280, so both pass, and nothing anyone could see changes. That's an equivalent mutant: it survives, but it's harmless.
So 52 of the 129 survivors, in 28 PRs, were read and labeled by hand:
| Verdict | Survivors |
|---|---|
| Real bug | 42 |
| Equivalent | 6 (for example a JSON indent of 3 instead of 2) |
| Unclear | 4 (behaviour changes only in a corner the spec doesn't decide) |
The 52 came in two groups: every survivor in the first 34 PRs (22: 19 bugs, 3 equivalent), and a random sample of 30 of the other 107 (23 bugs, 3 equivalent, 4 unclear). Only the second group is random, so the share to quote is from it: about 3 in 4 survivors are real bugs (23 of 30). Most of what CI lets through is a bug a reviewer has to catch.
How precise is one score?
Now the second question. A reviewer's recall is the share of planted bugs it finds. Say one finds 104 of the 173: 60%. On other, similar bugs it would score a bit higher or lower, so a score comes with a range, a 95% Wilson interval: where the reviewer's true rate most likely is.
| Bugs | Found (60%) | 95% range | Width |
|---|---|---|---|
| All 173 | 104 | 53–67% | about ±7 points |
| Logic, the biggest kind (31) | 19 | 44–76% | 32 points |
| Weakened tests, the smallest kind (11) | 7 | 35–85% | 50 points |
The overall range is the one to quote. Per kind (11 to 31 bugs each), the range is too wide to say much, so a claim like "this reviewer is bad at security" needs a big gap and an interval on it. One more caution: the 173 bugs sit in 73 changes and 58 families, and bugs in one change share code and a description. The independent sample is somewhere between 73 and 173, so the lab compares reviewers by resampling whole changes (stats.paired_bootstrap_clustered), not single bugs.
Telling two reviewers apart
The harder question: can this set tell two reviewers apart? To find out, the lab makes up two reviewers, so the true answer is known. A finds 60% of bugs; B finds 75%, so B is really better. Bugs get varied difficulty, and both reviewers see the same bugs (a hard bug is hard for both). A simulation makes a test set of a given size, lets both review it, and checks whether a paired comparison clearly shows B is better. It repeats that 300 times and counts the yeses: the power.
| Bugs | 60% vs 75% | 60% vs 68% | False alarm (60% vs 60%) |
|---|---|---|---|
| 100 | 43% | 18% | 1% |
| 173 | 68% | 29% | 5% |
| 200 | 77% | 25% | 1% |
| 300 | 93% | 45% | 3% |
With 173 bugs, the 15-point gap shows about 2 times in 3, so one time in 3 the better reviewer wouldn't clearly look better. The usual bar is 4 times in 5 (80%): that takes a bit over 200 bugs. An 8-point gap stays out of reach even at 300. Each cell is ±3–5 points (300 runs), which is why the 68% column dips from 173 to 200. The false-alarm column stays near the 2.5% a one-sided test should give, so the simulation is calibrated.
1 · How precise is one reviewer's score?
A Wilson interval: where the reviewer's true rate most likely is, given this many bugs. At 60%, all 173 bugs give 53–67%; the 11 weakened-test bugs alone give 35–85%.
2 · Can it tell two reviewers apart? A finds 60%, B finds 75%
Share of 300 simulated studies (each ±3–5 points) where a paired comparison clearly shows B is better. The line is the usual 80% bar. Bugs are treated as independent, so these are best cases. A smaller gap, 60% vs 68%, stays under 50% even at 300 bugs.
These are best cases: the simulation treats every bug as independent, and real bugs cluster in changes.
What would a bigger set cost? Checking the answer key is cheap: 2.0 seconds per PR in parallel, about 10 minutes for 300 PRs. Writing bugs and their hidden tests is the expensive part, and the existing changes are close to full: the agents adding bugs to them reached 26 of a planned 42, because every other idea turned CI red or repeated a bug already in the same family. Growing the set means writing new changes.
What to do
- Measure what CI protects, don't assume it. Mutate the lines a PR adds and count survivors; coverage only says a line ran.
- Look at where survivors cluster, not just the total: here the web app, exact limits, and deleted commits.
- Write the test that closes a class. For the commit gap, one test that reads through a second connection.
- Read a random sample of survivors before calling the survival rate a bug rate.
- Quote recall with its interval, and only for the whole set unless a kind has many bugs.
- Before comparing two reviewers, check the power for the gap you care about, and compare them on the same bugs.
Caveats
- The 18% isn't the share of bugs that reach review. Mutants are small, single-line and mechanical. Real bugs can be bigger (a wrong design, a contract between two parts) or a missing line, which no operator makes. Equivalent and unclear mutants inflate it too. It's best for comparing CI setups on the same mutants.
- Only 52 of 129 survivors are labeled, and only 30 of those are a random sample. "About 3 in 4 are bugs" is a rough share, not a precise one.
- A small set of operators, not a full mutation tool. The lab mutates only the lines each PR adds, across Python and TypeScript, rather than running mutmut or Stryker on the whole codebase.
- The power numbers are upper bounds with ±3–5 points of simulation noise. Clustered bugs make real comparisons harder.
- The reviewers in the power simulation are made up. No person or model reviews anything in this chapter.
The checklist
- Generate mutants of the added lines of each correct PR, and run the PR's own tests first, then the rest of CI.
- Report the survival share with a 95% interval, split by part of the code and by operator.
- Label a random sample of survivors as bug, equivalent or unclear.
- Add the tests that kill whole classes of survivors, then rerun on the same mutants.
- Compute the Wilson interval for a reviewer's recall at the set's size, overall and per kind.
- Simulate power for the smallest gap you need to detect, and grow the set until it reaches 80%.
Practice: what CI catches, in code
Split records into batches, decide when a test catches a mutant (and why the batch-size PR's own test catches or → and but not the planted bug), count survivors by part of the code, write the Wilson interval, and find how many bugs a ±5-point range needs. The tests expect the lab's numbers: 30 of 200, 33 of 84 and 66 of 450 survived; 15–20% overall; 53–67% for 104 of 173; 35–85% for 7 of 11.
Quiz
1.A script makes one small change to a line a PR adds, and CI stays green. What does that mean?
2.CI caught all 12 mutants of the batch-size PR (c20), but not the planted bug that caps the batch size at the default. Why?
3.Of 734 mutants, 129 survived CI. Which part of Harbor was least protected, and why?
4.A deleted `conn.commit()` survived CI 6 times out of 7. What would catch it?
5.With 173 planted bugs, a reviewer finds 104 (60%). What can you say?
6.Reviewer A really finds 60% of bugs and B 75%. With 173 bugs, how often does a study clearly show B is better?
Check your understanding
Try each question before opening its answer.
A PR's own tests run every line it adds. Does that mean CI protects every line?
No. Running a line isn't checking it. Mutate each added line and see whether a check fails: here 129 of 734 mutants (18%, 15–20%) survived CI even though the PRs' tests ran those lines.
Why did CI catch all 12 mutants of the batch-size PR (c20) but miss its planted bug?
The mutants change the line crudely, so the PR's test (a batch size of 4) notices. The planted bug caps the setting at the default of 100, which is wrong only above 100, and the test never tries a value that high: min(4, 100) is still 4.
Why is the web app the weakest part, and what would you add first?
Its tests render a component and check that some text appears, so a wrong number or a missing error still passes: 39% of its mutants survive, against 15% elsewhere. Add tests that assert what the value is, or that an error is shown, not just that text appears.
Why does a deleted commit survive, and how do you fix that in one test?
The worker's tests write and read back through one connection, so they see their own uncommitted change. A test that writes through one connection and reads through another can only see saved data, so it fails when the commit is missing.
Is the 18% survival rate the share of bugs that reach review?
No, it's a rough signal. Some survivors are equivalent or unclear (7 of the random 30), and real bugs are often bigger than a one-line swap or are missing code no mutant makes. It's most useful for comparing CI setups on the same mutants.
Are 173 planted bugs enough?
For one reviewer's overall recall, yes: about ±7 points (53–67% at 60%). For one kind of bug alone, no: 11 bugs give 35–85%. To tell 60% from 75% four times in five takes a bit over 200 bugs (173 gives about 2 in 3), and small gaps need far more.
Next up: Chapter 3 scores a reviewer on this set: how many bugs it finds, how many false alarms it raises, and how long each PR takes, using an AI stand-in for a human reviewer.