: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(slack): remove sandbox stopped notifications (#105037)
Vojta Bartoš24f9008938a5
diff --git a/products/slack_app/backend/slack_thread.py b/products/slack_app/backend/slack_thread.pyindex d9a1dca729a3..073393f98ada 100644--- a/products/slack_app/backend/slack_thread.py+++ b/products/slack_app/backend/slack_thread.py@@ -39,11 +39,6 @@ DEFAULT_FAILURE_RECOVERY_HINT = ("Reply in this thread with `retry` to try again from the latest checkpoint, ""or add the missing details and I'll re-plan before continuing.")-DEFAULT_CANCELLED_RECOVERY_HINT = (- "Reply in this thread when you want to resume, and include any new direction I should follow."-)--_TASK_FIELD_LIMIT = 256_MARKDOWN_CHUNK_LIMIT = 12000_SECTION_TEXT_LIMIT = 3000@@ -756,35 +751,6 @@ class SlackThreadHandler:self._delete_progress_and_post(f"{header}\n{truncated_error}", blocks)- def post_cancelled(self, task_url: str | None, recovery_hint: str | None = DEFAULT_CANCELLED_RECOVERY_HINT) -> None:- """Post cancelled message with link to PostHog for details."""- header = "*Sandbox stopped* :hedgehog:"-- blocks: list[dict[str, Any]] = [- {"type": "section", "text": {"type": "mrkdwn", "text": header}},- ]- if recovery_hint:- blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": recovery_hint}})- if task_url:- blocks.append(- {- "type": "actions",- "elements": [- {- "type": "button",- "text": {- "type": "plain_text",- "text": "Open in PostHog",- "emoji": True,- },- "url": task_url,- },- ],- }- )-- self._delete_progress_and_post(header, blocks)-def post_note(self, text: str) -> None:"""Post a plain one-line note to the thread, replacing any progress message."""blocks: list[dict[str, Any]] = [diff --git a/products/slack_app/backend/tests/test_slack_thread.py b/products/slack_app/backend/tests/test_slack_thread.pyindex e4dc87dfa159..d8770c87bcd5 100644--- a/products/slack_app/backend/tests/test_slack_thread.py+++ b/products/slack_app/backend/tests/test_slack_thread.py@@ -301,18 +301,6 @@ class TestSlackThreadHandlerWithoutTaskUrl(SimpleTestCase):# The error body itself must still surface — only the action block is gated.assert kwargs["blocks"][1]["text"]["text"] == "boom"- @patch.object(SlackThreadHandler, "delete_progress")- @patch.object(SlackThreadHandler, "_get_client")- def test_post_cancelled_without_task_url_drops_actions(self, mock_get_client, _mock_delete_progress):- mock_client = MagicMock()- mock_get_client.return_value = mock_client- handler = SlackThreadHandler(self._make_context())-- handler.post_cancelled(task_url=None)-- mock_client.chat_postMessage.assert_called_once()- assert _action_blocks(mock_client.chat_postMessage.call_args.kwargs) == []-class TestPostPrOpenedReplyTarget(SimpleTestCase):"""``post_pr_opened`` no longer owns the mention-target decision — thediff --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 cb387ad24789..6b662f694b1d 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@@ -114,7 +114,7 @@ def post_slack_update(input: PostSlackUpdateInput) -> None:handler.update_reaction("hedgehog")_post_pr_opened_notification_once(task_run, handler, pr_url, task_url)elif task_run.status == TaskRun.Status.CANCELLED:- _post_cancelled_once(task_run, handler, task_url)+ _post_cancelled_once(task_run, handler)elif task_run.status == TaskRun.Status.FAILED:_post_failure_or_timeout(task_run, handler, task_url)return@@ -129,7 +129,7 @@ def post_slack_update(input: PostSlackUpdateInput) -> None:else:handler.post_completion(task_url)elif task_run.status == TaskRun.Status.CANCELLED:- _post_cancelled_once(task_run, handler, task_url)+ _post_cancelled_once(task_run, handler)elif task_run.status == TaskRun.Status.FAILED:_post_failure_or_timeout(task_run, handler, task_url)else:@@ -301,7 +301,7 @@ def _post_error_once(task_run: Any, handler: Any, error: str, task_url: str | No_mark_terminal_notified(task_run, TaskRun.Status.FAILED, error)-def _post_cancelled_once(task_run: Any, handler: Any, task_url: str | None) -> None:+def _post_cancelled_once(task_run: Any, handler: Any) -> None:from products.tasks.backend.models import TaskRunif _is_terminal_notified(task_run, TaskRun.Status.CANCELLED):@@ -309,7 +309,7 @@ def _post_cancelled_once(task_run: Any, handler: Any, task_url: str | None) -> Nreturnhandler.update_reaction("hedgehog")- handler.post_cancelled(task_url, recovery_hint=_RECOVERY_PROMPTS[SLACK_RECOVERY_STRATEGY_CANCELLED])+ handler.delete_progress()_mark_terminal_notified(task_run, TaskRun.Status.CANCELLED)diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_post_slack_update.py b/products/tasks/backend/temporal/process_task/activities/tests/test_post_slack_update.pyindex 7f7929b05e4c..5c1a11c698c5 100644--- a/products/tasks/backend/temporal/process_task/activities/tests/test_post_slack_update.py+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_post_slack_update.py@@ -9,6 +9,7 @@ from products.tasks.backend.temporal.process_task.activities.post_slack_update iSLACK_RECOVERY_STRATEGY_UNBLOCK_AND_REPLAN,_classify_failure_recovery,_failure_recovery_prompt,+ _post_cancelled_once,_post_error_once,)@@ -64,3 +65,16 @@ def test_suppressed_permission_rejection_posts_note_instead_of_error(mock_updatehandler.post_note.assert_called_once_with(SLACK_DENIAL_STOP_MESSAGE)handler.post_error.assert_not_called()mock_update_state.assert_called_once()+++@patch("products.tasks.backend.models.TaskRun.update_state_atomic")+def test_cancelled_run_clears_progress_without_posting(mock_update_state: MagicMock) -> None:+ task_run = MagicMock()+ task_run.state = {}+ handler = MagicMock(spec=["update_reaction", "delete_progress"])++ _post_cancelled_once(task_run, handler)++ handler.update_reaction.assert_called_once_with("hedgehog")+ handler.delete_progress.assert_called_once_with()+ mock_update_state.assert_called_once()diff --git a/products/tasks/backend/tests/test_post_slack_update.py b/products/tasks/backend/tests/test_post_slack_update.pyindex 93c8c97a7709..13c5fb517312 100644--- a/products/tasks/backend/tests/test_post_slack_update.py+++ b/products/tasks/backend/tests/test_post_slack_update.py@@ -151,11 +151,11 @@ class TestPostSlackUpdate(TestCase):"Wait for this run's spend limit to reset before replying in the thread.")- @patch.object(SlackThreadHandler, "post_cancelled")+ @patch.object(SlackThreadHandler, "delete_progress")@patch.object(SlackThreadHandler, "update_reaction")@patch("products.tasks.backend.models.TaskRun")- def test_cancelled_run_posts_cancelled_message(- self, mock_task_run_class, mock_update_reaction, mock_post_cancelled+ def test_cancelled_run_clears_progress_without_posting(+ self, mock_task_run_class, mock_update_reaction, mock_delete_progress):mock_run = self._make_mock_run(mock_task_run_class.Status.CANCELLED)mock_task_run_class.objects.select_related.return_value.get.return_value = mock_run@@ -163,7 +163,7 @@ class TestPostSlackUpdate(TestCase):post_slack_update(PostSlackUpdateInput(run_id="run-1", slack_thread_context=self.slack_thread_context))mock_update_reaction.assert_called_once_with("hedgehog")- mock_post_cancelled.assert_called_once()+ mock_delete_progress.assert_called_once()@patch.object(SlackThreadHandler, "post_or_update_progress")@patch("products.tasks.backend.models.TaskRun")@@ -592,7 +592,6 @@ class TestPostSlackUpdate(TestCase):@patch.object(SlackThreadHandler, "post_completion")@patch.object(SlackThreadHandler, "post_or_update_progress")@patch.object(SlackThreadHandler, "post_error")- @patch.object(SlackThreadHandler, "post_cancelled")@patch.object(SlackThreadHandler, "post_pr_opened")@patch.object(SlackThreadHandler, "update_reaction")@patch("products.tasks.backend.models.TaskRun")@@ -601,7 +600,6 @@ class TestPostSlackUpdate(TestCase):mock_task_run_class,_mock_update_reaction,mock_post_pr_opened,- mock_post_cancelled,mock_post_error,mock_post_progress,mock_post_completion,@@ -627,9 +625,6 @@ class TestPostSlackUpdate(TestCase):failed = self._make_mock_run(mock_task_run_class.Status.FAILED, error_message="boom")scenarios.append((failed, mock_post_error))- cancelled = self._make_mock_run(mock_task_run_class.Status.CANCELLED)- scenarios.append((cancelled, mock_post_cancelled))-in_progress = self._make_mock_run(mock_task_run_class.Status.IN_PROGRESS, stage="Building")scenarios.append((in_progress, mock_post_progress))@@ -683,9 +678,6 @@ class TestPostSlackUpdate(TestCase):mock_update_reaction,mock_post_pr_opened,):- # A cancelled run that still produced a PR funnels through the same- # single template — the cancellation card only fires when no PR was- # opened.mock_run = self._make_mock_run(mock_task_run_class.Status.CANCELLED,output={"pr_url": "https://github.com/org/repo/pull/2"},