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.

13.5 KB
Raw Blame

Replay Vision

A sub-product of Session Replay. Users configure named scanners that PostHog applies to completed session recordings; results land as queryable $recording_observed events that feed insights, dashboards, and PostHog Signals.

Concepts

Scanner — a configured probe scoped to a team. Carries a prompt, a scanner type (monitor / classifier / scorer / summarizer), a RecordingsQuery that selects matching sessions, a Gemini model (which sets the per-observation credit price), and two volume levers: sampling_mode (a quality pre-filter over the matched sessions) and sampling_rate (a random downsample applied after it). Each enabled scanner has a Temporal schedule that fires every 5 minutes and sweeps for newly settled recordings past the scanner's watermark (last_swept_at); disabling a scanner removes its schedule, and re-enabling restarts the sweep from now rather than backfilling the gap (see Backfill for the explicit way to cover history). Every succeeded observation is embedded (the summary, or the reasoning) for downstream free-text search. The Search tab ranks observations by embedding distance, then a decision model rereads the query and each of the top 20 together and reorders them by how well they match. The reorder has a two-second budget, and search falls back to the embedding order when the model is slow, failing, or not configured. A scanner with emits_signals also pushes one signal per finding into the Signals inbox (replay_vision / scanner_finding), which is what the editor's Self-driving step turns on.

Inline scan — a prompt pointed at named sessions with nothing saved, for a one-off question (POST /vision/scanners/inline_scan/, and the path agents take instead of creating a throwaway scanner). An observation belongs to a scanner, so a scan mints one keyed by a fingerprint of its config: the same question reuses the observations it already has, a different question gets its own. Those rows carry origin=inline, are never listed or swept, and are reaped once they have nothing to show. See backend/inline_scan.py for why they exist and backend/scanner_access.py for how results are read back.

Observation — one application of a scanner to a session, unique per (scanner, session). Created in pending when triggered (by the scanner's schedule, the /observe/ and /bulk_observe/ actions, or a retry of a failed observation), transitions to running while ApplyScannerWorkflow executes (rasterize the recording to video → upload to Gemini → multi-turn scan), and lands in succeeded (result persisted under scanner_result.model_output, then a $recording_observed event plus embeddings/tags emitted fail-soft), failed (with a kind:message error_reason), or ineligible (the session doesn't qualify — too short, too idle, no recording). Each observation snapshots the full scanner state (scanner_snapshot) that produced it, so subsequent edits to the scanner don't retro-mutate history. Rows stranded in pending/running by a dead workflow are failed as orphaned by a reaper on the reconciler tick. Teams rate observations thumbs up/down, with optional written feedback. A scheduled job (backend/learned_rules.py) distills new ratings into hidden learned rules, one set for the project and one per scanner, and later scans include them in their prompt. Users never see or approve the rules. A finding can also be turned into a PostHog Task once (the observation remembers the task it minted).

Backfill — one historical scan of a scanner over a closed, past time window, walked newest-first. The window is closed, so the candidate query enumerates the exact eligible set at creation: the quoted cost (total_count x the model's credit price) is a ceiling, and actual spend only falls below it as already-observed sessions dedup, expired recordings land ineligible, and failures write no receipt. The scanner's full config is frozen into scanner_snapshot at creation, so later edits change neither the enumerated set nor the price nor what the observations record. A per-backfill Temporal schedule ticks every minute, dispatching the same ApplyScannerWorkflow children within the shared in-flight caps plus a per-backfill sub-cap; its window_end is clamped to the scanner's sweep watermark so live and backfill never contest a session. Backfill and live observations have equal quota priority: an active backfill's remaining commitment counts toward the projected monthly spend, the per-observation creation check enforces the org limit for both, and exhausting the monthly quota moves the backfill to paused_quota until an explicit resume.

Quota — succeeded observations write an immutable usage receipt priced in credits (1 credit = $0.01, set by the observation's model). Usage (receipts + in-flight rows) counts against the organization's credit limit for the current billing period, falling back to the calendar month when billing hasn't synced the product. Per-scanner volume estimates are credit-weighted and summed into a projected-spend prognosis shown at configuration time. Scheduled observations over budget are skipped; on-demand ones are rejected. A scanner can also carry its own optional credit_limit for the same period, so one broad scanner cannot drain the whole organization budget. A scanner that reaches its limit stops scanning until the period resets, stays enabled, and does not go back for the sessions it skipped.

Scenes and tabs

Scanner list (/replay-vision), two tabs switched through ?tab=:

Tab ?tab= What it shows
Scanners (none) The team's scanner roster plus the team-wide vision metrics.
Usage usage Credit spend over time for the org, bucketed daily/weekly/monthly/yearly.

Scanner (/replay-vision/<scanner-id>), five tabs switched through ?tab=. Overview is the default and writes no param.

Tab ?tab= What it shows
Overview overview Scanner status, findings (verdict mix, top tags, score distribution), the scout digest, a configuration summary, and self-driving results.
Observations observations The scanner's observations, filterable by status, verdict, tags, and date.
Run run Scan one recording, a batch of recordings, or backfill a date range. Old on-demand and backfills links open here, and configuration opens Overview.
Scouts scouts The scanner's signals scouts, including its daily digest.
Alerts alerts The scanner's alerts on the shared alerts platform.

Scanner editor (/replay-vision/<scanner-id>/<step>) opens a new scanner on a goal step (goal), where the agent drafts the whole scanner from a goal and a monthly budget for review on overview. Building by hand, or editing a saved scanner, uses a stepper rather than tabs: Details, Configure, Recordings (triggers), Budget. Observations have their own scene under /replay-vision/observations/…. An observation link carries the player's ?t=<seconds> param, so a shared observation opens with its recording expanded and playing from the shared moment.

Outside these scenes, the product also renders inside the session replay player: SummarizeRecordingBar under the player starts a summary, and the sidebar's Observations tab shows what the team's scanners found about the recording being watched. Summarizing switches the sidebar to that tab, and a recording that already has a summary lands there until the viewer picks another tab (standard players only — embedded, shared, and chromeless players skip every vision surface).

Experiment-created scanners

The experiment creation wizard offers an opt-in experiment scanner when the experiment-scanner feature flag is on, and offers no scanner without it. The scanner is the experiment type, saved off with start_on_launch, and the backend turns it on when the experiment launches. Its population comes from the experiment, never from its RecordingsQuery: the API derives the person-scoped exposure filter at scan time, the same resolution the experiment's Recordings tab uses, so the scanner watches the sessions that tab lists, including an exposure event that fires server-side or in an earlier session. The RecordingsQuery carries only the experiment's test-account setting, and the API rejects an experiment_exposure set there directly. Older wizard scanners are classifiers with experiment_targeting and keep working. Scanner creation runs after the experiment has been persisted and cannot roll back a successfully created experiment.

The experiment scanner type is the way agents (Max, MCP, the scanning-experiments-with-replay-vision skill) scan an experiment: its experiment lives in scanner_config, each session's variant comes from the exposure data, variants are sampled evenly, and GET scanners/{id}/variants/ reads the results per variant.

Layout

  • backend/models/ — ReplayScanner, ReplayObservation, ReplayScannerBackfill, ReplayObservationRequest (one handle over a programmatic batch of scans, served at vision/requests/ and open to project secret API keys), observation labels (ratings), usage receipts, and TeamReplayVisionConfig (the team's learned rules state).
  • backend/api/ — DRF viewsets and serializers (scanners, observations, backfills, quota, stats, live progress over SSE).
  • backend/queries/ — ClickHouse candidate selection (watermark + settle window + eligibility + sampling), the backfill's bounded descending walk and its exact count, and volume estimates.
  • backend/temporal/ — the apply workflow and its activities, per-scanner sweep, per-backfill tick, schedule reconciler (+ observation and backfill-schedule reapers), estimate refresher, vision alerts, and the Gemini file cleanup sweep.
  • backend/quota.py + backend/billing.py — credit accounting: the per-model price table, the receipt ledger, the quota snapshot the meter reads, and the per-org credit-limit override described below.
  • backend/gemini_client.py — every Gemini call goes through the Go AI gateway (AI_GATEWAY_URL and AI_GATEWAY_API_KEY). There is no direct route to Google, so local development needs a running gateway (bin/start-ai-gateway, credential from bin/setup-gateway-e2e).
  • backend/enqueue_claims.py — atomic slot claims that keep on-demand scans inside the in-flight caps.
  • backend/embeddings.py — the embedding identity shared by the write and search sides.
  • backend/search.py + backend/search_rerank.py — observation search: embedding rank, access-scoped hydration, and the decision-model rerank of the head.
  • backend/impact.py — affected sessions and users per scanner, exportable as a static cohort.
  • backend/watch_themes.py: example searches for the Search tab's empty state. The embedding consumer clusters each scanner's issue observations into themes. A small model names a theme when it reaches 5 members and again each time it doubles, and the Search tab shows the largest active themes.
  • backend/tags.py — tag slug normalization for classifiers.
  • backend/max_tools.py — Max AI tools (draft a scanner prompt, digest summaries, semantic search over observations).
  • backend/scanner_access.py — scanner-level RBAC shared by the API and the alert engine.
  • backend/facade/ — the cross-product entry point (session observations, formatted for Max reports).
  • backend/admin.py — Django admin registrations.
  • frontend/ — kea-first scenes and logics for the scanner management UI; frontend/generated/ carries the generated API types.

Per-org credit limit override

REPLAY_VISION_ORG_CREDIT_LIMIT_OVERRIDES caps monthly credit spend for named organizations, on top of whatever billing reports. It exists for organizations on unlimited plans, where billing correctly syncs no limit but spend still needs a ceiling — our own internal org being the case it was built for.

The value is a JSON object of organization id to monthly credit cap:

{ "01234567-89ab-cdef-0123-456789abcdef": 500000 }
  • The tighter of billing's limit and the override wins, so it can only ever reduce credits.
  • Every gate and spend surface reads it, because they all resolve through quota_state. An org at its override behaves exactly like an org at a billing limit: observations stop, and the quota UI and the cost preview both price against what is left.
  • Keys are normalized through UUID, so uppercase or unhyphenated ids still match the org they name.
  • Values clamp at zero, and booleans are rejected. A malformed entry is dropped on its own and logged; the rest of the map still applies. Unparseable JSON yields no overrides rather than failing startup.
  • Applied org ids are logged at startup, so a cap that silently failed to match is visible.

Changing it takes a deploy, since it is read once at import.