: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(search): test showing command k persons first for email searches (#123248)
Shy Alterec4567ac7b52
diff --git a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.mdindex 01535bdde630..bd94815857d2 100644--- a/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md+++ b/frontend/src/lib/components/CommandKSearch/COMMAND_K_SEARCH_UX.md@@ -97,7 +97,7 @@ The input is always in exactly one mode, decided from the token under the cursor2. In-memory lists, filtered on every keystroke: **Data management**, **People**, **Health**, **Misc**, **Settings** (with a Dark mode / Light mode row for "dark", "light", "theme", "appearance"), **Create new**. For a search with words they keep only items that match every word with no typo. Products rank with the results instead.3. Remote lists that the file system does not hold: **Events**, **Properties**, **Workflows** (one unified search request), **Accounts** (behind the customer analytics flag), **Support tickets** (3+ characters or a ticket number).4. **Ask PostHog AI**.- 5. **Persons**, **Groups**. Person and group searches can take seconds, so they come last and nothing above them waits for them. The person search starts with the file system search, after 50 ms.+ 5. **Persons**, **Groups**. Person and group searches can take seconds, so they come last and nothing above them waits for them. The person search starts with the file system search, after 50 ms. In the test group of the `command-k-persons-first-for-email` experiment, a search that contains "@" shows **Persons** right below **Results** instead, and the sections under it wait for the person search.- With any filter (a chip, or a valid `key:value` still being typed), only **Results** and **Ask PostHog AI** show, because filters apply only to objects.- With an `is:` chip (not negated), **Results** holds a **View all <types>** row (`View all feature flags`) that opens the list page of that type. With no search text it is the first row; once you type a search it moves below the results. It shows only for types with a list page.diff --git a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsxindex c7c7f40a2592..f00d315cd10e 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx+++ b/frontend/src/lib/components/CommandKSearch/commandKSearchLogic.tsx@@ -337,7 +337,8 @@ export interface commandKSearchLogicMeta {displayedQuery: {query: SectionsQuerystale: boolean- }+ },+ featureFlags: FeatureFlagsSet) => CommandKSection[]selectableRows: (sections: CommandKSection[]) => CommandKRow[]highlightedRow: (selectableRows: CommandKRow[], highlightedKey: string | null) => CommandKRow | null@@ -676,14 +677,23 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([): { query: SectionsQuery; stale: boolean } => pickDisplayedQuery(current, shown, remote),],sections: [- (s) => [s.mode, s.cursorContext, s.suggestionsSection, s.localLists, s.remote, s.displayedQuery],+ (s) => [+ s.mode,+ s.cursorContext,+ s.suggestionsSection,+ s.localLists,+ s.remote,+ s.displayedQuery,+ s.featureFlags,+ ],(mode: CommandKMode,context: CursorContext,suggestions: CommandKSection | null,local: LocalLists,remote: RemoteSlots,- displayed: { query: SectionsQuery; stale: boolean }+ displayed: { query: SectionsQuery; stale: boolean },+ featureFlags: FeatureFlagsSet): CommandKSection[] =>buildSections({mode,@@ -693,6 +703,9 @@ export const commandKSearchLogic = kea<commandKSearchLogicType>([remote,...displayed.query,stale: displayed.stale,+ personsFirst:+ !!displayed.query.remoteQueries.persons?.includes('@') &&+ featureFlags[FEATURE_FLAGS.COMMAND_K_PERSONS_FIRST_FOR_EMAIL] === 'test',}),],selectableRows: [diff --git a/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts b/frontend/src/lib/components/CommandKSearch/commandKSections.test.tsindex e91719e9d9eb..12a006561877 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKSections.test.ts@@ -51,6 +51,7 @@ const input = (mode: CommandKMode, overrides: Partial<SectionsInput>): SectionsIaskAiQuestion: null,viewAll: null,stale: false,+ personsFirst: false,...overrides,})@@ -186,23 +187,38 @@ describe('buildSections', () => {expect(pickDisplayedQuery(current, shown, remote)).toEqual({ query: current, stale: false })})- test.each<[string, Partial<Record<'events' | 'persons', SearchItem[]>>, string[]]>([+ test.each<[string, Partial<Record<'events' | 'persons', SearchItem[]>>, boolean, string[]]>([['only a loading row below Results while an earlier source loads',{ persons: [dashboard('p', '9')] },+ false,['results', 'loading-more'],],['PostHog AI without waiting for slow person searches',{ events: [dashboard('e', '8')] },+ false,['results', 'events', 'ask-ai', 'loading-more'],],['persons last, below PostHog AI, once they load',{ events: [dashboard('e', '8')], persons: [dashboard('p', '9')] },+ false,['results', 'events', 'ask-ai', 'persons'],],- ])('reveals %s', (_, loaded, expectedKeys) => {+ [+ 'only a loading row below Results while persons that go first load',+ { events: [dashboard('e', '8')] },+ true,+ ['results', 'loading-more'],+ ],+ [+ 'persons right below Results when they go first',+ { persons: [dashboard('p', '9')] },+ true,+ ['results', 'persons', 'loading-more'],+ ],+ ])('reveals %s', (_, loaded, personsFirst, expectedKeys) => {const remote = emptyRemoteSlots()remote.results = { cache: { 'type:dashboard': [dashboard('a', '1')] } }for (const [source, items] of Object.entries(loaded)) {@@ -213,6 +229,7 @@ describe('buildSections', () => {remote,remoteQueries: { results: 'type:dashboard', events: 'rev', persons: 'rev' },askAiQuestion: 'rev',+ personsFirst,}))expect(sections.map((section) => section.key)).toEqual(expectedKeys)diff --git a/frontend/src/lib/components/CommandKSearch/commandKSections.ts b/frontend/src/lib/components/CommandKSearch/commandKSections.tsindex ec4eb00b3d52..5396f6aa005d 100644--- a/frontend/src/lib/components/CommandKSearch/commandKSections.ts+++ b/frontend/src/lib/components/CommandKSearch/commandKSections.ts@@ -223,6 +223,7 @@ export interface SectionsInput extends SectionsQuery {local: LocalListsremote: RemoteSlotsstale: boolean+ personsFirst: boolean}const isRanked = (query: SectionsQuery): boolean =>@@ -281,6 +282,24 @@ function rankedResultsSections(function lowerSections(input: SectionsInput, ranked: boolean, state: CommandKSection['state']): CommandKSection[] {const { local, remote, remoteQueries, localQuery } = inputconst sections: (CommandKSection | null)[] = []+ const loaded = (): CommandKSection[] => sections.filter((section): section is CommandKSection => section !== null)+ const loadingMore = (): CommandKSection[] =>+ state === 'stale'+ ? loaded()+ : [...loaded(), readySection('loading-more', [{ kind: 'loading-more', key: 'loading-more/row' }])]+ const appendInOrder = (sources: RemoteSource[]): boolean => {+ for (const source of sources) {+ const query = remoteQueries[source]+ if (!isSettled(remote[source], query)) {+ return false+ }+ sections.push(query ? remoteSection(source, remote[source].cache[query], state) : null)+ }+ return true+ }+ if (input.personsFirst && !appendInOrder(['persons'])) {+ return loadingMore()+ }if (localQuery) {for (const source of LOCAL_SOURCES) {if (ranked && source === 'products') {@@ -297,21 +316,6 @@ function lowerSections(input: SectionsInput, ranked: boolean, state: CommandKSecsections.push(rows.length > 0 ? { ...readySection(source, rows), state } : null)}}- const loaded = (): CommandKSection[] => sections.filter((section): section is CommandKSection => section !== null)- const loadingMore = (): CommandKSection[] =>- state === 'stale'- ? loaded()- : [...loaded(), readySection('loading-more', [{ kind: 'loading-more', key: 'loading-more/row' }])]- const appendInOrder = (sources: RemoteSource[]): boolean => {- for (const source of sources) {- const query = remoteQueries[source]- if (!isSettled(remote[source], query)) {- return false- }- sections.push(query ? remoteSection(source, remote[source].cache[query], state) : null)- }- return true- }if (!appendInOrder(REMOTE_SOURCES.filter((source) => source !== 'results' && !TRAILING_SOURCES.includes(source)))) {return loadingMore()}@@ -321,7 +325,8 @@ function lowerSections(input: SectionsInput, ranked: boolean, state: CommandKSecstate,})}- return appendInOrder(TRAILING_SOURCES) ? loaded() : loadingMore()+ const trailing = input.personsFirst ? TRAILING_SOURCES.filter((source) => source !== 'persons') : TRAILING_SOURCES+ return appendInOrder(trailing) ? loaded() : loadingMore()}export function buildSections(input: SectionsInput): CommandKSection[] {diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex bfdc70806df3..1930e32c2ab5 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -281,6 +281,7 @@ export const FEATURE_FLAGS = {CLEARABLE_NOTIFICATIONS: 'clearable-notifications', // owner: @jordanm-posthog #team-web-analyticsCODE_BADGE_SELF_DRIVING_LABEL: 'code-badge-self-driving-label', // owner: #team-self-driving, experiment: label the Code badge "Self-driving" and compare setup activationsCOHORT_INLINE_CALCULATION: 'inline-cohort-calculation', // owner: #team-analytics-platform, inlines fast dynamic cohort queries instead of using precomputed cohortpeople table+ COMMAND_K_PERSONS_FIRST_FOR_EMAIL: 'command-k-persons-first-for-email', // owner: @puemos #team-platform-ux multivariate=control,test, experiment: show Persons right below Results when a Command K search contains "@"COHORTS_TAXONOMIC_BASIC_LIST: 'cohorts-taxonomic-basic-list', // owner: @adamleith, picker sends ?basic=true to the cohorts list endpoint (trimmed payload: no query/groups/last_error_message/experiment_set; filters is kept)CONDENSED_FILTER_BAR: 'condensed_filter_bar', // owner: @jordanm-posthog #team-web-analyticsCREATE_FORM_TOOL: 'phai-create-form-tool', // owner: @kappa90 #team-posthog-ai