: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(signals): add signals section to web inbox scout detail (#64682)
Andrew Maguirefc6b8de9e7ec
diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutDetailView.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutDetailView.tsxindex dac8ffc1c8b5..bd893061c9d2 100644--- a/frontend/src/scenes/inbox/components/config/scouts/ScoutDetailView.tsx+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutDetailView.tsx@@ -7,8 +7,10 @@ import { LemonButton, LemonSkeleton } from '@posthog/lemon-ui'import { pluralize } from 'lib/utils/strings'import { inboxSceneLogic } from '../../../inboxSceneLogic'+import { scoutDetailLogic } from '../../../logics/scoutDetailLogic'import { scoutFleetLogic } from '../../../logics/scoutFleetLogic'import { SCOUT_RUNS_WINDOW_SPAN, scoutRunsWindowLabel } from '../../../utils/scoutRunsWindow'+import { ScoutEmissionCard } from './ScoutEmissionCard'import { ScoutRowCard } from './ScoutRowCard'/**@@ -74,11 +76,45 @@ export function ScoutDetailView({ skillName }: { skillName: string }): JSX.Eleme</span></div>+ <ScoutSignalsSection skillName={skillName} />+<div className="rounded border border-dashed border-primary bg-bg-light px-4 py-6 text-center text-sm text-muted">- Signals and run history are coming to this view soon.+ Run history is coming to this view soon.</div></>)}</div>)}++/**+ * The Signals section: every finding this scout emitted in the recent window, newest first.+ * Emissions are fetched per emitted run by `scoutDetailLogic` (keyed by skill) off the fleet's+ * already-polled runs window. Most runs are quiet, so an empty list is the healthy default.+ */+function ScoutSignalsSection({ skillName }: { skillName: string }): JSX.Element {+ const { emissionRows, emissionsLoading, runsWindowLoadedOnce } = useValues(scoutDetailLogic({ skillName }))++ // "Loading" until the fleet's runs window has settled once AND this scout's emissions have+ // resolved — otherwise a fresh deep-link would flash the empty state before we know the+ // emitted runs. Gating on the fleet's first-load flag (not its per-poll loading) keeps the+ // quiet-scout empty state from flickering to a skeleton every 60s poll.+ const loading = !runsWindowLoadedOnce || emissionsLoading++ return (+ <div className="flex flex-col gap-2">+ <span className="text-xs font-medium text-default uppercase tracking-wide">Signals</span>+ {loading && emissionRows.length === 0 ? (+ <LemonSkeleton className="h-12 w-full rounded" />+ ) : emissionRows.length === 0 ? (+ <div className="rounded border border-dashed border-primary bg-bg-light px-4 py-6 text-center text-sm text-muted">+ No signals emitted in the last {SCOUT_RUNS_WINDOW_SPAN}.+ </div>+ ) : (+ emissionRows.map(({ emission, run }) => (+ <ScoutEmissionCard key={emission.id} emission={emission} run={run} />+ ))+ )}+ </div>+ )+}diff --git a/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx b/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsxnew file mode 100644index 000000000000..43fe7721f4e7--- /dev/null+++ b/frontend/src/scenes/inbox/components/config/scouts/ScoutEmissionCard.tsx@@ -0,0 +1,82 @@+import { useState } from 'react'++import { IconChevronDown, IconExternal } from '@posthog/icons'+import { Link } from '@posthog/lemon-ui'++import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'+import { humanFriendlyDetailedTime } from 'lib/utils/datetime'++import { SignalScoutEmission, SignalScoutRunSummary } from '../../../types'+import { SignalReportPriorityBadge } from '../../badges/SignalReportPriorityBadge'++/** Truncated mono identifier rendering for the footer finding id. */+function MonoId({ label, value }: { label: string; value: string }): JSX.Element {+ return (+ <span className="inline-flex items-center gap-1">+ <span>{label}</span>+ <span className="font-mono">{value.length > 12 ? `${value.slice(0, 12)}…` : value}</span>+ </span>+ )+}++/**+ * One emitted finding in the scout detail Signals section. Shares the collapse/expand grammar of+ * the run rows: a header (chevron · severity · confidence · timestamp) that stays visible, a 2-line+ * markdown preview when collapsed, and the full markdown plus an id/task-run footer when expanded.+ */+export function ScoutEmissionCard({+ emission,+ run,+}: {+ emission: SignalScoutEmission+ run: SignalScoutRunSummary+}): JSX.Element {+ const [expanded, setExpanded] = useState(false)+ const confidencePercent = Math.round((emission.confidence ?? 0) * 100)++ return (+ <div className="flex flex-col rounded border border-primary bg-bg-light">+ <button+ type="button"+ onClick={() => setExpanded((value) => !value)}+ className="flex items-center gap-2 px-3 py-2 text-left"+ aria-expanded={expanded}+ >+ <IconChevronDown+ className={`size-4 shrink-0 text-muted transition-transform ${expanded ? '' : '-rotate-90'}`}+ />+ <SignalReportPriorityBadge priority={emission.severity} />+ <span className="whitespace-nowrap text-[11px] text-muted tabular-nums">+ {confidencePercent}% confidence+ </span>+ <span className="flex-1" />+ <span className="whitespace-nowrap text-[11px] text-muted">+ {humanFriendlyDetailedTime(emission.emitted_at)}+ </span>+ </button>++ <div className="px-3 pb-2 pl-9">+ <LemonMarkdown+ disableImages+ className={expanded ? 'text-sm text-primary' : 'text-sm text-primary line-clamp-2'}+ >+ {emission.description || '_No description._'}+ </LemonMarkdown>++ {expanded && (+ <div className="flex items-center flex-wrap gap-x-3 gap-y-1 border-t pt-2 mt-2 text-xs text-tertiary">+ <MonoId label="Finding" value={emission.finding_id} />+ {run.task_url && (+ <>+ <span className="flex-1" />+ <Link to={run.task_url} className="flex items-center gap-1 font-medium shrink-0">+ Open task run <IconExternal className="size-3" />+ </Link>+ </>+ )}+ </div>+ )}+ </div>+ </div>+ )+}diff --git a/frontend/src/scenes/inbox/logics/scoutDetailLogic.ts b/frontend/src/scenes/inbox/logics/scoutDetailLogic.tsnew file mode 100644index 000000000000..57b191b2279a--- /dev/null+++ b/frontend/src/scenes/inbox/logics/scoutDetailLogic.ts@@ -0,0 +1,114 @@+import { connect, kea, key, path, props, selectors } from 'kea'+import { loaders } from 'kea-loaders'+import { subscriptions } from 'kea-subscriptions'++import api from 'lib/api'++import { SignalScoutEmission, SignalScoutRunSummary } from '../types'+import type { scoutDetailLogicType } from './scoutDetailLogicType'+import { scoutFleetLogic } from './scoutFleetLogic'++export interface ScoutDetailLogicProps {+ skillName: string+}++// A noisy scout on the 10-minute floor can rack up hundreds of emitted runs across the window;+// fetching emissions for all of them at once would fan out hundreds of concurrent requests and+// render hundreds of markdown cards. Bound both to the most recent N emitted runs — older+// findings live on in the inbox reports they produced.+const MAX_EMITTED_RUNS = 50++/** An emitted finding paired with the run that produced it (for the run-level task link). */+export interface ScoutEmissionRow {+ emission: SignalScoutEmission+ run: SignalScoutRunSummary+}++/**+ * Per-scout detail logic, keyed by skill_name. Reuses the singleton `scoutFleetLogic`'s+ * runs window (already polled while the detail page is open) to find this scout's emitted+ * runs, then fetches each run's emissions and flattens them into one newest-first list — the+ * Signals section. The runs endpoint has no per-finding listing, so emissions are fetched+ * per emitted run; quiet runs (the vast majority) are never hit.+ */+export const scoutDetailLogic = kea<scoutDetailLogicType>([+ path((key) => ['scenes', 'inbox', 'logics', 'scoutDetailLogic', key]),+ props({} as ScoutDetailLogicProps),+ key((props) => props.skillName),++ connect(() => ({+ values: [scoutFleetLogic, ['rollups', 'runsWindowLoadedOnce']],+ })),++ loaders(({ values }) => ({+ emissions: [+ [] as SignalScoutEmission[],+ {+ loadEmissions: async () => {+ const runs = values.emittedRuns+ if (runs.length === 0) {+ return []+ }+ // allSettled, not all: one failed run's fetch (transient 500, deleted run)+ // shouldn't discard every other run's findings — surface the partial set.+ const settled = await Promise.allSettled(+ runs.map((run) => api.signalScout.runs.emissions(run.run_id))+ )+ return settled+ .filter(+ (result): result is PromiseFulfilledResult<SignalScoutEmission[]> =>+ result.status === 'fulfilled'+ )+ .flatMap((result) => result.value)+ },+ },+ ],+ })),++ selectors({+ // This scout's runs that emitted at least one finding, newest first, capped to the most+ // recent MAX_EMITTED_RUNS. `.filter()` returns a fresh array, so the in-place `.sort()`+ // never touches the shared rollup `runs` the header timeline reads (oldest-first).+ emittedRuns: [+ (s) => [s.rollups, (_, props) => props.skillName],+ (rollups, skillName): SignalScoutRunSummary[] =>+ (rollups.get(skillName)?.runs ?? [])+ .filter((run) => (run.emitted_count ?? 0) > 0)+ .sort((a, b) => (b.created_at ?? '').localeCompare(a.created_at ?? ''))+ .slice(0, MAX_EMITTED_RUNS),+ ],+ // Stable string key over the emitted runs — refetch emissions only when the set actually+ // changes, not on every 60s runs-window poll that returns the same runs. Includes+ // `emitted_count` so a run that emits more findings while still in progress retriggers.+ emittedRunsKey: [+ (s) => [s.emittedRuns],+ (emittedRuns): string =>+ emittedRuns+ .map((run) => `${run.run_id}:${run.emitted_count ?? 0}`)+ .sort()+ .join(','),+ ],+ // Join fetched emissions back to their run (for the per-row task-run link), newest first.+ emissionRows: [+ (s) => [s.emissions, s.emittedRuns],+ (emissions, emittedRuns): ScoutEmissionRow[] => {+ const runsById = new Map(emittedRuns.map((run) => [run.run_id, run]))+ return emissions+ .map((emission) => {+ const run = runsById.get(emission.run_id)+ return run ? { emission, run } : null+ })+ .filter((row): row is ScoutEmissionRow => row !== null)+ .sort((a, b) => (b.emission.emitted_at ?? '').localeCompare(a.emission.emitted_at ?? ''))+ },+ ],+ }),++ subscriptions(({ actions }) => ({+ // Fires on mount (empty → real ids once the runs window loads) and whenever the set of+ // emitted runs changes; the string key holds equal across no-op polls so we don't refetch.+ emittedRunsKey: () => {+ actions.loadEmissions()+ },+ })),+])diff --git a/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts b/frontend/src/scenes/inbox/logics/scoutFleetLogic.tsindex c7299152e264..63306b54b422 100644--- a/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts+++ b/frontend/src/scenes/inbox/logics/scoutFleetLogic.ts@@ -153,6 +153,16 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([state?.map((config) => (config.id === configId ? { ...config, ...updates } : config)) ?? state,},],+ // Flips true the first time the runs window settles (success or failure) and stays true+ // across the 60s polls. Consumers (e.g. the scout detail Signals section) use it to tell+ // "not loaded yet" from "loaded, genuinely empty" without flickering a skeleton on polls.+ runsWindowLoadedOnce: [+ false,+ {+ loadRunsWindowSuccess: () => true,+ loadRunsWindowFailure: () => true,+ },+ ],}),selectors({