Skip to content

: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.

fix(signals): run inbox ranking promotion gates before the wait (#113720)

posthog[bot]2adebf92e588
diff --git a/posthog/settings/object_storage.py b/posthog/settings/object_storage.py
index 643a03cb51cb..7300867ead0b 100644
--- a/posthog/settings/object_storage.py
+++ b/posthog/settings/object_storage.py
@@ -106,7 +106,7 @@ INBOX_RANKING_DATASET_S3_PREFIX = os.getenv("INBOX_RANKING_DATASET_S3_PREFIX", "
INBOX_RANKING_TRAINING_LOOKBACK_DAYS = get_from_env("INBOX_RANKING_TRAINING_LOOKBACK_DAYS", 60, type_cast=int)
INBOX_RANKING_TRAINING_HOLDOUT_DAYS = get_from_env("INBOX_RANKING_TRAINING_HOLDOUT_DAYS", 7, type_cast=int)
INBOX_RANKING_AUTO_PROMOTE = get_from_env("INBOX_RANKING_AUTO_PROMOTE", False, type_cast=str_to_bool)
-INBOX_RANKING_PROMOTION_MIN_DAYS = get_from_env("INBOX_RANKING_PROMOTION_MIN_DAYS", 3, type_cast=int)
+INBOX_RANKING_PROMOTION_MIN_DAYS = get_from_env("INBOX_RANKING_PROMOTION_MIN_DAYS", 0, type_cast=int)
# Labels refresh sensor (products/signals/dags/inbox_ranking/dataset): how many stale labels
# partitions one hourly tick rewrites after a FEATURE_SCHEMA_VERSION bump, newest first.
INBOX_RANKING_LABELS_REFRESH_MAX_RUNS = get_from_env("INBOX_RANKING_LABELS_REFRESH_MAX_RUNS", 6, type_cast=int)
diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.md
index 82ea1f0cc583..7f6fabcb4e8f 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. 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`.
+- **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 quality gates run before the wait: `gates_passed` on the decision event and the `<family>_gates_passed` asset metadata say whether the candidate passed them, also on a day the wait blocks it, and `would_promote` stays the final decision. 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:
@@ -292,7 +292,7 @@ Like the dataset job, this one reads the dogfood project's ClickHouse, so it can
| `INBOX_RANKING_TRAINING_LOOKBACK_DAYS` | `60` | How many daily snapshots back the training examples reach. |
| `INBOX_RANKING_TRAINING_HOLDOUT_DAYS` | `7` | Trailing days of reports that grade a candidate. |
| `INBOX_RANKING_AUTO_PROMOTE` | `false` | Whether a winning candidate rewrites `champion.json`; off, the decision is only logged. |
-| `INBOX_RANKING_PROMOTION_MIN_DAYS` | `3` | Minimum age of the champion before another promotion. |
+| `INBOX_RANKING_PROMOTION_MIN_DAYS` | `0` | Minimum age of the champion before another promotion. The scoring sweep stamps each score with its model key, so no wait is needed for a clean read. |
| `INBOX_RANKING_SERVED_FAMILY` | `report_embeddings` | Family whose champion the serving manifest serves. |
| `INBOX_RANKING_SERVING_MIRROR_BUCKET` | unset | A second deployment's object-storage bucket that receives a copy of every serving publish, through ambient AWS config. Unset means no mirror. |
| `INBOX_RANKING_SERVING_MIRROR_REGION` | unset | AWS region of the mirror bucket. |
diff --git a/products/signals/dags/inbox_ranking/tests/test_training.py b/products/signals/dags/inbox_ranking/tests/test_training.py
index 1478b9228243..f6b0913f79e1 100644
--- a/products/signals/dags/inbox_ranking/tests/test_training.py
+++ b/products/signals/dags/inbox_ranking/tests/test_training.py
@@ -1533,7 +1533,9 @@ def test_training_events_carry_the_dashboard_contract(monkeypatch):
partition_key="2026-08-25",
run_id="run-1",
model_name=STATE_MODEL_NAME,
- decision=PromotionDecision(promote=True, reason="no champion yet", skipped_heads=("discuss",)),
+ decision=PromotionDecision(
+ promote=True, reason="no champion yet", gates_passed=True, skipped_heads=("discuss",)
+ ),
outcome=PromotionOutcome(promote=True, override=None),
promoted=False,
champion_version="none",
@@ -1613,6 +1615,7 @@ def test_training_events_carry_the_dashboard_contract(monkeypatch):
promotion_props = by_event["inbox_ranking_promotion_decided"][0]["properties"]
assert {
"would_promote": True,
+ "gates_passed": True,
"promoted": False,
"incumbent_champion_version": "none",
"skipped_heads": ["discuss"],
@@ -1717,12 +1720,6 @@ def _metadata(version: str, **aucs: float | None) -> dict:
False,
"regressed",
),
- (
- _metadata("d2", open=0.70),
- {**_metadata("d1", open=0.65), "promoted_at": "2026-08-19T00:00:00+00:00"},
- False,
- "less than 3d ago",
- ),
(
_metadata("d2", open=0.70),
{**_metadata("d1", open=0.65, action=0.6), "promoted_at": "2026-08-10T00:00:00+00:00"},
@@ -1751,6 +1748,25 @@ def test_decide_promotion(candidate, champion, expected_promote, reason_fragment
assert reason_fragment in decision.reason
+ "candidate_auc,expected_gates_passed,reason_fragment",
+ [
+ (0.70, True, "candidate passed every gate but champion d1 promoted less than 3d ago"),
+ # The wait must not hide a regression: the reason names the failed gate.
+ (0.65 - AUC_TOLERANCE - 0.01, False, "open regressed"),
+ ],
+)
+def test_decide_promotion_runs_the_quality_gates_before_the_wait(candidate_auc, expected_gates_passed, reason_fragment):
+ candidate = _metadata("d2", open=candidate_auc)
+ champion = {**_metadata("d1", open=0.65), "promoted_at": "2026-08-19T00:00:00+00:00"}
+
+ decision = decide_promotion(candidate, champion, now=NOW, min_days_between=3)
+
+ assert not decision.promote
+ assert decision.gates_passed is expected_gates_passed
+ assert reason_fragment in decision.reason
+
+
def test_decide_promotion_grades_the_champion_on_the_candidate_holdout():
candidate = _metadata("d2", open=0.66)
champion = {**_metadata("d1", open=0.60), "promoted_at": "2026-08-10T00:00:00+00:00"}
@@ -1900,8 +1916,10 @@ def test_a_waived_holdout_floor_still_blocks_a_head_the_candidate_lost():
assert not decision.promote
-_REFUSED = PromotionDecision(promote=False, reason="open regressed: 0.600 vs champion 0.700")
-_PROMOTED = PromotionDecision(promote=True, reason="candidate at or above champion on every readable head")
+_REFUSED = PromotionDecision(promote=False, reason="open regressed: 0.600 vs champion 0.700", gates_passed=False)
+_PROMOTED = PromotionDecision(
+ promote=True, reason="candidate at or above champion on every readable head", gates_passed=True
+)
_OLDER_CHAMPION = {**_metadata("2026-08-10", open=0.70), "promoted_at": "2026-08-10T00:00:00+00:00"}
diff --git a/products/signals/dags/inbox_ranking/training/dag.py b/products/signals/dags/inbox_ranking/training/dag.py
index db795c10f5f8..a6d78a7a06a9 100644
--- a/products/signals/dags/inbox_ranking/training/dag.py
+++ b/products/signals/dags/inbox_ranking/training/dag.py
@@ -883,6 +883,7 @@ def _decide_champion(
)
return {
f"{family.name}_would_promote": dagster.MetadataValue.bool(decision.promote),
+ f"{family.name}_gates_passed": dagster.MetadataValue.bool(decision.gates_passed),
f"{family.name}_promoted": dagster.MetadataValue.bool(promoted),
f"{family.name}_reason": dagster.MetadataValue.text(decision.reason),
f"{family.name}_override": dagster.MetadataValue.text(outcome.override or "none"),
diff --git a/products/signals/dags/inbox_ranking/training/promotion.py b/products/signals/dags/inbox_ranking/training/promotion.py
index b7ff5a5c035d..0bb25720a1c7 100644
--- a/products/signals/dags/inbox_ranking/training/promotion.py
+++ b/products/signals/dags/inbox_ranking/training/promotion.py
@@ -1,9 +1,10 @@
"""Champion promotion rule.
A candidate replaces the champion when it is at least as good on every head the champion could
-read, 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.
+read, has at least one readable head itself, and enough days have passed since the last promotion.
+The quality gates run before the wait, so `gates_passed` says whether the candidate is good enough
+even on a day the wait blocks it. 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.
@@ -45,6 +46,8 @@ ECE_TOLERANCE = 0.02
class PromotionDecision:
promote: bool
reason: str
+ # True when the candidate passed every quality gate, whether or not the wait blocked it.
+ gates_passed: bool
# Champion-readable heads whose shared holdout had too few positives to compare.
skipped_heads: tuple[str, ...] = ()
@@ -77,12 +80,10 @@ def decide_promotion(
"""`skip_gates` waives `min_days` (the wait since the last promotion), `ece` (the calibration
check) and `min_holdout_positives` (a head whose candidate holdout has fewer positives than its
minimum is skipped rather than blocking)."""
- candidate_aucs = _readable_aucs(candidate)
- 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 not _readable_aucs(candidate):
+ return PromotionDecision(promote=False, reason="candidate has no readable head", gates_passed=False)
if champion is None:
- return PromotionDecision(promote=True, reason="no champion yet")
+ return PromotionDecision(promote=True, reason="no champion yet", gates_passed=True)
# A backfill replays old partitions, so reject any candidate not newer than the champion to keep
# the pointer from moving backwards to a stale model. model_version is the partition date, and
@@ -91,45 +92,72 @@ def decide_promotion(
return PromotionDecision(
promote=False,
reason=f"candidate {candidate['model_version']} is not newer than champion {champion['model_version']}",
+ gates_passed=False,
)
+ decision = _compare_to_champion(candidate, champion, champion_grades or {}, min_holdout_positives or {}, skip_gates)
promoted_at = datetime.datetime.fromisoformat(champion["promoted_at"])
- if "min_days" not in skip_gates and now - promoted_at < datetime.timedelta(days=min_days_between):
+ if (
+ decision.promote
+ and "min_days" not in skip_gates
+ and now - promoted_at < datetime.timedelta(days=min_days_between)
+ ):
return PromotionDecision(
- promote=False, reason=f"champion {champion['model_version']} promoted less than {min_days_between}d ago"
+ promote=False,
+ reason=f"candidate passed every gate but champion {champion['model_version']} promoted less than {min_days_between}d ago",
+ gates_passed=True,
+ skipped_heads=decision.skipped_heads,
)
+ return decision
+
+
+def _compare_to_champion(
+ candidate: Mapping[str, Any],
+ champion: Mapping[str, Any],
+ champion_grades: Mapping[str, HoldoutGrade],
+ min_holdout_positives: Mapping[str, int],
+ skip_gates: Collection[str],
+) -> PromotionDecision:
+ candidate_aucs = _readable_aucs(candidate)
+ candidate_heads = {head["head"]: head for head in candidate.get("heads", [])}
skipped: list[str] = []
for head, stored_auc in _readable_aucs(champion).items():
candidate_positives = candidate_heads.get(head, {}).get("holdout_positives")
if (
"min_holdout_positives" in skip_gates
and candidate_positives is not None
- and candidate_positives < (min_holdout_positives or {}).get(head, 0)
+ and candidate_positives < min_holdout_positives.get(head, 0)
):
skipped.append(head)
continue
- grade = (champion_grades or {}).get(head)
+ grade = champion_grades.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")
+ return PromotionDecision(
+ promote=False, reason=f"{head} readable on champion but not on candidate", gates_passed=False
+ )
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):
+ return PromotionDecision(promote=False, reason=f"{head} not trained on candidate", gates_passed=False)
+ if grade.positives < min_holdout_positives.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")
+ return PromotionDecision(
+ promote=False, reason=f"{head} has no holdout AUC on candidate", gates_passed=False
+ )
candidate_auc = float(raw_auc)
champion_auc = grade.auc if grade.auc is not None else stored_auc
if candidate_auc < champion_auc - AUC_TOLERANCE:
return PromotionDecision(
- promote=False, reason=f"{head} regressed: {candidate_auc:.3f} vs champion {champion_auc:.3f}"
+ promote=False,
+ reason=f"{head} regressed: {candidate_auc:.3f} vs champion {champion_auc:.3f}",
+ gates_passed=False,
)
champion_ece = grade.expected_calibration_error if grade is not None else None
raw_ece = candidate_heads.get(head, {}).get("holdout_expected_calibration_error")
@@ -143,14 +171,18 @@ def decide_promotion(
return PromotionDecision(
promote=False,
reason=f"{head} calibration regressed: ECE {candidate_ece:.3f} vs champion {champion_ece:.3f}",
+ gates_passed=False,
)
if skipped:
return PromotionDecision(
promote=True,
reason=f"candidate at or above champion on every comparable head (skipped: {', '.join(skipped)})",
+ gates_passed=True,
skipped_heads=tuple(skipped),
)
- return PromotionDecision(promote=True, reason="candidate at or above champion on every readable head")
+ return PromotionDecision(
+ promote=True, reason="candidate at or above champion on every readable head", gates_passed=True
+ )
def apply_promotion_override(
diff --git a/products/signals/dags/inbox_ranking/training/telemetry.py b/products/signals/dags/inbox_ranking/training/telemetry.py
index 7a1e105a2e18..60ee81c27aae 100644
--- a/products/signals/dags/inbox_ranking/training/telemetry.py
+++ b/products/signals/dags/inbox_ranking/training/telemetry.py
@@ -170,6 +170,7 @@ def promotion_event(
"model_version": partition_key,
"run_id": run_id,
"would_promote": decision.promote,
+ "gates_passed": decision.gates_passed,
"promoted": promoted,
"reason": decision.reason,
"override": outcome.override,