: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
refactor(replay): keep idle out of chapters and list inactive periods (#110349)
Tue Haulund45e187b93453
diff --git a/products/replay_vision/backend/temporal/scanners/prompts/summarizer_summary_step.jinja b/products/replay_vision/backend/temporal/scanners/prompts/summarizer_summary_step.jinjaindex 5cfeeda61042..f52e454b4a5a 100644--- a/products/replay_vision/backend/temporal/scanners/prompts/summarizer_summary_step.jinja+++ b/products/replay_vision/backend/temporal/scanners/prompts/summarizer_summary_step.jinja@@ -7,11 +7,7 @@ Additional context from the team operating the product being recorded:{{ cite_in('summary') }}-Then break the whole recording down into `chapters`: the distinct parts of what the user did, in order, from the start of the video to its end. A new chapter starts where the user moves on to something else: a new page, a new task, a change of approach, or a different section or feature of the same page. Aim for about {{ chapter_target }} chapters when the session has that many distinct parts, and never split where nothing changes on screen. A long stretch on one page still splits by what the user reads or does there, and no chapter should cover several minutes of varied activity with a generic heading like "Browses page". Each chapter gives the video second it starts at, a heading of a few words, and the frame that best shows it. The chapters describe the recording as it happened, even when the context above asks the summary to focus on one area.{% if long_idle_breaks %}--The user was idle for a long time at these points, and the idle time is cut from the video, so the video jumps straight past it. Start a new chapter at each of these video seconds:-{% for idle_break in long_idle_breaks %}{% set minutes = (idle_break.idle_s / 60) | round | int %}- video second {{ idle_break.video_s }}, after about {{ minutes }} minute{{ "" if minutes == 1 else "s" }} idle-{% endfor %}{% endif %}+Then break the whole recording down into `chapters`: the distinct parts of what the user did, in order, from the start of the video to its end. A new chapter starts where the user moves on to something else: a new page, a new task, a change of approach, or a different section or feature of the same page. Aim for about {{ chapter_target }} chapters when the session has that many distinct parts, and never split where nothing changes on screen. Keep each chapter at least about 20 seconds long, except a notable moment. A long stretch on one page still splits by what the user reads or does there, and no chapter should cover several minutes of varied activity with a generic heading like "Browses page". Each chapter gives the video second it starts at, a heading of a few words, and the frame that best shows it. The chapters describe the recording as it happened, even when the context above asks the summary to focus on one area.{{ rate_notability() }}diff --git a/products/replay_vision/backend/temporal/scanners/summarizer.py b/products/replay_vision/backend/temporal/scanners/summarizer.pyindex d99982bbfb6e..9f5612d45cf8 100644--- a/products/replay_vision/backend/temporal/scanners/summarizer.py+++ b/products/replay_vision/backend/temporal/scanners/summarizer.py@@ -5,8 +5,6 @@ from typing import Any, ClassVar, Literal, Selffrom pydantic import BaseModel, Field, field_validator-from posthog.dataclasses import frozen-from products.replay_vision.backend.models.replay_scanner import ScannerTypefrom products.replay_vision.backend.temporal.scanners.base import (BaseScanner,@@ -20,7 +18,7 @@ from products.replay_vision.backend.temporal.scanners.base import (strip_citation_markers,thumbnail_field,)-from products.replay_vision.backend.temporal.video_clock import IdleStretch, VideoClock+from products.replay_vision.backend.temporal.video_clock import VideoClockSummaryLength = Literal["short", "medium", "long"]@@ -84,17 +82,15 @@ class SummaryChapterResponse(BaseModel, frozen=True):return cleaned[: CHAPTER_TITLE_MAX_LENGTH + 1].rsplit(" ", 1)[0].rstrip(" ,;:-")-IDLE_CHAPTER_TITLE = "Idle"-# A shorter pause is part of whatever the user was doing around it, so it stays inside that chapter.-LONG_IDLE_MS = 60_000-MAX_IDLE_CHAPTERS = 10+# A boundary the model put this close to a cut was meant for the cut, because whole video seconds cannot hit it exactly.+CUT_SNAP_S = 3.0class SummaryChapter(BaseModel, frozen=True):- """One persisted chapter, on the session clock the player seeks to; chapters tile the recording in order.+ """One persisted chapter, on the session clock the player seeks to; chapters are in order and never overlap.- An `idle` chapter is a stretch of at least `LONG_IDLE_MS` the player marked inactive. It comes from the render,- never from the model, and has no thumbnail because the analysis video cut it out.+ Inactive time between chapters is a gap, listed in `SummarizerOutput.inactive_periods`. Chapters stored+ before that list existed can carry `kind: idle` entries, which readers skip."""kind: Literal["activity", "idle"] = "activity"@@ -104,6 +100,13 @@ class SummaryChapter(BaseModel, frozen=True):thumbnail_ms: int | None = Field(default=None, ge=0)+class InactivePeriod(BaseModel, frozen=True):+ """A stretch the replay player marked inactive, which the analysis video cut out."""++ start_ms: int = Field(ge=0)+ end_ms: int = Field(ge=0)++class SummarizerSummaryResponse(BaseModel, frozen=True):"""The core turn: title + body summary. Field order is load-bearing — `confidence` last, after the content."""@@ -139,6 +142,7 @@ class SummarizerOutput(BaseScannerOutput, frozen=True):summary: str = ""summary_segments: list[Segment] = Field(default_factory=list)chapters: list[SummaryChapter] = Field(default_factory=list)+ inactive_periods: list[InactivePeriod] = Field(default_factory=list)def embedding_document(self) -> EmbeddingDocument | None:text = summary_embedding_text(self)@@ -148,6 +152,7 @@ class SummarizerOutput(BaseScannerOutput, frozen=True):# A count is enough to chart adoption, and the full list would make every event carry the whole breakdown.properties = super().to_event_properties()del properties["scanner_output_chapters"]+ del properties["scanner_output_inactive_periods"]properties["scanner_output_chapter_count"] = len(self.chapters)return properties@@ -160,155 +165,52 @@ def summary_embedding_text(output: SummarizerOutput) -> str:def resolve_chapters(chapters: Sequence[SummaryChapterResponse], duration_ms: int, clock: VideoClock) -> list[SummaryChapter]:- """Repair the model's chapters into an ordered list that tiles the recording, on the session clock.+ """Repair the model's chapters into an ordered list over the active time, on the session clock.A malformed breakdown is repaired rather than re-prompted, because a re-prompt bills the whole conversation- again for a field the scan does not depend on. Each chapter ends where the next one starts, so the list can- have neither gaps nor overlaps. The stretches the player marked inactive are then cut out into idle chapters.+ again for a field the scan does not depend on. Chapters tile the video, which has the inactive time cut out.+ A boundary near a cut snaps onto it, so on the session clock the inactive time falls between two chapters."""video_end_s = clock.citable_duration_s(duration_ms / 1000)if not video_end_s:return []- starts: dict[int, SummaryChapterResponse] = {}+ cuts = clock.cuts_video_s()+ starts: dict[float, SummaryChapterResponse] = {}# A negative start clamps to 0, and a start at or past the video's end is a time the model invented, which# would make an empty chapter.for chapter in chapters:- if chapter.start_t is not None and chapter.title and chapter.start_t < video_end_s:- starts.setdefault(max(0, chapter.start_t), chapter)+ if chapter.start_t is None or not chapter.title or chapter.start_t >= video_end_s:+ continue+ start_s = float(max(0, chapter.start_t))+ nearest_cut = min(cuts, key=lambda cut: abs(cut - start_s), default=None)+ # The first chapter starts at 0 regardless, so snapping a 0 start would only collide it with the next one.+ if start_s > 0 and nearest_cut is not None and abs(nearest_cut - start_s) <= CUT_SNAP_S:+ start_s = nearest_cut+ starts.setdefault(start_s, chapter)kept = sorted(starts.items())[:MAX_CHAPTERS]if not kept:return []resolved: list[SummaryChapter] = []- for index, (start_t, chapter) in enumerate(kept):- start_s = 0.0 if index == 0 else float(start_t)- end_s = float(kept[index + 1][0]) if index + 1 < len(kept) else video_end_s- thumbnail_t = chapter.thumbnail_t- # A pick outside its chapter is dropped here, and `_split_out_idle` falls back to the midpoint.- thumbnail_ms = (- clock.video_s_to_session_ms(thumbnail_t)- if thumbnail_t is not None and start_s <= thumbnail_t < end_s- else None- )+ for index, (start_s, chapter) in enumerate(kept):+ start_s = 0.0 if index == 0 else start_s+ end_s = kept[index + 1][0] if index + 1 < len(kept) else video_end_s+ start_ms, end_ms = clock.video_s_to_session_ms(start_s), clock.video_end_s_to_session_ms(end_s)+ # Checked on the session clock, because a video second at a cut can map onto the chapter's exclusive end.+ thumbnail_ms = clock.video_s_to_session_ms(chapter.thumbnail_t) if chapter.thumbnail_t is not None else None+ if thumbnail_ms is None or not start_ms <= thumbnail_ms < end_ms:+ thumbnail_ms = clock.video_s_to_session_ms((start_s + end_s) / 2)resolved.append(- SummaryChapter(- # Pinned, because the render's first kept stretch can start after the session does.- start_ms=0 if index == 0 else clock.video_s_to_session_ms(start_s),- # The last chapter runs to the end of the session, which can be past the video's end when the render cut trailing inactivity.- end_ms=clock.video_s_to_session_ms(end_s) if index + 1 < len(kept) else duration_ms,- title=chapter.title,- thumbnail_ms=thumbnail_ms,- )- )- return _split_out_idle(resolved, _long_idle(clock, duration_ms))---@frozen-class IdleBreak:- """A long idle stretch as the prompt names it: where the video resumes, and how long the user was away."""-- video_s: int- idle_s: int---def long_idle_breaks(clock: VideoClock, duration_ms: int) -> tuple[IdleBreak, ...]:- """One break per long idle between two stretches of activity.-- Idle at the very start or end of the session has no activity on one side, so it cannot split a chapter.- """- return tuple(- IdleBreak(- video_s=int(clock.session_ms_to_video_s(stretch.end_ms)),- idle_s=(stretch.end_ms - stretch.start_ms) // 1000,+ SummaryChapter(start_ms=start_ms, end_ms=end_ms, title=chapter.title, thumbnail_ms=thumbnail_ms))- for stretch in _long_idle(clock, duration_ms)- if stretch.start_ms > 0 and stretch.end_ms < duration_ms- )---def _long_idle(clock: VideoClock, duration_ms: int) -> list[IdleStretch]:- """The long idle stretches, at most the `MAX_IDLE_CHAPTERS` longest, in order.-- Each one adds an idle chapter and can split another, so the bound keeps the timeline and its frames bounded.- """- long_idle = [s for s in clock.inactive_session_ms(duration_ms) if s.end_ms - s.start_ms >= LONG_IDLE_MS]- longest = sorted(long_idle, key=lambda s: s.start_ms - s.end_ms)[:MAX_IDLE_CHAPTERS]- return sorted(longest, key=lambda s: s.start_ms)---# The model cites whole video seconds, so a boundary it meant to put at a cut can land a second or two past it.-_MIN_ACTIVITY_FRAGMENT_MS = 3_000---@frozen(frozen=False)-class _Piece:- """A stretch of the session while idle stretches are cut out; `source` is None for an idle one."""+ return resolved- start_ms: int- end_ms: int- source: SummaryChapter | None- # True for a piece an idle stretch cut off a chapter; a whole chapter is never merged away, however short.- fragment: bool = False--def _split_out_idle(chapters: list[SummaryChapter], idle: list[IdleStretch]) -> list[SummaryChapter]:- """Cut each inactive stretch out of the chapters it overlaps and put an idle chapter in its place.-- A chapter that an idle stretch splits keeps its title on both sides. A fragment too short to be a real- part of the session joins the neighbouring activity chapter, or the idle stretch when it has none.- """- pieces: list[_Piece] = []- for chapter in chapters:- cursor = chapter.start_ms- cut = False- for stretch in idle:- start, end = max(stretch.start_ms, chapter.start_ms), min(stretch.end_ms, chapter.end_ms)- if end <= start:- continue- if start > cursor:- pieces.append(_Piece(start_ms=cursor, end_ms=start, source=chapter, fragment=True))- pieces.append(_Piece(start_ms=start, end_ms=end, source=None))- cursor, cut = end, True- if cursor < chapter.end_ms:- pieces.append(_Piece(start_ms=cursor, end_ms=chapter.end_ms, source=chapter, fragment=cut))-- index = 0- while index < len(pieces):- piece = pieces[index]- if not piece.fragment or piece.end_ms - piece.start_ms >= _MIN_ACTIVITY_FRAGMENT_MS:- index += 1- continue- before = pieces[index - 1] if index > 0 else None- after = pieces[index + 1] if index + 1 < len(pieces) else None- if after is not None and after.source is not None:- after.start_ms = piece.start_ms- elif before is not None and before.source is not None:- before.end_ms = piece.end_ms- else:- piece.source = None- index += 1- continue- pieces.pop(index)-- resolved: list[SummaryChapter] = []- for piece in pieces:- if piece.source is None:- if resolved and resolved[-1].kind == "idle":- resolved[-1] = resolved[-1].model_copy(update={"end_ms": piece.end_ms})- else:- resolved.append(- SummaryChapter(kind="idle", start_ms=piece.start_ms, end_ms=piece.end_ms, title=IDLE_CHAPTER_TITLE)- )- continue- thumbnail_ms = piece.source.thumbnail_ms- if thumbnail_ms is None or not piece.start_ms <= thumbnail_ms < piece.end_ms:- thumbnail_ms = (piece.start_ms + piece.end_ms) // 2- resolved.append(- SummaryChapter(- start_ms=piece.start_ms, end_ms=piece.end_ms, title=piece.source.title, thumbnail_ms=thumbnail_ms- )- )- return resolved+def inactive_periods(clock: VideoClock, duration_ms: int) -> list[InactivePeriod]:+ return [+ InactivePeriod(start_ms=stretch.start_ms, end_ms=stretch.end_ms)+ for stretch in clock.inactive_session_ms(duration_ms)+ ]class SummarizerScanner(BaseScanner, frozen=True):@@ -317,10 +219,8 @@ class SummarizerScanner(BaseScanner, frozen=True):citation_fields: ClassVar[tuple[str, ...]] = ("summary",)output_cls: ClassVar[type[BaseScannerOutput]] = SummarizerOutputlength: SummaryLength = "medium"- # (video second the video resumes at, idle seconds) per long idle stretch, set per session before the scan runs.- long_idle_breaks: tuple[IdleBreak, ...] = ()chapter_target: int = MIN_CHAPTER_TARGET- session_fields: ClassVar[frozenset[str]] = frozenset({"long_idle_breaks", "chapter_target"})+ session_fields: ClassVar[frozenset[str]] = frozenset({"chapter_target"})@propertydef llm_response_schema(self) -> type[BaseModel]:@@ -329,17 +229,13 @@ class SummarizerScanner(BaseScanner, frozen=True):def prompt_context(self) -> dict[str, Any]:return {"length_guidance": _LENGTH_GUIDANCE[self.length],- "long_idle_breaks": self.long_idle_breaks,"chapter_target": self.chapter_target,}def bind_session(self, clock: VideoClock, duration_ms: int) -> Self:- # The video has the idle time cut out, so the model cannot see a long break unless the prompt names it.+ # The video is the active time only, so the target follows how much the user did, not how long the tab was open.return self.model_copy(- update={- "long_idle_breaks": long_idle_breaks(clock, duration_ms),- "chapter_target": chapter_target(clock.citable_duration_s(duration_ms / 1000) or 0),- }+ update={"chapter_target": chapter_target(clock.citable_duration_s(duration_ms / 1000) or 0)})def resolve_session_clock(@@ -348,7 +244,12 @@ class SummarizerScanner(BaseScanner, frozen=True):if not isinstance(output, SummarizerOutput):return outputchapters = getattr(core_response, "chapters", ())- return output.model_copy(update={"chapters": resolve_chapters(chapters, duration_ms, clock)})+ return output.model_copy(+ update={+ "chapters": resolve_chapters(chapters, duration_ms, clock),+ "inactive_periods": inactive_periods(clock, duration_ms),+ }+ )def finalize(self, llm_response: BaseModel) -> BaseScannerOutput:# Chapters join the output in the provider activity, which holds the clock that moves them onto session time.diff --git a/products/replay_vision/backend/temporal/video_clock.py b/products/replay_vision/backend/temporal/video_clock.pyindex a8c289f765af..05c47baff9a9 100644--- a/products/replay_vision/backend/temporal/video_clock.py+++ b/products/replay_vision/backend/temporal/video_clock.py@@ -65,6 +65,30 @@ class VideoClock:def video_s_to_session_ms(self, video_s: float) -> int:return int(self._project(video_s, to_video=False) * 1000)+ def video_end_s_to_session_ms(self, video_s: float) -> int:+ """Where a range that ends at `video_s` ends on the session clock.++ A second shared across a cut resolves to the earlier stretch here, so a range that stops at a cut ends+ where the user went idle rather than where they came back.+ """+ if self.is_identity:+ return int(video_s * 1000)+ for index, span in enumerate(self.spans):+ if video_s <= span.video_to_s:+ # A range ending at a cut, or in the frame the cut costs, ends with the stretch before the cut.+ if video_s <= span.video_from_s and index > 0:+ return int(self.spans[index - 1].session_to_s * 1000)+ return int((span.session_from_s + max(0.0, video_s - span.video_from_s)) * 1000)+ return int(self.spans[-1].session_to_s * 1000)++ def cuts_video_s(self) -> list[float]:+ """The video seconds where the render cut inactive time, so the video jumps forward on the session clock."""+ return [+ later.video_from_s+ for earlier, later in zip(self.spans, self.spans[1:])+ if later.session_from_s > earlier.session_to_s+ ]+def inactive_session_ms(self, duration_ms: int) -> list[IdleStretch]:"""The inactive stretches, clipped to the session, in order and merged where they touch."""merged: list[IdleStretch] = []diff --git a/products/replay_vision/backend/tests/test_scanners.py b/products/replay_vision/backend/tests/test_scanners.pyindex b2562e6bd082..a57a206abcd0 100644--- a/products/replay_vision/backend/tests/test_scanners.py+++ b/products/replay_vision/backend/tests/test_scanners.py@@ -29,7 +29,6 @@ from products.replay_vision.backend.temporal.scanners.base import (SignalsResponse,)from products.replay_vision.backend.temporal.scanners.summarizer import (- IdleBreak,SummaryChapter,SummaryChapterResponse,chapter_target,@@ -783,17 +782,6 @@ class TestSummarizerScannerSteps:scanner = SummarizerScanner(prompt="p", chapter_target=chapter_target(video_s))assert f"Aim for about {expected} chapters" in scanner.core_steps()[0].instruction- def test_summary_step_names_the_long_idle_breaks_the_video_cut(self) -> None:- scanner = SummarizerScanner(prompt="p")- assert "idle for a long time" not in scanner.core_steps()[0].instruction-- with_breaks = scanner.model_copy(- update={"long_idle_breaks": (IdleBreak(video_s=92, idle_s=240), IdleBreak(video_s=300, idle_s=70))}- )- instruction = with_breaks.core_steps()[0].instruction- assert "video second 92, after about 4 minutes idle" in instruction- assert "video second 300, after about 1 minute idle" in instruction-def test_summary_step_opts_into_citations(self) -> None:scanner = scanner_from_db(_build_replay_scanner(scanner_type=ScannerType.SUMMARIZER, scanner_config={"prompt": "p"})diff --git a/products/replay_vision/backend/tests/test_video_clock.py b/products/replay_vision/backend/tests/test_video_clock.pyindex 98769c4aed77..cb01f908a74e 100644--- a/products/replay_vision/backend/tests/test_video_clock.py+++ b/products/replay_vision/backend/tests/test_video_clock.py@@ -1,4 +1,3 @@-from dataclasses import replacefrom types import SimpleNamespaceimport pytest@@ -14,9 +13,11 @@ from products.replay_vision.backend.temporal.activities.call_scanner_provider imfrom products.replay_vision.backend.temporal.errors import ScannerFailureErrorfrom products.replay_vision.backend.temporal.scanners.base import ChipSegmentfrom products.replay_vision.backend.temporal.scanners.summarizer import (- IdleBreak,+ InactivePeriod,+ SummarizerOutput,+ SummarizerScanner,+ SummarizerSummaryResponse,SummaryChapterResponse,- long_idle_breaks,resolve_chapters,)from products.replay_vision.backend.temporal.video_clock import (@@ -112,20 +113,25 @@ class TestMissingCutMapIsRefusedUnlessProvablyUncut:self._load(export_context, session_duration_s)-def test_the_first_chapter_starts_with_the_session_when_the_render_starts_later() -> None:- clock = VideoClock(- spans=(ActiveSpan(session_from_s=0.333, session_to_s=60.0, video_from_s=0.0, video_to_s=59.667),)- )- resolved = resolve_chapters([_chapter(0, "Browses")], 60_000, clock)- assert (resolved[0].start_ms, resolved[0].end_ms) == (0, 60_000)+def _chapter(start_t: int, title: str = "Part", thumbnail_t: int | None = None) -> SummaryChapterResponse:+ return SummaryChapterResponse(start_t=start_t, title=title, thumbnail_t=thumbnail_t)-def test_only_long_idle_between_activity_is_named_to_the_model() -> None:- clock = VideoClock(spans=(), inactive=((0, 90), (100, 130), (200, 300), (320, 400)))- assert long_idle_breaks(clock, 400_000) == (IdleBreak(video_s=300, idle_s=100),)- # Only the longest stretches count, so a session of many long idles keeps a bounded timeline.- many = VideoClock(spans=(), inactive=tuple((i * 200 + 10, i * 200 + 70 + i) for i in range(15)))- assert [b.video_s for b in long_idle_breaks(many, 3_100_000)] == [i * 200 + 70 + i for i in range(5, 15)]+def test_inactive_time_at_the_ends_is_left_out_of_the_chapters_and_listed_as_inactive() -> None:+ clock = VideoClock(+ spans=(ActiveSpan(session_from_s=10.0, session_to_s=60.0, video_from_s=0.0, video_to_s=50.0),),+ inactive=((0.0, 10.0), (60.0, 70.0)),+ )+ core = SummarizerSummaryResponse(title="t", summary="s", confidence=0.9, chapters=[_chapter(0, "Browses")])+ output = SummarizerScanner(prompt="p").resolve_session_clock(+ SummarizerOutput(title="t", summary="s", confidence=0.9), core, clock, 70_000+ )+ assert isinstance(output, SummarizerOutput)+ assert [(c.start_ms, c.end_ms) for c in output.chapters] == [(10_000, 60_000)]+ assert output.inactive_periods == [+ InactivePeriod(start_ms=0, end_ms=10_000),+ InactivePeriod(start_ms=60_000, end_ms=70_000),+ ]def test_the_players_inactive_periods_are_the_idle_stretches() -> None:@@ -155,138 +161,88 @@ class TestCitationsPastTheVideoEnd:assert [s.timestamp_ms for s in segments if isinstance(s, ChipSegment)] == [80_000]-def _chapter(start_t: int, title: str = "Part", thumbnail_t: int | None = None) -> SummaryChapterResponse:- return SummaryChapterResponse(start_t=start_t, title=title, thumbnail_t=thumbnail_t)--class TestResolveChapters:+ def test_a_start_at_0_never_snaps_so_it_cannot_swallow_a_chapter_that_snaps_onto_an_early_cut(self) -> None:+ clock = VideoClock(+ spans=(+ ActiveSpan(session_from_s=0.0, session_to_s=2.0, video_from_s=0.0, video_to_s=2.0),+ ActiveSpan(session_from_s=30.0, session_to_s=60.0, video_from_s=2.0, video_to_s=32.0),+ )+ )+ resolved = resolve_chapters([_chapter(0, "Loads"), _chapter(3, "Buys")], 60_000, clock)+ assert [(c.start_ms, c.end_ms, c.title) for c in resolved] == [(0, 2_000, "Loads"), (30_000, 60_000, "Buys")]++ def test_a_cut_that_costs_a_video_frame_still_ends_the_chapter_where_the_user_went_idle(self) -> None:+ clock = VideoClock(+ spans=(+ ActiveSpan(session_from_s=0.0, session_to_s=58.0, video_from_s=0.0, video_to_s=58.0),+ ActiveSpan(session_from_s=62.0, session_to_s=80.0, video_from_s=59.0, video_to_s=77.0),+ )+ )+ resolved = resolve_chapters([_chapter(0, "Browses", 58), _chapter(60, "Buys")], 80_000, clock)+ assert [(c.start_ms, c.end_ms) for c in resolved] == [(0, 58_000), (62_000, 80_000)]+ # Video second 58 is where the user went idle, the first chapter's exclusive end, so the frame falls back.+ assert resolved[0].thumbnail_ms == 29_500+@parameterized.expand([(- "chapters tile the session, and a start after the cut moves onto the session clock",+ "a boundary near a cut snaps onto it, so the inactive time falls between chapters",[_chapter(0, "Opens the app", 10), _chapter(30, "Edits a form", 40), _chapter(60, "Saves", 70)],[(0, 30_000, "Opens the app", 10_000),- (30_000, 64_000, "Edits a form", 40_000),- (64_000, 80_000, "Saves", 74_000),+ (30_000, 58_000, "Edits a form", 40_000),+ (62_000, 80_000, "Saves", 74_000),],),+ (+ "a boundary just before a cut snaps onto it too",+ [_chapter(0, "Browses"), _chapter(56, "Buys")],+ [(0, 58_000, "Browses", 29_000), (62_000, 80_000, "Buys", 71_000)],+ ),+ (+ "a boundary far from a cut stays, and the inactive time sits inside its chapter",+ [_chapter(0, "Browses"), _chapter(52, "Buys")],+ [(0, 52_000, "Browses", 26_000), (52_000, 80_000, "Buys", 68_000)],+ ),("out of order input is sorted and a repeated start keeps the first chapter",[_chapter(30, "Second"), _chapter(0, "First"), _chapter(30, "Duplicate")],- [(0, 30_000, "First", 15_000), (30_000, 80_000, "Second", 55_000)],+ [(0, 30_000, "First", 15_000), (30_000, 80_000, "Second", 53_000)],),(- "the first chapter starts at 0 even when the model skipped the page load",+ "the first chapter starts at the start of the video even when the model skipped the page load",[_chapter(5, "Only part", 20)],[(0, 80_000, "Only part", 20_000)],),("a start at or past the video's end is invented and dropped",[_chapter(0, "Real"), _chapter(76, "Invented"), _chapter(900, "Invented")],- [(0, 80_000, "Real", 40_000)],+ [(0, 80_000, "Real", 38_000)],),("a thumbnail outside its chapter falls back to the midpoint",[_chapter(0, "Browses", 50), _chapter(30, "Buys")],- [(0, 30_000, "Browses", 15_000), (30_000, 80_000, "Buys", 55_000)],+ [(0, 30_000, "Browses", 15_000), (30_000, 80_000, "Buys", 53_000)],),(- "a title that was only a leaked citation marker is dropped",- [_chapter(0, "Browses"), _chapter(30, "(t 30)")],- [(0, 80_000, "Browses", 40_000)],- ),- (- "a chapter with no start is dropped and negative starts clamp to 0",+ "malformed chapters are dropped and negative starts clamp to 0",[SummaryChapterResponse(title="No start"),_chapter(-9, "Opens"),_chapter(-2, "Also opens"),- _chapter(30, "Buys"),+ _chapter(30, "(t 30)"),+ _chapter(40, "Buys"),],- [(0, 30_000, "Opens", 15_000), (30_000, 80_000, "Buys", 55_000)],+ [(0, 40_000, "Opens", 20_000), (40_000, 80_000, "Buys", 62_000)],),("no chapters stay no chapters", [], []),])def test_the_models_chapters_are_repaired_onto_the_session_clock(- self,- _label: str,- chapters: list[SummaryChapterResponse],- expected: list[tuple[int, int, str, int]],+ self, _label: str, chapters: list[SummaryChapterResponse], expected: list[tuple[int, int, str, int]]) -> None:clock = video_clock_from_export_context({"inactivity_periods": _PERIODS})assert clock is not None- # Only the cut map, so these cases cover the repair on its own; idle stretches have their own test.- resolved = resolve_chapters(chapters, 80_000, replace(clock, inactive=()))+ resolved = resolve_chapters(chapters, 80_000, clock)assert [(c.start_ms, c.end_ms, c.title, c.thumbnail_ms) for c in resolved] == expected-- @parameterized.expand(- [- (- "a short pause stays inside its chapter",- [(40, 70)],- [_chapter(0, "Reads docs", 50), _chapter(200, "Signs up")],- [- ("activity", 0, 200_000, "Reads docs", 50_000),- ("activity", 200_000, 400_000, "Signs up", 300_000),- ],- ),- (- "a boundary a second past a long idle snaps to its end",- [(100, 200)],- [_chapter(0, "Browses"), _chapter(201, "Buys")],- [- ("activity", 0, 100_000, "Browses", 50_000),- ("idle", 100_000, 200_000, "Idle", None),- ("activity", 200_000, 400_000, "Buys", 300_000),- ],- ),- (- "a long idle inside a chapter splits it and both sides keep the title",- [(100, 200)],- [_chapter(0, "Reads docs", 150)],- [- ("activity", 0, 100_000, "Reads docs", 50_000),- ("idle", 100_000, 200_000, "Idle", None),- ("activity", 200_000, 400_000, "Reads docs", 300_000),- ],- ),- (- "long idle at the start and the end of the session",- [(0, 70), (320, 400)],- [_chapter(0, "Browses", 100)],- [- ("idle", 0, 70_000, "Idle", None),- ("activity", 70_000, 320_000, "Browses", 100_000),- ("idle", 320_000, 400_000, "Idle", None),- ],- ),- (- "a short chapter the model gave its own entry is kept, however short",- [],- [_chapter(0, "Browses"), _chapter(100, "Rage clicks buy button"), _chapter(102, "Buys")],- [- ("activity", 0, 100_000, "Browses", 50_000),- ("activity", 100_000, 102_000, "Rage clicks buy button", 101_000),- ("activity", 102_000, 400_000, "Buys", 251_000),- ],- ),- (- "a sliver of activity between two long idles folds into them",- [(0, 100), (101, 400)],- [_chapter(0, "Browses")],- [("idle", 0, 400_000, "Idle", None)],- ),- ]- )- def test_long_inactive_stretches_become_idle_chapters(- self,- _label: str,- inactive: list[tuple[float, float]],- chapters: list[SummaryChapterResponse],- expected: list[tuple[str, int, int, str, int | None]],- ) -> None:- clock = VideoClock(spans=(), inactive=tuple(inactive))- resolved = resolve_chapters(chapters, 400_000, clock)- assert [(c.kind, c.start_ms, c.end_ms, c.title, c.thumbnail_ms) for c in resolved] == expecteddiff --git a/products/replay_vision/skills/exploring-replay-vision-observations/SKILL.md b/products/replay_vision/skills/exploring-replay-vision-observations/SKILL.mdindex 0601ad303f6b..88214d459f18 100644--- a/products/replay_vision/skills/exploring-replay-vision-observations/SKILL.md+++ b/products/replay_vision/skills/exploring-replay-vision-observations/SKILL.md@@ -20,7 +20,7 @@ and doing something useful with it. For creating or sizing scanners, use [[creat- `classifier` → one or more `tags` from the scanner's label set, plus `tags_freeform` when the scannerallows freeform tags, and the `reasoning`.- `scorer` → a numeric `score` on the scanner's `scale`, and the `reasoning`.- - `summarizer` → a `title`, a free-text `summary`, and `chapters`: the recording broken into ordered parts, each with `start_ms`, `end_ms`, a short `title` and a `thumbnail_ms`, all offsets into the recording (seek with `?t=<start_ms / 1000>`). A chapter with `kind: idle` is a stretch of a minute or more that the replay player marked inactive (no interaction recorded), taken from the render rather than the model.+ - `summarizer` → a `title`, a free-text `summary`, `chapters` (the active parts of the recording in order, each with `start_ms`, `end_ms`, a short `title` and a `thumbnail_ms`; seek with `?t=<start_ms / 1000>`) and `inactive_periods` (`start_ms`/`end_ms` stretches the replay player marked inactive, usually the gaps between chapters). Skip any chapter with `kind: idle`, which only older summaries carry.- **Only `succeeded` observations carry a finding.** Triage the rest by `status`/`error_reason` (see below).- **Observations are LLM judgments, not ground truth.** One observation is one model's read of one session —corroborate before you act on it.