Why do tests pass when the program is wrong?
Gary Bernhardt’s isolated tests and Andrej Karpathy’s neural network both deliver good news when the code is wrong.
A passing test is useful evidence. What specific mistake could still produce that result? These talks offer two surprisingly different answers.
When the mock shares your mistake
Imagine testing a reminder service. You tell a fake user repository which accounts have expired, then check whether the service emails them. The fake and the caller can agree perfectly even if both misunderstand the real repository. One integration check against real records tests a different promise.
if you don't stub the boundary correctly, your test will pass and your production system will be wrong.Replay 4:14–4:25 →
Running the real program is no guarantee either
Karpathy trains a small network and watches loss fall. But the training loop forgot to clear old gradients. On this easy problem the accumulated gradients took larger steps and appeared to work even better. Falling loss could never distinguish these implementations.
you may have lots of bugs in the code and uh your network might actually workReplay 2:13:44–2:13:51 →
Replace “loss fell” with a prediction that can fail
At the start of the second step in the experiment above, the parameter is 3. Make a prediction before running the code: for loss w²/2, the derivative at that point must be 3. That is a number, not just a direction vaguely pointing downhill. The calculus treatment of backpropagation extends the same check to a network: multiply local sensitivities along a computational path to find the effect of the current weight.
This right here is the chain rule, where multiplying together these three ratios gives us the sensitivity of c to small changes in WL.Replay 3:45–3:55 →
Now reconsider the accumulated value of 7. It also moves the parameter toward zero, so a test for falling loss passes. But 7 is not 3. This check can fail for an identifiable reason: the update includes a contribution from the preceding step. Deliberately accumulating gradients across examples would be a different update convention.
Equal, close enough, or the same amount?
A failed equality test can look like an algorithm bug if you assume 0.1 survived storage exactly. Its binary expansion repeats, so a finite floating-point format has already made an approximation. A geometry calculation might have an error budget. If the question is whether two receipt totals agree, and every price is a whole number of cents, adding integer cents preserves exactly that promise. Before loosening a test tolerance, say what the permitted difference means in the application.
Compare passages and timestamps
We've run out of digits!Replay 6:07–6:14 →
store everything as an integer in terms of pence, centsReplay 8:13–8:18 →
A reference bullet has a job of its own
A reference bullet carries manufactured marks. Running it alongside a case sample checks whether the instrument can recover known features. The requirement is stronger than testing a familiar input. The reference must be independently characterized and resemble the material at issue. Agreement between two readings alone can otherwise amount to a repeatable measurement of the wrong thing.
Compare passages and timestamps
you would want to use the closest standard reference materialReplay 6:26–6:31 →
They weren't fired through a gun, they were manufactured.Replay 14:19–14:21 →
Did the implementations agree because they read the same documentation?
Tom Scott and the coding assistant both treated a Gmail label as acting on one message; he reports thread-level behavior in Apps Script. A thread containing two messages can distinguish the interpretations more effectively than asking someone else to implement the same documentation. Choose an input that makes the competing accounts predict different visible effects.
Compare passages and timestamps
made the same mistake I did with my backup.Replay 7:59–8:03 →
treats labels as attaching to threads not messages.Replay 8:05–8:09 →
Give the suspected error a chance to fail
For the mock, compare its output with a real query. For gradient accumulation, hand-calculate two small updates and compare the second one. Deliberately introduce the mistake: does the new check turn red?