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.

fix(replay-vision): stop starting points inheriting an editor-picked experiment (#118056)

Kim Svatos Dugan498c9699c475
diff --git a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
index 1b1331ba978b..e557d75d1909 100644
--- a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
@@ -124,7 +124,8 @@ export function ScannerEditorSceneComponent(): JSX.Element {
const scannerLogic = replayScannerLogic({ id: scannerId })
useAttachedLogic(scannerLogic, scannerEditorSceneLogic)
- const { scanner, scannerLoading, isScannerSubmitting, stepErrors, experimentContext } = useValues(scannerLogic)
+ const { scanner, scannerLoading, isScannerSubmitting, stepErrors, linkedExperimentContext } =
+ useValues(scannerLogic)
const { submitScanner } = useActions(scannerLogic)
// An experiment cross-sell entry point has already said what to watch and deep-linked the
@@ -222,7 +223,7 @@ export function ScannerEditorSceneComponent(): JSX.Element {
scanner from scratch.
</p>
</div>
- <ExperimentScopeNote experimentName={experimentContext?.experiment.name} />
+ <ExperimentScopeNote experimentName={linkedExperimentContext?.experiment.name} />
<ScannerTemplatePicker />
{/* The goal flow supersedes this box, so someone who has already
turned it down to build by hand should not be offered it again.
diff --git a/products/replay_vision/frontend/replay_scanners/components/ExperimentScannerConfigFields.tsx b/products/replay_vision/frontend/replay_scanners/components/ExperimentScannerConfigFields.tsx
index 13f384d44274..0051fb1fbd97 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ExperimentScannerConfigFields.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ExperimentScannerConfigFields.tsx
@@ -62,10 +62,10 @@ export function ExperimentScannerConfigFields({ scannerId }: ExperimentScannerCo
<>
Watches sessions of people exposed to{' '}
<Link to={urls.experiment(experiment.id)}>{experiment.name}</Link>. Each summary gets the
- person's variant from exposure data.
+ person's variant from exposure data. Experiments that aggregate by group aren't listed.
</>
) : (
- "Watches sessions of people exposed to this experiment. Each summary gets the person's variant from exposure data."
+ "Watches sessions of people exposed to this experiment. Each summary gets the person's variant from exposure data. Experiments that aggregate by group aren't listed."
)
}
>
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalDraft.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalDraft.tsx
index 32a6844bb5b2..f09126bc1ae4 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalDraft.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalDraft.tsx
@@ -15,7 +15,7 @@ import { replayScannerLogic } from '../replayScannerLogic'
export function ScannerGoalDraft(): JSX.Element {
const textAreaRef = useRef<HTMLTextAreaElement>(null)
const logic = replayScannerLogic({ id: 'new' })
- const { goalDraftInput, goalDraftLoading, experimentContext } = useValues(logic)
+ const { goalDraftInput, goalDraftLoading, linkedExperimentContext } = useValues(logic)
const { draftScannerFromGoal, setGoalDraftInput } = useActions(logic)
// Drafting creates a scanner, so it needs the same editor access as the rest of the wizard.
@@ -65,10 +65,10 @@ export function ScannerGoalDraft(): JSX.Element {
/>
{/* The page-level scope note sits above the template grid, so someone who
scrolled down to this box has lost sight of it. */}
- {experimentContext ? (
+ {linkedExperimentContext ? (
<div className="px-4 pb-2 text-xs text-muted">
Whatever you describe, this scanner keeps watching people exposed to{' '}
- {experimentContext.experiment.name}. You don't have to mention the experiment.
+ {linkedExperimentContext.experiment.name}. You don't have to mention the experiment.
</div>
) : null}
<div className="flex items-center justify-between px-4 pb-3">
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalFlow.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalFlow.tsx
index d83b5371785a..429b36da698a 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerGoalFlow.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerGoalFlow.tsx
@@ -1,9 +1,10 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { IconChevronRight, IconPlus, IconSparkles } from '@posthog/icons'
+import { IconChevronRight, IconFlask, IconPlus, IconSparkles } from '@posthog/icons'
import { LemonButton, LemonInput, LemonSegmentedButton, LemonTextArea } from '@posthog/lemon-ui'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { PopoverReferenceContext } from 'lib/lemon-ui/Popover/Popover'
import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'
import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'
@@ -34,10 +35,12 @@ interface PendingDraft {
* step to review it, so a one-click start still gets a scanner fitted to the project. */
export function ScannerGoalFlow(): JSX.Element {
const logic = replayScannerLogic({ id: 'new' })
- const { goalDraftInput, goalBudgetInput, goalSpendMode, goalDraftLoading, experimentContext } = useValues(logic)
+ const { goalDraftInput, goalBudgetInput, goalSpendMode, goalDraftLoading, linkedExperimentContext } =
+ useValues(logic)
const { draftScannerFromGoal, setGoalDraftInput, setGoalBudgetInput, setGoalSpendMode } = useActions(logic)
const { dataProcessingAccepted } = useValues(aiConsentLogic)
const { freeCreditsLeft } = useValues(visionQuotaLogic)
+ const experimentScanners = useFeatureFlag('VISION_EXPERIMENT_SCANNER')
// The spend choice is captured with the goal, so a quota that loads while consent is open cannot change it.
const [pendingDraft, setPendingDraft] = useState<PendingDraft | null>(null)
@@ -117,10 +120,10 @@ export function ScannerGoalFlow(): JSX.Element {
</div>
{/* A draft restored from an earlier experiment-scoped session keeps its targeting
through this flow, so say whose sessions the scanner ends up watching. */}
- {experimentContext ? (
+ {linkedExperimentContext ? (
<div className="text-xs text-muted">
- This scanner keeps watching people exposed to {experimentContext.experiment.name}.
- You don't have to mention the experiment.
+ This scanner keeps watching people exposed to{' '}
+ {linkedExperimentContext.experiment.name}. You don't have to mention the experiment.
</div>
) : null}
</div>
@@ -222,6 +225,19 @@ export function ScannerGoalFlow(): JSX.Element {
{template.goal_question}
</LemonButton>
))}
+ {experimentScanners && (
+ <LemonButton
+ fullWidth
+ icon={<IconFlask />}
+ sideIcon={<IconChevronRight />}
+ tooltip="Pick a running experiment and compare what people do in each variant"
+ disabledReason={editDisabledReason}
+ onClick={() => startScannerFromTemplate(null, 'experiment')}
+ data-attr="vision-goal-starter-experiment"
+ >
+ Watch my experiment
+ </LemonButton>
+ )}
</div>
</div>
</div>
diff --git a/products/replay_vision/frontend/replay_scanners/components/startScannerFromTemplate.ts b/products/replay_vision/frontend/replay_scanners/components/startScannerFromTemplate.ts
index 63cd6183856f..3611cb1c5760 100644
--- a/products/replay_vision/frontend/replay_scanners/components/startScannerFromTemplate.ts
+++ b/products/replay_vision/frontend/replay_scanners/components/startScannerFromTemplate.ts
@@ -4,14 +4,19 @@ import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { urls } from 'scenes/urls'
import { replayScannerLogic } from '../replayScannerLogic'
+import type { ScannerType } from '../types'
import { scannerStartSearchParams } from './scannerStartParams'
/** Starts a new scanner from a template, or from scratch when `templateKey` is null, and opens the
- * details step. A saved draft would be replaced, so the person confirms that first. */
-export function startScannerFromTemplate(templateKey: string | null): void {
+ * details step. A saved draft would be replaced, so the person confirms that first. A scratch start
+ * can also preset the type. */
+export function startScannerFromTemplate(templateKey: string | null, scannerType?: ScannerType): void {
const logic = replayScannerLogic({ id: 'new' })
const start = (): void => {
logic.actions.startFromTemplate(templateKey)
+ if (scannerType) {
+ logic.actions.setScannerType(scannerType)
+ }
router.actions.push(
combineUrl(
urls.replayVisionScannerDetails('new'),
diff --git a/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.test.ts b/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.test.ts
new file mode 100644
index 000000000000..1c2b6e92d34f
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.test.ts
@@ -0,0 +1,42 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { experimentScannerPickerLogic } from './experimentScannerPickerLogic'
+
+describe('experimentScannerPickerLogic', () => {
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/projects/:team/experiments/': () => [
+ 200,
+ {
+ results: [
+ {
+ id: 1,
+ name: 'Checkout redesign',
+ feature_flag: { id: 10, key: 'checkout', filters: {} },
+ },
+ {
+ id: 2,
+ name: 'Org pricing page',
+ feature_flag: { id: 20, key: 'pricing', filters: { aggregation_group_type_index: 0 } },
+ },
+ ],
+ },
+ ],
+ },
+ })
+ initKeaTests()
+ })
+
+ it('leaves out experiments that aggregate by group', async () => {
+ const logic = experimentScannerPickerLogic()
+ logic.mount()
+
+ await expectLogic(logic, () => logic.actions.loadOptions()).toFinishAllListeners()
+
+ expect(logic.values.experimentOptions.map((experiment) => experiment.id)).toEqual([1])
+ })
+})
diff --git a/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.ts b/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.ts
index 60670f08bf41..ac356aadea0b 100644
--- a/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/experimentScannerPickerLogic.ts
@@ -92,7 +92,10 @@ export const experimentScannerPickerLogic = kea<experimentScannerPickerLogicType
search: values.search || undefined,
})
breakpoint()
- return response.results ?? []
+ // A group-aggregated flag exposes groups, not persons, so the API refuses a scanner on it.
+ return (response.results ?? []).filter(
+ (experiment) => experiment.feature_flag?.filters?.aggregation_group_type_index == null
+ )
},
},
],
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
index 8dea5afd0a92..a25b85bc1a2a 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
@@ -441,7 +441,7 @@ describe('replayScannerLogic', () => {
])
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 })
+ expect(logic.values.linkedExperimentContext).toMatchObject({ experiment: { id: 7 }, variantKey: null })
await expectLogic(logic, () =>
logic.actions.draftScannerFromGoal('where do people give up in billing')
@@ -451,6 +451,42 @@ describe('replayScannerLogic', () => {
}
)
+ it('does not carry an experiment picked in the editor into a later starting point', async () => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })
+ useMocks({
+ get: {
+ '/api/projects/:team/experiments/:id/': () => [
+ 200,
+ { id: 7, name: 'Checkout redesign', start_date: '2026-09-20T00:00:00Z' },
+ ],
+ },
+ })
+ draftSpy.mockReturnValue([
+ 200,
+ {
+ name: 'Dead ends',
+ description: '',
+ scanner_type: 'monitor',
+ scanner_config: { prompt: 'Watch for dead ends.' },
+ rationale: '',
+ query: { kind: 'RecordingsQuery' },
+ },
+ ])
+ logic.actions.setScannerType('experiment')
+ await expectLogic(logic, () => logic.actions.setScannerExperiment(7)).toFinishAllListeners()
+ expect(logic.values.experimentContext).toMatchObject({ experiment: { id: 7 } })
+ // The goal page and template step promise to keep watching only a linked experiment.
+ expect(logic.values.linkedExperimentContext).toBeNull()
+ router.actions.push(urls.replayVisionScannerTemplate('new'))
+
+ await expectLogic(logic, () =>
+ logic.actions.draftScannerFromGoal('where do people get stuck')
+ ).toFinishAllListeners()
+
+ expect(logic.values.scanner).toMatchObject({ name: 'Dead ends', scanner_type: 'monitor' })
+ expect(logic.values.experimentContext).toBeNull()
+ })
+
it('drops a stale draft when the user has left the template step mid-request', async () => {
draftSpy.mockReturnValue([
200,
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
index f2ec48412899..24784ad38f6d 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
@@ -504,6 +504,7 @@ export interface replayScannerLogicValues {
durationValidationError: string | null
estimateRequestVersion: number
experimentContext: ExperimentScannerContext | null
+ experimentContextLinked: boolean
goalBudgetInput: number | null
goalDraft: DraftScannerResponseApi | null
goalDraftInput: string
@@ -515,6 +516,7 @@ export interface replayScannerLogicValues {
isNew: boolean
isScannerSubmitting: boolean
isScannerValid: boolean
+ linkedExperimentContext: ExperimentScannerContext | null
observationBackfillFilter: string | null
observationDateFrom: string | null
observationDateTo: string | null
@@ -636,6 +638,9 @@ export interface replayScannerLogicActions {
templateKey: string | undefined
}
}
+ linkExperimentContext: (context: ExperimentScannerContext) => {
+ context: ExperimentScannerContext
+ }
loadObservationStats: () => {
value: true
}
@@ -951,6 +956,10 @@ export interface replayScannerLogicMeta {
scannerValidationErrors: DeepPartialMap<ScannerFormValues, ValidationErrorType>,
durationValidationError: string | null
) => Partial<Record<ScannerEditorStep, string[]>>
+ linkedExperimentContext: (
+ experimentContext: ExperimentScannerContext | null,
+ experimentContextLinked: boolean
+ ) => ExperimentScannerContext | null
hasUnsavedChanges: (scanner: ScannerFormValues, originalScanner: ScannerFormValues | null) => boolean
hasObservationsInFlight: (observationStatsApi: ObservationStatsApi | null) => boolean
hasActiveObservationFilters: (
@@ -1016,6 +1025,8 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
// originalScanner, and submitIntent, and can refire the observation loads.
scannerWatermarkRefreshed: (scanner: ReplayScanner) => ({ scanner }),
setExperimentContext: (context: ExperimentScannerContext | null) => ({ context }),
+ // The context of an experiment the wizard was entered from, as opposed to one picked in the editor.
+ linkExperimentContext: (context: ExperimentScannerContext) => ({ context }),
setExperimentVariant: (variantKey: string | null) => ({ variantKey }),
setScannerExperiment: (experimentId: number | null) => ({ experimentId }),
detachExperimentContext: true,
@@ -1401,10 +1412,21 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
null as ExperimentScannerContext | null,
{
setExperimentContext: (_, { context }) => context,
+ linkExperimentContext: (_, { context }) => context,
setExperimentVariant: (state, { variantKey }) => (state ? { ...state, variantKey } : state),
detachExperimentContext: () => null,
},
],
+ // Only an experiment the wizard was entered from carries into a new start. One picked in the
+ // editor belongs to that scanner, so a starting point clicked later must not inherit it.
+ experimentContextLinked: [
+ false,
+ {
+ linkExperimentContext: () => true,
+ setExperimentContext: () => false,
+ detachExperimentContext: () => false,
+ },
+ ],
originalScanner: [
null as ScannerFormValues | null,
{
@@ -1710,6 +1732,13 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
? scannerStepErrors({ ...scannerValidationErrors, duration: durationValidationError })
: {},
],
+ linkedExperimentContext: [
+ (s) => [s.experimentContext, s.experimentContextLinked],
+ (
+ experimentContext: ExperimentScannerContext | null,
+ experimentContextLinked: boolean
+ ): ExperimentScannerContext | null => (experimentContextLinked ? experimentContext : null),
+ ],
hasUnsavedChanges: [
(s) => [s.scanner, s.originalScanner],
(scanner: ReplayScanner | null, original: ReplayScanner | null): boolean => {
@@ -2071,7 +2100,7 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
)
// 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)
+ actions.linkExperimentContext(context)
actions.loadScannerSuccess(prefilled)
} catch {
// Clear any context a partial run left set before surfacing the failure.
@@ -2292,8 +2321,9 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
// 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) {
+ const linkedContext = values.linkedExperimentContext
+ const context = draftedExperiment ? null : linkedContext
+ if (values.experimentContext && (draftedExperiment || !linkedContext)) {
// 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.
@@ -2433,7 +2463,10 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
// An experiment prefill (targeted query, scoped name) has to survive the template
// 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
+ const context = values.linkedExperimentContext
+ if (values.experimentContext && !context) {
+ actions.setExperimentContext(null)
+ }
actions.resetScanner(
context ? prefillScannerForExperiment(base, context, experimentScannersEnabled()) : base
)