Checking how many agents are working

How this works
Contact
← Blog
A heavy steel gate with a single closed latch on a dark stone wall, lit in cold teal with a warm amber light along the latch, the AMARBARO mark and wordmark centered over it.
✎blogbericht

What a gate is: a check that can say no

The short version

A gate is only trustworthy after someone has seen it fail on code that is known to be wrong.

Part 6 in Gates that lie. This part is for readers who are new to testing. Part 5 was A gate you have never seen fail is not a gate yet.

What this is about

A gate is a check that decides whether work may go forward. If the work follows the rule, the gate says yes. If it does not, the gate says no and the work stops.

Gates are everywhere in software. A test that must pass before code is saved is a gate. A rule that blocks a file with a secret in it is a gate. A script that compares two results and exits with an error is a gate.

The key idea in this article is simple. A gate that has only ever said yes has not shown you anything. You must see it say no.

Why it matters

Imagine a smoke alarm that has never made a sound. Is the house safe, or is the alarm broken? From the outside you cannot tell. Both cases look the same: silence.

A green light on a gate is the same. Green means "the check ran and found no problem". It does not mean "the check can find problems". If the check looks at the wrong file, or allows too much error, it will say green for good code and for bad code alike.

We have been caught by this. So we made a habit that you can copy.

How it works

Here is the habit, as steps.

Step 1: Say what the gate guards

Write one sentence. "This gate checks that the fast version of our code gives the same answer as the slow version." Now you know what a failure should look like.

Step 2: Run it on good code

Run the gate on code you believe is right. It should pass. This is the easy part, and it is the part everyone does.

Step 3: Break the code on purpose

Make a small change that you know is wrong. Change a plus into a minus. Nudge a number by a tiny amount. This broken copy is called a mutant, which just means a changed copy.

Step 4: Run the gate again

Now the gate must say no. If it still says yes, you have found a gate that does not guard what you thought. Fix the gate before you trust it.

Step 5: Keep the proof

Save the output of the failed run. Next time you doubt the gate, you can point at it.

A real case from our code

Our engine for running language models has a fast path, where several small GPU steps are joined into one. The change cut the number of GPU launches for each generated word from 1244 to 992. It sat behind a gate: a test that runs the fast path and the plain path and compares the results bit by bit.

That gate passed. It had never failed.

So we added a switch to the code, off by default, that nudges one result by a tiny amount: it multiplies it by 1.0000005, about five parts in ten million. We did this in three different places, one at a time, and built a copy for each.

The shipped copy passed. All three nudged copies failed. Each failure named its own part: "hcdown inject", "hcup cur", "gnorm_ffn residual". That is the good outcome. The gate does not just shout at everything. It points at the right place.

Our full write-up is in A gate you have never seen fail is not a gate yet.

Another gate, with three conditions

We have a second example, for a maths function that the CPU and the GPU paths share. Its check script asks for three things on 40,017 generated inputs. The CPU and the GPU must return the same bits. Both must stay within one unit of error in the last place of a trusted reference. And a planted mutant, with one correction term removed, must go above that limit. The script prints FAIL <step>: <reason> and exits with an error on any miss, and a skipped step does not count as a pass. Three conditions leave less room for a gate to be green by accident.

What a gate is not

  • A gate is not a promise that the code is right. It only checks the one rule it was given.
  • A green gate is not a proof. It is one witness, and you have to know the witness can speak.
  • A gate that fails on everything is not a good gate either. It must pass on good code. Our check script requires both: the shipped copy must pass, and the nudged copies must fail.

Glossary

  • Gate: a check that must pass before work goes forward.
  • Mutant: a copy of code with one small deliberate change.
  • Bit for bit: two results match exactly, with no allowed difference.
  • Exit code: the number a program returns when it finishes. Zero means success, anything else means failure.
  • Tolerance: how much difference a check allows before it says no.

Try it

You can do the whole habit in one afternoon with a small program.

Our tool mojo-port is built around it. You give it a small Python command-line tool and a Mojo version of the same tool. Its verify command runs both on the same test cases and compares what they print and how they exit. Its mutants command then changes one operator per line of your Mojo code and fails if no test case notices. In the demo in its README, a line counter called wcl passes 9 of 9 cases, and the mutant check reports 8 of 8 killed.

Read that README, run the demo, then break the demo code yourself and watch verify say no.

What to remember

A gate is a check that can say no. Before you trust one, make it say no.

Reacties

Nog geen reacties.

Inloggen om te reageren.