ways an experiment silently loses or skews data, caught as you type, each with a fix
experiments for self-hosted Flagsmith · open source · MIT
$npx petri-check .
No install at all? Run the checks in your browser on your own code.
Catch it.
Read it.
Ship it.
Petri runs Flagsmith experiments from VS Code. It flags the wiring bugs that make an experiment collect nothing while you type, puts lift and chance to win above the line that reads the flag, decides with one pre-registered rule, then ships the winner and deletes the losing code. Every change waits for your approval.
- diagnostics
- 20
- diagnostics
- ways in
- 5
- ways in
- price
- $0
- MIT licensed
Works with
- VS Code
- Cursor
- VSCodium · Windsurf
- Open VSX
- npx petri-check
- GitHub Action
- Codespaces
- Flagsmith API
- Claude
from a one-line idea to a running experiment, with 4 approvals
changes to flags, experiments or code without your approval
tests: every diagnostic, the decision rule and stats, Watch, the lock, the CLI, MCP server and approval policy
Measured in the recorded demo run against self-hosted Flagsmith · the tests
Select code, describe the idea, approve each request and diff. The experiment is running, and the self-hosted measurement bug is fixed on the way (3× speed).
01 · The problem
An experiment can run for a week, collect nothing, and never raise an error.
Flags keep working, so nobody looks. The bugs that break an experiment live in the code that feeds it: where events go, what they're called, how the flag is read. Flagsmith's dashboard can't see that code, and it calls a winner early.
| By hand | With Petri | |
|---|---|---|
| Self-hosted events | The SDK sends them to Flagsmith Cloud unless eventsApiUrl is set. Zero data, no error. | PETRI012 on the line that creates the client, and the fix |
| Event names | Checkout_Completed is stored but never counted by a metric on checkout_completed | PETRI002 with a one-click rename |
| Reading the flag | getValue() serves the variant and records no exposure | PETRI005: switch to getExperimentFlag() |
| A fair split | Flagsmith reports no sample-ratio p-value while an experiment runs (#9128) | Petri's own chi-square; it won't ship on a broken split |
| When to stop | "94% Winner Probability Confirmed" after 3 hours and 894 shoppers | One pre-registered rule and a locked stop date; a peek-safe sequential test if you must watch live |
| Code changed mid-run | Someone edits the treatment on day 3; the results now mix two versions | PETRI013: the code serving each arm is fingerprinted in petri.lock.json |
| Breaks on day 3 | An arm stops converting after a deploy; the totals still look plausible | Petri Watch reads the hourly timelines and names the commit that likely did it |
| Afterwards | The losing branch stays in the code for good | The copilot deletes it in one approved diff |
02 · What Petri is
The experiment's whole life, next to the code that runs it.
Other Flagsmith editor tools show flag state. Petri runs the experiment: it wires the code, starts it, watches the measurement, judges it and cleans up. It uses Flagsmith's Admin and Experiments APIs, on your own server or on Cloud.
Catch
20 diagnostics, PETRI001–PETRI020, in the Problems panel as you type. Each is a way an experiment silently loses or skews data.
Show
CodeLens above every flag read with the leading arm, lift and chance to win. Hovers with the live split. A results panel with 95% intervals.
Decide
One deterministic rule shared by the UI and the copilot: ship at ≥ 95%, no guardrail likely hurt, no sample-ratio mismatch, no phantom arms.
Act
Start, pause and complete from the tree or the palette. Ship a variant, keep control or turn the flag off, then remove the losing code path.
Delegate
The Experiment Copilot (Claude) goes from idea to flag, metrics, code and start, then judges, ships and deletes the dead branch.
Trust
Every Flagsmith write shows the exact HTTP request, every code change a diff. Nothing runs without your OK, and it's all in .petri/audit.jsonl.
Built for experiments that run for days
Treatment lock
petri-check lock fingerprints the code serving each arm, plus the split, metrics and a pre-registered stop. Change any of it while the experiment runs and PETRI013 fails the PR.
Petri Watch
Reads Flagsmith's hourly timelines per arm. An arm that stops enrolling or converting, or a split that drifts, raises an alert with the commit that likely caused it.
Health scorecard
Pass / warn / fail on the split (α = 0.001), arms, data per arm, event storage, continuity, treatment, freshness and novelty.
Recount before launch
petri-check rehearse sends N visitors through your real app and checks Flagsmith counted exactly that many. Sent 15 conversions, counted 7? Fix it before real users.
Experiments as PRs
Start, pause, complete and ramp the winner (10 → 50 → 100%) as entries in petri.plan.json. The review is the approval; petri-check apply runs it on merge.
Decisions stay with the code
Every completed experiment is recorded in the lock with its evidence, and shown as a CodeLens above the code it decided, so nobody re-tests a settled question.
Petri Watch → · Health scorecard → · Experiments as pull requests →




03 · Playground
Try the checks on your own code.
This is the extension's own rule engine, compiled for the browser: 17 of the 20 diagnostics run here (the other three need your lock file, package.json or a non-JS SDK). It checks your code against a copy of the real Petri Coffee project. Flip the switches to break the Flagsmith side. Nothing leaves the page.
Try "Traffic split went wrong": Flagsmith still says confirmed, and Petri refuses to ship.
04 · The experiment
We ran one, and we knew the right answer in advance.
Petri Coffee is a real A/B/n test on self-hosted Flagsmith, set up and finished from the editor. Shoppers are simulated but go through the real SDK: assignment, exposures and events are all real. Only the buy decision is random, with true rates we hid from Flagsmith and Petri, so we can check whether the pipeline found them.
- Hypothesis
- A delivery promise on the buy button raises checkout conversion without lowering order value.
- Arms
- control "Buy now" · free_shipping · arrives_tomorrow, 33/33/33
- Metrics
- Checkout conversion (primary) · revenue per shopper (guardrail)
- Rule
- Pre-registered before the first shopper: ship at ≥ 95%, one look at the planned stop
- Power
- ~1,200 shoppers per arm to detect 9% → 12.5%
| Arm | True rate | Measured | True lift | Measured lift (95%) | Truth inside? |
|---|---|---|---|---|---|
| control | 9.0% | 8.0% | — | — | — |
| free_shipping | 12.5% | 12.1% | +38.9% | +50.4% (+0.6% … +100.3%) | yes |
| arrives_tomorrow | 9.8% | 9.3% | +8.9% | +16.0% (−24.3% … +56.3%) | yes |
2,028 shoppers so far. Both true effects sit inside Flagsmith's intervals. Read the full experiment: the pre-registration, the power calculation and the decision.
05 · Install
Pick your way in.
Petri connects to any Flagsmith, self-hosted or Cloud. A repo bound with the Flagsmith CLI, or set up by bootstrap.mjs, connects without a prompt.
VS Code
One line, from the latest GitHub release.
$ curl -fsSL -o petri.vsix https://github.com/Ivan825/petri/releases/latest/download/petri.vsix \
&& code --install-extension petri.vsixCursor, VSCodium, Windsurf
Search Petri in Extensions. It's on Open VSX.
Terminal
The same diagnostics, headless. No install, no setup for the code-only rules.
$ npx petri-check . # all 20 rules against live data: $ FLAGSMITH_API_KEY=… npx petri-check . --environment <env key>
GitHub Action
Fail a pull request that would break an experiment.
- uses: Ivan825/petri@v0.1.5
with:
path: .
self_hosted: "true"Self-hosted Flagsmith, zero clicks
Starts Flagsmith with experimentation, then creates the admin, project, API key and event storage.
$ docker compose -f selfhost/docker-compose.yml up -d $ node selfhost/bootstrap.mjs
GitHub Codespaces
All of the above in the cloud: Flagsmith, the bootstrap, Petri built and installed, the demo shop ready.