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.

feat(workflows): filter invocations by picked person (#70410)

Meikel Ratz5d30bbf08844
diff --git a/frontend/src/scenes/hog-functions/invocations/HogInvocations.tsx b/frontend/src/scenes/hog-functions/invocations/HogInvocations.tsx
index b00356b8059b..01b357761812 100644
--- a/frontend/src/scenes/hog-functions/invocations/HogInvocations.tsx
+++ b/frontend/src/scenes/hog-functions/invocations/HogInvocations.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { ReactNode, useEffect, useState } from 'react'
-import { IconChevronDown, IconRefresh, IconRevert, IconSearch, IconWarning } from '@posthog/icons'
+import { IconChevronDown, IconPerson, IconRefresh, IconRevert, IconSearch, IconWarning, IconX } from '@posthog/icons'
import {
LemonButton,
LemonCheckbox,
@@ -15,6 +15,9 @@ import {
LemonTableColumns,
LemonTag,
LemonTagProps,
+ Popover,
+ ProfilePicture,
+ Spinner,
Tooltip,
} from '@posthog/lemon-ui'
@@ -26,11 +29,12 @@ import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
import { Link } from 'lib/lemon-ui/Link'
import { DATE_TIME_FORMAT, formatDateRange } from 'lib/utils/datetime'
+import { asDisplay } from 'scenes/persons/person-utils'
import { PersonDisplay } from 'scenes/persons/PersonDisplay'
import { urls } from 'scenes/urls'
import { escapeHogQLString, hogql } from '~/queries/utils'
-import { DateMappingOption } from '~/types'
+import { DateMappingOption, PersonType } from '~/types'
import { LogsViewer } from '../logs/LogsViewer'
import { LogsViewerLogicProps } from '../logs/logsViewerLogic'
@@ -476,13 +480,14 @@ export function HogInvocations({ id, functionKind, renderLogMessage }: HogInvoca
<LemonInput
type="search"
size="small"
- placeholder="Search by invocation, event, distinct ID, person ID, or email…"
+ placeholder="Search by invocation, event, distinct, or person ID…"
fullWidth
value={filters.search ?? ''}
onChange={(value) => setFilters({ search: value || undefined })}
prefix={<IconSearch />}
allowClear
/>
+ <PersonFilterPicker id={id} functionKind={functionKind} />
</div>
<div className="flex items-center gap-2 flex-wrap">
<StatusFilterDropdown
@@ -1011,3 +1016,98 @@ function Row({ label, help, children }: { label: string; help?: string; children
</div>
)
}
+
+/**
+ * Person filter chip that resolves the picked person to a concrete `person_id` on the frontend
+ * via `api.persons.list`. Keeps the invocations query on its own CH cluster — no cross-cluster
+ * subquery against `persons` needed. Follows the same shape as the notification-panel picker
+ * in `HogFlowEditorNotificationPanelTest.tsx`.
+ */
+function PersonFilterPicker({ id, functionKind }: HogInvocationsLogicProps): JSX.Element {
+ const logic = hogInvocationsLogic({ id, functionKind })
+ const { pickedPerson, personSearchResults, personSearchResultsLoading, filters } = useValues(logic)
+ const { setPickedPerson, searchPersons } = useActions(logic)
+ const [open, setOpen] = useState(false)
+ const [search, setSearch] = useState('')
+
+ // Show whatever the URL / picker holds. If we have a full PersonType (chip picked in-session or
+ // hydrated from a shared URL), use PersonDisplay; otherwise render the raw UUID short form.
+ const activeUuid = filters.person_uuid
+ const activeDisplay = pickedPerson
+ ? asDisplay(pickedPerson)
+ : activeUuid
+ ? `${activeUuid.slice(0, 4)}…${activeUuid.slice(-4)}`
+ : null
+
+ if (activeDisplay) {
+ return (
+ <LemonButton
+ type="secondary"
+ size="small"
+ icon={<IconPerson />}
+ sideIcon={<IconX />}
+ onClick={() => setPickedPerson(null)}
+ tooltip="Clear person filter"
+ >
+ {activeDisplay}
+ </LemonButton>
+ )
+ }
+
+ return (
+ <Popover
+ visible={open}
+ onClickOutside={() => setOpen(false)}
+ overlay={
+ <div className="p-2 min-w-80">
+ <LemonInput
+ type="search"
+ placeholder="Search by name, email, or distinct ID"
+ value={search}
+ onChange={(value) => {
+ setSearch(value)
+ searchPersons({ search: value })
+ }}
+ autoFocus
+ className="mb-2"
+ />
+ {personSearchResultsLoading ? (
+ <div className="p-4 text-center">
+ <Spinner />
+ </div>
+ ) : search.trim() && personSearchResults.length === 0 ? (
+ <div className="p-4 text-center text-muted text-sm">No persons found</div>
+ ) : (
+ <div className="max-h-64 overflow-y-auto">
+ {personSearchResults.map((person: PersonType) => (
+ <LemonButton
+ key={person.uuid}
+ fullWidth
+ size="small"
+ onClick={() => {
+ setPickedPerson(person)
+ setOpen(false)
+ setSearch('')
+ }}
+ className="justify-start"
+ >
+ <ProfilePicture name={asDisplay(person)} size="sm" className="mr-2" />
+ <div className="flex-1 text-left">
+ <div className="font-semibold">{asDisplay(person)}</div>
+ {person.properties?.email ? (
+ <div className="text-xs text-muted">{person.properties.email}</div>
+ ) : null}
+ </div>
+ </LemonButton>
+ ))}
+ </div>
+ )}
+ </div>
+ }
+ >
+ <LemonButton type="secondary" size="small" icon={<IconPerson />} onClick={() => setOpen((prev) => !prev)}>
+ Filter by person
+ </LemonButton>
+ </Popover>
+ )
+}
diff --git a/frontend/src/scenes/hog-functions/invocations/hogInvocationsLogic.tsx b/frontend/src/scenes/hog-functions/invocations/hogInvocationsLogic.tsx
index 31ffeaa501aa..4816b8e2bf54 100644
--- a/frontend/src/scenes/hog-functions/invocations/hogInvocationsLogic.tsx
+++ b/frontend/src/scenes/hog-functions/invocations/hogInvocationsLogic.tsx
@@ -10,6 +10,7 @@ import { dateStringToDayJs } from 'lib/utils/dateFilters'
import { teamLogic } from 'scenes/teamLogic'
import { escapeHogQLString, hogql } from '~/queries/utils'
+import { PersonType } from '~/types'
import { hogFunctionsRerunCreate } from 'products/cdp/frontend/generated/api'
import type { HogInvocationRerunFilterStatusEnumApi } from 'products/cdp/frontend/generated/api.schemas'
@@ -81,6 +82,13 @@ export interface HogInvocationsFilters {
* aren't otherwise findable here without scanning the logs tab.
*/
problem_only?: boolean
+ /**
+ * UUID of a person picked from the person search chip. Resolved on the frontend via
+ * `api.persons.list` (Django), then applied to the invocations query as a hard
+ * `AND person_id = '<uuid>'`. Keeps the invocations query on its own CH cluster —
+ * no cross-shard subquery against `persons`.
+ */
+ person_uuid?: string
}
export interface HogInvocationsLogicProps {
@@ -120,6 +128,7 @@ const URL_PARAMS = {
search: `${URL_PARAM_PREFIX}search`,
order_by: `${URL_PARAM_PREFIX}order`,
problem_only: `${URL_PARAM_PREFIX}problems`,
+ person_uuid: `${URL_PARAM_PREFIX}person`,
} as const
const filtersToSearchParams = (filters: HogInvocationsFilters): Record<string, string | undefined> => ({
@@ -131,6 +140,7 @@ const filtersToSearchParams = (filters: HogInvocationsFilters): Record<string, s
[URL_PARAMS.search]: filters.search,
[URL_PARAMS.order_by]: filters.order_by === 'first_scheduled' ? undefined : filters.order_by,
[URL_PARAMS.problem_only]: filters.problem_only ? '1' : undefined,
+ [URL_PARAMS.person_uuid]: filters.person_uuid,
})
const searchParamsToFilters = (searchParams: Record<string, string | undefined>): Partial<HogInvocationsFilters> => {
@@ -164,6 +174,9 @@ const searchParamsToFilters = (searchParams: Record<string, string | undefined>)
if (searchParams[URL_PARAMS.problem_only]) {
next.problem_only = true
}
+ if (searchParams[URL_PARAMS.person_uuid]) {
+ next.person_uuid = searchParams[URL_PARAMS.person_uuid]
+ }
return next
}
@@ -175,6 +188,7 @@ const DEFAULT_FILTERS: HogInvocationsFilters = {
kind: undefined,
search: undefined,
order_by: 'first_scheduled',
+ person_uuid: undefined,
}
const AUTO_REFRESH_INTERVAL_MS = 10000
@@ -385,13 +399,6 @@ async function fetchSparkline(props: HogInvocationsLogicProps, filters: HogInvoc
? hogql.raw(`AND error_kind IN (${filters.error_kind.map(escapeHogQLString).join(',')})`)
: hogql.raw('')
const trimmedSearch = filters.search?.trim()
- // Email is stored on `persons.properties.email`, not on `hog_invocation_results` —
- // resolve to person_ids via an `ILIKE %value%` subquery on `persons`. Runs on every
- // non-empty search so partial matches (`meikel`, `@company.com`) work without the user
- // having to type a full email.
- const emailSearchClause = trimmedSearch
- ? `OR person_id IN (SELECT id FROM persons WHERE properties.email ILIKE ${escapeHogQLString(`%${trimmedSearch}%`)})`
- : ''
const optionalSearchClause = trimmedSearch
? hogql.raw(
`AND (
@@ -399,10 +406,15 @@ async function fetchSparkline(props: HogInvocationsLogicProps, filters: HogInvoc
OR event_uuid = ${escapeHogQLString(trimmedSearch)}
OR distinct_id = ${escapeHogQLString(trimmedSearch)}
OR person_id = ${escapeHogQLString(trimmedSearch)}
- ${emailSearchClause}
)`
)
: hogql.raw('')
+ // Person filter is applied as a hard equality on `person_id`. The UUID is resolved
+ // client-side via `api.persons.list` (Django/Postgres) — we can't join `persons` in
+ // the invocations query itself because the two tables live on different CH clusters.
+ const optionalPersonClause = filters.person_uuid
+ ? hogql.raw(`AND person_id = ${escapeHogQLString(filters.person_uuid)}`)
+ : hogql.raw('')
const kindClause = kindClauseFor(props, filters)
const dateClause = dateClauseFor(filters)
@@ -429,6 +441,7 @@ async function fetchSparkline(props: HogInvocationsLogicProps, filters: HogInvoc
${optionalStatusClause}
${optionalErrorKindClause}
${optionalSearchClause}
+ ${optionalPersonClause}
${problemClauseFor(props, filters)}
)
GROUP BY bucket, status
@@ -484,13 +497,6 @@ async function fetchRunsPage(
? hogql.raw(`AND error_kind IN (${filters.error_kind.map(escapeHogQLString).join(', ')})`)
: hogql.raw('')
const trimmedSearch = filters.search?.trim()
- // Email is stored on `persons.properties.email`, not on `hog_invocation_results` —
- // resolve to person_ids via an `ILIKE %value%` subquery on `persons`. Runs on every
- // non-empty search so partial matches (`meikel`, `@company.com`) work without the user
- // having to type a full email.
- const emailSearchClause = trimmedSearch
- ? `OR person_id IN (SELECT id FROM persons WHERE properties.email ILIKE ${escapeHogQLString(`%${trimmedSearch}%`)})`
- : ''
const optionalSearchClause = trimmedSearch
? hogql.raw(
`AND (
@@ -498,10 +504,15 @@ async function fetchRunsPage(
OR event_uuid = ${escapeHogQLString(trimmedSearch)}
OR distinct_id = ${escapeHogQLString(trimmedSearch)}
OR person_id = ${escapeHogQLString(trimmedSearch)}
- ${emailSearchClause}
)`
)
: hogql.raw('')
+ // Person filter is applied as a hard equality on `person_id`. The UUID is resolved
+ // client-side via `api.persons.list` (Django/Postgres) — we can't join `persons` in
+ // the invocations query itself because the two tables live on different CH clusters.
+ const optionalPersonClause = filters.person_uuid
+ ? hogql.raw(`AND person_id = ${escapeHogQLString(filters.person_uuid)}`)
+ : hogql.raw('')
// `ORDER BY max(scheduled_at)` is safe only because the SELECT alias isn't
// named `scheduled_at` — otherwise HogQL substitutes the alias and produces
@@ -539,6 +550,7 @@ async function fetchRunsPage(
${optionalStatusClause}
${optionalErrorKindClause}
${optionalSearchClause}
+ ${optionalPersonClause}
${problemClauseFor(props, filters)}
${orderClause}
LIMIT ${HOG_INVOCATIONS_PAGE_SIZE}
@@ -675,6 +687,11 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
rerunInvocations: (invocationIds: string[]) => ({ invocationIds }),
bulkRerun: (params: BulkRerunParams) => ({ params }),
setHasMore: (hasMore: boolean) => ({ hasMore }),
+ // Person filter picker: user picks a person from the typeahead → chip stays in the
+ // input row. Passing `null` clears the filter. `setFilters` still owns URL sync and
+ // refresh; `pickedPerson` just carries display state so the chip can render name/email
+ // without an extra roundtrip.
+ setPickedPerson: (person: PersonType | null) => ({ person }),
}),
reducers({
@@ -729,6 +746,18 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
setHasMore: () => true,
},
],
+ pickedPerson: [
+ null as PersonType | null,
+ {
+ setPickedPerson: (_, { person }) => person,
+ // A URL-driven filter change without a matching pickedPerson means we came in
+ // from a shared link — clear the stale display until the hydrator populates it.
+ // `person.uuid` is the actual UUID; `person.id` is Django's numeric PK.
+ setFilters: (state, { filters }) =>
+ 'person_uuid' in filters && filters.person_uuid !== state?.uuid ? null : state,
+ resetFilters: () => null,
+ },
+ ],
}),
loaders(({ props, values, actions, cache }) => ({
@@ -797,6 +826,26 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
},
},
],
+ personSearchResults: [
+ [] as PersonType[],
+ {
+ searchPersons: async ({ search }: { search: string }, breakpoint) => {
+ const trimmed = search.trim()
+ if (!trimmed) {
+ return []
+ }
+ // Debounce so quick typing doesn't fan out to N requests.
+ await breakpoint(300)
+ try {
+ const response = await api.persons.list({ search: trimmed, limit: 10 })
+ breakpoint()
+ return response.results ?? []
+ } catch {
+ return []
+ }
+ },
+ },
+ ],
personPropertiesById: [
{} as Record<string, { properties: Record<string, any>; distinct_ids?: string[] }>,
{
@@ -845,7 +894,7 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
selectors({
statusCounts: [
(s) => [s.runs],
- (runs): Record<RunStatus, number> => {
+ (runs: HogInvocationRow[]): Record<RunStatus, number> => {
const counts: Record<RunStatus, number> = { running: 0, succeeded: 0, failed: 0 }
for (const r of runs) {
counts[r.status] = (counts[r.status] ?? 0) + 1
@@ -853,14 +902,17 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
return counts
},
],
- selectedCount: [(s) => [s.selectedIds], (selectedIds) => Object.keys(selectedIds).length],
+ selectedCount: [
+ (s) => [s.selectedIds],
+ (selectedIds: Record<string, boolean>) => Object.keys(selectedIds).length,
+ ],
canBulkRerun: [
(s) => [s.selectedCount],
- (selectedCount) => selectedCount > 0 && selectedCount <= HOG_INVOCATIONS_RERUN_MAX_COUNT,
+ (selectedCount: number) => selectedCount > 0 && selectedCount <= HOG_INVOCATIONS_RERUN_MAX_COUNT,
],
rerunableSelectedIds: [
(s) => [s.selectedIds, s.runs],
- (selectedIds, runs): string[] => {
+ (selectedIds: Record<string, boolean>, runs: HogInvocationRow[]): string[] => {
const ids = Object.keys(selectedIds)
if (ids.length === 0) {
return []
@@ -873,17 +925,20 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
})
},
],
- hasRunningRows: [(s) => [s.runs], (runs): boolean => runs.some((r) => r.status === 'running')],
+ hasRunningRows: [
+ (s) => [s.runs],
+ (runs: HogInvocationRow[]): boolean => runs.some((r) => r.status === 'running'),
+ ],
selectableIds: [
(s) => [s.runs],
- (runs): string[] =>
+ (runs: HogInvocationRow[]): string[] =>
runs
.filter((r) => !isRerunWrapperKind(r.function_kind) && r.status !== 'running')
.map((r) => r.invocation_id),
],
selectAllState: [
(s) => [s.selectedIds, s.selectableIds],
- (selectedIds, selectableIds): 'all' | 'some' | 'none' => {
+ (selectedIds: Record<string, boolean>, selectableIds: string[]): 'all' | 'some' | 'none' => {
if (selectableIds.length === 0) {
return 'none'
}
@@ -901,12 +956,35 @@ export const hogInvocationsLogic = kea<hogInvocationsLogicType>([
actions.loadRuns(null)
actions.loadSparkline(null)
},
- setFilters: () => {
+ setFilters: async ({ filters }) => {
actions.refresh()
+ // Hydrate the picked-person display when a shared link seeds `person_uuid`
+ // without a matching pickedPerson (e.g. someone pasted the URL).
+ if ('person_uuid' in filters && filters.person_uuid && values.pickedPerson?.uuid !== filters.person_uuid) {
+ const targetUuid = filters.person_uuid
+ try {
+ const byUuid = await api.persons.getByUUIDs([targetUuid])
+ // Re-check after the await: the user may have cleared the filter or picked a
+ // different person while the hydrate was in flight. Restoring the stale hit
+ // would silently reload invocations for the wrong person.
+ if (values.filters.person_uuid !== targetUuid) {
+ return
+ }
+ const person = byUuid[targetUuid]
+ if (person) {
+ actions.setPickedPerson(person)
+ }
+ } catch {
+ // Best-effort; the chip falls back to showing the raw UUID.
+ }
+ }
},
resetFilters: () => {
actions.refresh()
},
+ setPickedPerson: ({ person }) => {
+ actions.setFilters({ person_uuid: person?.uuid ?? undefined })
+ },
loadRunsSuccess: () => {
scheduleAutoRefresh(cache, actions, values)
// Full-list enrichment: a 10s poll can surface brand-new invocation ids.