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
~/petri-coffee · Experiment Copilotlive
YouTurn this buy button into an experiment: mention a delivery promise.
    56 s idea → running4 approvalsevery step in .petri/audit.jsonl

    Works with

    • VS Code
    • Cursor
    • VSCodium · Windsurf
    • Open VSX
    • npx petri-check
    • GitHub Action
    • Codespaces
    • Flagsmith API
    • Claude
    20

    ways an experiment silently loses or skews data, caught as you type, each with a fix

    56s

    from a one-line idea to a running experiment, with 4 approvals

    0

    changes to flags, experiments or code without your approval

    82

    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

    server.mjs · Petri Coffee · VS Code
    The Experiment Copilot turns a plain buy button into a running experiment, asking for approval at each step

    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 handWith Petri
    Self-hosted eventsThe 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 namesCheckout_Completed is stored but never counted by a metric on checkout_completedPETRI002 with a one-click rename
    Reading the flaggetValue() serves the variant and records no exposurePETRI005: switch to getExperimentFlag()
    A fair splitFlagsmith 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 shoppersOne pre-registered rule and a locked stop date; a peek-safe sequential test if you must watch live
    Code changed mid-runSomeone edits the treatment on day 3; the results now mix two versionsPETRI013: the code serving each arm is fingerprinted in petri.lock.json
    Breaks on day 3An arm stops converting after a deploy; the totals still look plausiblePetri Watch reads the hourly timelines and names the commit that likely did it
    AfterwardsThe losing branch stays in the code for goodThe copilot deletes it in one approved diff

    All 20 diagnostics, with fixes →

    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.

    01

    Catch

    20 diagnostics, PETRI001–PETRI020, in the Problems panel as you type. Each is a way an experiment silently loses or skews data.

    02

    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.

    03

    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.

    04

    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.

    05

    Delegate

    The Experiment Copilot (Claude) goes from idea to flag, metrics, code and start, then judges, ships and deletes the dead branch.

    06

    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

    Lock

    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.

    Watch

    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

    Health scorecard

    Pass / warn / fail on the split (α = 0.001), arms, data per arm, event storage, continuity, treatment, freshness and novelty.

    Rehearse

    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.

    GitOps

    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.

    Memory

    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 →

    How it works, stage by stage → · How approvals work →

    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.

    Your code
    What Petri finds
      The Flagsmith project it checks against
      Results and the decision rule
      Flagsmith's dashboard says
      Petri's rule says

        Try "Traffic split went wrong": Flagsmith still says confirmed, and Petri refuses to ship.

        Open the full-page playground →

        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%
        ● interim · 28 Nov 2026, 17:23 IST · submitted before the pre-registered stop
        ArmTrue rateMeasuredTrue liftMeasured lift (95%)Truth inside?
        control9.0%8.0%———
        free_shipping12.5%12.1%+38.9%+50.4% (+0.6% … +100.3%)yes
        arrives_tomorrow9.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.

        Pre-registration, traffic and results →

        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.

        terminal
        $ curl -fsSL -o petri.vsix https://github.com/Ivan825/petri/releases/latest/download/petri.vsix \
          && code --install-extension petri.vsix

        Cursor, 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.

        terminal
        $ 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.

        .github/workflows/petri.yml
        - 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.

        repo root
        $ 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.

        Every install route, plus the MCP server and Agent Skill →

        Run your next experiment where the code lives.