: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: Clamp last seen time to first seen time (#62992)
Luke Belton427da05a393e
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodePerson.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodePerson.tsxindex 9baf30fe8aab..25815263e55e 100644--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodePerson.tsx+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodePerson.tsx@@ -7,6 +7,7 @@ import { Tooltip } from '@posthog/lemon-ui'import { NotFound } from 'lib/components/NotFound'import { PropertyIcon } from 'lib/components/PropertyIcon/PropertyIcon'import { TZLabel } from 'lib/components/TZLabel'+import { dayjs } from 'lib/dayjs'import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { compactNumber } from 'lib/utils'@@ -165,6 +166,19 @@ function FirstSeen({ person }: { person: PersonType }): JSX.Element {)}+// `last_seen_at` is floored to the hour, so for a person whose first and last activity+// fall in the same hour it can resolve to *before* `created_at`. Clamp to `created_at` so+// "Last seen" never appears earlier than "First seen" — the real last activity is within+// the rounding hour of first seen anyway.+function clampLastSeenToFirstSeen(lastSeenAt: string, createdAt?: string): dayjs.Dayjs {+ const lastSeen = dayjs(lastSeenAt)+ if (!createdAt) {+ return lastSeen+ }+ const firstSeen = dayjs(createdAt)+ return lastSeen.isBefore(firstSeen) ? firstSeen : lastSeen+}+function LastSeen(): JSX.Element {const { person, personLoading } = useValues(personLogic)return (@@ -173,7 +187,7 @@ function LastSeen(): JSX.Element {{personLoading ? (<LemonSkeleton className="h-4 w-24" />) : person?.last_seen_at ? (- <TZLabel time={person.last_seen_at} />+ <TZLabel time={clampLastSeenToFirstSeen(person.last_seen_at, person.created_at)} />) : ('unknown')}