: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-app): bound the feedback reply to the webhook window (#109754)
Vojta Bartoš8c37ac6856de
diff --git a/products/slack_app/backend/api.py b/products/slack_app/backend/api.pyindex 99513989a817..e64f2cd4156d 100644--- a/products/slack_app/backend/api.py+++ b/products/slack_app/backend/api.py@@ -338,17 +338,22 @@ def _post_slack_user_feedback(A thread post whose root has been deleted is skipped rather than posted — see``post_slack_thread_reply``. That counts as "nothing reached Slack", which isaccurate: the user retracted the message this feedback answers."""+ # Every caller runs inside the Slack webhook, so the SDK's 30 second default would+ # outlast the acknowledgement window. The client is held in a local because+ # ``SlackIntegration.client`` builds a new one on every access.+ client = slack.client+ client.timeout = SLACK_WEBHOOK_TIMEOUT_SECONDSif prefer_thread_message:try:- return post_slack_thread_reply(slack.client, channel=channel, thread_ts=thread_ts, text=text) is not None+ return post_slack_thread_reply(client, channel=channel, thread_ts=thread_ts, text=text) is not Noneexcept Exception:logger.warning("slack_user_feedback_thread_post_failed", channel=channel, slack_user_id=slack_user_id)try:- slack.client.chat_postEphemeral(channel=channel, user=slack_user_id, thread_ts=thread_ts, text=text)+ client.chat_postEphemeral(channel=channel, user=slack_user_id, thread_ts=thread_ts, text=text)except Exception:try:- return post_slack_thread_reply(slack.client, channel=channel, thread_ts=thread_ts, text=text) is not None+ return post_slack_thread_reply(client, channel=channel, thread_ts=thread_ts, text=text) is not Noneexcept Exception:logger.warning("slack_user_feedback_failed", channel=channel, slack_user_id=slack_user_id)return Falsediff --git a/products/slack_app/backend/tests/test_posthog_code_event_handler.py b/products/slack_app/backend/tests/test_posthog_code_event_handler.pyindex 871d0992ceed..99cfba9a3b81 100644--- a/products/slack_app/backend/tests/test_posthog_code_event_handler.py+++ b/products/slack_app/backend/tests/test_posthog_code_event_handler.py@@ -1767,12 +1767,19 @@ class TestUntaggedFollowupPrompt(SimpleTestCase):class TestPostSlackUserEphemeral(SimpleTestCase):- def test_request_timeout_applies_to_the_client_that_makes_the_call(self):+ @parameterized.expand(+ [+ ("ephemeral", lambda slack, api: api._post_slack_user_ephemeral(slack, "C001", "U123", None, "nope")),+ ("feedback", lambda slack, api: api._post_slack_user_feedback(slack, "C001", "U123", "1.0", "nope")),+ ]+ )+ def test_request_timeout_applies_to_the_client_that_makes_the_call(self, _name, post):# ``SlackIntegration.client`` builds a fresh WebClient on every access, so setting# the timeout on one access and calling on another leaves the request on the SDK# default. Nothing about the app's behavior changes when that happens, so only an# assertion on the client instance catches it.- from products.slack_app.backend.api import SLACK_WEBHOOK_TIMEOUT_SECONDS, _post_slack_user_ephemeral+ from products.slack_app.backend import api+ from products.slack_app.backend.api import SLACK_WEBHOOK_TIMEOUT_SECONDSbuilt_clients: list[MagicMock] = []@@ -1782,7 +1789,7 @@ class TestPostSlackUserEphemeral(SimpleTestCase):built_clients.append(MagicMock())return built_clients[-1]- posted = _post_slack_user_ephemeral(cast(SlackIntegration, _NewClientPerAccess()), "C001", "U123", None, "nope")+ posted = post(cast(SlackIntegration, _NewClientPerAccess()), api)assert posted is Trueassert len(built_clients) == 1