: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): report no scan outcome before a request's scan starts (#115276)
Tue Haulund74a1ac5c9cb0
diff --git a/products/replay_vision/backend/api/observation_requests.py b/products/replay_vision/backend/api/observation_requests.pyindex d14746aba207..ff37a88e3f77 100644--- a/products/replay_vision/backend/api/observation_requests.py+++ b/products/replay_vision/backend/api/observation_requests.py@@ -22,7 +22,11 @@ from posthog.rate_limit import PersonalOrProjectSecretApiKeyRateThrottle, Projecfrom products.replay_vision.backend.api.errors import ReplayVisionErrorSerializerfrom products.replay_vision.backend.api.observations import ScannerResultSerializer-from products.replay_vision.backend.api.scanners import BulkObserveResultSerializer, InlineScanConfigSerializer+from products.replay_vision.backend.api.scanners import (+ BulkObserveResultSerializer,+ InlineScanConfigSerializer,+ ScanOutcome,+)from products.replay_vision.backend.consent import AI_CONSENT_REQUIRED_CODE, is_ai_data_processing_approvedfrom products.replay_vision.backend.models.replay_observation import ObservationStatus, ReplayObservationfrom products.replay_vision.backend.models.replay_observation_request import (@@ -117,6 +121,15 @@ class CreateObservationRequestSerializer(serializers.Serializer):class ObservationRequestSessionSerializer(BulkObserveResultSerializer):"""One session of a request: how it started and where it stands now."""+ scan_outcome = serializers.ChoiceField(+ choices=ScanOutcome.choices,+ allow_null=True,+ help_text=(+ "How the session's scan started, with the same values as a bulk scan trigger. Null while the "+ "request still waits for the session to end, or before its scan has started."+ ),+ )+state = serializers.ChoiceField(choices=RequestSessionState.choices,help_text=(diff --git a/products/replay_vision/backend/api/scanners.py b/products/replay_vision/backend/api/scanners.pyindex adbd24c636f1..0521aa07fc1f 100644--- a/products/replay_vision/backend/api/scanners.py+++ b/products/replay_vision/backend/api/scanners.py@@ -1316,6 +1316,16 @@ class BulkObserveRequestSerializer(serializers.Serializer):)+class ScanOutcome(models.TextChoices):+ STARTED = "started", "Started"+ ALREADY_RUNNING = "already_running", "Already running"+ ALREADY_SCANNED = "already_scanned", "Already scanned"+ SKIPPED_LIMIT = "skipped_limit", "Skipped, in-flight limit reached"+ SKIPPED_QUOTA = "skipped_quota", "Skipped, the org's credit quota for this period was reached"+ SKIPPED_SCANNER_LIMIT = "skipped_scanner_limit", "Skipped, scanner's own credit limit reached"+ FAILED = "failed", "Failed to start"++class BulkObserveResultSerializer(serializers.Serializer):"""Per-session outcome of a bulk scan trigger."""@@ -1323,15 +1333,7 @@ class BulkObserveResultSerializer(serializers.Serializer):# Named scan_outcome (not outcome) so its generated enum doesn't collide with other products'# `outcome` enums — a bare `outcome` ChoiceField forces the shared OutcomeEnum to be renamed.scan_outcome = serializers.ChoiceField(- choices=[- ("started", "Started"),- ("already_running", "Already running"),- ("already_scanned", "Already scanned"),- ("skipped_limit", "Skipped, in-flight limit reached"),- ("skipped_quota", "Skipped, the org's credit quota for this period was reached"),- ("skipped_scanner_limit", "Skipped, scanner's own credit limit reached"),- ("failed", "Failed to start"),- ],+ choices=ScanOutcome.choices,help_text=("'started' - a scan workflow was kicked off; 'already_running' - a scan for this session is ""already in flight (no-op, not recharged); 'already_scanned' - this scanner already has a "diff --git a/products/replay_vision/backend/observation_requests.py b/products/replay_vision/backend/observation_requests.pyindex 999aa6c4b670..331b5d95ea09 100644--- a/products/replay_vision/backend/observation_requests.py+++ b/products/replay_vision/backend/observation_requests.py@@ -98,7 +98,8 @@ class InlineScanSpec:@frozenclass RequestSession:session_id: str- scan_outcome: str+ # None until the session's scan has started.+ scan_outcome: str | Nonestate: RequestSessionStateobservation: ReplayObservation | None@@ -346,7 +347,7 @@ def _progress(state = RequestSessionState.PENDING if age < grace else RequestSessionState.FAILEDreturn RequestProgress(sessions=[- RequestSession(session_id=sid, scan_outcome="failed", state=state, observation=None)+ RequestSession(session_id=sid, scan_outcome=None, state=state, observation=None)for sid in request.session_ids])diff --git a/products/replay_vision/backend/tests/test_observation_requests_api.py b/products/replay_vision/backend/tests/test_observation_requests_api.pyindex af0d15cf34c0..63065f67b593 100644--- a/products/replay_vision/backend/tests/test_observation_requests_api.py+++ b/products/replay_vision/backend/tests/test_observation_requests_api.py@@ -189,7 +189,10 @@ class TestObservationRequestAPI(APIBaseTest):)self.assertEqual(response.status_code, 202, response.json())- self.assertEqual((response.json()["status"], response.json()["sessions"][0]["state"]), ("running", "pending"))+ session = response.json()["sessions"][0]+ self.assertEqual(+ (response.json()["status"], session["state"], session["scan_outcome"]), ("running", "pending", None)+ )self.start_workflow.assert_not_called()def test_inline_question_mints_a_hidden_scanner_and_reports_its_id(self) -> None:diff --git a/products/replay_vision/frontend/generated/api.schemas.ts b/products/replay_vision/frontend/generated/api.schemas.tsindex 4a17d241366d..95cea47935b1 100644--- a/products/replay_vision/frontend/generated/api.schemas.ts+++ b/products/replay_vision/frontend/generated/api.schemas.ts@@ -1093,7 +1093,7 @@ export const RequestSessionStateEnumApi = {export interface ObservationRequestSessionApi {/** The session recording this outcome is for. */session_id: string- /** 'started' - a scan workflow was kicked off; 'already_running' - a scan for this session is already in flight (no-op, not recharged); 'already_scanned' - this scanner already has a finished observation for this session, so nothing was started and nothing was charged (read it back, or use the retry action to run it again); 'skipped_limit' - the in-flight cap was reached before this session; 'skipped_quota' - the org's credit quota for this period would be exceeded; 'skipped_scanner_limit' - this scanner's own credit limit would be exceeded; 'failed' - the workflow failed to start.+ /** How the session's scan started, with the same values as a bulk scan trigger. Null while the request still waits for the session to end, or before its scan has started.** * `started` - Started* * `already_running` - Already running@@ -1102,7 +1102,7 @@ export interface ObservationRequestSessionApi {* * `skipped_quota` - Skipped, the org's credit quota for this period was reached* * `skipped_scanner_limit` - Skipped, scanner's own credit limit reached* * `failed` - Failed to start */- scan_outcome: ScanOutcomeEnumApi+ scan_outcome: ScanOutcomeEnumApi | null/** Where the session stands now. 'pending' and 'running' are still in progress; 'succeeded' has a result; 'failed' and 'ineligible' finished without one; 'skipped' never started because a limit was reached (`scan_outcome` names which); 'lost' started but produced nothing before the scan timed out.** * `pending` - Pendingdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 0110cb0a32a0..d8547ec7c631 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -67215,7 +67215,7 @@ export namespace Schemas {export interface ObservationRequestSession {/** The session recording this outcome is for. */session_id: string;- /** 'started' - a scan workflow was kicked off; 'already_running' - a scan for this session is already in flight (no-op, not recharged); 'already_scanned' - this scanner already has a finished observation for this session, so nothing was started and nothing was charged (read it back, or use the retry action to run it again); 'skipped_limit' - the in-flight cap was reached before this session; 'skipped_quota' - the org's credit quota for this period would be exceeded; 'skipped_scanner_limit' - this scanner's own credit limit would be exceeded; 'failed' - the workflow failed to start.+ /** How the session's scan started, with the same values as a bulk scan trigger. Null while the request still waits for the session to end, or before its scan has started.** * `started` - Started* * `already_running` - Already running@@ -67224,7 +67224,7 @@ export namespace Schemas {* * `skipped_quota` - Skipped, the org's credit quota for this period was reached* * `skipped_scanner_limit` - Skipped, scanner's own credit limit reached* * `failed` - Failed to start */- scan_outcome: ScanOutcomeEnum;+ scan_outcome: ScanOutcomeEnum | null;/** Where the session stands now. 'pending' and 'running' are still in progress; 'succeeded' has a result; 'failed' and 'ineligible' finished without one; 'skipped' never started because a limit was reached (`scan_outcome` names which); 'lost' started but produced nothing before the scan timed out.** * `pending` - Pending