: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): coerce mention workflow activity inputs across version skew (#68806)
posthog[bot]4892fff2d57f
diff --git a/posthog/temporal/ai/slack_app/activities/messaging.py b/posthog/temporal/ai/slack_app/activities/messaging.pyindex 41596cde9966..ef571b9d3b53 100644--- a/posthog/temporal/ai/slack_app/activities/messaging.py+++ b/posthog/temporal/ai/slack_app/activities/messaging.py@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Anyimport structlogfrom temporalio import activity-from posthog.temporal.ai.slack_app.types import PostHogCodeSlackMentionWorkflowInputs+from posthog.temporal.ai.slack_app.types import PostHogCodeSlackMentionWorkflowInputs, coerce_mention_workflow_inputsfrom posthog.temporal.common.utils import close_db_connectionsif TYPE_CHECKING:@@ -28,6 +28,7 @@ def post_posthog_code_no_repos_activity() -> None:from posthog.models.integration import Integration, SlackIntegration+ inputs = coerce_mention_workflow_inputs(inputs)integration = Integration.objects.select_related("team", "team__organization").get(id=inputs.integration_id,kind="slack",@@ -69,6 +70,7 @@ def post_posthog_code_repo_picker_activity("""from posthog.models.integration import Integration, SlackIntegration+ inputs = coerce_mention_workflow_inputs(inputs)if user_id is None:logger.warning("posthog_code_picker_legacy_call_skipped",@@ -170,6 +172,7 @@ def block_posthog_code_task_if_no_personal_github_activity(from products.slack_app.backend.feature_flags import is_slack_app_bot_prs_enabled+ inputs = coerce_mention_workflow_inputs(inputs)has_personal_github = UserIntegration.objects.filter(user_id=user_id,kind=UserIntegration.IntegrationKind.GITHUB,@@ -222,6 +225,7 @@ def resolve_posthog_code_authorship_activity(from products.slack_app.backend.feature_flags import is_slack_app_bot_prs_enabledfrom products.tasks.backend.facade import api as tasks_facade+ inputs = coerce_mention_workflow_inputs(inputs)if tasks_facade.user_can_author_repository(user_id, repository):return "proceed"@@ -329,6 +333,7 @@ def post_posthog_code_authorship_timeout_activity(from products.slack_app.backend.models import SlackThreadTaskMapping+ inputs = coerce_mention_workflow_inputs(inputs)# Skip the expired message if another workflow already created a task for this thread.if SlackThreadTaskMapping.objects.filter(integration_id=inputs.integration_id,@@ -360,6 +365,7 @@ def post_posthog_code_picker_timeout_activity(from products.slack_app.backend.api import _clear_pending_repo_pickerfrom products.slack_app.backend.models import SlackThreadTaskMapping+ inputs = coerce_mention_workflow_inputs(inputs)slack_user_id = inputs.event.get("user")if isinstance(slack_user_id, str) and slack_user_id:_clear_pending_repo_picker(@@ -401,6 +407,7 @@ def post_posthog_code_internal_error_activity(from products.slack_app.backend.api import _clear_pending_repo_picker+ inputs = coerce_mention_workflow_inputs(inputs)slack_user_id = inputs.event.get("user")if isinstance(slack_user_id, str) and slack_user_id:_clear_pending_repo_picker(diff --git a/posthog/temporal/ai/slack_app/types.py b/posthog/temporal/ai/slack_app/types.pyindex a492a6b5cf01..663177287a5c 100644--- a/posthog/temporal/ai/slack_app/types.py+++ b/posthog/temporal/ai/slack_app/types.py@@ -5,7 +5,7 @@ package can take the inputs dataclass as their typed signature withoutcreating an import cycle with the workflow modules."""-from dataclasses import dataclass+from dataclasses import dataclass, fieldsfrom typing import Any, Literal@@ -35,6 +35,35 @@ class PostHogCodeSlackMentionWorkflowInputs:untagged_followup: bool = False+def coerce_mention_workflow_inputs(inputs: object) -> PostHogCodeSlackMentionWorkflowInputs:+ """Normalise an activity's ``inputs`` back into the dataclass.++ Temporal's default converter rebuilds the dataclass from the activity's type+ hint, but during a rolling deploy workers can briefly disagree on the+ activity signature and a payload arrives as a raw ``dict``. Reading+ ``inputs.integration_id`` on a dict then raises an opaque ``AttributeError``+ deep in the body. Rebuilding here keeps the flow working across version skew,+ and unknown keys are dropped so a newer sender's extra field doesn't blow up+ an older activity. A payload missing the required fields fails loudly with+ context instead of surfacing as an ``AttributeError``.+ """+ if isinstance(inputs, PostHogCodeSlackMentionWorkflowInputs):+ return inputs+ if isinstance(inputs, dict):+ known = {f.name for f in fields(PostHogCodeSlackMentionWorkflowInputs)}+ try:+ return PostHogCodeSlackMentionWorkflowInputs(**{k: v for k, v in inputs.items() if k in known})+ except TypeError as e:+ raise TypeError(+ "Could not coerce activity inputs into PostHogCodeSlackMentionWorkflowInputs "+ f"(keys={sorted(inputs)}): {e}"+ ) from e+ raise TypeError(+ f"Unexpected activity inputs type {type(inputs).__name__}; "+ "expected PostHogCodeSlackMentionWorkflowInputs or dict"+ )++@dataclassclass PostHogCodeSlackMentionCommandWorkflowInputs:event: dict[str, Any]diff --git a/posthog/temporal/tests/ai/slack_app/test_types.py b/posthog/temporal/tests/ai/slack_app/test_types.pynew file mode 100644index 000000000000..e66b8c93f096--- /dev/null+++ b/posthog/temporal/tests/ai/slack_app/test_types.py@@ -0,0 +1,45 @@+import pytest++from posthog.temporal.ai.slack_app.types import PostHogCodeSlackMentionWorkflowInputs, coerce_mention_workflow_inputs+++def test_coerce_returns_dataclass_unchanged():+ inputs = PostHogCodeSlackMentionWorkflowInputs(event={"ts": "1.2"}, integration_id=7, slack_team_id="T1")+ assert coerce_mention_workflow_inputs(inputs) is inputs+++def test_coerce_rebuilds_dataclass_from_dict():+ # A rolling deploy can deliver the payload as a raw dict; reading+ # ``.integration_id`` on it used to raise an opaque AttributeError.+ coerced = coerce_mention_workflow_inputs(+ {"event": {"ts": "1.2"}, "integration_id": 7, "slack_team_id": "T1", "user_id": 42}+ )+ assert isinstance(coerced, PostHogCodeSlackMentionWorkflowInputs)+ assert coerced.integration_id == 7+ assert coerced.slack_team_id == "T1"+ assert coerced.user_id == 42+++def test_coerce_drops_unknown_keys_from_dict():+ # A newer sender's extra field must not blow up an older activity mid-deploy.+ coerced = coerce_mention_workflow_inputs(+ {"event": {}, "integration_id": 1, "slack_team_id": "T1", "some_future_field": "x"}+ )+ assert coerced.integration_id == 1+++ "payload",+ [+ {"integration_id": 1, "slack_team_id": "T1"}, # missing required ``event``+ {"event": {}}, # missing required ``integration_id`` / ``slack_team_id``+ ],+)+def test_coerce_raises_with_context_when_required_fields_missing(payload):+ with pytest.raises(TypeError, match="PostHogCodeSlackMentionWorkflowInputs"):+ coerce_mention_workflow_inputs(payload)+++def test_coerce_raises_on_unexpected_type():+ with pytest.raises(TypeError, match="Unexpected activity inputs type"):+ coerce_mention_workflow_inputs("not-a-dict")