WRITE · TRACE · UNDERSTAND

Project: make a replay-safe, cohort-aware rollout monitor

Predictions have unique id,cohort,baseline,candidate probabilities; outcomes have unique id,binary integer y,finite available.

Read lesson: Project: make a replay-safe, cohort-aware rollout monitor →

Your experiment

Predictions have unique id,cohort,baseline,candidate probabilities; outcomes have unique id,binary integer y,finite available. Pair only outcomes available<=finite asof. For every predicted cohort compute count and mean(candidate squared error - baseline squared error). A window has enough evidence only if every cohort reaches positive integer min_pairs. It is bad if sufficient and any cohort delta>nonnegative finite tolerance. Track consecutive bad windows, resetting on all other windows; rollback after two and latch rollback forever. Otherwise return continue for sufficient good evidence, hold otherwise. Window is a nonnegative increasing integer; identical canonical payload replay returns copied state, conflicting or older windows raise ValueError. Never mutate input state.

Python runs in your browser. Your draft stays on this device.

What to look for

Review delayed-label coverage, cohort policy, sequential monitoring and replay state. A two-window rule is an operational policy, not a statistical significance test. Replay follows the main orchestration function; helper computations execute and are checked separately.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.

About this algorithm

How Project: make a replay-safe, cohort-aware rollout monitor works

The idea

When a candidate model gradually replaces a baseline, a rollout monitor decides, one time window at a time, whether to continue, hold or rollback. monitor_rollout compares the two models' squared errors on the same predictions, using only outcomes whose labels have arrived by asof.

The design is a small state machine with three guards. Evidence is judged per cohort, because an overall average can hide harm to a small group. Rollback needs two bad windows in a row, so one noisy window cannot trigger it, and once set it stays. Each window's payload is hashed, so a retried delivery returns the stored result instead of counting the same bad window twice.

How it works

  1. Check window, min_pairs, asof and tolerance, then hash the whole payload with SHA-256.
  2. If window equals the stored one, return a deep copy of the state when the digest matches; a changed payload or an older window raises ValueError.
  3. Validate ids, probabilities and outcomes, then pair each prediction with an outcome whose available <= asof.
  4. Per cohort, average (candidate - y)**2 - (baseline - y)**2; a positive value means the candidate is worse.
  5. Evidence is enough only if every predicted cohort has min_pairs pairs; the window is bad if any cohort's delta exceeds tolerance.
  6. Two bad windows in a row set rollback for good; otherwise sufficient good evidence gives continue, and anything else hold.

What it costs

Per window
O(p + o) rows
State kept
O(cohorts)
Rollback after
2 bad windows in a row

Each window makes a fixed number of passes over its p predictions and o outcomes, including the JSON hash; only a short summary per cohort is carried forward.

Where it is used

  • Argo Rollouts and Flagger run automated canary analysis, promoting or rolling back a release from metric checks at each step.
  • Amazon SageMaker deployment guardrails shift traffic to a new model in stages and roll back automatically on alarms.
  • Stripe's idempotency keys follow the same replay rule: a retry returns the stored result, and changed parameters under the same key are an error.

Watch out for

  • Pooling all cohorts into one average, where a large cohort's gain hides harm to a small one.
  • Counting labels that arrive after asof, or treating a cohort with no labels as good news; it must hold.
  • Counting a retried window twice, or returning the stored state itself on replay so a caller can edit it; return a copy.