: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
fix(tasks): keep 👀 reaction while PostHog Code agent is working (#62298)
Joshua Snyderbe1e0a54dc63
diff --git a/posthog/temporal/ai/posthog_code_slack_mention.py b/posthog/temporal/ai/posthog_code_slack_mention.pyindex eaa44acc7635..6fafe98549d0 100644--- a/posthog/temporal/ai/posthog_code_slack_mention.py+++ b/posthog/temporal/ai/posthog_code_slack_mention.py@@ -941,7 +941,7 @@ def create_posthog_code_task_for_repo_activity()slack = SlackIntegration(integration)- # Refuse before the :seedling: reaction or the permalink fetch: a denied+ # Refuse before the :eyes: reaction or the permalink fetch: a denied# mention should not first ack-react and then refuse a second later.if _block_if_team_over_quota(integration=integration,@@ -955,7 +955,7 @@ def create_posthog_code_task_for_repo_activity(user_message_ts = event.get("ts")if user_message_ts:- _safe_react(slack.client, channel, user_message_ts, "seedling")+ _safe_react(slack.client, channel, user_message_ts, "eyes")user_text = re.sub(r"<@[A-Z0-9]+>", "", event.get("text", "")).strip()title = user_text[:255] if user_text else "Task from Slack"@@ -1254,9 +1254,9 @@ def forward_posthog_code_followup_activity(status_code=result.status_code,)if result.retryable and result.status_code == 504:- # Agent is still processing. relayAgentResponse fires when it- # finishes, delivering the correct response to Slack.- _set_followup_done_reaction(slack, channel, user_message_ts, "hedgehog")+ # Agent is still processing — leave the :eyes: reaction up so the thread+ # reads as in-progress. relayAgentResponse fires when it finishes,+ # delivering the correct response to Slack._delete_followup_progress(integration_id=inputs.integration_id,channel=channel,@@ -1274,8 +1274,8 @@ def forward_posthog_code_followup_activity()return True- _set_followup_done_reaction(slack, channel, user_message_ts, "hedgehog")-+ # Message delivered; the agent is now working on it, so leave the :eyes: reaction+ # up. relayAgentResponse posts the agent's response once it finishes._delete_followup_progress(integration_id=inputs.integration_id,channel=channel,@@ -1450,11 +1450,10 @@ def _set_followup_done_reaction(slack: Any, channel: str, user_message_ts: str |if not user_message_ts:return- for stale_emoji in ("eyes", "seedling"):- try:- slack.client.reactions_remove(channel=channel, timestamp=user_message_ts, name=stale_emoji)- except Exception:- pass+ try:+ slack.client.reactions_remove(channel=channel, timestamp=user_message_ts, name="eyes")+ except Exception:+ pass_safe_react(slack.client, channel, user_message_ts, done_emoji)diff --git a/products/slack_app/backend/slack_thread.py b/products/slack_app/backend/slack_thread.pyindex 4699420dd519..1a5b28c61ea3 100644--- a/products/slack_app/backend/slack_thread.py+++ b/products/slack_app/backend/slack_thread.py@@ -117,11 +117,10 @@ class SlackThreadHandler:target_ts = self.context.user_message_ts or self.context.thread_tstry:client = self._get_client()- for stale in ("seedling", "eyes"):- try:- client.reactions_remove(channel=self.context.channel, timestamp=target_ts, name=stale)- except Exception:- pass+ try:+ client.reactions_remove(channel=self.context.channel, timestamp=target_ts, name="eyes")+ except Exception:+ passclient.reactions_add(channel=self.context.channel,timestamp=target_ts,diff --git a/products/slack_app/backend/tests/test_followup_forwarding.py b/products/slack_app/backend/tests/test_followup_forwarding.pyindex c8ef998a1624..9b8df1da37ea 100644--- a/products/slack_app/backend/tests/test_followup_forwarding.py+++ b/products/slack_app/backend/tests/test_followup_forwarding.py@@ -890,11 +890,12 @@ class TestForwardPostHogCodeFollowupActivity(TestCase):assert result is Truemock_token.assert_called_once()mock_send.assert_called_once_with(self.task_run, "do something", auth_token="jwt-token", timeout=90)- assert mock_slack_instance.client.reactions_add.call_count == 2- mock_slack_instance.client.reactions_remove.assert_any_call(channel="C123", timestamp="1234.5679", name="eyes")- mock_slack_instance.client.reactions_remove.assert_any_call(- channel="C123", timestamp="1234.5679", name="seedling"+ # Agent is now working on the message, so the :eyes: reaction stays up — it is+ # not swapped to :hedgehog: until the task genuinely completes.+ mock_slack_instance.client.reactions_add.assert_called_once_with(+ channel="C123", timestamp="1234.5679", name="eyes")+ mock_slack_instance.client.reactions_remove.assert_not_called()# Response is delivered by relayAgentResponse from the agent-server, not by this activity.mock_slack_instance.client.chat_postMessage.assert_not_called()@@ -935,10 +936,11 @@ class TestForwardPostHogCodeFollowupActivity(TestCase):mock_send.assert_called_once()# Agent is still processing — relayAgentResponse delivers the response.mock_slack_instance.client.chat_postMessage.assert_not_called()- mock_slack_instance.client.reactions_remove.assert_any_call(channel="C123", timestamp="1234.5679", name="eyes")- mock_slack_instance.client.reactions_remove.assert_any_call(- channel="C123", timestamp="1234.5679", name="seedling"+ # The :eyes: reaction stays up while the agent works — no swap to :hedgehog:.+ mock_slack_instance.client.reactions_add.assert_called_once_with(+ channel="C123", timestamp="1234.5679", name="eyes")+ mock_slack_instance.client.reactions_remove.assert_not_called()@patch("posthog.temporal.ai.posthog_code_slack_mention.create_sandbox_connection_token", return_value="jwt-token")@patch("posthog.temporal.ai.posthog_code_slack_mention.send_user_message")@@ -959,10 +961,11 @@ class TestForwardPostHogCodeFollowupActivity(TestCase):assert result is Trueassert mock_send.call_count == 2- mock_slack_instance.client.reactions_remove.assert_any_call(channel="C123", timestamp="1234.5679", name="eyes")- mock_slack_instance.client.reactions_remove.assert_any_call(- channel="C123", timestamp="1234.5679", name="seedling"+ # The :eyes: reaction stays up while the agent works — no swap to :hedgehog:.+ mock_slack_instance.client.reactions_add.assert_called_once_with(+ channel="C123", timestamp="1234.5679", name="eyes")+ mock_slack_instance.client.reactions_remove.assert_not_called()# Response is delivered by relayAgentResponse, not by this activity.mock_slack_instance.client.chat_postMessage.assert_not_called()diff --git a/products/slack_app/backend/tests/test_post_slack_update.py b/products/slack_app/backend/tests/test_post_slack_update.pyindex c96dfdcffc94..9d41fad37906 100644--- a/products/slack_app/backend/tests/test_post_slack_update.py+++ b/products/slack_app/backend/tests/test_post_slack_update.py@@ -115,7 +115,7 @@ class TestPostSlackUpdate(TestCase):@patch.object(SlackThreadHandler, "post_pr_opened")@patch.object(SlackThreadHandler, "__init__", return_value=None)@patch("products.tasks.backend.models.TaskRun")- def test_in_progress_with_pr_swaps_reaction_and_deletes_progress(+ def test_in_progress_with_pr_keeps_eyes_reaction_and_deletes_progress(self,mock_task_run_class,mock_handler_init,@@ -134,7 +134,8 @@ class TestPostSlackUpdate(TestCase):post_slack_update(PostSlackUpdateInput(run_id="run-1", slack_thread_context=self.slack_thread_context))mock_post_progress.assert_not_called()- mock_update_reaction.assert_called_once_with("hedgehog")+ # Task is still running (PR opened mid-run) — reaction stays :eyes:, not :hedgehog:.+ mock_update_reaction.assert_called_once_with("eyes")mock_delete_progress.assert_called_once()@patch.object(SlackThreadHandler, "delete_progress")@@ -174,7 +175,7 @@ class TestPostSlackUpdate(TestCase):"https://github.com/org/repo/pull/1","http://localhost:8000/project/1/tasks/10?runId=run-1",)- mock_update_reaction.assert_called_once_with("hedgehog")+ mock_update_reaction.assert_called_once_with("eyes")mock_delete_progress.assert_called_once()mock_post_progress.assert_not_called()mock_task_run_class.update_state_atomic.assert_called_once_with(diff --git a/products/slack_app/backend/tests/test_slack_thread.py b/products/slack_app/backend/tests/test_slack_thread.pyindex de27a925d182..3dc0210963f0 100644--- a/products/slack_app/backend/tests/test_slack_thread.py+++ b/products/slack_app/backend/tests/test_slack_thread.py@@ -84,7 +84,7 @@ class TestSlackThreadHandler(TestCase):mock_client.chat_delete.assert_not_called()@patch.object(SlackThreadHandler, "_get_client")- def test_update_reaction_removes_seedling_and_eyes(self, mock_get_client):+ def test_update_reaction_removes_eyes_then_adds_new(self, mock_get_client):mock_client = MagicMock()mock_get_client.return_value = mock_client@@ -98,9 +98,8 @@ class TestSlackThreadHandler(TestCase):handler.update_reaction("hedgehog")remove_calls = mock_client.reactions_remove.call_args_list- assert len(remove_calls) == 2- assert remove_calls[0].kwargs["name"] == "seedling"- assert remove_calls[1].kwargs["name"] == "eyes"+ assert len(remove_calls) == 1+ assert remove_calls[0].kwargs["name"] == "eyes"mock_client.reactions_add.assert_called_once_with(channel="C001", timestamp="1234.5678", name="hedgehog")@patch.object(SlackThreadHandler, "_get_client")diff --git a/products/tasks/backend/temporal/process_task/activities/post_slack_update.py b/products/tasks/backend/temporal/process_task/activities/post_slack_update.pyindex a6887bf7fd8b..c4ed19ac0a18 100644--- a/products/tasks/backend/temporal/process_task/activities/post_slack_update.py+++ b/products/tasks/backend/temporal/process_task/activities/post_slack_update.py@@ -99,7 +99,9 @@ def post_slack_update(input: PostSlackUpdateInput) -> None:else:if pr_url:_post_pr_opened_notification_once(task_run, handler, pr_url, task_url)- handler.update_reaction("hedgehog")+ # Task is still running (PR opened mid-run) — keep the :eyes: reaction+ # so the thread reads as in-progress until it genuinely completes.+ handler.update_reaction("eyes")handler.delete_progress()returnstage = _get_stage_from_status(task_run.status, task_run.stage)