: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(signals): preserve scout scopes when reconciler re-dispatches a run (#69693)
posthog[bot]81c7fe39ef5e
diff --git a/products/tasks/backend/temporal/client.py b/products/tasks/backend/temporal/client.pyindex 8575ee72ce28..409eb2ff5ded 100644--- a/products/tasks/backend/temporal/client.py+++ b/products/tasks/backend/temporal/client.py@@ -17,7 +17,7 @@ from posthog.temporal.oauth import PosthogMcpScopesfrom products.tasks.backend.constants import SANDBOX_EVENT_INGEST_FEATURE_FLAGfrom products.tasks.backend.metrics import observe_task_run_workflow_start-from products.tasks.backend.models import TaskRun+from products.tasks.backend.models import Task, TaskRunfrom products.tasks.backend.temporal.build_image.workflow import BuildSandboxImageInputfrom products.tasks.backend.temporal.process_task.workflow import ProcessTaskInputfrom products.tasks.backend.temporal.slack_relay.activities import RelaySlackMessageInput@@ -307,12 +307,27 @@ def execute_task_processing_workflow(def _resolve_mcp_scopes(task_run: TaskRun) -> PosthogMcpScopes:- """Mirror ``_trigger_task_processing_workflow``: full scopes unless the run_source is scoped down."""+ """Best-effort scope posture for the reconciler when ``pending_dispatch`` didn't carry+ ``posthog_mcp_scopes`` (pre-reconciler rows, or the bootstrap/start path). Mirrors+ ``_trigger_task_processing_workflow``: full scopes unless the run_source is scoped down.++ Signals scout runs are the exception. Their posture (``signal_scout_internal:*`` ++ ``signal_scout_report:write``) is carried by neither ``"full"`` nor ``"read_only"``, so a scout+ re-dispatched on this fallback with a generic posture loses every ``signals-scout-*`` tool — they+ drop out of the MCP catalog and surface to the agent as "Unknown tool", burning the whole run+ (it investigates, then can't emit a report, write scratchpad, or build its profile). Pin+ scout-origin runs to the most-capable scout posture so a reconciled scout stays fully functional.+ Over-granting the report scope to a non-report scout is harmless: the report endpoints+ independently gate on the skill's ``allowed_tools`` opt-in.+ """from products.tasks.backend.temporal.process_task.utils import ( # noqa: PLC0415 — avoid an import cycleRunSource,parse_run_state,)+ if task_run.task.origin_product == Task.OriginProduct.SIGNALS_SCOUT:+ return "signals_scout_reports"+run_source = parse_run_state(task_run.state).run_sourcereturn "full" if run_source in (None, RunSource.MANUAL, RunSource.SIGNAL_REPORT) else "read_only"diff --git a/products/tasks/backend/tests/test_temporal_client.py b/products/tasks/backend/tests/test_temporal_client.pyindex 72d55bf43f36..edc38204e0bb 100644--- a/products/tasks/backend/tests/test_temporal_client.py+++ b/products/tasks/backend/tests/test_temporal_client.py@@ -254,6 +254,26 @@ class TestRedispatchOrphanedTaskRun(TestCase):_, workflow_input = start_workflow.call_args.argsself.assertEqual(workflow_input.posthog_mcp_scopes, expected_scopes)+ def test_falls_back_to_scout_scopes_for_signals_scout_run(self) -> None:+ # A scout run reconciled without a persisted scope must keep its scout posture — falling back+ # to "full"/"read_only" strips every signal_scout_* scope, so the scout can't emit a report,+ # write scratchpad, or build its profile, and every signals-scout-* tool reads as "Unknown tool".+ scout_task = Task.objects.create(+ team=self.team,+ created_by=self.user,+ title="Scout Task",+ description="Scout Description",+ origin_product=Task.OriginProduct.SIGNALS_SCOUT,+ )+ run = TaskRun.objects.create(task=scout_task, team=self.team, status=TaskRun.Status.QUEUED, state={})+ start_workflow = AsyncMock()++ outcome = self._run_reconcile(run, start_workflow)++ self.assertEqual(outcome, "recovered")+ _, workflow_input = start_workflow.call_args.args+ self.assertEqual(workflow_input.posthog_mcp_scopes, "signals_scout_reports")+def test_does_not_fail_run_when_workflow_already_started(self) -> None:run = self._orphaned_run()start_workflow = AsyncMock(side_effect=WorkflowAlreadyStartedError(run.workflow_id, "process-task"))