Part 11 in Measuring things honestly. Part 7 of Gates that lie, a test that cannot fail, explains the first half of this idea.
What this is about
A planted bug is a mistake you put into your own code on purpose, to see whether your checks notice. If the checks fail, they work. If they stay green, they do not.
It is a good habit, and we use it for every stage of our physics engine. But it has a limit. A planted bug only tests the checks against bugs you thought of. This article is about a real bug that nobody thought of, and what it taught us.
Why it matters
Planted bugs make people feel safe. "Every stage has a planted bug its check catches." That sounds like proof. It is proof of something narrower.
If you believe the wider claim, you stop looking for the bugs outside the list. We almost did.
How it works
The project
kinestride is our engine for simulating bodies on a GPU. It runs many animals in one launch, 65,536 bodies at once, and every stage is compared with MuJoCo, a well-known physics program that serves as the answer key. You can read more about it at github.com/amarbarosys/kinestride.
Every stage of our fly's engine passed that comparison. Every stage also had a planted bug that its check was proven to catch. We felt good about it.
The review
An outside reviewer then read the code. The reviewer was Codex, an AI coding agent, working only from the source and from saved profiler files. It made no edits, no builds and no GPU runs. It found ten defects in one pass, and rated correctness 7 out of 10 and the quality of our checks 7 out of 10.
The bug the planted bugs missed
The first finding, called B1, was in the Newton solver. This is the loop that finds forces by taking repeated improving steps. Each step uses a matrix, H, that records how the active limits and contacts affect each other. When a limit switches on or off, H must change.
Our code watched contacts for switches. It did not watch tendon limits. When a tendon limit flipped, the solver went on using an old H.
We had ported tendon limits the day before. The check for them had caught 4 of 4 planted bugs.
Why did the checks stay quiet? A solver like this still reaches the right answer with an old matrix, as long as the matrix is of a certain well-behaved kind. It takes more steps to get there, but it lands in the same place. Our checks compare the final answer with MuJoCo's. A defect that only costs more steps is outside what they look at.
At the time of the review, if you deleted the fix, our check script still printed PASS on all three test setups.
Is it serious?
We disagree with the reviewer on how serious it is. The reviewer rated it high. We measured it as a cost problem and not as a wrong-answer problem, unless the limit on the number of steps cuts the solve short. In the reviewer's small toy version of the loop, the old matrix does hit the limit of 100 steps and stops short of the best answer, by more than our checks allow. That toy is not our real code, so we read it as a warning sign, not a measurement.
We also have a rough upper bound from an earlier experiment. When we made H stale on purpose for contacts, the step took 389.6 ms against 88.9 ms, at 75.6 Newton steps against a cap of 100. That is the extreme case, not the tendon one.
Six more, found by reading
Six more of the ten findings came from reading the code, not from running anything, and none of them came from a failing check. Reading found what running with our checks could not.
What we took from it
- A planted bug measures what we thought of, not what we missed.
- Checks that compare only the final answer cannot see defects that cost time but not accuracy.
- A second pair of eyes finds a different class of mistake.
- When you disagree with a review on severity, say so in the open and show the measurement.
What counts and what does not
Counts:
- Planting a bug and watching a named check fail.
- Asking someone else to read the code cold.
- Listing which kinds of defect your checks cannot see.
Does not count:
- Saying "all stages have planted bugs" as if it were "all stages are right".
- Treating a green check as a statement about things it never looked at.
Glossary
- Planted bug (mutant): a deliberate mistake used to test a check.
- Parity: matching a reference program's answers.
- Newton solver: a loop that improves an answer step by step.
- Fixture: a fixed test setup.
- Reviewer: someone who reads your code to find faults.
Try it
For a project of your own, write a short list titled "what my checks cannot see". Be concrete, such as "extra iterations that do not change the answer".
To see our own habit in a small, runnable form, use mojo-port and its mutants command, which plants one-operator bugs in a port and fails if no test notices. Then read what kinestride's own review found in github.com/amarbarosys/kinestride and the matching post, Our Planted Bugs Were Blind to the Bug That Mattered.
What to remember
Planted bugs test your checks against your imagination. A review tests them against someone else's.

Comments
No comments yet.
Log in to comment.