: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
fix(signals): bound the wizard wait that can hide the inbox prompt (#80471)
Tom Owers5988b5404024
diff --git a/products/signals/frontend/inbox/inboxAnalytics.ts b/products/signals/frontend/inbox/inboxAnalytics.tsindex 0f1c147d48ff..b081668316c1 100644--- a/products/signals/frontend/inbox/inboxAnalytics.ts+++ b/products/signals/frontend/inbox/inboxAnalytics.ts@@ -35,6 +35,7 @@ export const INBOX_EVENTS = {SCOUT_ACTION: 'Scout action',SCOUT_CHAT_STARTED: 'Scout chat started',RUN_OPENED: 'Inbox run opened',+ ONBOARDING_DECIDED: 'Inbox onboarding decided',} as consttype InboxEvent = (typeof INBOX_EVENTS)[keyof typeof INBOX_EVENTS]@@ -561,6 +562,24 @@ export function captureInboxRunOpened(params: {})}+/**+ * What the inbox decided to do about self-driving onboarding, and when it decided nothing, why.+ *+ * The takeover and banner are the only prompt to run the wizard, and several inputs can hold them+ * back — a run already in flight, loaders still settling, a wizard verdict that hasn't landed. None+ * of that left a trace, so a drop in wizard runs was indistinguishable from a drop in intent: the+ * inbox pageview fires either way. `reason` separates "we chose not to ask" from "nobody wanted it".+ */+export function captureInboxOnboardingDecided(params: {+ mode: 'takeover' | 'banner' | 'none'+ reason: string | null+}): void {+ captureInboxEvent(INBOX_EVENTS.ONBOARDING_DECIDED, {+ mode: params.mode,+ suppression_reason: params.reason,+ })+}+/** A scout CTA kicked off a cloud task ("Suggest a scout", the fleet-overview chips). */export function captureScoutChatStarted(params: {chatType: ScoutChatTypediff --git a/products/signals/frontend/inbox/logics/inboxOnboardingLogic.test.ts b/products/signals/frontend/inbox/logics/inboxOnboardingLogic.test.tsindex e6bc78911dcc..a30e125c0f2d 100644--- a/products/signals/frontend/inbox/logics/inboxOnboardingLogic.test.ts+++ b/products/signals/frontend/inbox/logics/inboxOnboardingLogic.test.ts@@ -1,50 +1,124 @@-import { computeOnboardingMode, InboxOnboardingMode, OnboardingModeInputs } from './inboxOnboardingLogic'+import { SELF_DRIVING_WORKFLOW_ID } from 'scenes/onboarding/shared/wizard-sync/workflows'-describe('computeOnboardingMode', () => {- const base: OnboardingModeInputs = {- isSetupLoaded: true,- isSelfDrivingSetUp: false,- areCountsResolved: true,- hasExistingWork: false,- bannerDismissed: false,- isWizardRunning: false,- isWizardStateResolved: true,- }+import {+ computeOnboardingDecision,+ InboxOnboardingDecision,+ OnboardingModeInputs,+ resolveWizardState,+ WizardStateInputs,+} from './inboxOnboardingLogic'- it.each<[string, Partial<OnboardingModeInputs>, InboxOnboardingMode]>([- // Until the config check resolves, stay on the normal inbox (its own skeleton) – never guess- // the takeover, which would jolt for a set-up user.- ['config still loading', { isSetupLoaded: false }, 'none'],- // Config not loaded wins even if the set-up flag is incidentally true – we don't trust it yet.- ['config still loading, set-up flag ignored', { isSetupLoaded: false, isSelfDrivingSetUp: true }, 'none'],- // Not set up, counts still loading → keep the inbox until we can choose takeover vs banner.- ['not set up, counts still loading', { areCountsResolved: false }, 'none'],- // Set up (a source or scout is watching) → no onboarding at all, and no wait on counts.- ['set up, empty inbox', { isSelfDrivingSetUp: true }, 'none'],- ['set up, with work', { isSelfDrivingSetUp: true, hasExistingWork: true }, 'none'],- ['set up, counts unresolved (skipped)', { isSelfDrivingSetUp: true, areCountsResolved: false }, 'none'],- // Not set up + nothing in the inbox → full-pane takeover (nothing to block).- ['not set up, empty inbox', {}, 'takeover'],- // Not set up but work exists → non-blocking banner, so existing work stays accessible.- ['not set up, with work', { hasExistingWork: true }, 'banner'],- // A dismissed banner falls back to the normal inbox for the session.- ['not set up, with work, banner dismissed', { hasExistingWork: true, bannerDismissed: true }, 'none'],- // Dismissing the banner has no effect on the takeover (the takeover has no dismiss).- ['not set up, empty inbox, banner dismissed', { bannerDismissed: true }, 'takeover'],- // A run in flight is setup in progress: telling the user to go run the wizard would- // contradict the progress widget already showing it running.- ['wizard running, would otherwise take over', { isWizardRunning: true }, 'none'],- ['wizard running, would otherwise banner', { isWizardRunning: true, hasExistingWork: true }, 'none'],- // Until the detector has actually checked, "not running" is absence of evidence: the- // config/count loaders settle far faster than the detector's jittered poll, so acting on it- // would show the takeover to someone landing in the inbox mid-run.- ['wizard state unknown, would otherwise take over', { isWizardStateResolved: false }, 'none'],- [- 'wizard state unknown, would otherwise banner',- { isWizardStateResolved: false, hasExistingWork: true },- 'none',- ],- ])('%s', (_label, overrides, expected) => {- expect(computeOnboardingMode({ ...base, ...overrides })).toBe(expected)+describe('inboxOnboardingLogic', () => {+ describe('computeOnboardingDecision', () => {+ const base: OnboardingModeInputs = {+ isSetupLoaded: true,+ isSelfDrivingSetUp: false,+ areCountsResolved: true,+ hasExistingWork: false,+ bannerDismissed: false,+ isWizardRunning: false,+ isWizardStateResolved: true,+ }++ it.each<[string, Partial<OnboardingModeInputs>, InboxOnboardingDecision]>([+ // Until the config check resolves, stay on the normal inbox (its own skeleton) – never guess+ // the takeover, which would jolt for a set-up user.+ ['config still loading', { isSetupLoaded: false }, { mode: 'none', reason: 'setup_loading' }],+ // Config not loaded wins even if the set-up flag is incidentally true – we don't trust it yet.+ [+ 'config still loading, set-up flag ignored',+ { isSetupLoaded: false, isSelfDrivingSetUp: true },+ { mode: 'none', reason: 'setup_loading' },+ ],+ // Not set up, counts still loading → keep the inbox until we can choose takeover vs banner.+ [+ 'not set up, counts still loading',+ { areCountsResolved: false },+ { mode: 'none', reason: 'counts_loading' },+ ],+ // Set up (a source or scout is watching) → no onboarding at all, and no wait on counts.+ ['set up, empty inbox', { isSelfDrivingSetUp: true }, { mode: 'none', reason: 'already_set_up' }],+ [+ 'set up, with work',+ { isSelfDrivingSetUp: true, hasExistingWork: true },+ { mode: 'none', reason: 'already_set_up' },+ ],+ [+ 'set up, counts unresolved (skipped)',+ { isSelfDrivingSetUp: true, areCountsResolved: false },+ { mode: 'none', reason: 'already_set_up' },+ ],+ // Not set up + nothing in the inbox → full-pane takeover (nothing to block).+ ['not set up, empty inbox', {}, { mode: 'takeover', reason: null }],+ // Not set up but work exists → non-blocking banner, so existing work stays accessible.+ ['not set up, with work', { hasExistingWork: true }, { mode: 'banner', reason: null }],+ // A dismissed banner falls back to the normal inbox for the session.+ [+ 'not set up, with work, banner dismissed',+ { hasExistingWork: true, bannerDismissed: true },+ { mode: 'none', reason: 'banner_dismissed' },+ ],+ // Dismissing the banner has no effect on the takeover (the takeover has no dismiss).+ [+ 'not set up, empty inbox, banner dismissed',+ { bannerDismissed: true },+ { mode: 'takeover', reason: null },+ ],+ // A run in flight is setup in progress: telling the user to go run the wizard would+ // contradict the progress widget already showing it running.+ [+ 'wizard running, would otherwise take over',+ { isWizardRunning: true },+ { mode: 'none', reason: 'wizard_running' },+ ],+ [+ 'wizard running, would otherwise banner',+ { isWizardRunning: true, hasExistingWork: true },+ { mode: 'none', reason: 'wizard_running' },+ ],+ // Until the detector has actually checked, "not running" is absence of evidence: the+ // config/count loaders settle far faster than the detector's jittered poll, so acting on it+ // would show the takeover to someone landing in the inbox mid-run.+ [+ 'wizard state unknown, would otherwise take over',+ { isWizardStateResolved: false },+ { mode: 'none', reason: 'wizard_state_unknown' },+ ],+ [+ 'wizard state unknown, would otherwise banner',+ { isWizardStateResolved: false, hasExistingWork: true },+ { mode: 'none', reason: 'wizard_state_unknown' },+ ],+ ])('%s', (_label, overrides, expected) => {+ expect(computeOnboardingDecision({ ...base, ...overrides })).toEqual(expected)+ })+ })++ describe('resolveWizardState', () => {+ const base: WizardStateInputs = {+ hasResolvedSessionState: false,+ watchedWorkflows: [SELF_DRIVING_WORKFLOW_ID],+ receivedFeatureFlags: true,+ verdictWaitExpired: false,+ }++ it.each<[string, Partial<WizardStateInputs>, boolean]>([+ // The detector answered, so `isWizardRunning` can be acted on however it landed.+ ['detector settled', { hasResolvedSessionState: true }, true],+ // Not watching the self-driving program: the detector's verdict could never flip+ // `isWizardRunning`, so waiting on it would cost every inbox user a hold for nothing.+ ['not watching the self-driving program', { watchedWorkflows: [] }, true],+ // The shortcut above needs flags in hand — without them every user reads as the control+ // arm, which would show the takeover to someone mid-run and then snatch it back.+ ['not watching, but flags not in yet', { watchedWorkflows: [], receivedFeatureFlags: false }, false],+ // Watching and unsettled is the one case that genuinely has no answer yet.+ ['watching, detector still pending', {}, false],+ // The backstop. Without it, a flag payload an ad blocker drops or a detector whose polls+ // keep erroring hides the only prompt to set self-driving up, for the whole session.+ ['deadline elapsed with no verdict', { verdictWaitExpired: true }, true],+ ['deadline elapsed with no flags either', { receivedFeatureFlags: false, verdictWaitExpired: true }, true],+ ])('%s', (_label, overrides, expected) => {+ expect(resolveWizardState({ ...base, ...overrides })).toBe(expected)+ })})})diff --git a/products/signals/frontend/inbox/logics/inboxOnboardingLogic.ts b/products/signals/frontend/inbox/logics/inboxOnboardingLogic.tsindex 4f26bc1ac849..08dad1cdbc6e 100644--- a/products/signals/frontend/inbox/logics/inboxOnboardingLogic.ts+++ b/products/signals/frontend/inbox/logics/inboxOnboardingLogic.ts@@ -1,4 +1,5 @@import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'+import { subscriptions } from 'kea-subscriptions'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { wizardActiveSessionDetectorLogic } from 'scenes/onboarding/shared/wizard-sync/wizardActiveSessionDetectorLogic'@@ -6,6 +7,7 @@ import { SELF_DRIVING_WORKFLOW_ID } from 'scenes/onboarding/shared/wizard-sync/wimport type { SignalScoutConfigApi as SignalScoutConfig } from 'products/signals/frontend/generated/api.schemas'+import { captureInboxOnboardingDecided } from '../inboxAnalytics'import { signalSourcesLogic } from '../signalSourcesLogic'import type { SignalSourceConfig } from '../types'import { INBOX_FLAT_TAB_LIST_PARAMS, reportListLogic } from './reportListLogic'@@ -15,9 +17,74 @@ import { scoutFleetLogic } from './scoutFleetLogic'// their verdict almost immediately, long enough that a fleet-wide reload doesn't land as one spike.const MOUNT_CHECK_JITTER_MS = 3 * 1000+// Ceiling on how long the wizard verdict may hold the prompt back. The verdict can never arrive:+// the shortcut below needs the feature-flag payload, which an ad blocker can drop entirely, and a+// detector whose endpoint keeps erroring only settles after enough consecutive failures. Both leave+// someone who has not set self-driving up on an inbox that never offers to. Well past the sub-second+// window the guard exists for (jitter plus one request), so capping it costs the normal path nothing.+const WIZARD_VERDICT_DEADLINE_MS = 15 * 1000+/** How the self-driving onboarding presents itself over the inbox. */export type InboxOnboardingMode = 'takeover' | 'banner' | 'none'+/**+ * Why the onboarding is not showing. `null` whenever it is.+ *+ * `'wizard_running'` is the only deliberate suppression; every other value is an input the decision+ * is still waiting on, or a user who does not need onboarding at all. Carried into telemetry so a+ * withheld prompt is distinguishable from an absent one.+ */+export type InboxOnboardingSuppressionReason =+ | 'wizard_running'+ | 'wizard_state_unknown'+ | 'setup_loading'+ | 'already_set_up'+ | 'counts_loading'+ | 'banner_dismissed'+ | null++export interface InboxOnboardingDecision {+ mode: InboxOnboardingMode+ reason: InboxOnboardingSuppressionReason+}++export interface WizardStateInputs {+ /** The detector reached a verdict: a poll settled, a stream reported in, or polling was killed. */+ hasResolvedSessionState: boolean+ /** Programs the detector polls. Derived from the onboarding variant, so it needs flags in hand. */+ watchedWorkflows: string[]+ receivedFeatureFlags: boolean+ /** The deadline above elapsed with no verdict, so waiting longer only withholds the prompt. */+ verdictWaitExpired: boolean+}++/**+ * Whether `isWizardRunning === false` can be acted on.+ *+ * Trivially true when the detector isn't watching the self-driving program (control variant, no+ * surface registered): its verdict could never flip `isWizardRunning`, so waiting on it — or polling+ * eagerly for it — would cost every inbox user something for nothing. That shortcut needs flags in+ * hand though: `watchedWorkflows` is derived from the onboarding variant, and before the flags land+ * it reads as the control arm for everyone, which would let the takeover render for a user whose run+ * is mid-flight and then flicker back out once the flags arrive.+ *+ * The deadline is the backstop for the case where neither of those ever resolves. A takeover that+ * flickers is a worse first second than one that waits; a takeover that never renders is worse than+ * both, and it is the only failure of the three a user can't recover from by waiting.+ */+export function resolveWizardState({+ hasResolvedSessionState,+ watchedWorkflows,+ receivedFeatureFlags,+ verdictWaitExpired,+}: WizardStateInputs): boolean {+ return (+ hasResolvedSessionState ||+ (receivedFeatureFlags && !watchedWorkflows.includes(SELF_DRIVING_WORKFLOW_ID)) ||+ verdictWaitExpired+ )+}+export interface OnboardingModeInputs {/** Both source + scout config loaders have settled, so the set-up verdict is trustworthy. */isSetupLoaded: boolean@@ -44,7 +111,7 @@ export interface OnboardingModeInputs {* on `'none'` (the familiar skeleton) until both the config check and, if needed, the report counts* have settled. This avoids flashing the takeover/banner before we know the verdict.*/-export function computeOnboardingMode({+export function computeOnboardingDecision({isSetupLoaded,isSelfDrivingSetUp,areCountsResolved,@@ -52,36 +119,36 @@ export function computeOnboardingMode({bannerDismissed,isWizardRunning,isWizardStateResolved,-}: OnboardingModeInputs): InboxOnboardingMode {+}: OnboardingModeInputs): InboxOnboardingDecision {// A run in flight is setup in progress: sources and scouts land as it goes, so telling the user// to go and run the wizard would contradict the progress widget already showing it running.if (isWizardRunning) {- return 'none'+ return { mode: 'none', reason: 'wizard_running' }}// The config and count loaders settle in under a second; the wizard detector answers on its own// polling cadence. Until it has, "not running" is absence of evidence, and acting on it here is// exactly the wrong-takeover case for someone landing in the inbox mid-run — so hold the normal- // inbox, same as the other unsettled inputs below.+ // inbox, same as the other unsettled inputs below. `resolveWizardState` bounds that wait.if (!isWizardStateResolved) {- return 'none'+ return { mode: 'none', reason: 'wizard_state_unknown' }}// Until the config check resolves we don't know the verdict – stay on the normal inbox skeleton.if (!isSetupLoaded) {- return 'none'+ return { mode: 'none', reason: 'setup_loading' }}// Set-up users go straight to their inbox – no need to wait on the report counts.if (isSelfDrivingSetUp) {- return 'none'+ return { mode: 'none', reason: 'already_set_up' }}// Not set up: the report counts decide takeover (empty inbox) vs. banner (work already exists).// Keep the inbox skeleton until they settle, rather than guessing.if (!areCountsResolved) {- return 'none'+ return { mode: 'none', reason: 'counts_loading' }}if (hasExistingWork) {- return bannerDismissed ? 'none' : 'banner'+ return bannerDismissed ? { mode: 'none', reason: 'banner_dismissed' } : { mode: 'banner', reason: null }}- return 'takeover'+ return { mode: 'takeover', reason: null }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -105,7 +172,9 @@ export interface inboxOnboardingLogicValues {isSetupLoaded: booleanisWizardRunning: booleanisWizardStateResolved: boolean+ onboardingDecision: InboxOnboardingDecisiononboardingMode: InboxOnboardingMode+ verdictWaitExpired: boolean}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -116,6 +185,9 @@ export interface inboxOnboardingLogicActions {dismissBanner: () => {value: true}+ expireWizardVerdictWait: () => {+ value: true+ }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -134,9 +206,10 @@ export interface inboxOnboardingLogicMeta {isWizardStateResolved: (hasResolvedSessionState: boolean,watchedWorkflows: string[],- receivedFeatureFlags: boolean+ receivedFeatureFlags: boolean,+ verdictWaitExpired: boolean) => boolean- onboardingMode: (+ onboardingDecision: (isSetupLoaded: boolean,isSelfDrivingSetUp: boolean,areCountsResolved: boolean,@@ -144,7 +217,8 @@ export interface inboxOnboardingLogicMeta {bannerDismissed: boolean,isWizardRunning: boolean,isWizardStateResolved: boolean- ) => InboxOnboardingMode+ ) => InboxOnboardingDecision+ onboardingMode: (onboardingDecision: InboxOnboardingDecision) => InboxOnboardingMode}}@@ -196,6 +270,7 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([actions({dismissBanner: true,+ expireWizardVerdictWait: true,}),reducers({@@ -205,6 +280,12 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([dismissBanner: () => true,},],+ verdictWaitExpired: [+ false,+ {+ expireWizardVerdictWait: () => true,+ },+ ],}),selectors({@@ -243,20 +324,22 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([(s) => [s.activeWorkflowId],(activeWorkflowId: string | null): boolean => activeWorkflowId === SELF_DRIVING_WORKFLOW_ID,],- // Trivially resolved when the detector isn't watching the self-driving program (control- // variant, no surface registered): its verdict could never flip `isWizardRunning`, so- // waiting on it — or polling eagerly for it — would cost every inbox user something for- // nothing. That shortcut needs flags in hand though: `watchedWorkflows` is derived from the- // onboarding variant, and before the flags land it reads as the control arm for everyone,- // which would let the takeover render for a user whose run is mid-flight and then flicker- // back out once the flags arrive.isWizardStateResolved: [- (s) => [s.hasResolvedSessionState, s.watchedWorkflows, s.receivedFeatureFlags],- (hasResolvedSessionState: boolean, watchedWorkflows: string[], receivedFeatureFlags: boolean): boolean =>- hasResolvedSessionState ||- (receivedFeatureFlags && !watchedWorkflows.includes(SELF_DRIVING_WORKFLOW_ID)),+ (s) => [s.hasResolvedSessionState, s.watchedWorkflows, s.receivedFeatureFlags, s.verdictWaitExpired],+ (+ hasResolvedSessionState: boolean,+ watchedWorkflows: string[],+ receivedFeatureFlags: boolean,+ verdictWaitExpired: boolean+ ): boolean =>+ resolveWizardState({+ hasResolvedSessionState,+ watchedWorkflows,+ receivedFeatureFlags,+ verdictWaitExpired,+ }),],- onboardingMode: [+ onboardingDecision: [(s) => [s.isSetupLoaded,s.isSelfDrivingSetUp,@@ -274,8 +357,8 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([bannerDismissed: boolean,isWizardRunning: boolean,isWizardStateResolved: boolean- ): InboxOnboardingMode =>- computeOnboardingMode({+ ): InboxOnboardingDecision =>+ computeOnboardingDecision({isSetupLoaded,isSelfDrivingSetUp,areCountsResolved,@@ -285,8 +368,26 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([isWizardStateResolved,}),],+ onboardingMode: [+ (s) => [s.onboardingDecision],+ (onboardingDecision: InboxOnboardingDecision): InboxOnboardingMode => onboardingDecision.mode,+ ],}),+ subscriptions(({ cache }) => ({+ // One event per distinct verdict per mount. The decision settles through several+ // intermediate `none`s as its inputs load, so reporting every transition would drown the+ // real answer; deduping on the pair keeps the loading states as the trail that explains it.+ onboardingDecision: (decision: InboxOnboardingDecision) => {+ const key = `${decision.mode}:${decision.reason ?? 'shown'}`+ if (cache.reportedDecisions?.has(key)) {+ return+ }+ cache.reportedDecisions = (cache.reportedDecisions ?? new Set<string>()).add(key)+ captureInboxOnboardingDecided({ mode: decision.mode, reason: decision.reason })+ },+ })),+// The detector's own first poll is jittered up to 30s to spread deploy-reload herds; someone// landing in the inbox straight from onboarding can't wait that out with the takeover verdict// hanging on the answer. One targeted poll on mount settles it in a request — gated on the@@ -312,5 +413,17 @@ export const inboxOnboardingLogic = kea<inboxOnboardingLogicType>([}, Math.random() * MOUNT_CHECK_JITTER_MS)return () => window.clearTimeout(id)}, 'mount-wizard-check')++ // Backstop for a verdict that never lands. Runs while the tab is hidden too: a user who+ // opens the inbox in a background tab and comes back to it should find the prompt already+ // decided, not a timer that only started when they looked.+ cache.disposables.add(+ () => {+ const id = window.setTimeout(() => actions.expireWizardVerdictWait(), WIZARD_VERDICT_DEADLINE_MS)+ return () => window.clearTimeout(id)+ },+ 'wizard-verdict-deadline',+ { pauseOnPageHidden: false }+ )}),])