: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): keep thumbnails off the unstyled edges of the video (#105930)
Tue Haulund6720a1cb044d
diff --git a/products/replay_vision/backend/temporal/activities/call_scanner_provider.py b/products/replay_vision/backend/temporal/activities/call_scanner_provider.pyindex 3d71fc800b4a..74ef529a3d39 100644--- a/products/replay_vision/backend/temporal/activities/call_scanner_provider.py+++ b/products/replay_vision/backend/temporal/activities/call_scanner_provider.py@@ -327,20 +327,12 @@ async def run_scan(model_output=finalized,signals=signals,verification=outcome.verification,- thumbnail_video_s=_clamp_thumbnail(outcome.thumbnail_video_s, video_clock, duration_ms),+ thumbnail_video_s=outcome.thumbnail_video_s,# Read off `outcome.signals`, which is still on the video clock; `signals` above is not.signal_video_spans=[(s.start_time, s.end_time) for s in outcome.signals],)-def _clamp_thumbnail(thumbnail_video_s: int | None, video_clock: VideoClock, duration_ms: int) -> int | None:- """Hold the model's pick inside the rendered video, which is shorter than the session wherever the render cut."""- if thumbnail_video_s is None:- return None- ceiling = video_clock.video_duration_s if video_clock.video_duration_s is not None else duration_ms / 1000- return max(0, min(thumbnail_video_s, int(ceiling)))--def _scan_trace_id(inputs: CallScannerProviderInputs) -> str:"""LLM analytics trace id for one scan: the observation id, so every step, tool round-trip, and retry ofa scan reads as a single conversation and the observation id doubles as the trace search key. Evaluationdiff --git a/products/replay_vision/backend/temporal/activities/observation_media.py b/products/replay_vision/backend/temporal/activities/observation_media.pyindex f876ec01d8ac..43418d525baa 100644--- a/products/replay_vision/backend/temporal/activities/observation_media.py+++ b/products/replay_vision/backend/temporal/activities/observation_media.py@@ -31,8 +31,8 @@ from products.replay_vision.backend.temporal.video_clock import VideoClock, videlogger = structlog.get_logger(__name__)_MEDIA_EXPIRY = timedelta(days=90)-# ffmpeg writes no frame when the seek lands past the end of the video.-_END_MARGIN_S = 0.5+# The first and last seconds of an analysis video show the page before its CSS applies or while it unloads.+_EDGE_MARGIN_S = 3.0def _media_key_prefix(team_id: int, observation_id: Any) -> str:@@ -63,7 +63,9 @@ def _pick_video_time_s(picked = (start + end) / 2if picked is None:picked = duration_s * FALLBACK_THUMBNAIL_FRACTION- return max(0.0, min(picked, max(0.0, duration_s - _END_MARGIN_S)))+ if duration_s <= 2 * _EDGE_MARGIN_S:+ return duration_s / 2+ return min(max(picked, _EDGE_MARGIN_S), duration_s - _EDGE_MARGIN_S)@activity.defndiff --git a/products/replay_vision/backend/temporal/scanners/prompts/_macros.jinja b/products/replay_vision/backend/temporal/scanners/prompts/_macros.jinjaindex 3a3cf790b9b5..54734a3e4108 100644--- a/products/replay_vision/backend/temporal/scanners/prompts/_macros.jinja+++ b/products/replay_vision/backend/temporal/scanners/prompts/_macros.jinja@@ -15,5 +15,5 @@ Separately from your answer above, judge the session itself: in `notability_reas{# The poster frame, asked in the core turn: a turn of its own costs a full conversation re-send per scan. Call as `{{ pick_media() }}`. #}{%- macro pick_media() -%}-Last, pick the single frame that best illustrates what you found, so a person scanning a list of recordings can tell at a glance what this one is about, and give it in `thumbnail_t` in whole seconds of video time, the same scale you cite moments in, not the footer's `REC_T`. Pick a frame where the screen shows the thing itself: the error, the broken layout, the step the user was stuck on, the page your answer is about. Avoid a blank page, a full-page spinner, a modal backdrop mid-fade, and the first seconds of the recording, which are usually still loading. When nothing stands out, pick a moment where the user was clearly doing something rather than the start of the video.+Last, pick the single frame that best illustrates what you found, so a person scanning a list of recordings can tell at a glance what this one is about, and give it in `thumbnail_t` in whole seconds of video time, the same scale you cite moments in, not the footer's `REC_T`. Pick a frame where the screen shows the thing itself: the error, the broken layout, the step the user was stuck on, the page your answer is about. Avoid a blank page, a full-page spinner, a modal backdrop mid-fade, and the first and last seconds of the recording, which usually show the page loading or unloading. When nothing stands out, pick a moment where the user was clearly doing something rather than the start of the video.{%- endmacro -%}diff --git a/products/replay_vision/backend/tests/test_call_scanner_provider.py b/products/replay_vision/backend/tests/test_call_scanner_provider.pyindex 9131b0d82f6a..661a6bfa10aa 100644--- a/products/replay_vision/backend/tests/test_call_scanner_provider.py+++ b/products/replay_vision/backend/tests/test_call_scanner_provider.py@@ -19,7 +19,6 @@ from posthog.dataclasses import frozenfrom products.replay_vision.backend.models.replay_scanner import ScannerTypefrom products.replay_vision.backend.temporal.activities.call_scanner_provider import (- _clamp_thumbnail,_maybe_create_video_cache,_MissionOutcome,_remaining_verify_budget_seconds,@@ -913,17 +912,3 @@ async def test_video_cache_creation_is_best_effort() -> None:cast(Any, _BoomClient()), "models/gemini-3-flash-preview", _VIDEO, "PRE", tools=[events_tool()])assert result is None--- "picked,expected",- [- (None, None),- (5, 5),- (40, 30),- (-3, 0),- ],-)-def test_the_thumbnail_pick_is_held_inside_the_rendered_video(picked: int | None, expected: int | None) -> None:- # A seek past the end makes ffmpeg exit 0 with no frame, which would leave the observation without a poster.- assert _clamp_thumbnail(picked, _IDENTITY_CLOCK, duration_ms=30_000) == expecteddiff --git a/products/replay_vision/backend/tests/test_observation_media.py b/products/replay_vision/backend/tests/test_observation_media.pyindex e52b8325e266..88d20a7bd4f1 100644--- a/products/replay_vision/backend/tests/test_observation_media.py+++ b/products/replay_vision/backend/tests/test_observation_media.py@@ -24,6 +24,7 @@ from products.replay_vision.backend.models.replay_observation import (from products.replay_vision.backend.models.replay_observation_media import ReplayObservationMediafrom products.replay_vision.backend.models.replay_scanner import ReplayScanner, ScannerModel, ScannerTypefrom products.replay_vision.backend.temporal.activities.observation_media import (+ _pick_video_time_s,finalize_observation_thumbnail_activity,prepare_observation_thumbnail_activity,)@@ -283,3 +284,21 @@ class TestObservationMediaSerialization(BaseTest):assert [entry["id"] for entry in media] == [ready.id]assert media[0]["asset_id"] == ready.asset_idassert media[0]["video_start_ms"] == 1000+++ "thumbnail_video_s,model_output,duration_s,expected_s",+ [+ (0, None, 100.0, 3.0),+ (500, None, 100.0, 97.0),+ (None, {"summary_segments": [{"kind": "chip", "timestamp_ms": 0}]}, 100.0, 3.0),+ (1, None, 4.0, 2.0),+ ],+)+def test_the_thumbnail_moment_stays_off_the_unstyled_edges_of_the_video(+ thumbnail_video_s: int | None, model_output: dict[str, Any] | None, duration_s: float, expected_s: float+) -> None:+ inputs = ObservationMediaInputs(+ team_id=1, observation_id=uuid7(), session_id="s", analysis_asset_id=1, thumbnail_video_s=thumbnail_video_s+ )+ assert _pick_video_time_s(inputs, model_output, None, duration_s) == expected_s