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): bypass compute quota for staff (#87092)

Adam Bowkere3f9c3e38ad8
diff --git a/products/tasks/backend/logic/services/compute_quota.py b/products/tasks/backend/logic/services/compute_quota.py
index 4fa7191b6bef..8d9ecf962f3f 100644
--- a/products/tasks/backend/logic/services/compute_quota.py
+++ b/products/tasks/backend/logic/services/compute_quota.py
@@ -3,7 +3,7 @@ from enum import StrEnum
from django.conf import settings
-from posthog.models import Team
+from posthog.models import Team, User
from products.tasks.backend.metrics import observe_compute_quota_check
from products.tasks.backend.models import Task, TaskClientProvenance
@@ -24,6 +24,10 @@ def organization_deactivated(team_id: int) -> bool:
return Team.objects.filter(id=team_id, organization__is_active=False).exists()
+def task_creator_is_staff(task: Task) -> bool:
+ return bool(task.created_by_id and User.objects.filter(id=task.created_by_id, is_staff=True).exists())
+
+
def is_task_billable_compute(task: Task) -> bool:
source_loop = task.loop if task.loop_id is not None else None
return is_billable_compute(
@@ -54,6 +58,8 @@ def get_compute_quota_denial_reason(task: Task) -> ComputeQuotaDenialReason | No
if organization_deactivated(task.team_id):
observe_compute_quota_check("checked_blocked")
return ComputeQuotaDenialReason.ORGANIZATION_DEACTIVATED
+ if task_creator_is_staff(task):
+ return None
if not getattr(settings, "TASKS_COMPUTE_QUOTA_ENFORCEMENT_ENABLED", False):
return None
if not is_task_billable_compute(task):
diff --git a/products/tasks/backend/logic/services/tests/test_compute_quota.py b/products/tasks/backend/logic/services/tests/test_compute_quota.py
index c65979c0a56a..b3970d10653b 100644
--- a/products/tasks/backend/logic/services/tests/test_compute_quota.py
+++ b/products/tasks/backend/logic/services/tests/test_compute_quota.py
@@ -3,7 +3,7 @@ from unittest.mock import patch
from django.test import override_settings
-from posthog.models import Organization, Team
+from posthog.models import Organization, Team, User
from products.tasks.backend.logic.services.compute_quota import (
ComputeQuotaDenialReason,
@@ -58,6 +58,25 @@ class TestComputeQuota:
assert not is_compute_quota_exhausted(task)
limited.assert_called_with(self.team.api_token)
+ @override_settings(TASKS_COMPUTE_QUOTA_ENFORCEMENT_ENABLED=True)
+ @patch("products.tasks.backend.logic.services.compute_quota._is_posthog_code_quota_limited", return_value=True)
+ def test_staff_task_bypasses_compute_quota(self, limited):
+ staff_user = User.objects.create(email="[email protected]", is_staff=True)
+
+ assert not is_compute_quota_exhausted(self.task(created_by=staff_user))
+ limited.assert_not_called()
+
+ @override_settings(TASKS_COMPUTE_QUOTA_ENFORCEMENT_ENABLED=True)
+ def test_deactivated_organization_still_blocks_staff_task(self):
+ staff_user = User.objects.create(email="[email protected]", is_staff=True)
+ self.team.organization.is_active = False
+ self.team.organization.save(update_fields=["is_active"])
+
+ assert (
+ get_compute_quota_denial_reason(self.task(created_by=staff_user))
+ == ComputeQuotaDenialReason.ORGANIZATION_DEACTIVATED
+ )
+
@override_settings(TASKS_COMPUTE_QUOTA_ENFORCEMENT_ENABLED=True)
@patch(
"products.tasks.backend.logic.services.compute_quota._is_posthog_code_quota_limited",