:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(signals): stop sparse holdouts from vetoing inbox ranking promotion (#111257)
posthog[bot]8d7d59dbf9ca
diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.mdindex c38042977879..f5a4ca01ea72 100644--- a/products/signals/dags/inbox_ranking/README.md+++ b/products/signals/dags/inbox_ranking/README.md@@ -96,7 +96,7 @@ s3://<bucket>/<prefix>/- **One rendering's vectors are held at a time.** The examples asset loads a set's side inputs, builds that set's object, and releases them before the next set. Each snapshot carries a vector per live report, so a further embedding family costs runtime rather than peak memory. The scores asset narrows each snapshot to the newborn pool it scores for the same reason. Raising the pod memory limit is not the first move here.- **Candidate**: one per family, per-head XGBoost with fixed params, holdout = the last `holdout_days` of reports (cut by report, never by row), AUC + a label-permutation null. Each family trains on the examples of the feature set its registry entry names, and a family whose examples or metadata are missing that day is logged and skipped rather than failing the asset. A head is _readable_ when it has enough holdout positives and clears its null by 0.05. The shipped booster (`<head>.ubj`) is refit on everything; the train-only fit is kept as `<head>.holdout.ubj` so a later candidate can grade this model on its own holdout.- **Metrics telemetry**: each asset also captures its metrics as events into the dogfood project (the same project the label events land in), through `training/telemetry.py`: `inbox_ranking_examples_built` once per head and feature set, `inbox_ranking_candidate_trained` once per head (`head`, `model_role` always `candidate`, holdout / train AUC, average precision, logloss, positive rate, mean predicted score, the row-weighted decile calibration error, the permutation-null mean and spread, counts, `readable`), `inbox_ranking_holdout_calibration` once per head and holdout score decile `inbox_ranking_promotion_decided` once per run and `inbox_ranking_serving_manifest_published` once per run, all carrying `model_name` and `model_version` and stamped midday UTC on the partition day so re-runs and backfills chart on the day they describe. Per-head stability is a trends insight with a `head` breakdown; a readability drop is an insight alert. `metadata.json` stays the durable record. Capture is best-effort. Local dev runs (`DEBUG`) emit too, under `distinct_id` `inbox_ranking_training_local` with `environment=local`, so filter or break down on `environment` when reading the prod series; any other non-Cloud deployment emits nothing.-- **Champion**: one decision per family against that family's own pointer. `promotion.decide_promotion` — promote when the candidate has a readable head, is within 0.02 AUC and 0.02 holdout ECE of the champion on every head the champion could read, and the champion is at least `INBOX_RANKING_PROMOTION_MIN_DAYS` old. The champion's AUCs and ECEs come from its `<head>.holdout.ubj` scored on the candidate's holdout (`paired_champion_grades`), so both models are compared on one set of reports; a champion without that file falls back to its stored AUC and skips the calibration check. The pointer is rewritten only when `INBOX_RANKING_AUTO_PROMOTE` is on; otherwise the decision is logged and surfaced as asset metadata, so the daily candidate series is monitoring while the first shadow read runs on a frozen champion. To promote by hand, copy a candidate's `metadata.json` to `champion.json` with a `promoted_at`.+- **Champion**: one decision per family against that family's own pointer. `promotion.decide_promotion` — promote when the candidate has a readable head, is within 0.02 AUC and 0.02 holdout ECE of the champion on every head the champion could read, and the champion is at least `INBOX_RANKING_PROMOTION_MIN_DAYS` old. The champion's AUCs and ECEs come from its `<head>.holdout.ubj` scored on the candidate's holdout (`paired_champion_grades`), so both models are compared on one set of reports; a champion without that file falls back to its stored AUC and skips the calibration check. A head whose shared holdout has fewer than its `min_holdout_positives` is skipped rather than blocking, and is listed in `skipped_heads` on the decision event and the asset metadata; a head the candidate did not train still blocks. The pointer is rewritten only when `INBOX_RANKING_AUTO_PROMOTE` is on; otherwise the decision is logged and surfaced as asset metadata, so the daily candidate series is monitoring while the first shadow read runs on a frozen champion. To promote by hand, copy a candidate's `metadata.json` to `champion.json` with a `promoted_at`.- **Serving manifest**: the dag's decision about what the scoring sweep runs, published where the sweep can read it. The Temporal workers have no credential for the dataset bucket, so `inbox_ranking_serving_manifest` copies the models the sweep needs into the deployment's own object store and writes a manifest naming them:diff --git a/products/signals/dags/inbox_ranking/tests/test_training.py b/products/signals/dags/inbox_ranking/tests/test_training.pyindex 5a7ddbdf9447..cfd1673c24e4 100644--- a/products/signals/dags/inbox_ranking/tests/test_training.py+++ b/products/signals/dags/inbox_ranking/tests/test_training.py@@ -138,7 +138,12 @@ from products.signals.dags.inbox_ranking.training.telemetry import (unseen_report_graded_events,unseen_score_events,)-from products.signals.dags.inbox_ranking.training.train import _head_readable, booster_holdout_grade, train_head+from products.signals.dags.inbox_ranking.training.train import (+ HoldoutGrade,+ _head_readable,+ booster_holdout_grade,+ train_head,+)from products.signals.dags.inbox_ranking.training.unseen import (CANDIDATE_ROLE,CHAMPION_ROLE,@@ -1508,7 +1513,7 @@ def test_training_events_carry_the_dashboard_contract(monkeypatch):partition_key="2026-08-25",run_id="run-1",model_name=TABULAR_MODEL_NAME,- decision=PromotionDecision(promote=True, reason="no champion yet"),+ decision=PromotionDecision(promote=True, reason="no champion yet", skipped_heads=("discuss",)),promoted=False,champion_version="none",incumbent_champion_version="none",@@ -1589,6 +1594,7 @@ def test_training_events_carry_the_dashboard_contract(monkeypatch):"would_promote": True,"promoted": False,"incumbent_champion_version": "none",+ "skipped_heads": ["discuss"],"champion_open_auc_on_this_holdout": 0.6,"champion_open_ece_on_this_holdout": 0.05,}.items() <= promotion_props.items()@@ -1729,10 +1735,71 @@ def test_decide_promotion_grades_the_champion_on_the_candidate_holdout():champion = {**_metadata("d1", open=0.60), "promoted_at": "2026-08-10T00:00:00+00:00"}assert decide_promotion(candidate, champion, now=NOW, min_days_between=3).promote# Paired on this holdout the champion is stronger than its stored number said.- paired = decide_promotion(candidate, champion, now=NOW, min_days_between=3, champion_aucs={"open": 0.75})+ paired = decide_promotion(+ candidate, champion, now=NOW, min_days_between=3, champion_grades={"open": _grade(auc=0.75, positives=50)}+ )assert not paired.promote and "regressed" in paired.reason+def _grade(*, auc: float | None, positives: int, ece: float | None = None) -> HoldoutGrade:+ return HoldoutGrade(auc=auc, expected_calibration_error=ece, positives=positives)+++def _head(name: str, auc: float, *, readable: bool) -> dict:+ return {"head": name, "holdout_auc": auc, "readable": readable}+++ "candidate_heads,discuss_grade,expected_promote,reason_fragment,expected_skipped",+ [+ # The shared holdout is too thin to read discuss on either model: no evidence, not a regression.+ (+ [_head("open", 0.70, readable=True), _head("discuss", 0.77, readable=False)],+ _grade(auc=0.70, positives=26),+ True,+ "skipped: discuss",+ ("discuss",),+ ),+ # A thin holdout must not hide a head the candidate lost.+ ([_head("open", 0.70, readable=True)], _grade(auc=0.70, positives=0), False, "discuss not trained", ()),+ # Enough positives, the candidate sits inside its null and well under the champion: its numbers fail it.+ (+ [_head("open", 0.70, readable=True), _head("discuss", 0.55, readable=False)],+ _grade(auc=0.70, positives=40),+ False,+ "discuss regressed",+ (),+ ),+ (+ [_head("open", 0.70, readable=True), _head("discuss", 0.71, readable=True)],+ _grade(auc=0.70, positives=40),+ True,+ "every readable head",+ (),+ ),+ ],+ ids=["thin_holdout_skipped", "head_not_trained", "unreadable_regressed", "both_readable"],+)+def test_decide_promotion_skips_heads_the_shared_holdout_cannot_read(+ candidate_heads, discuss_grade, expected_promote, reason_fragment, expected_skipped+):+ candidate = {"model_version": "d2", "heads": candidate_heads}+ champion = {**_metadata("d1", open=0.70, discuss=0.70), "promoted_at": "2026-08-10T00:00:00+00:00"}++ decision = decide_promotion(+ candidate,+ champion,+ now=NOW,+ min_days_between=3,+ champion_grades={"open": _grade(auc=0.70, positives=60), "discuss": discuss_grade},+ min_holdout_positives={"open": 50, "discuss": 30},+ )++ assert decision.promote is expected_promote+ assert reason_fragment in decision.reason+ assert decision.skipped_heads == expected_skipped++@pytest.mark.parametrize("candidate_ece,champion_eces,expected_promote",[@@ -1749,9 +1816,8 @@ def test_decide_promotion_refuses_a_worse_calibrated_candidate(candidate_ece, chcandidate["heads"][0]["holdout_expected_calibration_error"] = candidate_ecechampion = {**_metadata("d1", open=0.66), "promoted_at": "2026-08-10T00:00:00+00:00"}- decision = decide_promotion(- candidate, champion, now=NOW, min_days_between=3, champion_aucs={"open": 0.66}, champion_eces=champion_eces- )+ grade = _grade(auc=0.66, ece=(champion_eces or {}).get("open"), positives=50)+ decision = decide_promotion(candidate, champion, now=NOW, min_days_between=3, champion_grades={"open": grade})assert decision.promote is expected_promoteassert expected_promote or "open calibration regressed" in decision.reasondiff --git a/products/signals/dags/inbox_ranking/training/dag.py b/products/signals/dags/inbox_ranking/training/dag.pyindex b8b5a559d553..282a83119431 100644--- a/products/signals/dags/inbox_ranking/training/dag.py+++ b/products/signals/dags/inbox_ranking/training/dag.py@@ -780,6 +780,7 @@ def _decide_champion(return Nonechampion_key = champion_object_key(prefix, family.name)champion = _read_json_if_exists(client, bucket, champion_key)+ champion_grades: dict[str, HoldoutGrade] = {}champion_aucs: dict[str, float] = {}champion_eces: dict[str, float] = {}if champion is not None:@@ -801,7 +802,7 @@ def _decide_champion(f"the {family.name} champion is compared on its stored AUC")else:- grades = paired_champion_grades(+ champion_grades = paired_champion_grades(client,bucket,prefix,@@ -810,10 +811,10 @@ def _decide_champion(feature_set=champion_feature_set,holdout_days=settings.INBOX_RANKING_TRAINING_HOLDOUT_DAYS,)- champion_aucs = {head: grade.auc for head, grade in grades.items() if grade.auc is not None}+ champion_aucs = {head: grade.auc for head, grade in champion_grades.items() if grade.auc is not None}champion_eces = {head: grade.expected_calibration_error- for head, grade in grades.items()+ for head, grade in champion_grades.items()if grade.expected_calibration_error is not None}context.log.info(@@ -825,8 +826,8 @@ def _decide_champion(champion,now=datetime.datetime.now(datetime.UTC),min_days_between=settings.INBOX_RANKING_PROMOTION_MIN_DAYS,- champion_aucs=champion_aucs,- champion_eces=champion_eces,+ champion_grades=champion_grades,+ min_holdout_positives={name: head.min_holdout_positives for name, head in HEADS_BY_NAME.items()},)context.log.info(f"{family.name} promotion decision for dt={partition_key}: promote={decision.promote} ({decision.reason})"@@ -873,6 +874,7 @@ def _decide_champion(f"{family.name}_would_promote": dagster.MetadataValue.bool(decision.promote),f"{family.name}_promoted": dagster.MetadataValue.bool(promoted),f"{family.name}_reason": dagster.MetadataValue.text(decision.reason),+ f"{family.name}_skipped_heads": dagster.MetadataValue.json(list(decision.skipped_heads)),**{f"{family.name}_champion_{head}_auc_on_this_holdout": dagster.MetadataValue.float(auc)for head, auc in champion_aucs.items()diff --git a/products/signals/dags/inbox_ranking/training/promotion.py b/products/signals/dags/inbox_ranking/training/promotion.pyindex 37a95bba04f4..3d0c422d585d 100644--- a/products/signals/dags/inbox_ranking/training/promotion.py+++ b/products/signals/dags/inbox_ranking/training/promotion.py@@ -3,14 +3,20 @@A candidate replaces the champion when it is at least as good on every head the champion couldread, has at least one readable head itself, and enough days have passed since the last promotion(scores are consumed by an online shadow read, and a champion that changes every day muddies it).-Pure function over the two metadata records so the rule is testable without S3. The champion's-AUCs should be `champion_aucs`, its holdout booster graded on the candidate's holdout, so both-models are compared on one set of reports; the stored numbers are the fallback.+Pure function over the two metadata records so the rule is testable without S3.++`champion_grades` holds the champion's holdout booster graded on the candidate's holdout, so both+models are compared on one set of reports; the stored AUCs are the fallback for a head without one.AUC reads the ranking only, so a candidate must also not be worse calibrated than the champion on-those heads. The champion's calibration error comes from `champion_eces`, graded on the candidate's-holdout the same way. There is no stored fallback: a champion's stored error was read on its own-holdout, which can hold a different base rate, so a head without a paired error skips this check.+those heads. The champion's calibration error comes from the same paired grade. There is no stored+fallback: a champion's stored error was read on its own holdout, which can hold a different base+rate, so a head without a paired error skips this check.++A paired grade also says how many positives the shared holdout holds. Below the head's+`min_holdout_positives` neither model can be read on it, so the head is skipped, not counted as a+regression. A head the candidate did not train still blocks: a candidate must not replace a champion+by losing a head the champion serves."""import datetime@@ -19,6 +25,8 @@ from typing import Anyfrom posthog.dataclasses import frozen+from products.signals.dags.inbox_ranking.training.train import HoldoutGrade+# A candidate may be this much worse than the champion on a readable head and still promote: at# the readability floor the AUC's noise is about this size, so exact dominance would never trigger.AUC_TOLERANCE = 0.02@@ -32,6 +40,8 @@ ECE_TOLERANCE = 0.02class PromotionDecision:promote: boolreason: str+ # Champion-readable heads whose shared holdout had too few positives to compare.+ skipped_heads: tuple[str, ...] = ()def _readable_aucs(metadata: Mapping[str, Any]) -> dict[str, float]:@@ -48,15 +58,11 @@ def decide_promotion(*,now: datetime.datetime,min_days_between: int,- champion_aucs: Mapping[str, float] | None = None,- champion_eces: Mapping[str, float] | None = None,+ champion_grades: Mapping[str, HoldoutGrade] | None = None,+ min_holdout_positives: Mapping[str, int] | None = None,) -> PromotionDecision:candidate_aucs = _readable_aucs(candidate)- candidate_eces = {- head["head"]: float(head["holdout_expected_calibration_error"])- for head in candidate.get("heads", [])- if head.get("holdout_expected_calibration_error") is not None- }+ candidate_heads = {head["head"]: head for head in candidate.get("heads", [])}if not candidate_aucs:return PromotionDecision(promote=False, reason="candidate has no readable head")if champion is None:@@ -76,20 +82,43 @@ def decide_promotion(return PromotionDecision(promote=False, reason=f"champion {champion['model_version']} promoted less than {min_days_between}d ago")+ skipped: list[str] = []for head, stored_auc in _readable_aucs(champion).items():- champion_auc = champion_aucs.get(head, stored_auc) if champion_aucs else stored_auc- candidate_auc = candidate_aucs.get(head)- if candidate_auc is None:- return PromotionDecision(promote=False, reason=f"{head} readable on champion but not on candidate")+ grade = (champion_grades or {}).get(head)+ if grade is None:+ # No shared holdout: readability was read on two different holdouts, so compare it as stored.+ candidate_auc = candidate_aucs.get(head)+ if candidate_auc is None:+ return PromotionDecision(promote=False, reason=f"{head} readable on champion but not on candidate")+ champion_auc = stored_auc+ else:+ if head not in candidate_heads:+ return PromotionDecision(promote=False, reason=f"{head} not trained on candidate")+ if grade.positives < (min_holdout_positives or {}).get(head, 0):+ skipped.append(head)+ continue+ # The candidate is graded whether or not it cleared its null margin: a weak head fails on its numbers.+ raw_auc = candidate_heads[head].get("holdout_auc")+ if raw_auc is None:+ return PromotionDecision(promote=False, reason=f"{head} has no holdout AUC on candidate")+ candidate_auc = float(raw_auc)+ champion_auc = grade.auc if grade.auc is not None else stored_aucif candidate_auc < champion_auc - AUC_TOLERANCE:return PromotionDecision(promote=False, reason=f"{head} regressed: {candidate_auc:.3f} vs champion {champion_auc:.3f}")- champion_ece = (champion_eces or {}).get(head)- candidate_ece = candidate_eces.get(head)+ champion_ece = grade.expected_calibration_error if grade is not None else None+ raw_ece = candidate_heads.get(head, {}).get("holdout_expected_calibration_error")+ candidate_ece = float(raw_ece) if raw_ece is not None else Noneif champion_ece is not None and candidate_ece is not None and candidate_ece > champion_ece + ECE_TOLERANCE:return PromotionDecision(promote=False,reason=f"{head} calibration regressed: ECE {candidate_ece:.3f} vs champion {champion_ece:.3f}",)+ if skipped:+ return PromotionDecision(+ promote=True,+ reason=f"candidate at or above champion on every comparable head (skipped: {', '.join(skipped)})",+ skipped_heads=tuple(skipped),+ )return PromotionDecision(promote=True, reason="candidate at or above champion on every readable head")diff --git a/products/signals/dags/inbox_ranking/training/telemetry.py b/products/signals/dags/inbox_ranking/training/telemetry.pyindex 2001b828ca19..2dae1cb5197f 100644--- a/products/signals/dags/inbox_ranking/training/telemetry.py+++ b/products/signals/dags/inbox_ranking/training/telemetry.py@@ -168,6 +168,7 @@ def promotion_event("would_promote": decision.promote,"promoted": promoted,"reason": decision.reason,+ "skipped_heads": list(decision.skipped_heads),"champion_version": champion_version,"incumbent_champion_version": incumbent_champion_version,**{f"champion_{head}_auc_on_this_holdout": auc for head, auc in champion_aucs.items()},diff --git a/products/signals/dags/inbox_ranking/training/train.py b/products/signals/dags/inbox_ranking/training/train.pyindex cfc042d16526..90173945c697 100644--- a/products/signals/dags/inbox_ranking/training/train.py+++ b/products/signals/dags/inbox_ranking/training/train.py@@ -225,6 +225,7 @@ def holdout_calibration_rows(trained: Sequence[TrainedHead]) -> list[dict[str, oclass HoldoutGrade:auc: float | Noneexpected_calibration_error: float | None+ positives: intdef booster_holdout_grade(@@ -252,4 +253,5 @@ def booster_holdout_grade(return HoldoutGrade(auc=_auc(y, scores),expected_calibration_error=expected_calibration_error(calibration_buckets(y.astype(bool), scores)),+ positives=int(y.sum()),)