Checking how many agents are working

How this works
Contact
← Blog
A dark workbench with one small olive-lit tool under a magnifier, a cracked teal copy beside it and a tick mark, the AMARBARO mark centered.
✎blog post

How we test a tool before we share it

The short version

Our tools are checked against a trusted reference, broken on purpose to prove the check can fail, and published with their limits written down.

Part 20 of 20 in Tools we built and why. Previous: mojo-sqlite: a whole database in one file

What this is about

How do you know a program works? You run it and it gives an answer. But a program can give a wrong answer with confidence, and a test can pass for the wrong reason. This post lays out the short routine we follow before we share a tool: check it against a trusted copy, break it on purpose to prove the check can fail, write down what it does not do, and only then publish.

If you write code, you can use this routine tomorrow. If you only use code, it tells you what to look for before you trust a tool.

Why it matters

A green result reports that a check returned zero. It does not say the check could have returned anything else. If a test reads the wrong file, or a tolerance is wide enough to hide the very error you care about, the output looks exactly like a correct program. Nothing on the screen separates the two.

Our early physics prototype is an example. It passed its gate while the simulated fly was tipped over by 117 degrees. The gate printed PASS because it never measured tilt. Since then, we do not believe a check until we have watched it fail on purpose.

The routine, in five steps

1. Find a trusted copy

Pick something that already does the job and is widely trusted. We call it the oracle. For our libraries, it is the Python or C tool they copy. mojo-json is checked against Python's json. mojo-cv is checked against OpenCV. mojo-sqlite is checked against Python's sqlite3, and each SQL test file must give identical output through both. For a rewrite of a small program, the oracle is the original, and mojo-port runs both and compares what they print and how they exit.

2. Run the same input through both

Compare the outputs. For libraries, compare bytes. For physics, kinestride compares every output field with MuJoCo on random body states, with an error limit of 1e-5 of the field's own size.

3. Break it on purpose

This is the step that makes the others worth anything. Plant one believable bug and see whether the check fails. In mojo-port, a mutant gate flips one operator per line, and the demo's eight mutants were all caught. In kinestride, every stage gets a planted bug, such as a flipped sign, and the gate must fail. In corewait and heaptide, the repositories ship a planted mutant and a planted-leak demo for the same reason.

4. Write down what it does not do

Every tool here has a Limits section. It says things like "one machine only", "Linux only", "an estimate unless you pass a tokenizer", "internally audited, not independently audited". A limit written down is a promise that we looked.

5. Publish, with the check beside it

A tool goes public with a script that anyone can run. Speed numbers come last, and a speed from a build that did not pass the match is not reported.

One example in full

Our post A Gate You Have Never Seen Fail Is Not a Gate Yet tells this story in detail. We had fused several GPU kernels in mojo-baro. The change cut GPU dispatches per decoded token from 1244 to 992. Its safety check compared the fused path with the unfused path, bit for bit. That check passed. But it had never been seen to fail.

So we added a compile-time switch with four values. Value 0 is the shipped code. Values 1 to 3 each multiply one output of one fused kernel by 1.0000005, a nudge of about 5e-7. A script builds one program per value. It requires the shipped build to pass and requires each of the three nudged builds to fail.

They did. The three failures were named: hcdown inject, hcup cur and gnorm_ffn residual. Each nudge was caught by the check that owns its kernel, and by no other. That matters more than the count. A check that fails on everything is only loud. A check that fails on each planted bug and names it has a witness for each part.

The script also requires the shipped build to pass. A planted-bug script that only looks for failure can hide a check that fails on correct code.

How to use this on your own code

  1. Pick one function you rely on and find a trusted reference for it.
  2. Write a script that runs both on ten inputs and compares the results.
  3. Change one thing in your function, such as a plus into a minus. Run the script. It should fail.
  4. If it does not fail, your test is too weak. Add an input that catches that change.
  5. Write three lines in your README: what it does, what it was checked against, and one thing it does not do.

What this routine does not prove

  • A passing check says the tool matches the oracle on the inputs tried. It says nothing about inputs nobody tried.
  • A planted bug is a bug we thought of. Real bugs can be stranger.
  • The oracle can be wrong. We say which version of it we used.
  • Our tools are young. Two of the tools in this series, mojo-tls and ctxd, say so in their own limits.

Words you may not know

  • Oracle: a trusted program whose answers we compare ours with.
  • Gate: a check that must pass before work moves on.
  • Mutant: a copy of code with one small change planted on purpose.
  • Planted bug: a mistake added on purpose to test a check.
  • Bit for bit: identical in every stored bit.
  • Dispatch: one launch of a program on a graphics card.
  • Tolerance: how much difference a check allows.

Try it

Comments

No comments yet.

Log in to comment.