: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-vision): create experiment scanners from every experiment entry point (#112020)
Kim Svatos Duganbeceb0a53b3b
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.tsindex 4bdf6990506f..19583db97be9 100644--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts@@ -4,7 +4,9 @@ import { router } from 'kea-router'import { expectLogic, partial } from 'kea-test-utils'import posthog from 'posthog-js'+import { FEATURE_FLAGS } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { refreshTreeItem } from '~/layout/panel-layout/ProjectTree/projectTreeLogic'import { useMocks } from '~/mocks/jest'@@ -149,6 +151,7 @@ describe('createExperimentLogic', () => {})it('creates a scanner scoped to enrolled experiment sessions when selected', async () => {+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })await expectLogic(logic, () => {logic.actions.setCreateReplayVisionScanner(true)logic.actions.setExperiment({@@ -178,16 +181,16 @@ describe('createExperimentLogic', () => {expect(scannerCreateSpy).toHaveBeenCalledTimes(1)expect(scannerRequestBody).toMatchObject({name: 'Checkout flow (#123)',- scanner_type: 'classifier',- // Enabling starts credit spend, so a created scanner must never arrive switched on+ scanner_type: 'experiment',+ // The experiment is a draft, so the API refuses the scanner on; it turns on at launchenabled: false,+ scanner_config: { experiment_id: 123, variants: null, start_on_launch: true },// `model` is required by the create serializer — omitting it 400s every createprovider: DEFAULT_PROVIDER,model: DEFAULT_MODEL,- experiment_targeting: { experiment_id: 123, variant: null },query: { kind: 'RecordingsQuery', filter_test_accounts: true },})- // The API derives the exposure filter from the targeting and rejects one set in the+ // The API derives the exposure filter from the experiment and rejects one set in the// query, so a hand-built population here is the regression to catchexpect(scannerRequestBody?.query).not.toHaveProperty('events')expect(scannerRequestBody?.query).not.toHaveProperty('experiment_exposure')@@ -205,7 +208,7 @@ describe('createExperimentLogic', () => {}))expect(lemonToast.success).toHaveBeenCalledWith(- 'Experiment created. The Replay Vision scanner is off until you turn it on.',+ 'Experiment created. The Replay Vision scanner turns on when you launch the experiment.',expect.objectContaining({button: expect.objectContaining({ label: 'View scanner' }),})diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.tsindex 49f272b5db8a..5c25386ff978 100644--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts@@ -5,7 +5,9 @@ import posthog from 'posthog-js'import { ApiError } from 'lib/api-error'import { tryShowMCPHint } from 'lib/components/MCPHint/mcpHintLogic'import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'+import { FEATURE_FLAGS } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'import { featureFlagsLogic } from 'scenes/feature-flags/featureFlagsLogic'import { projectLogic } from 'scenes/projectLogic'import { teamLogic } from 'scenes/teamLogic'@@ -68,6 +70,7 @@ export interface CreateExperimentLogicProps {}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface createExperimentLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogiccurrentProjectId: number | null // projectLogicfeatureFlagKeyValidation: FeatureFlagKeyValidation | null // variantsPanelLogicfeatureFlagKeyValidationLoading: boolean // variantsPanelLogic@@ -199,6 +202,8 @@ export const createExperimentLogic = kea<createExperimentLogicType>([['featureFlagKeyValidation', 'featureFlagKeyValidationLoading'],projectLogic,['currentProjectId'],+ featureFlagLogic,+ ['featureFlags'],],actions: [featureFlagsLogic, ['updateFlag'], teamLogic, ['addProductIntent', 'addProductIntentForCrossSell']],})),@@ -500,11 +505,12 @@ export const createExperimentLogic = kea<createExperimentLogicType>([let replayScannerId: string | null = nulllet replayScannerCreationFailed = false+ const experimentScanners = !!values.featureFlags[FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]if (values.createReplayVisionScanner) {try {const replayScanner = await visionScannersCreate(String(values.currentProjectId),- experimentScannerBody(response)+ experimentScannerBody(response, experimentScanners))replayScannerId = replayScanner.idactions.addProductIntentForCrossSell({@@ -538,7 +544,9 @@ export const createExperimentLogic = kea<createExperimentLogicType>([})} else if (replayScannerId) {lemonToast.success(- 'Experiment created. The Replay Vision scanner is off until you turn it on.',+ experimentScanners+ ? 'Experiment created. The Replay Vision scanner turns on when you launch the experiment.'+ : 'Experiment created. The Replay Vision scanner is off until you turn it on.',{button: {label: 'View scanner',diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsxindex 37cc13c3dd33..f880f8eedf3f 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx@@ -259,6 +259,7 @@ function LinkedScannersCard({{scanner.name}</Link><LemonTag type="muted">{scannerTypeLabel(scanner.scannerType)}</LemonTag>+ {scanner.startsAtLaunch && <LemonTag type="highlight">Starts at launch</LemonTag>}</span><span className="text-muted shrink-0">{pluralize(scanner.observationsThisMonth, 'observation')} this monthdiff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.tsindex 29287d3a5228..a40e770bcf42 100644--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts@@ -2173,8 +2173,28 @@ describe('experimentReplayTabLogic', () => {featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS]: true });(visionScannersList as jest.Mock).mockResolvedValue({results: [- { id: 's1', name: 'Checkout confusion', scanner_type: 'classifier', observations_this_month: 50 },- { id: 's2', name: 'Rage clicks', scanner_type: 'summarizer', observations_this_month: 3 },+ {+ id: 's1',+ name: 'Checkout confusion',+ scanner_type: 'classifier',+ enabled: true,+ observations_this_month: 50,+ },+ {+ id: 's2',+ name: 'Rage clicks',+ scanner_type: 'summarizer',+ enabled: false,+ observations_this_month: 3,+ },+ {+ id: 's3',+ name: 'Checkout redesign (#42)',+ scanner_type: 'experiment',+ enabled: false,+ scanner_config: { experiment_id: 42, start_on_launch: true },+ observations_this_month: 0,+ },],})const withScanners = experimentReplayTabLogic({ experiment: EXPERIMENT })@@ -2183,9 +2203,29 @@ describe('experimentReplayTabLogic', () => {await expectLogic(withScanners).toFinishAllListeners().toMatchValues({+ // Only an off scanner that waits for launch says so; a scanner turned off by hand does not.linkedScanners: [- { id: 's1', name: 'Checkout confusion', scannerType: 'classifier', observationsThisMonth: 50 },- { id: 's2', name: 'Rage clicks', scannerType: 'summarizer', observationsThisMonth: 3 },+ {+ id: 's1',+ name: 'Checkout confusion',+ scannerType: 'classifier',+ observationsThisMonth: 50,+ startsAtLaunch: false,+ },+ {+ id: 's2',+ name: 'Rage clicks',+ scannerType: 'summarizer',+ observationsThisMonth: 3,+ startsAtLaunch: false,+ },+ {+ id: 's3',+ name: 'Checkout redesign (#42)',+ scannerType: 'experiment',+ observationsThisMonth: 0,+ startsAtLaunch: true,+ },],})expect(visionScannersList).toHaveBeenCalledWith(expect.any(String), { experiment_id: '42' })diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.tsindex 6b3a8717125a..d817ce441667 100644--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts@@ -121,6 +121,8 @@ export interface LinkedScanner {name: stringscannerType: ScannerTypeEnumApiobservationsThisMonth: number+ /** Saved off on a draft experiment; it turns on when the experiment launches. */+ startsAtLaunch: boolean}/** One experiment metric offered in the recordings tab's "Metric events" dropdown. */@@ -594,6 +596,7 @@ export interface experimentReplayTabLogicActions {name: stringobservationsThisMonth: numberscannerType: ScannerTypeEnumApi+ startsAtLaunch: boolean}[],payload?: unknown) => {@@ -602,6 +605,7 @@ export interface experimentReplayTabLogicActions {name: stringobservationsThisMonth: numberscannerType: ScannerTypeEnumApi+ startsAtLaunch: boolean}[]payload?: unknown}@@ -1059,6 +1063,10 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([name: scanner.name,scannerType: scanner.scanner_type,observationsThisMonth: scanner.observations_this_month,+ startsAtLaunch:+ !scanner.enabled &&+ (scanner.scanner_config as { start_on_launch?: boolean } | null)?.start_on_launch ===+ true,}))} catch {return []diff --git a/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx b/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsxindex 7f8229529307..af88936ed5c4 100644--- a/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx+++ b/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx@@ -4,6 +4,7 @@ import { useState } from 'react'import { IconInfo } from '@posthog/icons'import { LemonButton, LemonCheckbox, Tooltip } from '@posthog/lemon-ui'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'@@ -105,6 +106,7 @@ function ReplayVisionScannerCheckbox(): JSX.Element {const { setCreateReplayVisionScanner } = useActions(experimentWizardLogic)const { dataProcessingAccepted } = useValues(aiConsentLogic)const [consentRequested, setConsentRequested] = useState(false)+ const experimentScanners = useFeatureFlag('VISION_EXPERIMENT_SCANNER')const checkbox = (<LemonCheckbox@@ -124,10 +126,9 @@ function ReplayVisionScannerCheckbox(): JSX.Element {<div className="py-3"><div className="font-semibold">Watch participant behavior with Replay Vision</div><div className="mt-1 font-normal text-sm text-muted">- Set up a scanner that classifies what participants do after experiment exposure. It is created- turned off, so nothing is scanned and no credits are used until you turn it on. You can adjust- its prompt, filters, and sampling first. A scanner keeps running after the experiment ends, so- turn it off when you are done.+ {experimentScanners+ ? 'Set up a scanner that summarizes what participants do in each variant after exposure. It turns on when you launch the experiment and stops when the experiment ends. Until launch, nothing is scanned and no credits are used, and you can adjust its prompt, filters, and sampling.'+ : 'Set up a scanner that classifies what participants do after experiment exposure. It is created turned off, so nothing is scanned and no credits are used until you turn it on. You can adjust its prompt, filters, and sampling first. A scanner keeps running after the experiment ends, so turn it off when you are done.'}</div>{/* Per-session price only: a monthly projection needs the 30-day recording history the* estimate endpoint reads, and an unstarted experiment has no exposed sessions yet, sodiff --git a/frontend/src/scenes/experiments/replayVisionScanner.test.ts b/frontend/src/scenes/experiments/replayVisionScanner.test.tsindex ff7c695c9b34..a15c138d0d95 100644--- a/frontend/src/scenes/experiments/replayVisionScanner.test.ts+++ b/frontend/src/scenes/experiments/replayVisionScanner.test.ts@@ -5,36 +5,41 @@ import { NEW_EXPERIMENT } from 'products/experiments/frontend/constants'import { prefillScannerForExperiment } from 'products/replay_vision/frontend/replay_scanners/experimentTargeting'import type { ReplayScanner } from 'products/replay_vision/frontend/replay_scanners/types'-import { experimentScannerBody, experimentScannerPrompt } from './replayVisionScanner'+import { experimentScannerBody } from './replayVisionScanner'describe('replayVisionScanner', () => {- describe('experimentScannerPrompt', () => {+ describe('saved scanner config', () => {+ // The scanner API shows the config to anyone who can view the scanner, so the experiment's+ // hypothesis must stay out of it. Each scan adds the hypothesis after an access check.it.each([{- name: 'uses the hypothesis as the changed-surface grounding',- description: 'New one-page checkout',- expected: 'What the experiment changes: New one-page checkout',+ name: 'the scanner wizard prefill',+ build: (experiment: Experiment): unknown =>+ prefillScannerForExperiment(+ { name: 'Frustration score' } as ReplayScanner,+ { experiment, variantKey: null },+ true+ ).scanner_config,},{- name: 'falls back to the experiment name when the hypothesis is blank',- description: '',- expected: 'Its name is "Checkout redesign"',+ name: 'the experiment form checkbox',+ build: (experiment: Experiment): unknown => experimentScannerBody(experiment, true).scanner_config,},- {- name: 'treats a whitespace-only hypothesis as blank',- description: ' ',- expected: 'Its name is "Checkout redesign"',- },- ])('$name', ({ description, expected }) => {- const experiment: Experiment = { ...NEW_EXPERIMENT, name: 'Checkout redesign', description }- expect(experimentScannerPrompt(experiment)).toContain(expected)+ ])('$name keeps the experiment hypothesis out of it', ({ build }) => {+ const experiment: Experiment = {+ ...NEW_EXPERIMENT,+ id: 123,+ name: 'Checkout redesign',+ description: 'Private hypothesis about one-page checkout',+ }++ expect(JSON.stringify(build(experiment))).not.toContain('Private hypothesis')})})describe('experimentScannerBody', () => {- // Every experiment shape must produce the same population, because the API resolves the- // exposed sessions from the targeting. A query that carries an exposure filter is the old- // client-built shape, and the API rejects it.+ // The experiment is a draft at this point, so a scanner saved on, or without+ // start_on_launch, is refused by the API or never starts.it.each([{name: 'a default exposure event',@@ -58,7 +63,7 @@ describe('replayVisionScanner', () => {expectedFilterTestAccounts: true,},])(- 'targets all variants of the experiment and keeps the query free of filters: $name',+ 'saves an experiment scanner that waits for launch, with no filters: $name',({ exposure_criteria, expectedFilterTestAccounts }) => {const experiment: Experiment = {...NEW_EXPERIMENT,@@ -67,9 +72,14 @@ describe('replayVisionScanner', () => {exposure_criteria,}- const body = experimentScannerBody(experiment)+ const body = experimentScannerBody(experiment, true)- expect(body.experiment_targeting).toEqual({ experiment_id: 123, variant: null })+ expect(body).toMatchObject({+ scanner_type: 'experiment',+ scanner_config: { experiment_id: 123, variants: null, start_on_launch: true },+ enabled: false,+ })+ expect(body.experiment_targeting).toBeUndefined()expect(body.query).toEqual({kind: NodeKind.RecordingsQuery,filter_test_accounts: expectedFilterTestAccounts,@@ -77,20 +87,34 @@ describe('replayVisionScanner', () => {})- // The two entry points build different scanners on purpose: this one is a fixed classifier,- // and the Recordings tab hands the person the scanner wizard. The population is the part- // that must stay identical, because both feed the same server-derived exposure filter.+ // Both entry points feed the same server-derived exposure filter, so the population they+ // build must stay identical.it('builds the same population as the scanner wizard prefill', () => {const experiment: Experiment = { ...NEW_EXPERIMENT, id: 123, name: 'Checkout redesign' }- const prefilled = prefillScannerForExperiment({ name: 'Frustration score' } as ReplayScanner, {- experiment,- variantKey: null,- })+ const prefilled = prefillScannerForExperiment(+ { name: 'Frustration score' } as ReplayScanner,+ { experiment, variantKey: null },+ true+ )- const body = experimentScannerBody(experiment)+ const body = experimentScannerBody(experiment, true)- expect(body.experiment_targeting).toEqual(prefilled.experiment_targeting)+ expect(prefilled.scanner_type).toEqual(body.scanner_type)+ expect(prefilled.scanner_config).toMatchObject({ experiment_id: 123, variants: null })expect(body.query).toEqual(prefilled.query)})++ // Until the flag is on for a team, the checkbox keeps creating what it always has.+ it('without the experiment type, saves an off classifier with legacy targeting', () => {+ const experiment: Experiment = { ...NEW_EXPERIMENT, id: 123, name: 'Checkout redesign' }++ const body = experimentScannerBody(experiment, false)++ expect(body).toMatchObject({+ scanner_type: 'classifier',+ experiment_targeting: { experiment_id: 123, variant: null },+ enabled: false,+ })+ })})})diff --git a/frontend/src/scenes/experiments/replayVisionScanner.ts b/frontend/src/scenes/experiments/replayVisionScanner.tsindex e2c78145b2fa..fff8fda45f32 100644--- a/frontend/src/scenes/experiments/replayVisionScanner.ts+++ b/frontend/src/scenes/experiments/replayVisionScanner.ts@@ -3,6 +3,7 @@ import type { Experiment } from '~/types'import type { ReplayScannerApi } from 'products/replay_vision/frontend/generated/api.schemas'import {buildExperimentTargeting,+ experimentScannerConfig,experimentScannerQuery,} from 'products/replay_vision/frontend/replay_scanners/experimentTargeting'import {@@ -32,7 +33,7 @@ export const EXPERIMENT_SCANNER_TAGS = [* to, and a prompt that names them gets confident, wrong variant labels attached to observations.* Attribution comes from joining observations back to the exposure event at readout instead.*/-export function experimentScannerPrompt(experiment: Experiment): string {+function experimentClassifierPrompt(experiment: Experiment): string {const hypothesis = experiment.description?.trim()return ['Classify what this participant did after the point where the experiment change would first be visible to them. Ignore anything earlier in the session.',@@ -52,32 +53,45 @@ export function experimentScannerPrompt(experiment: Experiment): string {}/**- * The scanner's population lives in `experiment_targeting`, never in `query`: the API derives the- * person-scoped exposure filter from it at scan time, and rejects an exposure filter set in the- * query directly. That keeps the scanner on the same sessions the experiment's Recordings tab- * lists, including an exposure event that fires server-side or in an earlier session. `query`- * carries only the experiment's test-account setting.+ * An experiment scanner on the experiment the wizard just created. That experiment is a draft, so+ * the scanner is saved off with `start_on_launch`, and the backend turns it on when the experiment+ * launches. `query` carries only the experiment's test-account setting: the API derives the+ * exposed population from the experiment at scan time.*/-export function experimentScannerBody(experiment: Experiment): ReplayScannerApi {+export function experimentScannerBody(experiment: Experiment, asExperimentScanner: boolean): ReplayScannerApi {const nameSuffix = ` (#${experiment.id})`const name = `${experiment.name.slice(0, SCANNER_NAME_MAX_LENGTH - nameSuffix.length)}${nameSuffix}`+ if (!asExperimentScanner) {+ // Without the experiment type: a classifier with legacy targeting, created off.+ return scannerToApiBody({+ name,+ description: 'Classifies what participants do after they are exposed to this experiment.',+ scanner_type: 'classifier',+ scanner_config: {+ prompt: experimentClassifierPrompt(experiment),+ tags: [...EXPERIMENT_SCANNER_TAGS],+ multi_label: false,+ },+ provider: DEFAULT_PROVIDER,+ model: DEFAULT_MODEL,+ // A null variant watches every variant of the experiment.+ experiment_targeting: buildExperimentTargeting({ experiment, variantKey: null }),+ query: experimentScannerQuery(experiment),+ // Enabling starts real credit spend, so that stays a human decision on the scanner itself.+ enabled: false,+ })+ }+return scannerToApiBody({name,- description: 'Classifies what participants do after they are exposed to this experiment.',- scanner_type: 'classifier',- scanner_config: {- prompt: experimentScannerPrompt(experiment),- tags: [...EXPERIMENT_SCANNER_TAGS],- multi_label: false,- },+ description: 'Summarizes what participants do after they are exposed to this experiment, for each variant.',+ scanner_type: 'experiment',+ scanner_config: { ...experimentScannerConfig(experiment, null), start_on_launch: true },// `model` is required by the create serializer; the rest of the product picks the same defaults.provider: DEFAULT_PROVIDER,model: DEFAULT_MODEL,- // A null variant watches every variant of the experiment.- experiment_targeting: buildExperimentTargeting({ experiment, variantKey: null }),query: experimentScannerQuery(experiment),- // Enabling starts real credit spend, so that stays a human decision on the scanner itself.enabled: false,})}diff --git a/products/replay_vision/frontend/replay_scanners/experimentTargeting.test.ts b/products/replay_vision/frontend/replay_scanners/experimentTargeting.test.tsindex cd01718bc4b6..7ea25ea5d1fe 100644--- a/products/replay_vision/frontend/replay_scanners/experimentTargeting.test.ts+++ b/products/replay_vision/frontend/replay_scanners/experimentTargeting.test.ts@@ -1,7 +1,6 @@import { Experiment } from '~/types'import {- buildExperimentTargeting,experimentScannerName,experimentScannerParams,parseExperimentScannerParams,@@ -72,22 +71,34 @@ describe('experimentTargeting', () => {})it.each([- ['test', { experiment_id: 7, variant: 'test' }],- [null, { experiment_id: 7, variant: null }],- ])('builds the persisted targeting for variant %j', (variantKey, expected) => {- expect(buildExperimentTargeting({ experiment, variantKey })).toEqual(expected)- })-- it('prefills targeting and test-account filtering without touching exposure in the query', () => {- const scanner = { name: 'Frustration score', query: { kind: 'RecordingsQuery' } } as unknown as ReplayScanner+ ['test', ['test']],+ [null, null],+ ])('prefills an experiment scanner for variant %j, with no exposure in the query', (variantKey, variants) => {+ // A monitor template, because the prefill must replace the type: the API refuses legacy+ // targeting, so only the experiment type can watch an experiment.+ const scanner = {+ name: 'Frustration score',+ scanner_type: 'monitor',+ scanner_config: { prompt: 'Did they get stuck?' },+ query: { kind: 'RecordingsQuery' },+ } as unknown as ReplayScanner- const prefilled = prefillScannerForExperiment(scanner, { experiment, variantKey: 'test' })+ const prefilled = prefillScannerForExperiment(scanner, { experiment, variantKey }, true)- expect(prefilled.experiment_targeting).toEqual({ experiment_id: 7, variant: 'test' })+ expect(prefilled).toMatchObject({+ scanner_type: 'experiment',+ scanner_config: { experiment_id: 7, variants, balance_variants: true },+ experiment_targeting: null,+ })expect(prefilled.query?.filter_test_accounts).toBe(true)- // Exposure must never enter the query blob: the API rejects it there, and access control- // for the experiment hangs off experiment_targeting alone.+ // Exposure must never enter the query blob: the API rejects it there.expect(prefilled.query).not.toHaveProperty('experiment_exposure')++ // Until the flag is on for a team, the template keeps its type and gets legacy targeting.+ expect(prefillScannerForExperiment(scanner, { experiment, variantKey }, false)).toMatchObject({+ scanner_type: 'monitor',+ experiment_targeting: { experiment_id: 7, variant: variantKey },+ })})it.each([diff --git a/products/replay_vision/frontend/replay_scanners/experimentTargeting.ts b/products/replay_vision/frontend/replay_scanners/experimentTargeting.tsindex 84f6136a977c..7b5df773c5cf 100644--- a/products/replay_vision/frontend/replay_scanners/experimentTargeting.ts+++ b/products/replay_vision/frontend/replay_scanners/experimentTargeting.ts@@ -5,12 +5,12 @@ import { Experiment } from '~/types'import type { ScannerExperimentTargetingApi } from 'products/replay_vision/frontend/generated/api.schemas'-import type { ReplayScanner } from './types'+import type { ExperimentScannerConfig, ReplayScanner } from './types'/*** Experiment context a scanner is being created or edited against. Held by replayScannerLogic so- * the Triggers step can offer variant targeting instead of raw filters. A null `variantKey` means- * every variant of the experiment.+ * the editor can name the experiment and offer its variants. A null `variantKey` means every+ * variant of the experiment.*/export interface ExperimentScannerContext {experiment: Experiment@@ -50,20 +50,6 @@ export function parseExperimentScannerParams(searchParams: Record<string, any>):return { experimentId, variantKey }}-/**- * The scanner's persisted experiment targeting. The backend derives the person-scoped exposure- * filter from this field at scan time — the same resolution the experiment Recordings tab uses —- * so the scanner watches exactly the sessions that tab lists, including when the exposure event- * fires server-side or in an earlier session. The exposure filter never enters `query` directly;- * the API rejects it there so targeting stays behind this field's experiment access check.- */-export function buildExperimentTargeting(context: ExperimentScannerContext): ScannerExperimentTargetingApi {- return {- experiment_id: context.experiment.id as number,- variant: context.variantKey,- }-}-export interface ScannerExperimentScope {experimentId: number/** Null watches every variant. */@@ -99,7 +85,8 @@ export function scopeVariantsLabel(scope: ScannerExperimentScope, everyVariant:/*** The query keys an experiment-scoped scanner takes from its experiment. The population is never- * one of them: it lives in `experiment_targeting`, and the API rejects an exposure filter set here.+ * one of them: the API derives it from the experiment at scan time, and rejects an exposure filter+ * set here.* Every entry point that creates such a scanner reads this, so the test-account default cannot* drift between them.*/@@ -129,15 +116,71 @@ export function experimentScannerName(baseName: string, experimentName: string):return name.slice(0, 255)}-/** Applies the experiment context to a fresh (or freshly templated) scanner: targeting, scoped name. */-export function prefillScannerForExperiment(scanner: ReplayScanner, context: ExperimentScannerContext): ReplayScanner {+/**+ * The default focus for an experiment scanner's summaries. The variant keys are deliberately+ * absent: the scan reads each session's variant from exposure data, and a prompt that names them+ * invites the model to guess one instead. The experiment's name and hypothesis are absent too: each+ * scan adds them after an access check, and a saved prompt shows them to anyone who can view the+ * scanner, including people who cannot view the experiment.+ */+export const EXPERIMENT_SCANNER_PROMPT = [+ 'Summarize what this participant did after the point where the experiment change would first be visible to them. Ignore anything earlier in the session.',+ "Use the experiment's name and hypothesis, which every scan includes, to work out which part of the product it changes.",+ 'If they never reached the part of the product the experiment changes, say so in one sentence.',+ 'Otherwise describe how they used it: where they moved on without trouble, where they paused or went back, what they seemed to misread, and any error or dead end they hit.',+].join('\n\n')++/** The experiment type's config for an experiment, with every variant sampled evenly by default. */+export function experimentScannerConfig(+ experiment: Experiment,+ variants: string[] | null,+ prompt: string = EXPERIMENT_SCANNER_PROMPT+): ExperimentScannerConfig {+ return {+ prompt,+ length: 'medium',+ experiment_id: experiment.id as number,+ variants,+ balance_variants: true,+ }+}++/**+ * Legacy experiment targeting on another scanner type, for teams without the experiment type yet. The+ * backend derives the person-scoped exposure filter from it at scan time.+ */+export function buildExperimentTargeting(context: ExperimentScannerContext): ScannerExperimentTargetingApi {+ return {+ experiment_id: context.experiment.id as number,+ variant: context.variantKey,+ }+}++/**+ * Turns a fresh (or freshly templated) scanner into an experiment scanner for the context: the+ * experiment type, a scoped name, and the experiment's test-account setting. A template's type and+ * prompt give way, because only the experiment type compares variants.+ */+export function prefillScannerForExperiment(+ scanner: ReplayScanner,+ context: ExperimentScannerContext,+ asExperimentScanner: boolean+): ReplayScanner {+ const query = { ...scanner.query, ...experimentScannerQuery(context.experiment) }+ if (!asExperimentScanner) {+ return {+ ...scanner,+ name: experimentScannerName(scanner.name, context.experiment.name),+ experiment_targeting: buildExperimentTargeting(context),+ query,+ }+ }return {...scanner,name: experimentScannerName(scanner.name, context.experiment.name),- experiment_targeting: buildExperimentTargeting(context),- query: {- ...scanner.query,- ...experimentScannerQuery(context.experiment),- },+ scanner_type: 'experiment',+ scanner_config: experimentScannerConfig(context.experiment, context.variantKey ? [context.variantKey] : null),+ experiment_targeting: null,+ query,}}diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.tsindex c30761fc27e6..9a49640ddaf9 100644--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts@@ -4,7 +4,9 @@ import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import posthog from 'posthog-js'+import { FEATURE_FLAGS } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'@@ -153,9 +155,10 @@ describe('replayScannerLogic', () => {})// The replay filters entry point sends both when the filters scope to an experiment, since- // exposure can't ride inside the query. Keeping only the targeting would silently widen the+ // exposure can't ride inside the query. Keeping only the experiment would silently widen the// scanner to every session; keeping only the filters would drop the experiment entirely.it('combines an experiment deep link with a ?filters= query rather than dropping either', async () => {+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })useMocks({get: { '/api/projects/:team/experiments/:id/': () => [200, { id: 7, name: 'Checkout redesign' }] },})@@ -167,7 +170,11 @@ describe('replayScannerLogic', () => {await expectLogic(logic, () => logic.actions.loadScanner()).toFinishAllListeners()- expect(logic.values.scanner?.experiment_targeting).toMatchObject({ experiment_id: 7 })+ expect(logic.values.scanner).toMatchObject({+ scanner_type: 'experiment',+ scanner_config: { experiment_id: 7, variants: null },+ experiment_targeting: null,+ })expect(logic.values.scanner?.query).toMatchObject({ events: query.events })})})@@ -237,19 +244,34 @@ describe('replayScannerLogic', () => {expect(logic.values.scanner?.query).toEqual({ kind: 'RecordingsQuery' })})- it('carries the drafted experiment targeting onto the form', async () => {- // Targeting is not part of the query, so the form is its only carrier: dropped here, the- // saved scanner watches every visitor of the drafted pages instead of the participants.+ // The experiment is not part of the query, so the form is its only carrier: dropped here, the+ // saved scanner watches every visitor of the drafted pages instead of the participants. The+ // API refuses new legacy targeting, so either draft shape must become the experiment type.+ it.each([+ {+ shape: 'legacy targeting on another type',+ scanner_type: 'classifier',+ scanner_config: { prompt: 'Describe the friction.', tags: ['smooth'], multi_label: false },+ experiment_targeting: { experiment_id: 11, variant: 'test' },+ },+ {+ shape: 'the experiment type',+ scanner_type: 'experiment',+ scanner_config: { prompt: 'Describe the friction.', experiment_id: 11, variants: ['test'] },+ experiment_targeting: null,+ },+ ])('carries the drafted experiment onto the form from $shape', async (draft) => {+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })draftSpy.mockReturnValue([200,{name: 'New entrypoint friction',- description: 'Classifies friction in the new entrypoint.',- scanner_type: 'classifier',- scanner_config: { prompt: 'Classify the friction.', tags: ['smooth'], multi_label: false },+ description: 'Describes friction in the new entrypoint.',rationale: '',query: null,- experiment_targeting: { experiment_id: 11, variant: 'test' },+ scanner_type: draft.scanner_type,+ scanner_config: draft.scanner_config,+ experiment_targeting: draft.experiment_targeting,},])router.actions.push(urls.replayVisionScannerTemplate('new'))@@ -258,41 +280,66 @@ describe('replayScannerLogic', () => {logic.actions.draftScannerFromGoal('friction in the new AI entrypoint')).toFinishAllListeners()- expect(logic.values.scanner?.experiment_targeting).toEqual({ experiment_id: 11, variant: 'test' })+ expect(logic.values.scanner).toMatchObject({+ scanner_type: 'experiment',+ scanner_config: { prompt: 'Describe the friction.', experiment_id: 11, variants: ['test'] },+ experiment_targeting: null,+ })})- it('keeps an experiment prefill the AI draft did not name', async () => {- // The experiment cross-sell deep-links targeting the goal text never mentions. Dropping it- // here would save a scanner watching every visitor of the drafted pages, not the participants.- useMocks({- get: {- '/api/projects/:team/experiments/:id/': () => [200, { id: 7, name: 'Checkout redesign' }],+ // Until the flag is on for a team, the prefill stays legacy targeting on the drafted type.+ it.each([+ {+ experimentScanners: true,+ expected: {+ scanner_type: 'experiment',+ scanner_config: { prompt: 'Watch for drop-off.', experiment_id: 7, variants: null },+ experiment_targeting: null,},- })- draftSpy.mockReturnValue([- 200,- {- name: 'Billing drop-off',- description: 'Watches where people give up.',+ },+ {+ experimentScanners: false,+ expected: {scanner_type: 'monitor',scanner_config: { prompt: 'Watch for drop-off.' },- rationale: '',- query: { kind: 'RecordingsQuery' },+ experiment_targeting: { experiment_id: 7, variant: null },},- ])- router.actions.push(urls.replayVisionScannerTemplate('new'), { experiment: '7' })- await expectLogic(logic, () => logic.actions.loadScanner()).toFinishAllListeners()- expect(logic.values.experimentContext).toMatchObject({ experiment: { id: 7 }, variantKey: null })+ },+ ])(+ 'keeps an experiment prefill the AI draft did not name, experiment scanners $experimentScanners',+ async ({ experimentScanners, expected }) => {+ // The experiment cross-sell deep-links an experiment the goal text never mentions. Dropping it+ // here would save a scanner watching every visitor of the drafted pages, not the participants.+ featureFlagLogic.actions.setFeatureFlags([], {+ [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: experimentScanners,+ })+ useMocks({+ get: {+ '/api/projects/:team/experiments/:id/': () => [200, { id: 7, name: 'Checkout redesign' }],+ },+ })+ draftSpy.mockReturnValue([+ 200,+ {+ name: 'Billing drop-off',+ description: 'Watches where people give up.',+ scanner_type: 'monitor',+ scanner_config: { prompt: 'Watch for drop-off.' },+ rationale: '',+ query: { kind: 'RecordingsQuery' },+ },+ ])+ router.actions.push(urls.replayVisionScannerTemplate('new'), { experiment: '7' })+ await expectLogic(logic, () => logic.actions.loadScanner()).toFinishAllListeners()+ expect(logic.values.experimentContext).toMatchObject({ experiment: { id: 7 }, variantKey: null })- await expectLogic(logic, () =>- logic.actions.draftScannerFromGoal('where do people give up in billing')- ).toFinishAllListeners()+ await expectLogic(logic, () =>+ logic.actions.draftScannerFromGoal('where do people give up in billing')+ ).toFinishAllListeners()- expect(logic.values.scanner).toMatchObject({- name: 'Billing drop-off: Checkout redesign',- experiment_targeting: { experiment_id: 7, variant: null },- })- })+ expect(logic.values.scanner).toMatchObject({ name: 'Billing drop-off: Checkout redesign', ...expected })+ }+ )it('drops a stale draft when the user has left the template step mid-request', async () => {draftSpy.mockReturnValue([diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.tsindex bd0abd13c359..a5c2196c700a 100644--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts@@ -20,8 +20,10 @@ import { CombinedLocation } from 'kea-router/lib/utils'import posthog from 'posthog-js'import api from 'lib/api'+import { FEATURE_FLAGS } from 'lib/constants'import { scrollToFormError } from 'lib/forms/scrollToFormError'import { lemonToast } from 'lib/lemon-ui/LemonToast'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { copyToClipboard } from 'lib/utils/copyToClipboard'import { removeProjectIdIfPresent } from 'lib/utils/kea-router'import { objectsEqual } from 'lib/utils/objects'@@ -70,9 +72,11 @@ import { clampDurationFilter, durationFilterError } from './durationBounds'import {ExperimentScannerContext,buildExperimentTargeting,+ experimentScannerConfig,experimentScannerName,parseExperimentScannerParams,prefillScannerForExperiment,+ ScannerExperimentScope,reconcileVariantKey,scannerExperimentScope,} from './experimentTargeting'@@ -93,6 +97,7 @@ import type { ObservationStatusStats } from './scannerStats'import { availableTagsFromStats, daysFromDateRange, deriveObservationStatusStats } from './scannerStats'import { findScannerTemplate, newScanner } from './scannerTemplates'import {+ ExperimentScannerConfig,MAX_CREDIT_LIMIT,OBSERVATION_LIST_URL_PARAM_KEYS,SamplingMode,@@ -192,6 +197,56 @@ function defaultConfigForType(scannerType: ScannerType): ScannerConfig {return { prompt: '' }}+/** Until experiment scanners ship, the experiment entry points keep creating legacy targeting. */+function experimentScannersEnabled(): boolean {+ return !!featureFlagLogic.values.featureFlags[FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]+}++/** The experiment a goal draft named, in the experiment type's config or in the legacy targeting. */+function draftExperimentScope(goalDraft: DraftScannerResponseApi): ScannerExperimentScope | null {+ if (goalDraft.scanner_type === 'experiment') {+ const config = goalDraft.scanner_config as ExperimentScannerConfig+ return config.experiment_id ? { experimentId: config.experiment_id, variants: config.variants ?? null } : null+ }+ const targeting = goalDraft.experiment_targeting+ return targeting?.experiment_id+ ? { experimentId: targeting.experiment_id, variants: targeting.variant ? [targeting.variant] : null }+ : null+}++/** A draft that watches an experiment becomes the experiment type, keeping the drafted prompt as its focus. */+function draftScannerTypeAndConfig(+ goalDraft: DraftScannerResponseApi,+ draftedExperiment: ScannerExperimentScope | null,+ context: ExperimentScannerContext | null+): Pick<ScannerFormValues, 'scanner_type' | 'scanner_config'> {+ const draftConfig = goalDraft.scanner_config as ScannerConfig+ const scope =+ draftedExperiment ??+ (context+ ? {+ experimentId: context.experiment.id as number,+ variants: context.variantKey ? [context.variantKey] : null,+ }+ : null)+ if (!scope) {+ return { scanner_type: goalDraft.scanner_type as ScannerType, scanner_config: draftConfig } as Pick<+ ScannerFormValues,+ 'scanner_type' | 'scanner_config'+ >+ }+ return {+ scanner_type: 'experiment',+ scanner_config: {+ prompt: draftConfig.prompt,+ length: ('length' in draftConfig && draftConfig.length) || 'medium',+ experiment_id: scope.experimentId,+ variants: scope.variants,+ balance_variants: true,+ },+ }+}+function omitQuery(scanner: ReplayScanner): Omit<ReplayScanner, 'query'> {const { query: _query, ...rest } = scannerreturn rest@@ -1820,7 +1875,11 @@ export const replayScannerLogic = kea<replayScannerLogicType>([experiment,variantKey: reconcileVariantKey(experiment, experimentParams.variantKey),}- const prefilled = prefillScannerForExperiment(experimentBase, context)+ const prefilled = prefillScannerForExperiment(+ experimentBase,+ context,+ experimentScannersEnabled()+ )// Set the context only after the prefill is built, so a throw inside it// doesn't leave a dangling context that the next startFromTemplate re-applies.actions.setExperimentContext(context)@@ -1901,11 +1960,11 @@ export const replayScannerLogic = kea<replayScannerLogicType>([actions.rebuildExperimentContext()},- // Rebuilds the targeting card from the form's current targeting — a loaded scanner or a- // restored draft — so the variant picker and detach stay usable wherever it came from.- // The API nulls experiment_targeting for viewers denied the experiment, so this never- // fetches an experiment the viewer can't see. Fails soft: without the card the scanner- // still edits normally.+ // Rebuilds the experiment context from the form's current experiment — a loaded scanner+ // or a restored draft — so the editor can name it and list its variants wherever it came+ // from. The API hides the experiment from viewers denied it, so this never fetches an+ // experiment the viewer can't see. Fails soft: without the context the scanner still+ // edits normally.rebuildExperimentContext: async () => {const scope = scannerExperimentScope(values.scanner)if (!scope) {@@ -1942,8 +2001,10 @@ export const replayScannerLogic = kea<replayScannerLogicType>([}},- // The reducer has already stored the new key; targeting lives in its own field, so a- // variant change never touches `query` and filters the user added by hand survive.+ // The variants belong to the old experiment, so they reset with it. Only an unsaved scanner+ // gets here: the API fixes the experiment after creation.+ // Legacy targeting only. The reducer has already stored the new key; targeting lives in its+ // own field, so a variant change never touches `query` and filters added by hand survive.setExperimentVariant: () => {const context = values.experimentContextif (!context) {@@ -1952,8 +2013,6 @@ export const replayScannerLogic = kea<replayScannerLogicType>([actions.setScannerValue('experiment_targeting', buildExperimentTargeting(context))},- // The variants belong to the old experiment, so they reset with it. Only an unsaved scanner- // gets here: the API fixes the experiment after creation.setScannerExperiment: ({ experimentId }) => {actions.setScannerValues({ scanner_config: { experiment_id: experimentId, variants: null } })actions.rebuildExperimentContext()@@ -1978,11 +2037,17 @@ export const replayScannerLogic = kea<replayScannerLogicType>([// Only re-derive a name the user never edited, so a typed name always survives a type change.const keepsDefaultName =!current.name?.trim() || current.name === defaultScannerName(teamName, current.scanner_type)+ const context = values.experimentContext+ // A wizard entered from an experiment keeps watching it when the type returns to experiment.+ const config =+ scannerType === 'experiment' && context+ ? experimentScannerConfig(context.experiment, context.variantKey ? [context.variantKey] : null)+ : defaultConfigForType(scannerType)actions.resetScanner({...current,name: keepsDefaultName ? defaultScannerName(teamName, scannerType) : current.name,scanner_type: scannerType,- scanner_config: defaultConfigForType(scannerType),+ scanner_config: config,} as ScannerFormValues)persistDraft()},@@ -2021,19 +2086,21 @@ export const replayScannerLogic = kea<replayScannerLogicType>([) {return}- // An experiment prefill (targeting, scoped name, test-account setting) has to survive- // the AI draft the same way it survives a template pick, or a scanner started from an- // experiment would end up watching every visitor instead of the participants. A draft- // that named an experiment itself is fresher intent, so it wins.- const context = goalDraft.experiment_targeting ? null : values.experimentContext- if (goalDraft.experiment_targeting && values.experimentContext) {+ // An experiment prefill (experiment type, scoped name, test-account setting) has to+ // survive the AI draft the same way it survives a template pick, or a scanner started+ // from an experiment would end up watching every visitor instead of the participants.+ // A draft that named an experiment itself is fresher intent, so it wins.+ const asExperimentScanner = experimentScannersEnabled()+ const draftedExperiment = draftExperimentScope(goalDraft)+ const context = draftedExperiment ? null : values.experimentContext+ if (draftedExperiment && values.experimentContext) {// rebuildExperimentContext keeps a card whose experiment id already matches, so a// draft that renames the variant would leave the Recordings step showing the old// one while the scanner saves the new one. Drop the card and let it rebuild.actions.setExperimentContext(null)}const base = newScanner(null, teamLogic.values.currentTeam?.name)- actions.resetScanner(context ? prefillScannerForExperiment(base, context) : base)+ actions.resetScanner(context ? prefillScannerForExperiment(base, context, asExperimentScanner) : base)const draftQuery = goalDraft.query as RecordingsQuery | undefined// Applied as form values (not baked into the reset) so the draft persists like hand-edited// input and survives a reload of the configure step.@@ -2042,8 +2109,12 @@ export const replayScannerLogic = kea<replayScannerLogicType>([goal: payload?.goal.trim() || null,name: context ? experimentScannerName(goalDraft.name, context.experiment.name) : goalDraft.name,description: goalDraft.description,- scanner_type: goalDraft.scanner_type as ScannerType,- scanner_config: goalDraft.scanner_config as ScannerConfig,+ ...(asExperimentScanner+ ? draftScannerTypeAndConfig(goalDraft, draftedExperiment, context)+ : {+ scanner_type: goalDraft.scanner_type as ScannerType,+ scanner_config: goalDraft.scanner_config as ScannerConfig,+ }),// The drafted session filter (when the goal mapped to real screens or events); the// triggers step shows it for review like any hand-picked filter. Under an// experiment prefill it keeps that experiment's test-account setting.@@ -2067,14 +2138,14 @@ export const replayScannerLogic = kea<replayScannerLogicType>([...(goalDraft.credit_limit != null? { credit_limit: goalDraft.credit_limit, credit_limit_enabled: true }: {}),- // The experiment the goal named, if any. It watches that experiment's- // participants, which the query itself can't express — the backend derives the- // exposure filter from this field at scan time.- experiment_targeting:- goalDraft.experiment_targeting ?? (context ? buildExperimentTargeting(context) : null),+ // The experiment type carries the experiment. Without it, the experiment the goal+ // named (or the one the wizard was entered from) stays legacy targeting.+ experiment_targeting: asExperimentScanner+ ? null+ : (goalDraft.experiment_targeting ?? (context ? buildExperimentTargeting(context) : null)),})- // Loads the targeted experiment so the Triggers step shows its card and variant- // picker, the same way it does for a scanner started from the experiment itself.+ // Loads the experiment so the editor shows its name and variants, the same way it+ // does for a scanner started from the experiment itself.actions.rebuildExperimentContext()// Solved dials mark a goal-flow draft, which reviews on the overview; legacy drafts// open the details step. The goal flow is already on the overview (pushed on request),@@ -2157,7 +2228,9 @@ export const replayScannerLogic = kea<replayScannerLogicType>([// reset, so re-apply it when the wizard was entered from an experiment.const base = newScanner(templateKey, teamLogic.values.currentTeam?.name)const context = values.experimentContext- actions.resetScanner(context ? prefillScannerForExperiment(base, context) : base)+ actions.resetScanner(+ context ? prefillScannerForExperiment(base, context, experimentScannersEnabled()) : base+ )},discardScannerDraft: () => {// Storage holds one draft, and it belongs to the new-scanner wizard.diff --git a/products/replay_vision/frontend/replay_scanners/scannerHandoffFromFilters.ts b/products/replay_vision/frontend/replay_scanners/scannerHandoffFromFilters.tsindex 84e7d7f6811a..87ab7588d1f2 100644--- a/products/replay_vision/frontend/replay_scanners/scannerHandoffFromFilters.ts+++ b/products/replay_vision/frontend/replay_scanners/scannerHandoffFromFilters.ts@@ -32,11 +32,11 @@ export interface ScannerHandoffFromFilters {** - Session IDs pin the query to recordings that already exist. Nothing downstream removes them and* the sweep only moves forward, so a scanner carrying them never matches again.- * - Experiment exposure is rejected inside `query` by the API, which resolves it from- * `experiment_targeting` at scan time so the experiment stays behind that field's access check.+ * - Experiment exposure is rejected inside `query` by the API, which resolves it from the+ * experiment scanner's config at scan time so the experiment stays behind its access check.* Left in, the wizard can't be saved; dropped, the scanner silently widens past the experiment.- * It becomes the wizard's experiment deep link instead, which carries the same targeting the- * experiment's own entry point uses.+ * It becomes the wizard's experiment deep link instead, which builds the same experiment+ * scanner the experiment's own entry point does.* - The date range is dropped by the backend on save, because a scanner's schedule owns time.*/export function scannerHandoffFromFilters(filters: RecordingUniversalFilters): ScannerHandoffFromFilters {