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(workflows): say why a push registration was not stored (#101267)

Daniel Marchuk9c87bc86b0f1
diff --git a/docs/internal/push-subscription-registration.md b/docs/internal/push-subscription-registration.md
index 149df8bf60eb..7d1ca584b4ce 100644
--- a/docs/internal/push-subscription-registration.md
+++ b/docs/internal/push-subscription-registration.md
@@ -27,6 +27,12 @@ The 200 is deliberate. A 4xx makes this the error path for the majority of the r
receives, which is both wrong (nothing about the request was invalid) and expensive to everything
that watches non-2xx rates.
+The body carries `reason` and `detail` as well, naming the `app_id` that matched no channel. The
+status code cannot say this, and without it a developer whose token goes nowhere sees a success
+indistinguishable from a working registration. This has cost real setup time: a project sending to
+the wrong project token gets the same 200, and the failure only surfaces later as
+`No active FCM device token found` in a workflow run.
+
## The `push.appIds` remote config key
Remote config carries the list of `app_id`s a team can accept registrations for:
diff --git a/products/messaging/backend/api/push_subscriptions.py b/products/messaging/backend/api/push_subscriptions.py
index 13bedfd79b56..a6b911c041fc 100644
--- a/products/messaging/backend/api/push_subscriptions.py
+++ b/products/messaging/backend/api/push_subscriptions.py
@@ -404,6 +404,15 @@ def push_subscriptions(request: Request):
"distinct_id": distinct_id,
"stored": False,
"push_enabled": False,
+ # The status code cannot say this: a 4xx would make every SDK retry on every app
+ # open. Without a reason in the body, a developer whose token goes nowhere sees a
+ # success and has no way to tell the difference from a working registration.
+ "reason": "no_push_channel_for_app_id",
+ "detail": (
+ f"This project has no push channel for app_id '{app_id}'. The device token was "
+ "not stored. Add a push channel whose Firebase project id or APNs bundle id "
+ "matches this app_id, and check the project the SDK is sending to."
+ ),
},
status=status.HTTP_200_OK,
),
diff --git a/products/messaging/backend/api/test/test_push_subscriptions.py b/products/messaging/backend/api/test/test_push_subscriptions.py
index 382e1bdbeaa2..3f36589602d2 100644
--- a/products/messaging/backend/api/test/test_push_subscriptions.py
+++ b/products/messaging/backend/api/test/test_push_subscriptions.py
@@ -348,6 +348,10 @@ class TestPushSubscriptionsAPI(BaseTest):
data = response.json()
assert data["stored"] is False
assert data["push_enabled"] is False
+ # The 200 is what stops SDKs retrying on every app open, so the body has to carry the reason:
+ # it is the only thing that tells a developer their token went nowhere.
+ assert data["reason"] == "no_push_channel_for_app_id"
+ assert "nonexistent-project" in data["detail"]
mock_capture.assert_not_called()
assert counter._value.get() == before + 1