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(inbox): stabilize scout run identity across polls to cut re-render churn (#68446)

Paul D'Ambra9b622a7c252e
diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx
index 65f593420b10..e16301e30106 100644
--- a/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx
+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState } from 'react'
+import { memo, useEffect, useRef, useState } from 'react'
import { IconArrowRight, IconChevronDown, IconExternal } from '@posthog/icons'
import { LemonButton, LemonTag, Link } from '@posthog/lemon-ui'
@@ -6,13 +6,13 @@ import { LemonButton, LemonTag, Link } from '@posthog/lemon-ui'
import { IconLink } from 'lib/lemon-ui/icons'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
import { copyToClipboard } from 'lib/utils/copyToClipboard'
-import { humanFriendlyDetailedTime } from 'lib/utils/datetime'
import { addProjectIdIfMissing } from 'lib/utils/kea-router'
import { urls } from 'scenes/urls'
import { LinkedSignalReport, SignalScoutEmission, SignalScoutRunSummary } from '../../../types'
import { prettifyScoutSkillName } from '../../../utils/scoutRunsWindow'
import { SignalReportPriorityBadge } from '../../badges/SignalReportPriorityBadge'
+import { ScoutTimestamp } from './ScoutTimestamp'
/** Truncated mono identifier rendering for the footer finding id. */
function MonoId({ label, value }: { label: string; value: string }): JSX.Element {
@@ -31,8 +31,12 @@ function MonoId({ label, value }: { label: string; value: string }): JSX.Element
*
* `isDeepLinked` marks the finding the current `/inbox/scouts/<skill>/<finding>` URL points at — it
* auto-expands, highlights, and scrolls itself into view so a shared link lands on the right card.
+ *
+ * Memoized because the 60s runs-window poll re-renders the Signals list; the `emission` and `run`
+ * props keep stable references across polls (emissions don't refetch on no-op polls, and
+ * `loadRunsWindow` reconciles run identity), so unchanged cards skip re-rendering here.
*/
-export function ScoutEmissionCard({
+export const ScoutEmissionCard = memo(function ScoutEmissionCard({
skillName,
emission,
run,
@@ -99,9 +103,7 @@ export function ScoutEmissionCard({
{confidencePercent}% confidence
</span>
<span className="flex-1" />
- <span className="whitespace-nowrap text-[11px] text-muted">
- {humanFriendlyDetailedTime(emission.emitted_at)}
- </span>
+ <ScoutTimestamp time={emission.emitted_at} />
</button>
<LemonButton
size="xsmall"
@@ -165,4 +167,4 @@ export function ScoutEmissionCard({
</div>
</div>
)
-}
+})
diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutRunHistorySection.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutRunHistorySection.tsx
index 01b66ae6a227..365112c32067 100644
--- a/frontend/src/scenes/inbox/components/config/scouts/ScoutRunHistorySection.tsx
+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutRunHistorySection.tsx
@@ -1,11 +1,10 @@
import { useValues } from 'kea'
-import { useMemo, useState } from 'react'
+import { memo, useMemo, useState } from 'react'
import { IconArrowRight, IconChevronDown, IconExternal } from '@posthog/icons'
import { LemonButton, LemonSkeleton, Link } from '@posthog/lemon-ui'
import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
-import { humanFriendlyDetailedTime } from 'lib/utils/datetime'
import { pluralize } from 'lib/utils/strings'
import { urls } from 'scenes/urls'
@@ -23,6 +22,7 @@ import {
scoutReportActivityLabel,
SCOUT_RUNS_WINDOW_SPAN,
} from '../../../utils/scoutRunsWindow'
+import { ScoutTimestamp } from './ScoutTimestamp'
const FILTERS: { value: ScoutRunFilter; label: string }[] = [
{ value: 'all', label: 'All' },
@@ -56,8 +56,11 @@ function RunGlyph({ run }: { run: SignalScoutRunSummary }): JSX.Element {
* One run in the history list. Shares the collapse/expand grammar of `ScoutEmissionCard`: a header
* (chevron · glyph · timestamp · duration · failure · emitted count) that stays visible, the run
* summary markdown (2-line preview collapsed, full expanded), and an id/task-run footer when open.
+ *
+ * Memoized because the 60s runs-window poll re-renders the whole history list; `loadRunsWindow`
+ * reconciles run identity (see `reconcileById`) so unchanged runs keep their reference and skip here.
*/
-function ScoutRunRow({ run }: { run: SignalScoutRunSummary }): JSX.Element {
+const ScoutRunRow = memo(function ScoutRunRow({ run }: { run: SignalScoutRunSummary }): JSX.Element {
const [expanded, setExpanded] = useState(false)
const now = new Date()
const status = normalizeRunStatus(run.status)
@@ -80,9 +83,7 @@ function ScoutRunRow({ run }: { run: SignalScoutRunSummary }): JSX.Element {
className={`size-4 shrink-0 text-muted transition-transform ${expanded ? '' : '-rotate-90'}`}
/>
<RunGlyph run={run} />
- <span className="whitespace-nowrap text-[11px] text-muted">
- {humanFriendlyDetailedTime(run.started_at)}
- </span>
+ <ScoutTimestamp time={run.started_at} />
{duration && <span className="whitespace-nowrap text-[11px] text-muted">· {duration}</span>}
{failureKind && (
<span className="whitespace-nowrap text-[11px] text-warning">
@@ -154,7 +155,7 @@ function ScoutRunRow({ run }: { run: SignalScoutRunSummary }): JSX.Element {
)}
</div>
)
-}
+})
/**
* The Runs section on the scout detail surface: this scout's runs in the recent window, newest
diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutTimestamp.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutTimestamp.tsx
new file mode 100644
index 000000000000..7d7a99cf0793
--- /dev/null
+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutTimestamp.tsx
@@ -0,0 +1,15 @@
+import { TZLabel } from 'lib/components/TZLabel'
+
+/** Scout-standard timestamp: detailed date+time that self-updates across the "Today"/"Just now"
+ * boundaries, no hover popover (these render inside button headers), small muted text. */
+export function ScoutTimestamp({ time }: { time: string }): JSX.Element {
+ return (
+ <TZLabel
+ time={time}
+ showPopover={false}
+ formatDate="MMMM DD, YYYY"
+ formatTime="h:mm:ss A"
+ className="text-[11px] text-muted"
+ />
+ )
+}
diff --git a/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts b/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts
index f4d785cb1d2a..be8bb990d9b2 100644
--- a/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts
+++ b/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts
@@ -19,7 +19,9 @@ import {
computeFleetSummary,
computeScoutRollups,
FleetSummary,
+ isSettledRun,
prettifyScoutSkillName,
+ reconcileById,
SCOUT_RUNS_WINDOW_HOURS,
ScoutRollup,
sortConfigsForDisplay,
@@ -68,7 +70,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
startScoutChatTaskFailure: true,
}),
- loaders(() => ({
+ loaders(({ values }) => ({
scoutConfigs: [
null as SignalScoutConfig[] | null,
{
@@ -155,7 +157,14 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
cursor = oldest.created_at
}
- return { runs, complete }
+ // Reuse prior references for unchanged runs so the 60s poll doesn't churn every
+ // run's identity and needlessly re-render the memoized run/emission rows. Live
+ // (running/queued) runs are never reused: their rows show a wall-clock duration
+ // that must keep advancing with each poll.
+ return {
+ runs: reconcileById(values.runsWindow.runs, runs, (run) => run.run_id, isSettledRun),
+ complete,
+ }
},
},
],
diff --git a/frontend/src/scenes/inbox/utils/scoutRunsWindow.test.ts b/frontend/src/scenes/inbox/utils/scoutRunsWindow.test.ts
index 42ac56fdaea2..acade8011aa2 100644
--- a/frontend/src/scenes/inbox/utils/scoutRunsWindow.test.ts
+++ b/frontend/src/scenes/inbox/utils/scoutRunsWindow.test.ts
@@ -5,6 +5,7 @@ import {
computeFleetSummary,
computeScoutRollups,
deriveRunOutcome,
+ reconcileById,
runMatchesFilter,
ScoutRunOutcome,
scoutReportActivityLabel,
@@ -103,4 +104,47 @@ describe('scoutRunsWindow report channel', () => {
expect(computeFleetSummary([], rollups).emitRate).toEqual(1)
})
})
+
+ describe('reconcileById', () => {
+ it('keeps the previous reference for unchanged items and the fresh one for changed items', () => {
+ // Every runs-window poll returns freshly parsed objects; reconcileById is what preserves
+ // identity so memoized rows only re-render on real change. If it degrades to `return next`,
+ // unchanged runs churn references every 60s and the memo is silently defeated.
+ const prevUnchanged = makeRun({ run_id: 'run-1', emitted_count: 1 })
+ const prevChanged = makeRun({ run_id: 'run-2', status: 'in_progress' })
+
+ const nextUnchanged = makeRun({ run_id: 'run-1', emitted_count: 1 })
+ const nextChanged = makeRun({ run_id: 'run-2', status: 'completed' })
+ const nextNew = makeRun({ run_id: 'run-3' })
+
+ const result = reconcileById(
+ [prevUnchanged, prevChanged],
+ [nextUnchanged, nextChanged, nextNew],
+ (run) => run.run_id
+ )
+
+ expect(result[0]).toBe(prevUnchanged)
+ expect(result[1]).toBe(nextChanged)
+ expect(result[2]).toBe(nextNew)
+ })
+
+ it('returns the next array untouched when there is no previous window', () => {
+ const next = [makeRun({ run_id: 'run-1' })]
+ expect(reconcileById([], next, (run) => run.run_id)).toBe(next)
+ })
+
+ it('never reuses items the isReusable predicate rejects, even when deep-equal', () => {
+ // A running run's row renders a wall-clock duration: reusing its reference would let the
+ // memoized row skip the poll re-render and freeze the ticking timer.
+ const prev = makeRun({ run_id: 'run-1', status: 'in_progress' })
+ const next = makeRun({ run_id: 'run-1', status: 'in_progress' })
+ const result = reconcileById(
+ [prev],
+ [next],
+ (run) => run.run_id,
+ (run) => run.status !== 'in_progress'
+ )
+ expect(result[0]).toBe(next)
+ })
+ })
})
diff --git a/frontend/src/scenes/inbox/utils/scoutRunsWindow.ts b/frontend/src/scenes/inbox/utils/scoutRunsWindow.ts
index ef9a910cdc1c..37225539a077 100644
--- a/frontend/src/scenes/inbox/utils/scoutRunsWindow.ts
+++ b/frontend/src/scenes/inbox/utils/scoutRunsWindow.ts
@@ -6,6 +6,7 @@
// "the recent window" with a "truncated" suffix when that walk hits its page cap.
import { humanFriendlyDuration } from 'lib/utils/durations'
+import { objectsEqual } from 'lib/utils/objects'
import { pluralize } from 'lib/utils/strings'
import { SignalScoutConfig, SignalScoutRunStatus, SignalScoutRunSummary } from '../types'
@@ -90,6 +91,13 @@ export function normalizeRunStatus(status: SignalScoutRunStatus): ScoutRunStatus
return 'unknown'
}
+/** Returns true when a run's status has settled — not running or queued.
+ * Settled runs can be safely reused across polls without freezing wall-clock renders. */
+export function isSettledRun(run: SignalScoutRunSummary): boolean {
+ const status = normalizeRunStatus(run.status)
+ return status !== 'running' && status !== 'queued'
+}
+
export function runDurationSeconds(run: SignalScoutRunSummary, now: Date): number | null {
if (!run.started_at) {
return null
@@ -296,6 +304,34 @@ function emptyRollup(): ScoutRollup {
}
}
+/**
+ * Reuse the previous poll's object reference for any item whose content is unchanged. The runs
+ * endpoint returns freshly parsed objects on every 60s poll, so without this every run reference
+ * changes each poll and every memoized row re-renders even when nothing changed. Matching by id and
+ * reusing the old reference when deep-equal keeps identity stable through the rollup selectors, so
+ * `React.memo` on the rows can actually bite.
+ *
+ * Cost: O(n·fields) per call — one Map build + one deep-equal per matched pair. Fine for the
+ * runs window (≤100 items, 60s cadence); keep that in mind if pointed at a large, hot list.
+ */
+export function reconcileById<T>(
+ previous: T[],
+ next: T[],
+ getId: (item: T) => string,
+ // Items whose rendering depends on wall-clock time (e.g. a live run's ticking duration) must
+ // NOT be reused: a preserved reference lets a memoized row skip the poll's re-render and freeze.
+ isReusable: (item: T) => boolean = () => true
+): T[] {
+ if (previous.length === 0) {
+ return next
+ }
+ const previousById = new Map(previous.map((item) => [getId(item), item]))
+ return next.map((item) => {
+ const existing = previousById.get(getId(item))
+ return existing && isReusable(item) && objectsEqual(existing, item) ? existing : item
+ })
+}
+
/**
* Client-side rollup over the recent fleet runs, keyed by skill_name. The runs
* endpoint has no per-scout filter or aggregate stats yet and caps at 100 rows,