All docs

docs / use petri

The decision rule

One deterministic rule: when to ship, keep running, keep control or investigate.

On this page

Petri judges every experiment with one deterministic rule. The results panel, the CodeLens, the copilot, petri-check experiments, the MCP server and the Agent Skill all call the same function (recommend in extension/src/insights.ts), so they can't disagree. The copilot reports the rule's verdict; it doesn't judge results by feel.

The rule

Applied to the experiment's primary metric (the first one) and its guardrails (the rest), in this order:

  1. Investigate if there is a phantom arm (an arm in the results that isn't a variant key, PETRI009) or a sample-ratio mismatch with p < 0.001. The data can't be trusted, so nothing else is decided.
  2. Keep running while Flagsmith reports no inference yet. It needs at least 50 identities and 5 conversions per arm.
  3. Keep control if any guardrail is more than 80% likely to have moved the wrong way for the best variant.
  4. Ship the best variant at ≥ 95% chance to beat control on the primary metric.
  5. Keep control if the best variant is at most 5% likely to win.
  6. Otherwise keep running, and say what would settle it.

For a metric whose expected direction is "decrease", a lower value wins, and the chance to win is flipped accordingly.

The thresholds don't change during an experiment. For Petri Coffee they were committed before the first shopper arrived.

Where the numbers come from

Lift, the 95% credible interval and the chance to beat control are Flagsmith's own, from its Experiments API. Petri adds three things.

The sample-ratio check when Flagsmith reports none

While an experiment runs, Flagsmith returns null for the sample-ratio p-value: starting an experiment sets the flag's default weights to 0, and the check needs them (Flagsmith#9128). A tool that trusts that field never sees a broken split.

When it is null, Petri runs its own chi-square test of exposures against the configured split (from the experiment's rollout, or an even split if none can be read), from 100 exposures up. The tree view marks it "(Petri)", petri-check experiments adds *, and the copilot's report says which test it used. On Petri Coffee at 2,028 shoppers it gave p = 0.24: a fair split.

Several variants: the Bonferroni note

With two or more variants, each one gets a chance to cross 95%, so a borderline win among many arms is weaker evidence than the same number with one variant. A ship verdict then also says whether the result clears a Bonferroni-corrected bar (97.5% for two variants, 98.3% for three). The rule itself stays at 95%, as pre-registered; the note tells you how strong the win is.

Expected loss

"98% to win" says how likely the variant is better, not how bad it would be if it isn't. Expected loss is how much worse than control the variant is on average, in the cases where it is worse, as a share of the metric:

text
loss = σ·φ(μ/σ) − μ·Φ(−μ/σ)

where μ is Flagsmith's lift and σ comes from its 95% interval (a normal approximation of the posterior). A ship verdict states it, and the results panel, the copilot's report and the playground show it for every arm. On Petri Coffee: 0.23% for free_shipping, 2.57% for arrives_tomorrow.

Completing against the rule

You can still complete an experiment any way you like. If the decision goes against the rule (for example, shipping a variant at 80%), or there are no results yet, the approval dialog says so in a warning before you confirm.

How much longer?

When the verdict is keep running and the lift points the right way, Petri says how many more users per arm would decide it if the current lift held: the standard error shrinks with 1/√n, so the bar needs about n × (1.645 / z)², where z is the lift over its standard error. A smaller true effect needs more, and the reason says so.

Peek-safe sequential test

Alongside the Bayesian numbers, Petri runs a mixture sequential probability ratio test on each variant's hourly timeline. That's the always-valid kind of test production experimentation platforms use for continuous monitoring. Its p-value stays valid however often anyone looks: in 2,000 simulated A/A experiments peeked at hourly it ships a do-nothing variant 0.3% of the time, against 36.5% for a 95% banner. It shows as peek-safe p=… on petri-check experiments and in the report. On our experiment, at 2,028 shoppers it says p = 0.110: not yet, while Flagsmith's banner already says 98%. The decision rule itself is unchanged.

Pre-registered stop

Deciding early on a good-looking number is how experiments lie. Measured: over 2,000 simulated A/A experiments shaped like ours, peeking hourly and shipping at the first ≥ 95% ships a do-nothing variant 36.5% of the time. Petri's one look at the planned stop ships 8.0%, and 4.1% with the Bonferroni bar. Flagsmith's dashboard said "94% Winner Probability Confirmed" three hours into our 24-hour test. petri.lock.json can record when you planned to decide, as a time and/or a sample size:

sh
npx petri-check lock . --stop-at 2026-11-29T13:00+05:30 --stop-n 3600   # or: Petri: Pre-register When to Decide

Sized from your own data: npx petri-check lock . --mde 20% sets the stop to the sample needed to detect a +20% change at 80% power. It uses a two-proportion test on the experiment's own control rate, with α split across the variants (Bonferroni). For our experiment, 9% → 12.5% needs 1,226 users per arm, matching the hand calculation in the pre-registration.

From then on the CodeLens shows progress (⏱ pre-registered: 2,028 / 3,600 users, stops 29 Nov 13:00 (17 h left)), and the copilot and petri-check experiments mark a SHIP before the stop as provisional: "wait: the planned stop isn't reached… don't complete yet." The rule's thresholds don't change. Completing before the stop is still possible, but never silent: the approval says you're deciding early and the button reads Complete early. The decision memory then carries "decided before its pre-registered stop" for good.

docs/decision-rule.mdView or edit on GitHub →