: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
feat(replay): quill twins for the observations filmstrip and scan list (#129007)
Hayne Ryu86d99f1ebb60
diff --git a/products/replay_vision/frontend/components/QuillChapterFilmstrip.tsx b/products/replay_vision/frontend/components/QuillChapterFilmstrip.tsxnew file mode 100644index 000000000000..c146d05c6ca7--- /dev/null+++ b/products/replay_vision/frontend/components/QuillChapterFilmstrip.tsx@@ -0,0 +1,165 @@+import { useCallback, useEffect, useRef, useState } from 'react'++import { IconChevronLeft, IconChevronRight } from '@posthog/icons'+import { Button, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'++import { useResizeObserver } from 'lib/hooks/useResizeObserver'+import { cn } from 'lib/utils/css-classes'+import { colonDelimitedDuration, humanFriendlyDuration } from 'lib/utils/durations'++import type { ReplayObservationApi } from '../generated/api.schemas'+import { MIN_INACTIVE_ROW_MS, currentRowIndex } from '../utils/recordingTimeline'+import { QuillObservationThumbnail } from './QuillObservationThumbnail'+import { QuillRecordingTimelineProps, QuillSummaryNotice } from './QuillRecordingTimeline'++const formatSpan = (ms: number): string => humanFriendlyDuration(ms / 1000, { maxUnits: 1 })++export function QuillChapterFilmstrip(props: QuillRecordingTimelineProps): JSX.Element {+ const { timeline, rows, currentTimeMs, onSeek } = props+ const [edges, setEdges] = useState({ atStart: true, atEnd: true })+ const stripRef = useRef<HTMLDivElement | null>(null)+ const { width, ref: observeStrip } = useResizeObserver<HTMLDivElement>()+ const currentIndex = currentRowIndex(rows, currentTimeMs)+ const hasHours = rows.some((row) => row.kind === 'chapter' && row.chapter.startMs >= 3_600_000)+ const formatTime = (ms: number): string => colonDelimitedDuration(Math.floor(ms / 1000), hasHours ? 3 : 2)+ const summary = timeline.summary as ReplayObservationApi++ const updateEdges = useCallback((): void => {+ const strip = stripRef.current+ if (!strip) {+ return+ }+ setEdges({+ atStart: strip.scrollLeft <= 1,+ atEnd: strip.scrollLeft + strip.clientWidth >= strip.scrollWidth - 1,+ })+ }, [])++ useEffect(updateEdges, [updateEdges, width, rows.length])++ const setStrip = useCallback(+ (element: HTMLDivElement | null): void => {+ stripRef.current = element+ observeStrip(element)+ },+ [observeStrip]+ )++ const page = (direction: -1 | 1): void => {+ const strip = stripRef.current+ strip?.scrollBy({ left: direction * strip.clientWidth * 0.8, behavior: 'smooth' })+ }++ return (+ <div className="flex flex-col" data-attr="vision-chapter-filmstrip">+ {rows.length > 0 && (+ <div className="flex items-center gap-1 px-1.5 py-2">+ <Button+ size="icon-xs"+ tooltip="Earlier chapters"+ aria-label="Earlier chapters"+ disabledReason={edges.atStart ? 'At the start of the recording' : undefined}+ onClick={() => page(-1)}+ data-attr="vision-filmstrip-earlier"+ >+ <IconChevronLeft />+ </Button>+ <div+ ref={setStrip}+ onScroll={updateEdges}+ className="flex flex-1 min-w-0 gap-2 overflow-x-auto snap-x snap-proximity [scrollbar-width:thin]"+ >+ {rows.map((row, index) => {+ if (row.kind === 'boundary') {+ return null+ }+ if (row.kind === 'inactive') {+ return (+ <span+ key={`inactive-${row.startMs}`}+ className="flex w-11 shrink-0 flex-col items-center justify-center border-x border-dashed border-border text-center text-xxs text-muted-foreground"+ data-attr="vision-filmstrip-inactive"+ >+ <span>{formatSpan(row.endMs - row.startMs)}</span>+ <span>idle</span>+ </span>+ )+ }+ const { chapter } = row+ const isCurrent = index === currentIndex+ const poster = (+ <QuillObservationThumbnail+ observation={summary}+ chapter={chapter.position}+ className={cn('w-full', isCurrent && 'ring-2 ring-primary')}+ size="small"+ >+ <span+ className={cn(+ 'absolute bottom-1 left-1 rounded bg-black/70 px-1 font-mono text-xxs text-white',+ isCurrent && 'bg-primary'+ )}+ >+ {formatTime(chapter.startMs)}+ </span>+ </QuillObservationThumbnail>+ )+ return (+ <Button+ key={`chapter-${chapter.startMs}`}+ size="row"+ left+ onClick={() => onSeek(chapter.startMs)}+ data-current-moment={isCurrent ? true : undefined}+ className={cn(+ 'h-auto min-w-0 shrink-0 grow basis-[9.5rem] max-w-[14rem] snap-start flex-col items-stretch gap-1 p-1 whitespace-normal',+ isCurrent && 'bg-fill-selected'+ )}+ data-attr="vision-filmstrip-chapter"+ >+ {chapter.hasFrame ? (+ <Tooltip>+ <TooltipTrigger render={<span className="flex w-full" />}>+ {poster}+ </TooltipTrigger>+ <TooltipContent side="top" className="max-w-none p-1">+ <QuillObservationThumbnail+ observation={summary}+ chapter={chapter.position}+ className="w-128 border-0"+ />+ </TooltipContent>+ </Tooltip>+ ) : (+ <span className="flex w-full">{poster}</span>+ )}+ <span className="text-sm font-medium line-clamp-2 text-left">{chapter.title}</span>+ <span className="text-xs text-muted-foreground text-left">+ {formatSpan(chapter.endMs - chapter.startMs - chapter.inactiveMs)}+ {chapter.inactiveMs >= MIN_INACTIVE_ROW_MS && (+ <span className="opacity-70">+ {' '}+ · {formatSpan(chapter.inactiveMs)} inactive+ </span>+ )}+ </span>+ </Button>+ )+ })}+ </div>+ <Button+ size="icon-xs"+ tooltip="Later chapters"+ aria-label="Later chapters"+ disabledReason={edges.atEnd ? 'At the end of the recording' : undefined}+ onClick={() => page(1)}+ data-attr="vision-filmstrip-later"+ >+ <IconChevronRight />+ </Button>+ </div>+ )}+ <QuillSummaryNotice {...props} />+ </div>+ )+}diff --git a/products/replay_vision/frontend/components/QuillObservationProgressBar.tsx b/products/replay_vision/frontend/components/QuillObservationProgressBar.tsxnew file mode 100644index 000000000000..19931f0186e0--- /dev/null+++ b/products/replay_vision/frontend/components/QuillObservationProgressBar.tsx@@ -0,0 +1,55 @@+import { useActions, useValues } from 'kea'+import { useEffect } from 'react'++import { IconWarning } from '@posthog/icons'+import { Progress, Spinner } from '@posthog/quill'++import { DISPLAY_PHASES } from '../observations/observationProgress'+import { observationProgressLogic } from '../observations/observationProgressLogic'++export function QuillObservationProgressBar({+ observationId,+ sessionId,+}: {+ observationId: string+ sessionId: string+}): JSX.Element {+ const logic = observationProgressLogic({ observationId, sessionId })+ const { percent, displayPhase, stepNumber, frames, streamError } = useValues(logic)+ const { startStream } = useActions(logic)++ useEffect(() => {+ startStream()+ }, [observationId, startStream])++ if (streamError) {+ // The stream died but the observation may still be running; status polling keeps the page truthful.+ return (+ <div className="flex items-center gap-2 text-muted-foreground text-sm">+ <IconWarning className="text-warning text-base shrink-0" />+ <span>Live progress isn't available. This updates when the observation finishes.</span>+ </div>+ )+ }++ return (+ <div className="flex flex-col gap-1.5">+ <div className="flex items-center gap-2 text-muted-foreground text-sm">+ <Spinner />+ <span className="min-w-0 truncate">{displayPhase.label}…</span>+ </div>+ <Progress value={percent} />+ {/* Ticking numbers skip page translation, which would otherwise freeze them and crash React on removal (react#11538). */}+ <div className="flex items-center justify-between gap-2 text-muted-foreground text-xs" translate="no">+ <span>+ Step {stepNumber} of {DISPLAY_PHASES.length}+ </span>+ {frames && (+ <span>+ {frames.frame.toLocaleString()} / {frames.estimatedTotalFrames.toLocaleString()} frames+ </span>+ )}+ </div>+ </div>+ )+}diff --git a/products/replay_vision/frontend/components/QuillObservationRetryButton.tsx b/products/replay_vision/frontend/components/QuillObservationRetryButton.tsxnew file mode 100644index 000000000000..bdd8fbbbe830--- /dev/null+++ b/products/replay_vision/frontend/components/QuillObservationRetryButton.tsx@@ -0,0 +1,51 @@+import { IconRefresh } from '@posthog/icons'+import { Button } from '@posthog/quill'++import { AccessControlLevel } from '~/types'++import type { ReplayObservationApi } from '../generated/api.schemas'+import { observationRetryOffer } from '../replay_scanners/types'+import { getReplayVisionEditDisabledReason } from '../utils/accessControl'++/** Renders nothing when a retry isn't offered for the observation's status and kind (see `observationRetryOffer`). */+export function QuillObservationRetryButton({+ status,+ errorReason,+ onRetry,+ loading = false,+ userAccessLevel,+ emphasis = 'outline',+ size = 'xs',+ iconOnly = false,+ dataAttr,+}: {+ status: ReplayObservationApi['status']+ errorReason: string+ onRetry: () => void+ loading?: boolean+ userAccessLevel?: AccessControlLevel | null+ emphasis?: 'primary' | 'outline'+ size?: 'xs' | 'sm'+ iconOnly?: boolean+ dataAttr: string+}): JSX.Element | null {+ const { show, worthwhile, hint } = observationRetryOffer(status, errorReason)+ if (!show) {+ return null+ }+ return (+ <Button+ size={iconOnly ? (size === 'xs' ? 'icon-xs' : 'icon-sm') : size}+ variant={worthwhile ? emphasis : 'outline'}+ onClick={onRetry}+ loading={loading}+ disabledReason={getReplayVisionEditDisabledReason(userAccessLevel)}+ tooltip={hint ?? 'Retry scan'}+ aria-label={iconOnly ? 'Retry scan' : undefined}+ data-attr={dataAttr}+ >+ <IconRefresh />+ {iconOnly ? null : 'Retry scan'}+ </Button>+ )+}diff --git a/products/replay_vision/frontend/components/QuillRecordingMoments.tsx b/products/replay_vision/frontend/components/QuillRecordingMoments.tsxindex 91b5722719c1..7179e21a697a 100644--- a/products/replay_vision/frontend/components/QuillRecordingMoments.tsx+++ b/products/replay_vision/frontend/components/QuillRecordingMoments.tsx@@ -20,10 +20,10 @@ import {timelineRows as buildTimelineRows,} from '../utils/recordingTimeline'import { recordingScanBlock } from '../utils/scanEligibility'-import { ChapterFilmstrip } from './ChapterFilmstrip'+import { QuillChapterFilmstrip } from './QuillChapterFilmstrip'import { QuillRecordingTimeline } from './QuillRecordingTimeline'+import { QuillScanList } from './QuillScanList'import { QuillScannerPicker } from './QuillScannerPicker'-import { ScanList } from './ScanList'const CURRENT_MOMENT_SELECTOR = '[data-current-moment]'const FILMSTRIP_MIN_WIDTH_PX = 840@@ -159,9 +159,7 @@ export function QuillRecordingMoments({<div className="flex-1 min-h-0 overflow-y-auto" ref={timelineRef}>{/* Nothing before the width is known, so posters are fetched once. */}{width === undefined ? null : filmstrip ? (- <div data-not-quill className="contents">- <ChapterFilmstrip {...timelineProps} />- </div>+ <QuillChapterFilmstrip {...timelineProps} />) : (<><SectionHeader label="Timeline" />@@ -169,15 +167,13 @@ export function QuillRecordingMoments({</>)}<SectionHeader label="Scans" />- <div data-not-quill className="contents">- <ScanList- sessionId={sessionId}- observations={observations}- endMs={timelineEndMs(timeline, durationMs)}- currentTimeMs={currentPlayerTime}- onSeek={seekToTime}- />- </div>+ <QuillScanList+ sessionId={sessionId}+ observations={observations}+ endMs={timelineEndMs(timeline, durationMs)}+ currentTimeMs={currentPlayerTime}+ onSeek={seekToTime}+ /></div></div>)diff --git a/products/replay_vision/frontend/components/QuillScanList.tsx b/products/replay_vision/frontend/components/QuillScanList.tsxnew file mode 100644index 000000000000..9636ce01448d--- /dev/null+++ b/products/replay_vision/frontend/components/QuillScanList.tsx@@ -0,0 +1,280 @@+import { useActions, useValues } from 'kea'+import { router } from 'kea-router'+import { useMemo } from 'react'++import { IconChevronRight } from '@posthog/icons'+import { Button, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'++import { useResizeObserver } from 'lib/hooks/useResizeObserver'+import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { cn } from 'lib/utils/css-classes'+import { colonDelimitedDuration } from 'lib/utils/durations'++import type { ReplayObservationApi } from '../generated/api.schemas'+import { observationsDockLogic } from '../logics/observationsDockLogic'+import { scannerTypeLabel } from '../replay_scanners/types'+import { RECORDING_ORIGIN, currentReturnPath, observationFromOriginUrl } from '../utils/breadcrumbs'+import { isSummaryObservation, readModelOutput, readReasoning, scannerLabel } from '../utils/observation'+import { citedMoments } from '../utils/recordingTimeline'+import { CitedMarkdown } from './CitedMarkdown'+import {+ FailureDetail,+ IneligibleDetail,+ ObservationPrimaryOutput,+ ObservationResultSummary,+ ObservationStatusTag,+} from './ObservationCard'+import { QuillObservationProgressBar } from './QuillObservationProgressBar'+import { QuillObservationRetryButton } from './QuillObservationRetryButton'+import { QuillScannerTypeBadge } from './QuillScannerTypeBadge'++const NEAR_PLAYHEAD_MS = 60_000++const isInFlight = (o: ReplayObservationApi): boolean => o.status === 'pending' || o.status === 'running'++function defaultFocus(observations: ReplayObservationApi[]): ReplayObservationApi | null {+ return (+ observations.find(isInFlight) ?? observations.find((o) => o.status === 'succeeded') ?? observations[0] ?? null+ )+}++function RunResult({ observation }: { observation: ReplayObservationApi }): JSX.Element | null {+ if (observation.status !== 'succeeded') {+ return <ObservationStatusTag status={observation.status} errorReason={observation.error_reason} />+ }+ if (isSummaryObservation(observation)) {+ return null+ }+ return <ObservationResultSummary observation={observation} />+}++function MomentTicks({+ moments,+ endMs,+ currentTimeMs,+ onSeek,+}: {+ moments: number[]+ endMs: number+ currentTimeMs: number+ onSeek: (timestampMs: number) => void+}): JSX.Element {+ return (+ <span+ className="pointer-events-none absolute right-8 top-1/2 hidden h-2 w-28 -translate-y-1/2 rounded-sm bg-muted @[560px]:block"+ data-attr="vision-scan-moment-ticks"+ >+ {moments.map((ms) => {+ const label = colonDelimitedDuration(Math.floor(ms / 1000), null)+ return (+ <Tooltip key={ms}>+ <TooltipTrigger+ render={+ <Button+ size="inline"+ aria-label={`Jump to ${label}`}+ onClick={() => onSeek(ms)}+ className={cn(+ 'pointer-events-auto absolute -top-0.5 h-3 w-1 min-w-0 -translate-x-1/2 rounded-sm p-0',+ Math.abs(ms - currentTimeMs) < NEAR_PLAYHEAD_MS ? 'bg-primary' : 'bg-border'+ )}+ // eslint-disable-next-line react/forbid-dom-props+ style={{ left: `${Math.min(100, (ms / endMs) * 100)}%` }}+ data-attr="vision-scan-moment-tick"+ />+ }+ />+ <TooltipContent>Jump to {label}</TooltipContent>+ </Tooltip>+ )+ })}+ </span>+ )+}++function FocusPane({+ observation,+ onSeek,+ onRetry,+ retrying,+}: {+ observation: ReplayObservationApi+ onSeek: (timestampMs: number) => void+ onRetry: () => void+ retrying: boolean+}): JSX.Element {+ const { height: contentHeight, ref: contentRef } = useResizeObserver<HTMLDivElement>({ box: 'border-box' })+ const { location } = useValues(router)+ const isSummary = isSummaryObservation(observation)+ const reasoning = observation.status === 'succeeded' && !isSummary ? readReasoning(observation) : null+ const hasText = observation.status === 'succeeded' && (isSummary || reasoning !== null)+ return (+ <div+ className="overflow-hidden transition-[height] duration-200 ease-in-out border-t border-border bg-background"+ // eslint-disable-next-line react/forbid-dom-props+ style={{ height: contentHeight }}+ data-attr="vision-focus-run"+ >+ <div ref={contentRef}>+ {(observation.error_reason || isInFlight(observation)) && (+ <div className="flex flex-col gap-2 px-3 pb-2">+ <span data-not-quill className="contents">+ {observation.status === 'failed' && observation.error_reason && (+ <FailureDetail errorReason={observation.error_reason} />+ )}+ {observation.status === 'ineligible' && observation.error_reason && (+ <IneligibleDetail errorReason={observation.error_reason} />+ )}+ </span>+ {observation.error_reason && (+ <div>+ <QuillObservationRetryButton+ status={observation.status}+ errorReason={observation.error_reason}+ onRetry={onRetry}+ loading={retrying}+ dataAttr="vision-tab-retry-observation"+ />+ </div>+ )}+ {isInFlight(observation) && (+ <QuillObservationProgressBar+ observationId={observation.id}+ sessionId={observation.session_id}+ />+ )}+ </div>+ )}+ <div className="flex flex-col gap-2 px-3 py-2">+ {hasText && (+ <div className="text-sm max-w-[120ch]" data-not-quill>+ {isSummary ? (+ <ObservationPrimaryOutput+ observation={observation}+ showPrompt={false}+ expandSummary+ copyable+ onSeek={onSeek}+ />+ ) : (+ <CitedMarkdown+ text={reasoning ?? ''}+ segments={readModelOutput(observation)?.reasoning_segments}+ onSeek={onSeek}+ />+ )}+ </div>+ )}+ <Button+ variant="link"+ size="inline"+ className="text-xs self-start"+ render={+ <LinkPrimitive+ to={observationFromOriginUrl(+ observation.id,+ RECORDING_ORIGIN,+ currentReturnPath(location)+ )}+ />+ }+ data-attr="vision-observation-open-from-sidebar"+ >+ View details+ </Button>+ </div>+ </div>+ </div>+ )+}++export function QuillScanList({+ sessionId,+ observations,+ endMs,+ currentTimeMs,+ onSeek,+}: {+ sessionId: string+ observations: ReplayObservationApi[]+ endMs: number | null+ currentTimeMs: number+ onSeek: (timestampMs: number) => void+}): JSX.Element {+ const logic = observationsDockLogic({ sessionId })+ const { focusedObservationId, retryingObservationIds } = useValues(logic)+ const { focusObservation, retryObservation } = useActions(logic)+ const focused = observations.find((o) => o.id === focusedObservationId) ?? defaultFocus(observations)+ const moments = useMemo(() => new Map(observations.map((o) => [o.id, citedMoments(o)])), [observations])+ return (+ <div>+ {observations.map((observation) => {+ const scannerType = observation.scanner_snapshot?.scanner_type+ const isFocused = observation.id === focused?.id+ const ticks = moments.get(observation.id) ?? []+ const ticksEndMs = endMs !== null && ticks.length > 0 ? endMs : null+ return (+ <div key={observation.id} className="border-b border-border">+ <div className={cn('relative flex items-center', isFocused && 'bg-fill-selected')}>+ <Button+ size="row"+ left+ className="rounded-none min-w-0 flex-1 gap-2 font-normal"+ onClick={() => focusObservation(observation.id)}+ aria-expanded={isFocused}+ data-attr="vision-run-row"+ >+ {scannerType && (+ <Tooltip>+ <TooltipTrigger render={<span className="flex shrink-0" />}>+ <QuillScannerTypeBadge scannerType={scannerType} iconOnly />+ </TooltipTrigger>+ <TooltipContent>{scannerTypeLabel(scannerType)}</TooltipContent>+ </Tooltip>+ )}+ <span+ className={cn(+ 'flex items-center gap-2 min-w-0 flex-1',+ ticksEndMs !== null && '@[560px]:pr-32'+ )}+ >+ <span className="min-w-0 truncate text-sm @[760px]:shrink-0 @[760px]:max-w-[40%]">+ {scannerLabel(observation)}+ </span>+ <span+ className="flex items-center gap-2 min-w-0 shrink-0 max-w-[40%]"+ data-not-quill+ >+ <RunResult observation={observation} />+ </span>+ {!isFocused && observation.summary_line && (+ <span className="hidden min-w-0 flex-1 truncate text-xs text-muted-foreground @[760px]:block">+ {observation.summary_line}+ </span>+ )}+ </span>+ <IconChevronRight className={cn('shrink-0', isFocused && 'invisible')} />+ </Button>+ {ticksEndMs !== null && (+ <MomentTicks+ moments={ticks}+ endMs={ticksEndMs}+ currentTimeMs={currentTimeMs}+ onSeek={onSeek}+ />+ )}+ </div>+ {isFocused && (+ <FocusPane+ observation={observation}+ onSeek={onSeek}+ onRetry={() => retryObservation(observation.id)}+ retrying={retryingObservationIds.includes(observation.id)}+ />+ )}+ </div>+ )+ })}+ </div>+ )+}