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(vision): observation detail progress stuck and page refreshing (#61917)

Kim Svatos Dugana4acb9c65fb5
diff --git a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr
index 85ef7482f958..5baa5600e7e2 100644
--- a/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr
+++ b/products/experiments/backend/hogql_queries/test/experiment_query_runner/__snapshots__/test_mean_metric.ambr
@@ -179,60 +179,6 @@
use_hive_partitioning=0
'''
# ---
-# name: TestExperimentMeanMetric.test_conversion_window_extends_to_last_exposure_1_precomputed
- '''
- WITH exposures AS
- (SELECT accurateCastOrNull(t.entity_id, 'UUID') AS entity_id,
- if(ifNull(greater(uniqExact(t.variant), 1), 0), '$multiple', argMin(t.variant, toTimeZone(t.first_exposure_time, 'UTC'))) AS variant,
- min(toTimeZone(t.first_exposure_time, 'UTC')) AS first_exposure_time,
- max(toTimeZone(t.last_exposure_time, 'UTC')) AS last_exposure_time,
- argMin(t.exposure_event_uuid, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_event_uuid,
- argMin(t.exposure_session_id, toTimeZone(t.first_exposure_time, 'UTC')) AS exposure_session_id
- FROM experiment_exposures_preaggregated AS t
- WHERE and(equals(t.team_id, 99999), in(t.job_id, ['00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000']), equals(t.team_id, 99999), greaterOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), lessOrEquals(t.first_exposure_time, assumeNotNull(toDateTime('2020-01-10 00:00:00', 'UTC'))))
- GROUP BY entity_id),
- metric_events AS
- (SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS entity_id,
- toTimeZone(events.timestamp, 'UTC') AS timestamp,
- coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'amount'), ''), 'null'), '^"|"$', ''), 'Float64'), 0) AS value
- FROM events
- LEFT OUTER JOIN
- (SELECT tupleElement(argMax(tuple(person_distinct_id_overrides.person_id), person_distinct_id_overrides.version), 1) AS person_id,
- person_distinct_id_overrides.distinct_id AS distinct_id
- FROM person_distinct_id_overrides
- WHERE equals(person_distinct_id_overrides.team_id, 99999)
- GROUP BY person_distinct_id_overrides.distinct_id
- HAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 99999), greaterOrEquals(events.timestamp, assumeNotNull(toDateTime('2020-01-01 00:00:00', 'UTC'))), less(events.timestamp, plus(assumeNotNull(toDateTime('2020-01-10 00:00:00', 'UTC')), toIntervalSecond(86400))), equals(events.event, 'purchase'))),
- entity_metrics AS
- (SELECT exposures.entity_id AS entity_id,
- exposures.variant AS variant,
- sum(coalesce(accurateCastOrNull(metric_events.value, 'Float64'), 0)) AS value
- FROM exposures
- LEFT JOIN metric_events ON and(equals(exposures.entity_id, metric_events.entity_id), and(greaterOrEquals(toTimeZone(metric_events.timestamp, 'UTC'), exposures.first_exposure_time), less(toTimeZone(metric_events.timestamp, 'UTC'), plus(exposures.last_exposure_time, toIntervalSecond(86400)))))
- GROUP BY exposures.entity_id,
- exposures.variant)
- SELECT entity_metrics.variant AS variant,
- count(entity_metrics.entity_id) AS num_users,
- sum(entity_metrics.value) AS total_sum,
- sum(power(entity_metrics.value, 2)) AS total_sum_of_squares
- FROM entity_metrics
- GROUP BY entity_metrics.variant
- LIMIT 50000 SETTINGS join_algorithm='grace_hash',
- grace_hash_join_initial_buckets=2,
- load_balancing='in_order',
- readonly=2,
- max_execution_time=600,
- allow_experimental_object_type=1,
- max_ast_elements=4000000,
- max_expanded_ast_elements=4000000,
- max_bytes_before_external_group_by=39728447488,
- transform_null_in=1,
- optimize_min_equality_disjunction_chain_length=4294967295,
- allow_experimental_join_condition=1,
- use_hive_partitioning=0
- '''
-# ---
# name: TestExperimentMeanMetric.test_count_distinct_property_values_via_hogql_0_direct
'''
WITH exposures AS
diff --git a/products/replay_vision/backend/api/observations.py b/products/replay_vision/backend/api/observations.py
index cba18975156c..ebac37a093df 100644
--- a/products/replay_vision/backend/api/observations.py
+++ b/products/replay_vision/backend/api/observations.py
@@ -506,7 +506,7 @@ class SessionReplayObservationViewSet(ReplayObservationViewSet):
raise NotFound()
@extend_schema(exclude=True)
- @action(detail=True, methods=["GET"], url_path="progress")
+ @action(detail=True, methods=["GET"], url_path="progress", renderer_classes=[ServerSentEventRenderer])
def progress(self, request: Request, **kwargs: Any) -> StreamingHttpResponse:
"""Stream live progress (phase + rendering frame counts) for one in-flight observation as SSE.
diff --git a/products/replay_vision/backend/tests/test_api.py b/products/replay_vision/backend/tests/test_api.py
index da2d4a3804e5..6cc458dffdfa 100644
--- a/products/replay_vision/backend/tests/test_api.py
+++ b/products/replay_vision/backend/tests/test_api.py
@@ -4,6 +4,7 @@ from typing import Any
from posthog.test.base import APIBaseTest, ClickhouseTestMixin
from unittest.mock import MagicMock, patch
+from django.test import override_settings
from django.utils import timezone
from parameterized import parameterized
@@ -543,6 +544,21 @@ class TestReplayObservationViewSet(_VisionAPITestCase):
self.assertEqual(resp.status_code, 200)
self.assertEqual(len(resp.json()["results"]), 2)
+ @override_settings(SERVER_GATEWAY_INTERFACE="ASGI")
+ @patch("products.replay_vision.backend.api.observations.stream_observation_progress")
+ def test_progress_endpoint_accepts_event_stream_accept_header(self, mock_stream: MagicMock) -> None:
+ # The SSE client sends `Accept: text/event-stream`; without ServerSentEventRenderer on the action,
+ # DRF content negotiation rejects it with 406 before the view runs, so no progress ever reaches the
+ # page and it falls back to polling. Guard that the negotiated stream stays reachable.
+ mock_stream.return_value = iter(["event: observation-complete\ndata: {}\n\n"])
+ obs = self._create_observation(status=ObservationStatus.SUCCEEDED, completed_at=timezone.now())
+ url = f"/api/projects/{self.team.id}/vision/observations/{obs.id}/progress/"
+ resp = self.client.get(url, HTTP_ACCEPT="text/event-stream")
+ # A 406 here would mean content negotiation rejected the SSE Accept header before the view ran.
+ self.assertEqual(resp.status_code, 200)
+ self.assertEqual(resp["content-type"], "text/event-stream")
+ mock_stream.assert_called_once()
+
def test_malformed_scanner_id_returns_404(self) -> None:
resp = self.client.get(self.observations_url("not-a-uuid"))
self.assertEqual(resp.status_code, 404)
diff --git a/products/replay_vision/frontend/observations/ReplayObservation.tsx b/products/replay_vision/frontend/observations/ReplayObservation.tsx
index 29c2030d46be..3ae14cfcc454 100644
--- a/products/replay_vision/frontend/observations/ReplayObservation.tsx
+++ b/products/replay_vision/frontend/observations/ReplayObservation.tsx
@@ -100,7 +100,7 @@ export function ReplayObservationSceneComponent({ tabId }: { tabId: string }): J
const { observation, observationLoading } = useValues(observationLogic)
- if (observationLoading) {
+ if (observationLoading && !observation) {
return (
<SceneContent>
<SceneTitleSection name="Loading…" resourceType={{ type: 'replay_vision' }} />