Second Opinionfor Flagsmith

About and architecture

Why Second Opinion exists

A dashboard answers “did the primary metric go up?”. A release decision also has to ask who it went down for, what else moved, and whether you stopped too early.

The problem: broken winners

Feature flags make experiments cheap, so teams run many and decide quickly. A result can be statistically positive on the one metric on screen and still be a bad release. These broken winners get through because the faster the loop, the less often anyone slices the data by hand.

1. Hidden segment harm

The average rises while one group loses. In the demo, overall lift is +13.3% but mobile is −16.2%.

Often called Simpson's paradox. Strictly, that term is for a trend that reverses when groups are combined; here the groups disagree with each other.

2. Guardrail cannibalization

The target metric is bought at the cost of another. In the demo, purchases are up 26.0% and refund requests up 81.8%.

3. Daily peeking

Checking every day and stopping at the first “95%” inflates false wins. In 2,000 simulated A/A tests, naive peeking declared a winner in 19.6%; mSPRT raised a false alarm in 1.8%.

8% base rate, 500 users per arm per look; 14 naive looks, 20 mSPRT looks. Reproduce with so calibrate --replicates 2000.

The 7-layer statistical verification stack

Every layer runs on each analysis. The verdict then applies a fixed order of precedence.

L1Sample ratio: chi-squared goodness of fit

Compares how many users landed in each variant with how many the configured weights predict. A large gap means assignment or tracking is broken, so no later number can be trusted.

χ² = Σ (observed − expected)² / expected df = variants − 1

Decision rule: p < 0.001 blocks; p < 0.01 warns.

L2Primary effect: chance to win and expected loss

Each conversion rate gets a Beta posterior from a uniform prior. Chance to win is how often treatment beats control. Expected loss is how much conversion you give up, on average, if you ship it and it is worse. A z-test cross-checks the result.

rate ~ Beta(1 + conversions, 1 + non-conversions) chance to win = P(treatment > control) expected loss = E[ max(control − treatment, 0) ]

Decision rule: chance to win ≤ 5%, or a significant drop, vetoes. If the Bayesian and z-test answers disagree, warn and hold.

L3Guardrails: probability of unacceptable harm

For each metric you must not damage, estimates the probability that it worsened by more than your tolerance.

P( relative worsening > tolerance | data )

Decision rule: ≥ 90% vetoes; ≥ 70% warns.

L4Segments: subgroup harm and FDR control

Repeats the comparison inside each trait value, such as mobile and desktop, and checks that the trait mix is balanced between arms. Testing many segments inflates false discoveries, so Benjamini–Hochberg sorts the p-values and finds the largest rank k that passes its threshold.

largest k with p(k) ≤ (k / m) · q q = 0.10

Decision rule: A segment with at least 200 users per arm vetoes if its lift is negative and either its 95% interval is below zero or chance to win ≤ 5%. In v0.1.4 the Benjamini–Hochberg flag is reported as evidence; it does not gate this veto. A mix imbalance with p < 0.001 blocks.

L5Novelty decay: early versus later lift

Compares the Day 1 effect with Days 2–3 for users observed long enough, to catch excitement about something new that fades.

Decision rule: Veto when Day 1 chance to win ≥ 90% and the later chance to win is below 70% or the later lift is at most 5%.

L6Sequential stopping: mixture SPRT

An ordinary p-value assumes you look once. The mixture sequential probability ratio test averages the likelihood ratio over plausible effect sizes, giving a p-value that stays valid however often you check (Johari et al., 2017). It uses a normal approximation.

V = 2σ² + nτ² Λ = √(2σ² / V) · exp( n²τ²δ² / (4σ²V) ) p = min(1, 1 / Λ) δ: observed difference n: per-arm sample size σ²: pooled variance τ: 0.2 × baseline rate

Decision rule: Safe to stop only when p ≤ 0.05 and expected loss ≤ 0.001. Otherwise HOLD.

L7Event data quality

Lints the event stream for names that differ only by case or whitespace, duplicates, conversions without an exposure, and users who saw more than one variant.

Decision rule: A casing mismatch, or more than 5% unmatched, duplicated or contaminated data, blocks and yields HOLD.

How layers become one verdict

1 · EXIT 30

Too little data to judge

2 · EXIT 20

Any veto or blocker (except an L7 blocker)

3 · EXIT 10

Not safe to stop, estimators disagree, or L7 blocker

4 · EXIT 0

Nothing above applies

Architecture

Self-hosted FlagsmithMultivariate flags; SDKs record exposures and conversion events
↓ events
Event sourcePostgreSQL events table (SELECT only) or a CSV file
↓ per-variant aggregates
Seven checksL1 ratio · L2 effect · L3 guardrails · L4 segments · L5 novelty · L6 stopping · L7 data quality
↓ check results
Verdict engineDeterministic rules; text, JSON, Markdown or HTML output
↓ exit code
CI/CD pipelineShip, hold or block

In v0.1.4, CSV input supports the full set of checks. The PostgreSQL reader covers L1, L2, L3, L6, trait-mix balance in L4 and multi-variant contamination in L7. Segment harm (L4), novelty (L5) and the other L7 lint checks need data it does not yet load.

Track 03: Build on Open Source Flagsmith

Built for the WeMakeDevs Flagsmith Hackathon (“Toggle Wars”).

Open source and license

Released under the BSD-3-Clause license. Copyright 2026 Ankit Kumar Tiwari.

PyPI ↗

flagsmith-second-opinion 0.1.1

GitHub ↗

Source, fixtures and statistical methods