All docs
docs / use petri
Petri Watch: catch a running experiment's measurement breaking
Petri Watch: alerts when a running experiment's measurement breaks, and blames the commit.
On this page
The worst experiment failures happen in production, after a deploy. One variant's checkout stops sending its event, or one arm stops recording exposures. Flags keep working, the dashboard keeps showing a chance to win, and the experiment quietly measures one arm with half its data.
Flagsmith's results include hourly timelines per arm: new users enrolled, and users converted on each metric. Petri Watch reads them for every running experiment and looks for breaks:
| Alert | What it means | How it's decided |
|---|---|---|
| An arm stopped converting | That arm's users still arrive, but its events stopped being sent or counted | 0 conversions over ≥ 2 complete hours, when that arm's own earlier rate predicts enough that zero has < 1% probability (Poisson) |
| An arm stopped enrolling | Its exposures are no longer recorded | 0 new users over ≥ 2 hours while the other arms continue, with < 1% probability of that by chance |
| Enrolment stopped | Nobody is enrolled any more: the flag read or exposure stopped running, or traffic stopped | 0 new users across all arms for ≥ 2 hours after a steady rate |
| The split broke | The arms were balanced, then from some hour on they aren't | The change point where the split is fair before (p > 0.05) and mismatched after (p < 0.001) |
Only complete hours count: the newest bucket is still filling. A single quiet hour isn't an outage.
Blame. For each alert, Petri finds the last commit before the break that touched the experiment's code: files that read its flag, send events or initialise the SDK. The alert names it.
A real run
We staged the incident Watch exists for, on a throwaway self-hosted Flagsmith with the Petri Coffee shop and its experiment running, and simulated shoppers going through the real SDK path at 6 a minute. At 22:00 a commit gave free-shipping orders their own checkout route, which forgot trackEvent. Nothing errored, and all 20 of Petri's static rules still passed against the live environment. Over the next three hours the shop took 37 more free-shipping orders; Flagsmith counted none of them. Then:
$ petri-check watch . --refresh
✖ #1 checkout_cta: free_shipping stopped converting on Checkout conversion at 28 Nov, 22:30: 0 conversions
from 246 new users in 2 h (expected ~25). Its events are no longer sent or counted.
Likely cause: 8a459f8 "Free-shipping orders get their own checkout route (skip the delivery-fee step)"
(28 Nov, 22:00), touching server.mjs.
1 problem in 1 running experiment. (exit 1)It named the right commit, and petri-check experiments showed health 5 pass · 1 fail next to the verdict. Without Watch, free shipping would have looked like a loser from then on, and the experiment would have pointed at the wrong decision. The full transcript: docs/media/watch-incident.txt. rehearse catches the same bug before launch: 15 conversions sent, 7 counted.
Where it runs
- Editor: each refresh checks every running experiment. A new break raises one notification and a red "Measurement broke" line in the experiment's tree, with the commit in the tooltip. The notification offers Pause experiment, through the usual approval, so no more broken data is mixed in while you fix it. The copilot's report includes it too.
- Terminal:
npx petri-check watch . [--refresh]exits 1 when something broke, so it can gate a deploy.--refreshasks Flagsmith to recompute results first.petri-check experimentsshows the same alerts per experiment. - On a schedule: no new infrastructure, since a failed run emails you.
# .github/workflows/petri-watch.yml
on:
schedule: [{ cron: "17 * * * *" }] # hourly
jobs:
watch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with: { fetch-depth: 50 } # history, for blame
- uses: Ivan825/petri@v0.1.5
with:
command: watch
environment: ${{ vars.FLAGSMITH_ENVIRONMENT }}
api_url: https://flags.example.com/api/v1/
env:
FLAGSMITH_API_KEY: ${{ secrets.FLAGSMITH_API_KEY }}- Agents: the MCP tool
petri_experimentsreturns the alerts, so Claude Code or Cursor can report them.
What it doesn't do
It sees what Flagsmith recorded, hour by hour. It can't tell a real drop in buying from a tracking bug when the drop isn't to zero: that's what the results and guardrails are for. It needs a few hours of history before it calls anything.