: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
feat(signals): add a fixed outcome head to inbox ranking (#110921)
posthog[bot]8de9556d9455
diff --git a/docs/internal/inbox-ranking-training.md b/docs/internal/inbox-ranking-training.mdindex 195f6bbac749..93a4a6cfda99 100644--- a/docs/internal/inbox-ranking-training.md+++ b/docs/internal/inbox-ranking-training.md@@ -36,6 +36,7 @@ Each head is graded only on its cohort.| `thumbs_up` | P(thumbs up) over every report | 7d || `pr_created` | P(PR created) over every report | 7d || `pr_merged` | P(PR merged) over every report | 14d |+| `fixed` | P(fixed) over every report | 21d || `refund` | P(refund) over every report | 14d |Each head in `metadata.json` records `cohort` (`everyone`) and `horizon_days`.diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.mdindex 93bcb2f614b3..c3c42c3406e5 100644--- a/products/signals/dags/inbox_ranking/README.md+++ b/products/signals/dags/inbox_ranking/README.md@@ -83,7 +83,7 @@ s3://<bucket>/<prefix>/- **A model is a `(model_name, model_version, model_role)`.** `model_name` is the family: which features and which learner, `tabular_xgb` for the per-head XGBoost trained here. `model_version` is the partition day it was fit on, and `model_role` is `candidate` or `champion`. Each family owns a prefix under the models path and its own `champion.json`, so two families trained on the same day cannot collide, and promotion stays inside a family. A richer family is a second candidate graded on the same unseen rows, not a competitor for the tabular family's pointer.- **A feature set is one feature universe.** `products/signals/backend/ranking/features.py` holds a `FeatureSet` per universe: its name, its schema version, its ordered feature names, the report-state columns it reads, `build_matrix`, and how many rows it wants per report and per head. `tabular`, `report_embeddings` and `title_embeddings` are the three today. A candidate records the set it was fit on in its `metadata.json`, so the grader checks a model against its own set rather than one global contract, the examples asset writes one Parquet per set, and the unseen scorer builds one matrix per set and shares it across the families that read it. Adding a set means an entry in `FEATURE_SETS`; a model naming a set this build cannot produce is logged and left unscored.-- **Examples are one row per report at its birth, by default.** For partition `dt=D` the examples asset reads the report-state and labels snapshots `dt=D-lookback..D` and emits one row per report, on the snapshot of the day it was created, labeled from the snapshot `horizon_days` later (3 for open, 7 for action / pr_created / discuss / thumbs_up, 14 for pr_merged / refund / reviewer_fix, 21 for dismiss_wrong). Features are built by the feature set from that snapshot's state columns plus `age_hours`, the report's age at the snapshot. Labels are aligned to the state spine, so a report with no label event is a negative (all-zero labels), not absent. Label-only rows (no Postgres state) are skipped, as are state rows read long after their snapshot day (backfills carry current Postgres state; see `features_observed_at`) and, for the heads that read the status stream (`dismiss_wrong` and `action`), rows whose status telemetry fails the dataset's `label_provenance_ok` check. Birth is the moment serving scores a report, and the label that comes out is a per-report probability, which is what the inbox ordering needs. A report born before the window, or one whose birth-day snapshot is missing from it, is no example; `reports_missing_birth_snapshot` on the asset counts the second case, which is a gap in the partitions.+- **Examples are one row per report at its birth, by default.** For partition `dt=D` the examples asset reads the report-state and labels snapshots `dt=D-lookback..D` and emits one row per report, on the snapshot of the day it was created, labeled from the snapshot `horizon_days` later (3 for open, 7 for action / pr_created / discuss / thumbs_up, 14 for pr_merged / refund / reviewer_fix, 21 for dismiss_wrong / fixed). Features are built by the feature set from that snapshot's state columns plus `age_hours`, the report's age at the snapshot. Labels are aligned to the state spine, so a report with no label event is a negative (all-zero labels), not absent. Label-only rows (no Postgres state) are skipped, as are state rows read long after their snapshot day (backfills carry current Postgres state; see `features_observed_at`) and, for the heads that read the status stream (`dismiss_wrong`, `action` and `fixed`), rows whose status telemetry fails the dataset's `label_provenance_ok` check. Birth is the moment serving scores a report, and the label that comes out is a per-report probability, which is what the inbox ordering needs. A report born before the window, or one whose birth-day snapshot is missing from it, is no example; `reports_missing_birth_snapshot` on the asset counts the second case, which is a gap in the partitions.- **An outcome already visible on the birth day is a future positive.** A report born on day D has no scoring moment before D, so an outcome visible at D belongs to the moment being built rather than to an earlier one; the labels of D therefore read as their defaults for a report born on D. Most outcomes land on the birth day, so this is where the positives are: censoring on them costs the `pr_created` head most of its training signal. `<set>_<head>_birth_day_positives` on the examples asset, and `birth_day_positives` on the `inbox_ranking_examples_built` event, say how many positives the rule keeps. These rows carry a hindsight the other rows do not: the state snapshot reads `signal_count`, `total_weight`, `run_count` and the text sizes live from Postgres a few hours after day D ends, so a birth-day outcome happened before its own feature read. Both the holdout AUC and the newborn unseen grade therefore read optimistically on these rows, until the scoring sweep's timestamped score log replaces the daily snapshot as this table's source.- **Every head asks whether the outcome happened within N days of the scoring moment.** `pr_merged` includes every report, so the label covers the whole report-to-merge path without requiring a PR at birth or at the horizon.- **A set may ask for another grain**, and cap the rows one head keeps (`max_examples_per_head`, whole report-creation days, newest first). The scoring-moment grain is one row per (report, snapshot) whose head label is still 0 on that snapshot: the serving situation replayed over history, but its label is a hazard conditional on the report still being live, and one long-lived report contributes dozens of near-duplicate rows. The report grain is the first snapshot of the window where the report is a usable moment, which is later than birth only when a side input landed late. Both stay selectable for re-scoring families; nothing ships on them today. The row budget shortens the history a head is fit on and keeps each kept day whole, so the scores stay calibrated to the population of that window. The lookback is the tabular set's whatever the grain, so positives accrue over the whole window until the budget binds.@@ -121,6 +121,7 @@ The reader is `score_reports` in `products/signals/backend/ranking/scorer.py`. I| `dismiss_wrong` | Every report | 21 || `pr_created` | Every report | 7 || `pr_merged` | Every report | 14 |+| `fixed` | Every report | 21 || `discuss` | Every report | 7 || `refund` | Every report | 14 || `thumbs_up` | Every report | 7 |diff --git a/products/signals/dags/inbox_ranking/common.py b/products/signals/dags/inbox_ranking/common.pyindex fa55b6a10227..ac16da86fed0 100644--- a/products/signals/dags/inbox_ranking/common.py+++ b/products/signals/dags/inbox_ranking/common.py@@ -38,6 +38,16 @@ LABELS_EPOCH = "2026-04-01T00:00:00+00:00"# head predicts). already_fixed and wontfix_irrelevant are deliberately not here. Shared by the# labels SQL (cumulative count) and the head definition.WRONG_DISMISSAL_REASONS = ("analysis_wrong", "report_unclear", "wontfix_intentional")+# The resolve button used as a dismissal: the report was resolved, but the problem was not fixed.+NOT_FIXED_RESOLUTION_REASONS = (+ "analysis_wrong",+ "wontfix_intentional",+ "wontfix_irrelevant",+ "report_unclear",+ "wrong_repo",+)+# A dismissal that says the problem was real and is fixed somewhere.+FIXED_DISMISSAL_REASONS = ("already_fixed", "fixed_outside_posthog", "pr_merged")# Artefact actors whose writes count as a person acting on a report. `agent` is an external MCP# client that authenticates as a real user, so a person drove it. `task` is a self-driving sandboxdiff --git a/products/signals/dags/inbox_ranking/dataset/dag.py b/products/signals/dags/inbox_ranking/dataset/dag.pyindex 1332dc6d5c75..1ceb111d031a 100644--- a/products/signals/dags/inbox_ranking/dataset/dag.py+++ b/products/signals/dags/inbox_ranking/dataset/dag.py@@ -116,7 +116,7 @@ from products.signals.dags.inbox_ranking.dataset.queries import (valid_report_uuids,)-FEATURE_SCHEMA_VERSION = 7+FEATURE_SCHEMA_VERSION = 8STATE_TABLE = "inbox_report_state"EMBEDDINGS_TABLE = "inbox_report_embeddings"@@ -246,6 +246,8 @@ LABEL_FIELDS: list[tuple[str, pa.DataType]] = [("first_dismissal_reason", pa.string()),("wrong_dismissal_count", pa.int32()),("first_wrong_dismissed_at", _TIMESTAMP),+ ("fixed_count", pa.int32()),+ ("first_fixed_at", _TIMESTAMP),("status_event_priority", pa.string()),("status_event_actionability", pa.string()),("status_event_team_id", pa.int64()),diff --git a/products/signals/dags/inbox_ranking/dataset/queries.py b/products/signals/dags/inbox_ranking/dataset/queries.pyindex d45087f0075c..387b696f1471 100644--- a/products/signals/dags/inbox_ranking/dataset/queries.py+++ b/products/signals/dags/inbox_ranking/dataset/queries.py@@ -23,7 +23,13 @@ from posthog.clickhouse.client.connection import Workloadfrom posthog.cloud_utils import is_cloudfrom posthog.models import Team-from products.signals.dags.inbox_ranking.common import LABELS_EPOCH, WRONG_DISMISSAL_REASONS, ensure_utc+from products.signals.dags.inbox_ranking.common import (+ FIXED_DISMISSAL_REASONS,+ LABELS_EPOCH,+ NOT_FIXED_RESOLUTION_REASONS,+ WRONG_DISMISSAL_REASONS,+ ensure_utc,+)# All regions' label telemetry lands in the US dogfood project (PostHog internal, team 2).LABELS_TEAM_ID = 2@@ -394,6 +400,17 @@ GROUP BY report_id"""_WRONG_DISMISSAL_REASONS_SQL = ", ".join(f"'{reason}'" for reason in WRONG_DISMISSAL_REASONS)+_NOT_FIXED_RESOLUTION_REASONS_SQL = ", ".join(f"'{reason}'" for reason in NOT_FIXED_RESOLUTION_REASONS)+_FIXED_DISMISSAL_REASONS_SQL = ", ".join(f"'{reason}'" for reason in FIXED_DISMISSAL_REASONS)+# A transition that says the problem was real and is fixed, by anyone: a resolve without a not-fixed+# reason (a reason-less resolve is the PR-merge webhook), or a dismissal with a fixed reason.+_FIXED_TRANSITION_SQL = (+ "(toString(properties.status) = 'resolved' AND coalesce(toString(properties.dismissal_reason), '') NOT IN ("+ + _NOT_FIXED_RESOLUTION_REASONS_SQL+ + ")) OR (toString(properties.status) = 'suppressed' AND toString(properties.dismissal_reason) IN ("+ + _FIXED_DISMISSAL_REASONS_SQL+ + "))"+)STATUS_COLUMNS = ("first_resolved_at",@@ -408,6 +425,8 @@ STATUS_COLUMNS = ("first_wrong_dismissed_at","reasoned_resolution_count","first_reasoned_resolved_at",+ "fixed_count",+ "first_fixed_at","status_event_priority","status_event_actionability","status_event_team_id",@@ -490,6 +509,10 @@ SELECTbucket_first_reasoned_at,outcome = 'resolved' AND event_team_id = latest_event_team_id) AS first_reasoned_resolved_at,+ -- Cumulative and tenant-scoped like wrong_dismissal_count, so a reopen or a later re-dismissal+ -- with another reason cannot take the label back. The fixed head reads this column.+ countIf(bucket_fixed = 1 AND event_team_id = latest_event_team_id) AS fixed_count,+ minIf(bucket_first_fixed_at, event_team_id = latest_event_team_id) AS first_fixed_at,-- These two must stay paired with latest_status_event, so coalesce/nullIf keeps argMax from-- skipping a null: a judgment artefact can be deleted, and then the latest transition-- genuinely carries none. Plain argMax would reach back to an older transition and present@@ -552,6 +575,12 @@ FROM (nullIf(minIf(events.timestamp, coalesce(toString(properties.dismissal_reason), '') != ''), fromUnixTimestamp(0)) AS bucket_first_reasoned_at,+ max("""+ + _FIXED_TRANSITION_SQL+ + """) AS bucket_fixed,+ nullIf(minIf(events.timestamp, """+ + _FIXED_TRANSITION_SQL+ + """), fromUnixTimestamp(0)) AS bucket_first_fixed_at,nullIf(argMax(toString(properties.priority), events.timestamp), '') AS event_priority,nullIf(argMax(toString(properties.actionability), events.timestamp), '') AS event_actionability,nullIf(toString(properties.team_id), '') AS event_team_id@@ -725,6 +754,8 @@ LABEL_DEFAULTS: dict[str, Any] = {"first_dismissal_reason": None,"wrong_dismissal_count": 0,"first_wrong_dismissed_at": None,+ "fixed_count": 0,+ "first_fixed_at": None,"status_event_priority": None,"status_event_actionability": None,"status_event_team_id": None,@@ -797,6 +828,7 @@ OUTCOME_FIRST_EVENT_COLUMNS: dict[str, str] = {"feedback_positive_count": "first_positive_feedback_at","feedback_negative_count": "first_negative_feedback_at","wrong_dismissal_count": "first_wrong_dismissed_at",+ "fixed_count": "first_fixed_at","pr_created_count": "first_pr_created_at","pr_merged_count": "first_pr_merged_at","pr_closed_count": "first_pr_closed_at",diff --git a/products/signals/dags/inbox_ranking/tests/test_dataset.py b/products/signals/dags/inbox_ranking/tests/test_dataset.pyindex ac65c0af1074..4ebcab03e4f0 100644--- a/products/signals/dags/inbox_ranking/tests/test_dataset.py+++ b/products/signals/dags/inbox_ranking/tests/test_dataset.py@@ -600,6 +600,31 @@ class TestStatusStream(ClickhouseTestMixin, BaseTest):assert row["first_dismissed_server_at"] == T1assert row["first_wrong_dismissed_at"] == T1 + 2 * gap+ @parameterized.expand(+ [+ ("reasonless_resolve", "ready", "resolved", None, 1),+ ("already_fixed_dismissal", "ready", "suppressed", "already_fixed", 1),+ ("analysis_wrong_resolve", "ready", "resolved", "analysis_wrong", 0),+ ("other_dismissal", "ready", "suppressed", "other", 0),+ ]+ )+ def test_fixed_count_reads_the_transition_and_its_reason(self, _name, previous, status, reason, expected):+ self._transition(T1, previous, status, reason)++ row = self._status_row()+ assert row["fixed_count"] == expected+ assert row["first_fixed_at"] == (T1 if expected else None)++ @parameterized.expand([(datetime.timedelta(hours=1),), (datetime.timedelta(minutes=1),)])+ def test_fixed_count_survives_a_reopen(self, gap):+ self._transition(T1, "ready", "resolved", None)+ self._transition(T1 + gap, "resolved", "ready")++ row = self._status_row()+ assert row["latest_status_event"] == "ready"+ assert row["fixed_count"] == 1+ assert row["first_fixed_at"] == T1+@parameterized.expand([("later_bucket", T2, "ready", "resolved", None),diff --git a/products/signals/dags/inbox_ranking/tests/test_training.py b/products/signals/dags/inbox_ranking/tests/test_training.pyindex d97afb905c0e..5487caa05924 100644--- a/products/signals/dags/inbox_ranking/tests/test_training.py+++ b/products/signals/dags/inbox_ranking/tests/test_training.py@@ -404,6 +404,13 @@ def test_dismissed_as_wrong_prefers_the_cumulative_count(frame, expected):[True, True, True, True],[True, True, True, False],),+ # fixed: cohort is everyone, label is a fix read from the status stream.+ (+ "fixed",+ pd.DataFrame({"fixed_count": [1, 0, 0], "pr_merged_count": [0, 1, 0]}),+ [True, True, True],+ [True, False, False],+ ),# discuss: cohort is everyone, so a never-impressed report counts; label is a discuss action.("discuss",@@ -468,6 +475,7 @@ class _ParquetS3:"head_name,positive_column",[("pr_merged", "pr_merged_count"),+ ("fixed", "fixed_count"),("refund", "refund_count"),("thumbs_up", "feedback_positive_count"),("reviewer_fix", "reviewer_add_count"),@@ -485,6 +493,7 @@ def test_new_head_label_columns_survive_the_load_snapshots_projection(head_name,column: [0]for column in ("pr_merged_count",+ "fixed_count","refund_count","feedback_positive_count","reviewer_add_count",diff --git a/products/signals/dags/inbox_ranking/training/dag.py b/products/signals/dags/inbox_ranking/training/dag.pyindex bb77a3d3e93c..621f52795089 100644--- a/products/signals/dags/inbox_ranking/training/dag.py+++ b/products/signals/dags/inbox_ranking/training/dag.py@@ -186,6 +186,7 @@ _LABEL_COLUMNS = ("open_count","dismissal_reason","wrong_dismissal_count",+ "fixed_count","pr_created_count","pr_merged_count","refund_count",diff --git a/products/signals/dags/inbox_ranking/training/heads.py b/products/signals/dags/inbox_ranking/training/heads.pyindex b470f53c27a1..d8011e333a13 100644--- a/products/signals/dags/inbox_ranking/training/heads.py+++ b/products/signals/dags/inbox_ranking/training/heads.py@@ -17,7 +17,7 @@ The dataset keeps them for position bias and the shadow grades.Slack and the desktop app. Self-driving's own `task` and `system` writes are excluded, becausethey are internal operational work and not a person acting on the report.-Mirrors the workspace `heads.py` (random-dev-internal, `inbox-ranking/`). Seven heads are dense+Mirrors the workspace `heads.py` (random-dev-internal, `inbox-ranking/`). Eight heads are denseenough to read on the holdout. `thumbs_up` and `reviewer_fix` are the explicit human-feedback pair:they are rare, so they are carried for the pooled newborn grade and as scorer inputs rather thanfor a holdout AUC. The rest stay workspace-only.@@ -85,6 +85,10 @@ def dismissed_as_wrong(frame: pd.DataFrame) -> pd.Series:return frame["dismissal_reason"].isin(WRONG_DISMISSAL_REASONS)+def fixed(frame: pd.DataFrame) -> pd.Series:+ return _count(frame, "fixed_count") > 0++def pr_created(frame: pd.DataFrame) -> pd.Series:return _count(frame, "pr_created_count") > 0@@ -166,6 +170,18 @@ HEADS: tuple[Head, ...] = (min_holdout_positives=30,label_columns=("pr_merged_count",),),+ # Which reports flagged a real problem that then got fixed, by anyone and on any surface? Reads+ # only the status stream: a tracked PR merge, a hand-marked fix, or a dismissal as already+ # fixed all count. 21 days because fixes marked by hand arrive about two weeks after birth.+ Head(+ name="fixed",+ cohort=everyone,+ label=fixed,+ horizon_days=21,+ min_holdout_positives=30,+ label_columns=("fixed_count",),+ status_labels=True,+ ),# Which reports drew a discuss? Cohort is every report: a discuss from Slack, the desktop app or# MCP often has no list impression. A subset of the action head, which is fine - each head trains# independently.