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): resolve the shadow eval app host from the region (#103648)

posthog[bot]b9c73bb6c917
diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.md
index b62ab8853132..e31de12909db 100644
--- a/products/signals/dags/inbox_ranking/README.md
+++ b/products/signals/dags/inbox_ranking/README.md
@@ -184,7 +184,7 @@ s3://<bucket>/<prefix>/
Every other read of this model is offline. The holdout grades the recipe, the unseen read grades the model on reports it never saw, and neither compares the model against the list people actually get. That list is sorted without a model: the inbox asks for `priority,status,-updated_at` by default, a person can change the field and the direction, and the flat view re-sorts the merged per-state responses on the client with the same keys. (`-is_suggested_reviewer,status,-updated_at` in `products/signals/backend/views.py` is only the fallback for a caller that sends no ordering. The inbox always sends one, and reviewer scope is deliberately not a tiebreak there.) Nothing serves a model rank, so the model cannot be measured by what people clicked on it. What can be measured is the counterfactual, from data already flowing.
-- **Only this region's lists are read.** The dogfood project collects the inbox telemetry of every region, but the scoring pool reads report state from this region's Postgres, so a report another region served can never hold a score. The impression query is bounded to `properties.$host` = this deployment's app host (`urlparse(settings.SITE_URL).netloc`), which is the only thing on the event that says which app rendered the list. An impression with no host is dropped rather than assumed local. The outcome query is deliberately not scoped: about one engagement in ten carries no host, and attribution already requires the same person and report as a list that was kept.
+- **Only this region's lists are read.** The dogfood project collects the inbox telemetry of every region, but the scoring pool reads report state from this region's Postgres, so a report another region served can never hold a score. The impression query is bounded to `properties.$host` = this deployment's app host, which is the only thing on the event that says which app rendered the list. The host comes from `settings.CLOUD_DEPLOYMENT` (`us.posthog.com` for US, `eu.posthog.com` for EU), and falls back to `urlparse(settings.SITE_URL).netloc` off cloud, because a Dagster deployment sets the region and leaves `SITE_URL` at its localhost default. An impression with no host is dropped rather than assumed local. The outcome query is deliberately not scoped: about one engagement in ten carries no host, and attribution already requires the same person and report as a list that was kept.
- **Grade only complete reconstructed render windows.** An `Inbox reports impressed` event holds only newly shown rows. Union events by absolute rank for the same `distinct_id`, `$session_id`, `scope`, normalized `tab` and five-second UTC bucket, keeping the maximum `list_size`. State-section tabs normalize to `reports`, because the merged Reports view emits a different tab per section. Grade only windows with every rank from 1 through `list_size` and one distinct report per rank. Exclude missing sessions and conflicting assignments. Pagination inside a bucket extends the earlier list; an incomplete page in a later bucket is excluded. Exact repeats collapse only inside the bucket, so later visits remain separate. Without a render ID this is an approximation: a boundary can split one render, and nearby visits can combine. It does not recover every served list.
- **A report is relevant to a list when the same person opened it or acted on it within 30 minutes of seeing it there.** `open` and `action` name the heads whose scores order them, so a head is graded against the outcome it was fit toward. The relevance is a list-scoped proxy for that head's label, not the label itself: the `open` head predicts that anyone opens the report within three days, and `action` the same over seven, both counted per report rather than per viewer. A shadow NDCG and an unseen AUC of the same name therefore answer different questions. A window of hours would credit a list for a report the person came back to from a link. One engagement counts for one list, the last one the person saw the report in before it: changing a filter or a sort re-impresses the same rows at new ranks, so one person can hold several live lists holding the same report, and only one of them can have caused the open.
- **A list uses only scores available when each row was impressed.** Availability comes from S3 `LastModified` on the same GET response as the score data, not the training schedule. Delayed writes and backfills cannot backdate scores; a rewrite conservatively loses coverage before its new write time. Unscored reports keep their outcomes and rank last in the model order, tied on served rank. `score_coverage` is the scored share for each family, role and head; `positive_coverage` is the scored share of its engaged rows, and `full_list_coverage` is the share of served lists with every row scored. A group with no available scores is not graded.
diff --git a/products/signals/dags/inbox_ranking/dataset/queries.py b/products/signals/dags/inbox_ranking/dataset/queries.py
index 204f1afb7b0d..5763c3671db7 100644
--- a/products/signals/dags/inbox_ranking/dataset/queries.py
+++ b/products/signals/dags/inbox_ranking/dataset/queries.py
@@ -43,6 +43,9 @@ def labels_team() -> Team:
)
+REGION_APP_HOSTS = {"US": "us.posthog.com", "EU": "eu.posthog.com"}
+
+
def region_app_host() -> str:
"""The app host this deployment serves the inbox on.
@@ -51,8 +54,13 @@ def region_app_host() -> str:
the scoring pool (`training/unseen.py`) builds it from this region's Postgres, so a report
another region served can never hold a score. `$host` is the only property on those events
that says which app rendered the page.
+
+ The region is the source, not `SITE_URL`: a Dagster deployment sets `CLOUD_DEPLOYMENT` and
+ leaves `SITE_URL` at its localhost default, which no impression event carries. Off cloud
+ there is no region, so `SITE_URL` is the host, for local and self-hosted runs.
"""
- return urlparse(settings.SITE_URL).netloc
+ region = (settings.CLOUD_DEPLOYMENT or "").upper()
+ return REGION_APP_HOSTS.get(region) or urlparse(settings.SITE_URL).netloc
def etl_workload() -> Workload:
diff --git a/products/signals/dags/inbox_ranking/tests/test_dataset.py b/products/signals/dags/inbox_ranking/tests/test_dataset.py
index c5a564c130a8..85149f99de56 100644
--- a/products/signals/dags/inbox_ranking/tests/test_dataset.py
+++ b/products/signals/dags/inbox_ranking/tests/test_dataset.py
@@ -12,7 +12,7 @@ from products.event_definitions.backend.models.property_definition import Proper
from products.signals.backend.models import SignalReport
from products.signals.backend.report_embeddings import EMBEDDING_RENDERING_TITLE, EMBEDDING_RENDERING_TITLE_SUMMARY
from products.signals.dags.inbox_ranking import common
-from products.signals.dags.inbox_ranking.dataset import dag
+from products.signals.dags.inbox_ranking.dataset import dag, queries
from products.signals.dags.inbox_ranking.dataset.dag import (
EMBEDDINGS_SCHEMA,
LABELS_SCHEMA,
@@ -31,6 +31,7 @@ from products.signals.dags.inbox_ranking.dataset.queries import (
STATUS_SQL,
hogql_rows,
merge_label_streams,
+ region_app_host,
utc_bound,
valid_report_uuids,
)
@@ -73,6 +74,22 @@ def test_cloud_requires_dedicated_bucket(monkeypatch, cloud_deployment, bucket,
assert common.dataset_unconfigured() is expected_unconfigured
+ "cloud_deployment,expected",
+ [
+ ("US", "us.posthog.com"),
+ ("eu", "eu.posthog.com"),
+ (None, "localhost:8010"),
+ ],
+)
+def test_region_app_host_comes_from_the_region_not_the_site_url(monkeypatch, cloud_deployment, expected):
+ # A Dagster deployment sets CLOUD_DEPLOYMENT and leaves SITE_URL at its default, so a host
+ # read from SITE_URL matches no impression event and the shadow read grades nothing.
+ monkeypatch.setattr(queries.settings, "CLOUD_DEPLOYMENT", cloud_deployment)
+ monkeypatch.setattr(queries.settings, "SITE_URL", "http://localhost:8010")
+ assert region_app_host() == expected
+
+
@pytest.mark.parametrize(
"existing,partition_key,expected",
[