: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(canvas): reject org-deactivated agent requests with an error (#83607)
Peter Kirkhamfae8cb6ab8d3
diff --git a/products/canvas/backend/presentation/views.py b/products/canvas/backend/presentation/views.pyindex 0d784b32f2bf..784db3ab0f40 100644--- a/products/canvas/backend/presentation/views.py+++ b/products/canvas/backend/presentation/views.py@@ -1063,7 +1063,12 @@ class CanvasViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):202: CanvasAgentRequestResultSerializer,403: OpenApiResponse(description="Agent requests are not declared or the caller is a sandbox."),409: OpenApiResponse(description="The canvas has no authoring task."),- 429: OpenApiResponse(description="The team's compute quota is exhausted; retry later."),+ 429: OpenApiResponse(+ description=(+ "The request was denied for compute: the team's quota is exhausted (retry later), "+ "or the organization is deactivated (not retryable)."+ )+ ),},)# task:write as well: the dispatched run executes with the creator's@@ -1105,6 +1110,13 @@ class CanvasViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):{"detail": "The authoring task for this canvas no longer exists."},status=status.HTTP_409_CONFLICT,)+ if outcome == "organization_deactivated":+ return Response(+ {+ "detail": "Your organization has been deactivated. Contact PostHog support if you think this is a mistake."+ },+ status=status.HTTP_429_TOO_MANY_REQUESTS,+ )if outcome == "quota_exhausted":return Response({"detail": "The team's compute quota is exhausted; retry later."},diff --git a/products/canvas/backend/tests/test_canvas_api.py b/products/canvas/backend/tests/test_canvas_api.pyindex 79cd5a52fbec..6b7d19d328cb 100644--- a/products/canvas/backend/tests/test_canvas_api.py+++ b/products/canvas/backend/tests/test_canvas_api.py@@ -1511,6 +1511,28 @@ class TestCanvasErrorReports(CanvasAPIBaseTest):assert response.status_code == status.HTTP_403_FORBIDDEN+ @parameterized.expand(+ [+ ("deactivated", ComputeQuotaDenialReason.ORGANIZATION_DEACTIVATED, "deactivated"),+ ("quota_exhausted", ComputeQuotaDenialReason.COMPUTE_QUOTA_EXHAUSTED, "compute quota"),+ ]+ )+ def test_request_agent_reports_compute_denial_with_distinct_copy(self, _name, reason, expected_detail):+ # Every denial must be an error response: a denial outcome reaching the+ # 202 path would ship a request_outcome outside the response contract's+ # choices, which API clients validate against.+ canvas_id, _, _ = self._authored_canvas(agent_requests=True)++ with patch(+ "products.tasks.backend.logic.services.compute_quota.get_compute_quota_denial_reason",+ return_value=reason,+ ):+ response = self._request_agent(canvas_id, "Make it blue.")++ assert response.status_code == status.HTTP_429_TOO_MANY_REQUESTS, response.json()+ assert expected_detail in response.json()["detail"].lower()+ assert not TaskRun.objects.exists()+def test_request_fix_prompt_never_carries_unsafe_error_type(self):# The requester's error_type flows into the agent prompt; a hostile# value must be coerced, not interpolated.