: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(replay-vision): refuse backfills when AI analysis is off (#113770)
Tue Haulund0bb295a80ed0
diff --git a/products/replay_vision/backend/api/backfills.py b/products/replay_vision/backend/api/backfills.pyindex 17e85823665e..b0edb0d65a42 100644--- a/products/replay_vision/backend/api/backfills.py+++ b/products/replay_vision/backend/api/backfills.py@@ -24,6 +24,7 @@ from posthog.permissions import is_scout_sandbox_requestfrom posthog.rate_limit import PersonalApiKeyOrUserRateThrottlefrom products.replay_vision.backend.billing import observation_credits_for_model+from products.replay_vision.backend.consent import AI_CONSENT_REQUIRED_CODE, is_ai_data_processing_approvedfrom products.replay_vision.backend.models.replay_observation import IN_FLIGHT_STATUSES, ObservationStatusfrom products.replay_vision.backend.models.replay_scanner import SETTLE_INTERVAL, ReplayScanner, ScannerTypefrom products.replay_vision.backend.models.replay_scanner_backfill import (@@ -342,6 +343,14 @@ class ReplayScannerBackfillViewSet()return Response(response.data)+ def _require_ai_consent(self) -> None:+ # Each tick skips dispatch without consent, so a backfill accepted here would sit running and scan nothing.+ if not is_ai_data_processing_approved(self.team.id):+ raise ValidationError(+ "Your organization needs to allow AI analysis before you run a Replay Vision backfill.",+ code=AI_CONSENT_REQUIRED_CODE,+ )+@extend_schema(request=BackfillCreateSerializer, responses={201: ReplayScannerBackfillSerializer})def create(self, request: Request, **kwargs: Any) -> Response:"""Create a backfill: freeze the scanner config, enumerate the exact candidate set, start the tick schedule.@@ -351,6 +360,7 @@ class ReplayScannerBackfillViewSet(settled sessions between estimate and confirm can nudge total_count slightly."""scanner = self._scanner_for_url()+ self._require_ai_consent()window = BackfillCreateSerializer(data=request.data)window.is_valid(raise_exception=True)window_start, window_end = self._clamped_window(window.validated_data)@@ -423,6 +433,7 @@ class ReplayScannerBackfillViewSet(def resume(self, request: Request, **kwargs: Any) -> Response:"""Restart a backfill that paused when the monthly quota ran out."""backfill = self.get_object()+ self._require_ai_consent()updated = ReplayScannerBackfill.objects.filter(pk=backfill.pk, status=BackfillStatus.PAUSED_QUOTA).update(status=BackfillStatus.RUNNING)diff --git a/products/replay_vision/backend/tests/test_backfills.py b/products/replay_vision/backend/tests/test_backfills.pyindex 42061c1bd695..b200a3e0bf1c 100644--- a/products/replay_vision/backend/tests/test_backfills.py+++ b/products/replay_vision/backend/tests/test_backfills.py@@ -779,6 +779,30 @@ class TestBackfillsApi(APIBaseTest):response = self.client.post(f"{self.base_url}/{running.id}/resume/")assert response.status_code == 400+ @patch("products.replay_vision.backend.temporal.schedule.a_resume_backfill_schedule", new_callable=AsyncMock)+ @patch("products.replay_vision.backend.temporal.schedule.a_upsert_backfill_schedule", new_callable=AsyncMock)+ @patch("products.replay_vision.backend.api.backfills.WindowedCandidateQuery")+ def test_create_and_resume_refuse_without_ai_consent(+ self, mock_query: MagicMock, mock_upsert: AsyncMock, mock_resume: AsyncMock+ ) -> None:+ mock_query.return_value.count.return_value = 1+ self.organization.is_ai_data_processing_approved = False+ self.organization.save()+ paused = _make_backfill(self.scanner, status=BackfillStatus.PAUSED_QUOTA)++ create = self.client.post(+ f"{self.base_url}/", {**self._window_body(), "max_total_credits": 10**6}, format="json"+ )+ resume = self.client.post(f"{self.base_url}/{paused.id}/resume/")++ assert (create.status_code, resume.status_code) == (400, 400), (create.json(), resume.json())+ assert create.json()["code"] == resume.json()["code"] == "ai_data_processing_not_approved"+ paused.refresh_from_db()+ assert paused.status == BackfillStatus.PAUSED_QUOTA+ assert ReplayScannerBackfill.objects.for_team(self.team.id).filter(scanner=self.scanner).count() == 1+ mock_upsert.assert_not_awaited()+ mock_resume.assert_not_awaited()+def test_enumerating_actions_are_throttled_and_cheap_ones_are_not(self) -> None:# The global burst/sustained throttles extend PersonalApiKeyRateThrottle, which gates on# personal-API-key auth, so a UI session skips them and could resubmit wide windows until the