All docs

docs / reference

Measured: does Petri help?

Measured: an agent with Petri fixes the same 6 bugs with half the tokens and turns, and peeking vs Petri's rule in 2,000 A/A tests.

On this page

Two measurements: an agent with and without Petri (below), and how often each way of deciding ships a variant that's no better.

With and without Petri

Same model, same prompt, same six broken repos. One run had plain Claude Code; the other had Claude Code with Petri's Agent Skill and npx petri-check. Run on 28 Nov 2026.

Result

Bugs fixed Turns Time Tokens Est. cost*
Plain Claude Code 6 / 6 215 519 s 6,735,681 $2.94
With Petri 6 / 6 100 300 s 3,483,093 $1.56
Difference same −53% −42% −48% −47%

*The cost Claude Code reports at list API prices. The runs themselves used a Claude subscription.

What this shows:

  • Both fixed every bug; this model is good enough to find these bugs eventually. The difference is the route:
    • With Petri, the agent ran one command, got the file, line and rule, and fixed it.
    • Without Petri, it read the SDK docs and code, queried Flagsmith by hand and reasoned its way there, in twice the turns and tokens.
  • Every Petri fix was one line.
  • The plain agent's diffs were up to 3 lines, and once it touched a second file: it bumped the SDK version in package.json unasked.
  • Neither condition changed anything in Flagsmith. Both had the Flagsmith CLI with an admin key; the flag, metrics and experiment were identical afterwards.

What it doesn't show:

  • Six cases and one run per case is a small sample.
  • The bugs were planted one per repo. Real repos can have several, or bugs Petri has no rule for.
  • A weaker model may fail without Petri where this one succeeded. We didn't test that.

The cases

Each repo is the real Petri Coffee shop (demo-app/server.mjs), correct except for one planted bug, run against a running experiment:

Case Planted bug Petri rule
c1 eventsApiUrl removed on a self-hosted SDK: events go to Flagsmith Cloud PETRI012
c2 trackEvent("Checkout_Completed"): the metric listens for checkout_completed PETRI002
c3 Flag read with getIdentityFlags().getFlag(), so no exposure is recorded PETRI005
c4 getExperimentFlag("checkout_cta") with no identity PETRI006
c5 enableEvents: true removed PETRI007
c6 trackEvent("order_value") removed, but the guardrail metric counts it PETRI003

Method

  • Flagsmith: a fresh self-hosted Flagsmith (selfhost/bootstrap.mjs), loaded with the multivariate flag checkout_cta (keys free_shipping, arrives_tomorrow), both metrics, and a started experiment. The correct shop passes all of Petri's rules against it (12 at the time of the run).
  • Prompt (both conditions): "Our checkout A/B experiment (flag checkout_cta) on our self-hosted Flagsmith isn't measuring correctly. Find the problem in this repo and fix it. The Flagsmith CLI is configured for this project."
  • Agent: Claude Code 2.1.332, claude-sonnet-5-5, non-interactive, at most 25 turns.
    • Both conditions could read and edit files and run the flagsmith CLI, git and node --check.
    • The Petri condition could also use the skill and npx petri-check.
  • Grading: independent of Petri. A case passes if the final server.mjs contains the specific fix (for example a 2-argument getExperimentFlag("checkout_cta", …) call), still passes node --check, and keeps the other five correct lines, so there are no regressions.

Rerun it

The harness is in eval/:

sh
docker compose -p petri-eval -f selfhost/docker-compose.yml up -d     # or any fresh Flagsmith
node selfhost/bootstrap.mjs --dir eval/world
cd eval
node setup-world.mjs world && node fix-keys.mjs world                 # flag, metrics, started experiment
python3 make-cases.py                                                 # 6 cases × 2 conditions
ls -d cases/*/* | xargs -P 4 -n 1 ./run-one.sh                        # 12 Claude Code runs
python3 grade.py                                                      # writes results.json

Raw numbers per run: eval/results.json.

How often each way of deciding ships a variant that's no better

Peeking is the classic way experiments lie. eval/aa.mjs simulates 2,000 experiments shaped like Petri Coffee: control plus 2 variants, a 9% baseline, 360 users an hour for 24 hours. It compares two policies:

  • Peeking: ship the first time any variant shows ≥ 95% to beat control at an hourly look. This is what a "Winner Probability Confirmed" banner invites.
  • Petri's rule: one look, at the pre-registered stop.

"Chance to beat control" is a Beta-Binomial posterior, the kind of number Flagsmith reports.

Ships when nothing works (A/A, false ships) Ships the real winner (A/B, +39%) Ships a harmful variant (−20%)
Peek hourly, ship at first ≥ 95% 36.5% 93.8% 1.9%
Peek hourly with Petri's sequential test (mixture SPRT, always-valid p < 0.05 split across variants) 0.3% 87.0% 0 of 2,000
Petri: one look at the pre-registered stop 8.0% 99.7% 0 of 2,000
… and only ships when it also clears the Bonferroni bar (97.5%) 4.1% 98.8% 0 of 2,000

Seed 7. Seed 11 gives 34.7% / 0.5% / 8.0% / 4.5%, 94.5% / 86.0% / 99.7% / 99.3%, and 2.2% / 0 / 0 / 0. Rerun: node eval/aa.mjs --seed N.

The third column is a harmful case: one variant converts 20% worse than control (7.2% vs 9%) and the other is no better. Peeking ships the harmful variant about 1 time in 50, because early noise can make it look like a winner for an hour. None of Petri's ways of deciding shipped it in 2,000 runs.

Peeking ships a do-nothing variant more than a third of the time. It even ships the real winner less often, because it sometimes grabs the weaker variant early. Petri's single look cuts false ships by 4.5×. The 8% is above 5% because two variants each get a shot at 95%, which is exactly what the Bonferroni note on a ship verdict warns about. Heeding it gets false ships to about 4%, and still finds the real winner 99% of the time.

If you truly need to watch live, the sequential test Petri also reports keeps false ships at 0.3% under hourly peeking: it's valid at any look, and conservative, finding the real winner 87% of the time. The single look at the planned stop remains the most powerful honest choice.