Skip to content

: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.

fix(tasks): exempt inbox tasks from code access on warm resume (#118218)

Charles Viene5a3d64f4877
diff --git a/products/tasks/backend/presentation/views/api.py b/products/tasks/backend/presentation/views/api.py
index ec32f1e67c88..f5561c4787b7 100644
--- a/products/tasks/backend/presentation/views/api.py
+++ b/products/tasks/backend/presentation/views/api.py
@@ -1679,7 +1679,9 @@ class TaskViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
raise PermissionDenied("The analytics data in this task run is not available to you.")
if gate.runtime == tasks_facade.TaskRuntime.PI or not self._warm_enabled(gate.origin_product):
return Response(status=status.HTTP_200_OK)
- if access_response := code_access_required_response(request, self.organization, task_id=pk):
+ if not tasks_facade.task_exempt_from_code_access(pk, self.team_id) and (
+ access_response := code_access_required_response(request, self.organization, task_id=pk)
+ ):
return access_response
user_id = self._user_id()
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index f9eb9020b9d3..324b7ce8863f 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -16889,6 +16889,36 @@ class TestCloudUsageGate(BaseTaskAPITest):
self.assertEqual(response.status_code, status.HTTP_200_OK)
mock_resume.assert_called_once()
+ @parameterized.expand(
+ [
+ ("inbox_task", True, status.HTTP_200_OK),
+ ("plain_task", False, status.HTTP_403_FORBIDDEN),
+ ]
+ )
+ @patch("products.tasks.backend.facade.api.warm_task_resume_sandbox", return_value=None)
+ @patch("products.tasks.backend.presentation.views.api.TaskViewSet._warm_enabled", return_value=True)
+ @patch("products.tasks.backend.logic.services.code_usage_gate.get_posthog_code_usage", return_value=None)
+ def test_warm_resume_code_access_exempts_inbox_tasks(
+ self, _name, inbox, expected_status, _mock_gate, _mock_warm_enabled, mock_warm
+ ):
+ self.set_tasks_feature_flag(False)
+ task = self._inbox_task(Task.OriginProduct.SIGNAL_REPORT) if inbox else self.create_task()
+ run = TaskRun.objects.create(
+ task=task,
+ team=self.team,
+ environment=TaskRun.Environment.CLOUD,
+ status=TaskRun.Status.COMPLETED,
+ )
+
+ response = self.client.post(
+ f"/api/projects/@current/tasks/{task.id}/warm/",
+ {"resume_from_run_id": str(run.id)},
+ format="json",
+ )
+
+ self.assertEqual(response.status_code, expected_status)
+ self.assertEqual(mock_warm.called, inbox)
+
def test_exemption_ignores_cross_team_report_link(self):
# The write serializer blocks cross-team report links, so forge one at the ORM level:
# the exemption query must re-check the report's team rather than trust the FK alone.