: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
chore(tasks): remove the posthog-code-mobile-push flag check (#119259)
posthog[bot]e50508bde5fa
diff --git a/products/tasks/backend/push_dispatcher.py b/products/tasks/backend/push_dispatcher.pyindex 963319441e19..cc71476135ca 100644--- a/products/tasks/backend/push_dispatcher.py+++ b/products/tasks/backend/push_dispatcher.py@@ -4,14 +4,11 @@ Schedules the underlying Expo HTTP call as a Celery task via``transaction.on_commit`` so nothing here can block a request/response cycleor a Temporal activity's event loop.-Three guards before we enqueue:+Two guards before we enqueue:-1. **Feature flag.** ``posthog-code-mobile-push`` must be enabled for the- user. Off by default — flip on once the mobile build is ready and- tokens start arriving.-2. **Cooldown.** A per-source Redis lock collapses duplicate triggers in a+1. **Cooldown.** A per-source Redis lock collapses duplicate triggers in ashort window.-3. **Access.** Recipients must still be able to view the task.+2. **Access.** Recipients must still be able to view the task."""from __future__ import annotations@@ -25,7 +22,6 @@ from django.db.models import Exists, OuterReffrom django.utils import timezoneimport structlog-import posthoganalyticsfrom posthog.models.user import Userfrom posthog.models.user_push_token import UserPushToken@@ -44,7 +40,6 @@ if TYPE_CHECKING:logger = structlog.get_logger(__name__)PUSH_TITLE = "posthog"-FEATURE_FLAG_KEY = "posthog-code-mobile-push"# Cooldown windows per push kind. Terminal pushes get a longer window because# they should only fire once per run lifetime — anything more is a retry.@@ -178,7 +173,7 @@ def _project_awaiting_input_activity(task_run: TaskRun) -> None:"""Surface the wait in the in-app Activity feed.Runs ahead of, and independently of, the push guards above: the feed should update even- for users without the mobile push flag, and it has no cooldown to observe. Best-effort+ for users with no push device, and it has no cooldown to observe. Best-effortfor the same reason ``_enqueue`` is — this sits on the agent's turn-end path and mustnever fail it."""@@ -212,7 +207,7 @@ def _enqueue(task_run: TaskRun, *, kind: PushKind, body: str) -> None:"""Best-effort: this function MUST NOT raise.Wrap the whole body in a bare ``except Exception`` so a DB outage,- Redis hiccup, flag-service failure, or any other surprise can't bubble+ Redis hiccup, or any other surprise can't bubbleout of ``mark_completed`` / ``mark_failed`` / the API cancel handlerand fail the surrounding task-lifecycle activity."""@@ -273,22 +268,6 @@ def _enqueue_user() -> None:if task.is_scout_experiment:return- distinct_id = user.distinct_id or f"user_{user.id}"- try:- flag_enabled = posthoganalytics.feature_enabled(- FEATURE_FLAG_KEY,- distinct_id,- send_feature_flag_events=False,- )- except Exception:- # Failing closed on flag-evaluation errors keeps an outage from- # silently flipping pushes on for the whole user base.- logger.warning("push_dispatcher.flag_check_failed", user_id=user.id, exc_info=True)- PUSH_DISPATCHER_OUTCOMES_TOTAL.labels(kind=kind, outcome="flag_check_failed").inc()- return- if not flag_enabled:- PUSH_DISPATCHER_OUTCOMES_TOTAL.labels(kind=kind, outcome="flag_disabled").inc()- returncooldown_key = f"push_notification:{cooldown_subject}:{kind}"if not get_tasks_cache().add(cooldown_key, True, timeout=_COOLDOWN_SECONDS[kind]):diff --git a/products/tasks/backend/tests/test_channels_api.py b/products/tasks/backend/tests/test_channels_api.pyindex 64d252317dec..136af39356c2 100644--- a/products/tasks/backend/tests/test_channels_api.py+++ b/products/tasks/backend/tests/test_channels_api.py@@ -1090,9 +1090,8 @@ class TaskMentionsAPITestCase(ChannelTaskAPITestCase):# The author wasn't mentioned, so their own feed stays empty.self.assertEqual(self.author_client.get(self._mentions_url()).json(), [])- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_thread_message_notifies_creator_and_mentions_only(self, mock_delay, _flag):+ def test_thread_message_notifies_creator_and_mentions_only(self, mock_delay):mentioned = User.objects.create_user(email="[email protected]", first_name="Mina", password="password")unmentioned = User.objects.create_user(email="[email protected]", first_name="Other", password="password")self.organization.members.add(mentioned, unmentioned)@@ -1117,9 +1116,8 @@ class TaskMentionsAPITestCase(ChannelTaskAPITestCase):self.assertEqual(mock_enqueue.call_count, 2)@patch("products.tasks.backend.facade.api.TaskActivity.record", side_effect=RuntimeError("db is down"))- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_mention_activity_failure_does_not_discard_push_recipients(self, mock_delay, _flag, _record):+ def test_mention_activity_failure_does_not_discard_push_recipients(self, mock_delay, _record):mentioned = User.objects.create_user(email="[email protected]", first_name="Mina", password="password")self.organization.members.add(mentioned)@@ -1161,9 +1159,8 @@ class TaskMentionsAPITestCase(ChannelTaskAPITestCase):self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)@parameterized.expand([("private",), ("scout_trial",)])- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_mention_on_invisible_task_is_hidden(self, kind, mock_delay, _flag):+ def test_mention_on_invisible_task_is_hidden(self, kind, mock_delay):private_task = Task.objects.create(team=self.team,created_by=self.author,diff --git a/products/tasks/backend/tests/test_presence.py b/products/tasks/backend/tests/test_presence.pyindex 0ee35948ca34..9bac8ab3d23b 100644--- a/products/tasks/backend/tests/test_presence.py+++ b/products/tasks/backend/tests/test_presence.py@@ -220,9 +220,8 @@ class PresenceFanoutSuppressionTestCase(TestCase):("presence_on_other_task_suppresses_none", "other_task_only", "none"),])- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_fanout_suppression_matrix(self, _name, scenario, expected, mock_delay, _flag) -> None:+ def test_fanout_suppression_matrix(self, _name, scenario, expected, mock_delay) -> None:if scenario == "one_active":self._present(self.device_a, expires_in=timedelta(seconds=30))elif scenario == "both_active":diff --git a/products/tasks/backend/tests/test_push_dispatcher.py b/products/tasks/backend/tests/test_push_dispatcher.pyindex 252bce740d6d..d33a73299c1b 100644--- a/products/tasks/backend/tests/test_push_dispatcher.py+++ b/products/tasks/backend/tests/test_push_dispatcher.py@@ -54,9 +54,8 @@ class TestPushDispatcher(TestCase):("turn_completed", notify_task_run_turn_completed, "finished"),])- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_notify_enqueues_push(self, _name, notify_fn, expected_body_fragment, mock_delay, _flag):+ def test_notify_enqueues_push(self, _name, notify_fn, expected_body_fragment, mock_delay):with self.captureOnCommitCallbacks(execute=True):notify_fn(self.task_run)mock_delay.assert_called_once()@@ -70,20 +69,8 @@ class TestPushDispatcher(TestCase):# No presence rows in this test's setUp, so nothing to suppress.self.assertEqual(suppressed, [])- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=False)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_feature_flag_off_skips_dispatch(self, mock_delay, _flag):- labels = {"kind": "completed", "outcome": "flag_disabled"}- before = REGISTRY.get_sample_value("posthog_tasks_push_dispatcher_outcomes_total", labels) or 0.0- with self.captureOnCommitCallbacks(execute=True):- notify_task_run_completed(self.task_run)- mock_delay.assert_not_called()- after = REGISTRY.get_sample_value("posthog_tasks_push_dispatcher_outcomes_total", labels) or 0.0- self.assertEqual(after, before + 1)-- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)- @patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_trial_completion_does_not_notify_the_operator(self, mock_delay, mock_flag) -> None:+ def test_trial_completion_does_not_notify_the_operator(self, mock_delay) -> None:self.task.origin_product = Task.OriginProduct.SIGNALS_SCOUTself.task.origin_key = f"scout-trial:{uuid4()}"self.task.save(update_fields=["origin_product", "origin_key"])@@ -92,21 +79,9 @@ class TestPushDispatcher(TestCase):notify_task_run_completed(self.task_run)mock_delay.assert_not_called()- mock_flag.assert_not_called()-- @patch(- "products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled",- side_effect=RuntimeError("flag service down"),- )- @patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_flag_error_fails_closed(self, mock_delay, _flag):- with self.captureOnCommitCallbacks(execute=True):- notify_task_run_completed(self.task_run)- mock_delay.assert_not_called()- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_cooldown_collapses_duplicates(self, mock_delay, _flag):+ def test_cooldown_collapses_duplicates(self, mock_delay):labels = {"kind": "completed", "outcome": "cooldown_deduped"}before = REGISTRY.get_sample_value("posthog_tasks_push_dispatcher_outcomes_total", labels) or 0.0with self.captureOnCommitCallbacks(execute=True):@@ -117,9 +92,8 @@ class TestPushDispatcher(TestCase):after = REGISTRY.get_sample_value("posthog_tasks_push_dispatcher_outcomes_total", labels) or 0.0self.assertEqual(after, before + 2)- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_cooldown_is_per_kind(self, mock_delay, _flag):+ def test_cooldown_is_per_kind(self, mock_delay):# Different push kinds on the same run shouldn't share a cooldown key.with self.captureOnCommitCallbacks(execute=True):notify_task_run_completed(self.task_run)@@ -127,9 +101,8 @@ class TestPushDispatcher(TestCase):notify_task_run_turn_completed(self.task_run)self.assertEqual(mock_delay.call_count, 3)- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_handoff_cooldown_distinguishes_announcements(self, mock_delay, _flag):+ def test_handoff_cooldown_distinguishes_announcements(self, mock_delay):announcement_id = uuid4()with self.captureOnCommitCallbacks(execute=True):notify_task_handoff(self.task, recipient=self.user, actor=self.user, message_id=announcement_id)@@ -137,9 +110,8 @@ class TestPushDispatcher(TestCase):notify_task_handoff(self.task, recipient=self.user, actor=self.user, message_id=uuid4())self.assertEqual(mock_delay.call_count, 2)- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_recipient_without_team_access_is_skipped(self, mock_delay, _flag):+ def test_recipient_without_team_access_is_skipped(self, mock_delay):"""A user who has been removed from the task's organization must not receivepushes carrying that task's title — losing access should mean losing notifications."""outsider = User.objects.create_user(email="[email protected]", first_name="Out", password="x")@@ -156,9 +128,8 @@ class TestPushDispatcher(TestCase):notify_task_run_completed(outsider_run)mock_delay.assert_not_called()- @patch("products.tasks.backend.push_dispatcher.posthoganalytics.feature_enabled", return_value=True)@patch("products.tasks.backend.push_dispatcher.send_user_push.delay")- def test_anonymous_task_is_noop(self, mock_delay, _flag):+ def test_anonymous_task_is_noop(self, mock_delay):anonymous_task = Task.objects.create(team=self.team,title="Anon",@@ -173,7 +144,7 @@ class TestPushDispatcher(TestCase):@patch("products.tasks.backend.push_dispatcher._enqueue_inner", side_effect=RuntimeError("redis is down"))def test_enqueue_swallows_unexpected_errors(self, _mock_inner):- """The dispatcher MUST NOT raise. Any DB / Redis / flag-service hiccup+ """The dispatcher MUST NOT raise. Any DB / Redis hiccupmust be swallowed so it can't fail the task lifecycle activity thattriggered the push."""# The bare except in _enqueue should catch the RuntimeError. If it