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.

feat(replay-vision): surface the max active-time limit on scanner triggers (#68050)

Kim Svatos Dugana165f03e5b4a
diff --git a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
index 5e6831cc99d2..7d042422e092 100644
--- a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
@@ -75,8 +75,14 @@ export function ScannerEditorSceneComponent(): JSX.Element {
const scannerLogic = replayScannerLogic({ id: scannerId })
useAttachedLogic(scannerLogic, scannerEditorSceneLogic)
- const { scanner, scannerLoading, isScannerSubmitting, scannerValidationErrors, showScannerErrors } =
- useValues(scannerLogic)
+ const {
+ scanner,
+ scannerLoading,
+ isScannerSubmitting,
+ scannerValidationErrors,
+ showScannerErrors,
+ durationValidationError,
+ } = useValues(scannerLogic)
const { submitScanner, setSubmitIntent } = useActions(scannerLogic)
const { featureFlags } = useValues(featureFlagLogic)
@@ -98,7 +104,8 @@ export function ScannerEditorSceneComponent(): JSX.Element {
template: false,
self_driving: false,
configure: showScannerErrors && !!(scannerValidationErrors?.name || scannerValidationErrors?.scanner_config),
- triggers: showScannerErrors && scannerValidationErrors?.sampling_rate != null,
+ triggers:
+ showScannerErrors && (scannerValidationErrors?.sampling_rate != null || durationValidationError != null),
}
// Validate the current step and move on: submit routes to the next visible step on success.
@@ -333,10 +340,13 @@ function EditorFooter({
onAdvance: () => void
onSave: () => void
}): JSX.Element {
- const { scanner } = useValues(replayScannerLogic({ id: scannerId }))
+ const { scanner, durationValidationError } = useValues(replayScannerLogic({ id: scannerId }))
const stepIndex = visibleSteps.indexOf(step)
const prevStep = stepIndex > 0 ? visibleSteps[stepIndex - 1] : null
const nextStep = stepIndex < visibleSteps.length - 1 ? visibleSteps[stepIndex + 1] : null
+ // A broken duration filter (scans nothing) blocks the save — surface it as a disabled reason so the
+ // button explains itself instead of silently doing nothing.
+ const saveDisabledReason = durationValidationError ?? undefined
return (
<div className="flex items-center justify-between">
@@ -365,6 +375,7 @@ function EditorFooter({
<LemonButton
type="primary"
loading={isSubmitting}
+ disabledReason={saveDisabledReason}
onClick={onSave}
className="ml-auto"
data-attr="vision-editor-save"
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx
index 8d0e9ec5c788..4034e2fc155a 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx
@@ -1,6 +1,6 @@
import { useActions, useValues } from 'kea'
-import { LemonCard, LemonInput, LemonSegmentedButton } from '@posthog/lemon-ui'
+import { LemonCard, LemonInput, LemonSegmentedButton, LemonTag } from '@posthog/lemon-ui'
import { resolveCategoryDropdownVariant, TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'
@@ -11,6 +11,7 @@ import { FEATURE_FLAGS } from 'lib/constants'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel'
import { LemonSlider } from 'lib/lemon-ui/LemonSlider'
+import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { DurationFilter } from 'scenes/session-recordings/filters/DurationFilter'
import {
@@ -23,8 +24,9 @@ import { defaultRecordingDurationFilter } from 'scenes/session-recordings/playli
import { AndOrFilterSelect } from '~/queries/nodes/InsightViz/PropertyGroupFilters/AndOrFilterSelect'
import { RecordingsQuery } from '~/queries/schema/schema-general'
-import { DurationType, RecordingDurationFilter, RecordingUniversalFilters, UniversalFiltersGroup } from '~/types'
+import { RecordingUniversalFilters, UniversalFiltersGroup } from '~/types'
+import { clampDurationFilter, durationFilterError, MAX_ACTIVE_LABEL } from '../durationBounds'
import { replayScannerLogic } from '../replayScannerLogic'
import { SAMPLING_MODE_OPTIONS, SamplingMode } from '../types'
import { ScannerQuotaForecast } from './ScannerQuotaForecast'
@@ -42,27 +44,6 @@ const SCANNER_FILTER_TYPES: TaxonomicFilterGroupType[] = [
TaxonomicFilterGroupType.SessionProperties,
]
-// Vision only analyzes recordings within these server-enforced duration bounds (see backend constants.py).
-const DURATION_BOUNDS: Partial<Record<DurationType, { min?: number; max?: number }>> = {
- duration: { min: 15 },
- active_seconds: { min: 10, max: 3600 },
-}
-
-function clampDurationFilter(filter: RecordingDurationFilter): RecordingDurationFilter {
- const bounds = DURATION_BOUNDS[filter.key]
- if (!bounds) {
- return filter
- }
- let value = Number(filter.value) || 0
- if (bounds.min != null) {
- value = Math.max(value, bounds.min)
- }
- if (bounds.max != null) {
- value = Math.min(value, bounds.max)
- }
- return value === filter.value ? filter : { ...filter, value }
-}
-
// Renders the bound universal-filter group's values; adding is handled by the search bar above, not an inline button.
function ScannerFilterGroup(): JSX.Element {
const { filterGroup } = useValues(universalFiltersLogic)
@@ -184,6 +165,7 @@ export function ScannerTriggers({ scannerId }: { scannerId: string }): JSX.Eleme
})
}
const durationFilter = clampDurationFilter(universal.duration[0] ?? defaultRecordingDurationFilter)
+ const durationError = durationFilterError(durationFilter)
return (
<LemonCard hoverEffect={false} className="p-3 space-y-3">
<div className="flex items-start justify-between gap-2">
@@ -255,25 +237,40 @@ export function ScannerTriggers({ scannerId }: { scannerId: string }): JSX.Eleme
</UniversalFilters>
)}
<ScannerFilterGroup />
- <div className="flex flex-wrap items-center gap-2">
- <span className="font-medium">Duration</span>
- <DurationFilter
- recordingDurationFilter={durationFilter}
- durationTypeFilter={durationFilter.key}
- pageKey={`replay-scanner-${scanner.id}`}
- size="small"
- onChange={(recordingDurationFilter, durationType) =>
- applyUniversal({
- ...universal,
- duration: [
- clampDurationFilter({
- ...recordingDurationFilter,
- key: durationType,
- }),
- ],
- })
- }
- />
+ <div className="space-y-1">
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="font-medium">Duration</span>
+ <DurationFilter
+ recordingDurationFilter={durationFilter}
+ durationTypeFilter={durationFilter.key}
+ pageKey={`replay-scanner-${scanner.id}`}
+ size="small"
+ onChange={(recordingDurationFilter, durationType) =>
+ applyUniversal({
+ ...universal,
+ duration: [
+ clampDurationFilter({
+ ...recordingDurationFilter,
+ key: durationType,
+ }),
+ ],
+ })
+ }
+ />
+ <Tooltip title="Recordings with more than 1 hour of active interaction take too long to analyze well, so Vision always skips them. This limit can't be changed.">
+ <LemonTag type="muted" className="cursor-default">
+ Max {MAX_ACTIVE_LABEL} active time
+ </LemonTag>
+ </Tooltip>
+ </div>
+ {durationError ? (
+ <div className="text-danger text-xs">{durationError}</div>
+ ) : (
+ <div className="text-xs text-muted">
+ Vision only scans recordings up to {MAX_ACTIVE_LABEL} of active time. Longer
+ sessions are always skipped.
+ </div>
+ )}
</div>
</UniversalFilters>
</LemonCard>
diff --git a/products/replay_vision/frontend/replay_scanners/durationBounds.test.ts b/products/replay_vision/frontend/replay_scanners/durationBounds.test.ts
new file mode 100644
index 000000000000..3bc245f07138
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/durationBounds.test.ts
@@ -0,0 +1,30 @@
+import { PropertyFilterType, PropertyOperator, RecordingDurationFilter } from '~/types'
+
+import { durationFilterError } from './durationBounds'
+
+function durationFilter(
+ key: 'duration' | 'active_seconds' | 'inactive_seconds',
+ operator: PropertyOperator,
+ value: number
+): RecordingDurationFilter {
+ return { type: PropertyFilterType.Recording, key, operator, value }
+}
+
+describe('durationBounds', () => {
+ it.each([
+ // A filter that can't overlap the scannable window [min, max] scans nothing → error.
+ ['active time > ceiling', durationFilter('active_seconds', PropertyOperator.GreaterThan, 3600), true],
+ ['active time > above ceiling', durationFilter('active_seconds', PropertyOperator.GreaterThan, 5000), true],
+ ['active time < floor', durationFilter('active_seconds', PropertyOperator.LessThan, 10), true],
+ // Filters that do overlap the window are fine.
+ ['active time > small value', durationFilter('active_seconds', PropertyOperator.GreaterThan, 30), false],
+ ['active time < large value', durationFilter('active_seconds', PropertyOperator.LessThan, 600), false],
+ // `duration` has only a min bound, so a large `>` is not empty.
+ ['total duration > large value', durationFilter('duration', PropertyOperator.GreaterThan, 99999), false],
+ // Unbounded key and missing filter never error.
+ ['unbounded key', durationFilter('inactive_seconds', PropertyOperator.GreaterThan, 99999), false],
+ ['no filter', undefined, false],
+ ])('flags an empty duration filter: %s', (_label, filter, expectError) => {
+ expect(durationFilterError(filter)).toEqual(expectError ? expect.any(String) : null)
+ })
+})
diff --git a/products/replay_vision/frontend/replay_scanners/durationBounds.ts b/products/replay_vision/frontend/replay_scanners/durationBounds.ts
new file mode 100644
index 000000000000..a31868e99b65
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/durationBounds.ts
@@ -0,0 +1,47 @@
+import { DurationType, PropertyOperator, RecordingDurationFilter } from '~/types'
+
+// Vision only analyzes recordings within these server-enforced duration bounds (see backend constants.py).
+export const DURATION_BOUNDS: Partial<Record<DurationType, { min?: number; max?: number }>> = {
+ duration: { min: 15 },
+ active_seconds: { min: 10, max: 3600 },
+}
+
+// The hard ceiling Vision enforces on active interaction time — recordings above it are always skipped.
+export const MAX_ACTIVE_SECONDS = DURATION_BOUNDS.active_seconds?.max ?? 3600
+export const MAX_ACTIVE_LABEL = `${Math.round(MAX_ACTIVE_SECONDS / 3600)}h`
+
+export function clampDurationFilter(filter: RecordingDurationFilter): RecordingDurationFilter {
+ const bounds = DURATION_BOUNDS[filter.key]
+ if (!bounds) {
+ return filter
+ }
+ let value = Number(filter.value) || 0
+ if (bounds.min != null) {
+ value = Math.max(value, bounds.min)
+ }
+ if (bounds.max != null) {
+ value = Math.min(value, bounds.max)
+ }
+ return value === filter.value ? filter : { ...filter, value }
+}
+
+// A duration filter that can't overlap Vision's scannable window [min, max] selects only recordings that
+// are always skipped, so the scanner would produce nothing. Returns a human-readable reason for that case
+// (e.g. "active time > 1h", which the ceiling always skips), else null. The value is assumed clamped.
+export function durationFilterError(filter: RecordingDurationFilter | undefined): string | null {
+ if (!filter) {
+ return null
+ }
+ const bounds = DURATION_BOUNDS[filter.key]
+ if (!bounds) {
+ return null
+ }
+ const value = Number(filter.value) || 0
+ if (bounds.max != null && filter.operator === PropertyOperator.GreaterThan && value >= bounds.max) {
+ return `Vision skips recordings over ${MAX_ACTIVE_LABEL} of active time, so "greater than" this scans nothing. Lower the threshold or switch to "less than".`
+ }
+ if (bounds.min != null && filter.operator === PropertyOperator.LessThan && value <= bounds.min) {
+ return `Vision skips recordings under ${bounds.min}s of active time, so "less than" this scans nothing. Raise the threshold or switch to "greater than".`
+ }
+ return null
+}
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
index b9a16a2bc1c2..a778058fc314 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
@@ -8,6 +8,7 @@ import { dayjs } from 'lib/dayjs'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { dateStringToDayJs } from 'lib/utils/dateFilters'
import { objectsEqual } from 'lib/utils/objects'
+import { recordingsQueryToUniversalFilters } from 'scenes/session-recordings/filters/recordingsQueryConversions'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -32,6 +33,7 @@ import { OBSERVE_POLL_GRACE_MS, scheduleObservationPoll, shouldPollObservations
import { requestObservationRetry } from '../logics/observationRetry'
import { refreshVisionQuota } from '../logics/visionQuotaLogic'
import { type UrlSorting, parseCsvParam, parseSortParam, serializeSortParam } from '../utils/urlParams'
+import { clampDurationFilter, durationFilterError } from './durationBounds'
import type { replayScannerLogicType } from './replayScannerLogicType'
import { SCANNER_EDITOR_STEPS, scannerEditorSceneLogic, scannerStepUrl } from './scannerEditorSceneLogic'
import { findScannerTemplate, newScanner } from './scannerTemplates'
@@ -564,6 +566,18 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
selectors({
isNew: [(_, p) => [p.id], (id: string) => id === 'new'],
+ // A duration filter that can't overlap Vision's scannable window would scan nothing (e.g. active time
+ // > 1h, which the ceiling always skips). Surfaced as a save-blocking reason rather than a form error,
+ // since kea-forms can't attach a scalar error to the object-typed `query` field.
+ durationValidationError: [
+ (s) => [s.scanner],
+ (scanner: ReplayScanner | null): string | null => {
+ const durationFilter = scanner?.query
+ ? recordingsQueryToUniversalFilters(scanner.query).duration?.[0]
+ : undefined
+ return durationFilter ? durationFilterError(clampDurationFilter(durationFilter)) : null
+ },
+ ],
hasUnsavedChanges: [
(s) => [s.scanner, s.originalScanner],
(scanner: ReplayScanner | null, original: ReplayScanner | null): boolean => {