: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): stabilize backfill history pagination (#102491)
posthog[bot]be2382d3f291
diff --git a/products/replay_vision/backend/api/backfills.py b/products/replay_vision/backend/api/backfills.pyindex 520a452789a0..a8e9b37a8651 100644--- a/products/replay_vision/backend/api/backfills.py+++ b/products/replay_vision/backend/api/backfills.py@@ -194,7 +194,7 @@ class ReplayScannerBackfillViewSet(ineligible_count=Count("observations", filter=Q(observations__status=ObservationStatus.INELIGIBLE)),in_flight_count=Count("observations", filter=Q(observations__status__in=IN_FLIGHT_STATUSES)),)- .order_by("-created_at")+ .order_by("-created_at", "id"))def _clamped_window(self, data: dict[str, Any]) -> tuple[datetime, datetime]:diff --git a/products/replay_vision/backend/tests/test_backfills.py b/products/replay_vision/backend/tests/test_backfills.pyindex 91b8a6fff496..ed4278acae16 100644--- a/products/replay_vision/backend/tests/test_backfills.py+++ b/products/replay_vision/backend/tests/test_backfills.py@@ -783,6 +783,26 @@ class TestBackfillsApi(APIBaseTest):row = response.json()["results"][0]assert (row["succeeded_count"], row["failed_count"], row["in_flight_count"]) == (1, 1, 1)+ def test_list_pages_tied_created_at_rows_without_loss_or_repeats(self) -> None:+ # Backfills created in the same instant tie on created_at, so only the id term keeps the pages+ # from dropping or repeating a row.+ ids = [uuid.UUID(f"0199000{n}-0000-7000-8000-000000000000") for n in range(8)]+ for backfill_id in ids:+ _make_backfill(self.scanner, id=backfill_id, status=BackfillStatus.COMPLETED)+ # created_at is auto_now_add, so force the tie afterwards. One row at a time in descending id+ # order, so the physical row order disagrees with the order the endpoint owes.+ tied_at = timezone.now()+ for backfill_id in sorted(ids, reverse=True):+ ReplayScannerBackfill.objects.for_team(self.team.id).filter(id=backfill_id).update(created_at=tied_at)++ paged_ids: list[uuid.UUID] = []+ for offset in (0, 2, 4, 6):+ response = self.client.get(f"{self.base_url}/?limit=2&offset={offset}")+ assert response.status_code == 200+ paged_ids += [uuid.UUID(row["id"]) for row in response.json()["results"]]++ assert paged_ids == sorted(ids)+# BackfillScannerWorkflow (mocked-Temporal)