: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(autoresearch): show measured prediction coverage and score age (#114655)
posthog[bot]a108602e96d0
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 8fc28c509892..0cb12723dc5d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6524,14 +6524,38 @@ snapshots:hash: v1.k794b7964.5861f881393ab1dba59cb0330fd1704b278a76ac0748086f446d650e1ee88f80.GWFbkjd1OxgM33wYBC4Gncb_3jIWx1RIU5FGZ7ABzKUproducts-autoresearch-model-detail-scene--agent-research-wide--wide--light:hash: v1.k794b7964.61a18ed53831b16b23b3f5c5bf5db2311a2a67c3237d339a9559de7dd488432c.jsOveKxB0FdFA8m-z9oDOUxV_z4mbAXK9Lra6HxBrr0+ products-autoresearch-model-detail-scene--coverage-below-cap--narrow--dark:+ hash: v1.k794b7964.721530fcc755c7f3fdbd2ac8da72aeee7661e2cca2a594897bc63f0644c238ee.zJhue3x2e_jOlNhkf7MO1OaF4g1HG6E9ks29rkzZleE+ products-autoresearch-model-detail-scene--coverage-below-cap--narrow--light:+ hash: v1.k794b7964.fe0a81a4119d2cac8a693099bd5316b2d3725f611f3dd6a5ac68dff184e8a82c.cC5aTKRX4gyM-IEoUjYC0PXBgBVOIJ_YxdKABqOPPVU+ products-autoresearch-model-detail-scene--coverage-below-cap--wide--dark:+ hash: v1.k794b7964.44cd2d63e9cad9efe3147afe30f4c1094e19aea4bc000f29ceb9f4942374953c.8XtAEwpQ9G3eZlXhMeg-7PFH7doptrwHCWup1lvotu0+ products-autoresearch-model-detail-scene--coverage-below-cap--wide--light:+ hash: v1.k794b7964.30bf170449b1e41729af4fdd359f203c575b61cd86a91d1404474f1e9ce04aa2.nHtmktQwmYtROwQlkvF0Wai2UweaJG08Vtxj1wclyOQ+ products-autoresearch-model-detail-scene--coverage-rolling-mid-cycle--narrow--dark:+ hash: v1.k794b7964.66b9db1745b588df2a4c100c72773c8ed69e5b9c11bb06cee447e54c307add83.GupL02pHEAaRli9TEEU5xdNdWNYbzcYpb4MH3bQNnw0+ products-autoresearch-model-detail-scene--coverage-rolling-mid-cycle--narrow--light:+ hash: v1.k794b7964.8ec1ffa9de602b25d098cdb293fb245c4955c9ebc160224131db894519166017.P6ovEwupUpVHrf2cA_AfWooiNfwvMout6JT0PVwYqoU+ products-autoresearch-model-detail-scene--coverage-rolling-mid-cycle--wide--dark:+ hash: v1.k794b7964.c3e6c9ab12890444266e6cb1325b36a939c7c055bd8f57ab9cb23bdce497bf48.BanqKFIn98OeGkPzXVy-XZGrA--UG1Wfpm5WIsVbId0+ products-autoresearch-model-detail-scene--coverage-rolling-mid-cycle--wide--light:+ hash: v1.k794b7964.64af60e40bb95efceb94be384ba8a674477bb36e9765984b4ec4cb7aeb4d5b98.s9GNvnmp8Wv4AnoMU5kJIudkpsQTykdkhNphYliExUM+ products-autoresearch-model-detail-scene--coverage-with-failed-runs--narrow--dark:+ hash: v1.k794b7964.dc648673de2261f42b22ff5b443cfcea886722003a27774013104f074ef0f1d8.DkJOzJlZyxUuT3r21GuO4ETvOR69_qYU7XSiSYz1LK8+ products-autoresearch-model-detail-scene--coverage-with-failed-runs--narrow--light:+ hash: v1.k794b7964.14148a60a3672401ff7c13adfc2d9a730570c1975d6d28b6c4a5a61b2fd4e2ae.-bDkliOWb6Eg1KB0N2tTf8RC3PAk47BKl5PYany8hBs+ products-autoresearch-model-detail-scene--coverage-with-failed-runs--wide--dark:+ hash: v1.k794b7964.be3ca41a134359e6bece640a965f9cfcc333941ae5869625c4914d343e50f1db.zKecG11ytYgkA28oOOj3b8XoSF8rByx4Xrxv4ri2lPw+ products-autoresearch-model-detail-scene--coverage-with-failed-runs--wide--light:+ hash: v1.k794b7964.24f39e61b0e12e87c25873f586fe4d2353ae45ca15ab38182da8b6b9f4060ca5.23vLegDN9E_LgZmMW1R-X2B4CbdUbq2lvNy-Lq7YujYproducts-autoresearch-model-detail-scene--narrow--narrow--dark:- hash: v1.k794b7964.a8261167fe190a6da69fd2bc07cd0b45b9d69ddb6c502e6a76ab6545c9e043d6.3ScvmJEDOvl0AC3sWgI9d6tawFXTfq2B8p-pvUn2htw+ hash: v1.k794b7964.ccf500b86b8416ba6f5eb0585c4f2b1a651a7ee08197eb26acbf1159a98a5a9c.QZOCYtHGQLG2LxdHPOFSl3DEOeCQc2LhQJqnXabqih8products-autoresearch-model-detail-scene--narrow--narrow--light:- hash: v1.k794b7964.7e9a7baa51c5bfccfdc2f9d829213fb654249124270ef725da68b668c810e377.tdJkrS3ESfUX55iohONns0waCMExMUde4q0JwmLMqaY+ hash: v1.k794b7964.69ff7705b5a7a23f19da2825a77c0eaef3e99e4e59ee04f57a04a4529a39c6e6.eox1HduqmnWEHYcw9I6_McOvsjY3nTNRd1nm37Qrtd4products-autoresearch-model-detail-scene--wide--wide--dark:- hash: v1.k794b7964.9c69746cf2c5d848ae83c301d0dd50427d11fb2970ee26be5f07800ac9001405.K6PMRUi2ZPXkyMtB5NzSUiQqrI0QcSq5UC5IRzanmnk+ hash: v1.k794b7964.7ae6b811f9b09f8a9f518b758b008781c6f05ca0d0bea07c9e94b6c3e643e7af.p4p8au-9DAy6r2E5vQv0RUuUCak5FzUtNqSFCDdo9wAproducts-autoresearch-model-detail-scene--wide--wide--light:- hash: v1.k794b7964.45e55e328260992ff187aa5661b07ac3e8812db2df5c07f20ac9a7ff1dd0141b.ZkwHP20gbuIUXIHfzP_-zevfbJkv3AkQ7-DaMgcf5uw+ hash: v1.k794b7964.f93faffb29c817fc5d2b48b1cadeed596372e13c6870d0f695f90fb7b5a0f5ee.jr8VOYxzbK2nVfO08U2rOYdTytGsXuKT6WgXzi8Aqbcproducts-autoresearch-probability-histogram--bimodal--dark:hash: v1.k794b7964.f95d3982e7c08f2e1b51655520f15e37293aa98e5ca87126a5653d2300bd776b.2G0LsuSx-SLqWn1Oxm_bUHSqfeDPFF6Pof0vDvhZEHMproducts-autoresearch-probability-histogram--bimodal--light:diff --git a/products/autoresearch/frontend/AGENTS.md b/products/autoresearch/frontend/AGENTS.mdindex 32770692077a..fc0cce21612c 100644--- a/products/autoresearch/frontend/AGENTS.md+++ b/products/autoresearch/frontend/AGENTS.md@@ -20,6 +20,7 @@ The product is mostly a backend, and the UI is deliberately thin — it reads st| `pipelineLifecycle.ts` | The five lifecycle steps (question set to checked against reality) and which one is current. || `agentSearch.ts` | The agent's search across training runs: chart points, best score so far, AUC change per experiment, log groups and the latest agent notes. || `onlinePerformance.ts` | Accuracy tab helpers over the `online_performance` endpoint: the headline, the realized AUC series, predicted against actual by segment. |+| `predictionCoverage.ts` | Predictions tab coverage from the runs list: the measured summary and the coverage and score age per day. || `predictionSegments.ts` | The likelihood segment thresholds, from `predictionSegmentThresholds.json`. Online validation reads the same file for its Likely cutoff. || `PipelineStatusTag.tsx` | Status tag + tooltip shared by the list and detail scenes. || `ProbabilityHistogram.tsx` | Decile histogram of the latest scoring run's probabilities. |diff --git a/products/autoresearch/frontend/AutoresearchPipelineScene.stories.tsx b/products/autoresearch/frontend/AutoresearchPipelineScene.stories.tsxindex 1942a5fc2626..76d4e1ea0268 100644--- a/products/autoresearch/frontend/AutoresearchPipelineScene.stories.tsx+++ b/products/autoresearch/frontend/AutoresearchPipelineScene.stories.tsx@@ -292,3 +292,97 @@ export const AccuracyBeforePrecisionRecall: Story = {testOptions: { viewportWidths: ['wide'] },},}++function coverageRuns(days: number, perDay: (day: number) => Partial<AutoresearchRunApi>): AutoresearchRunApi[] {+ return Array.from({ length: days }, (_, day) => ({+ id: `coverage-${day}`,+ pipeline: PIPELINE_ID,+ run_type: 'inference',+ status: 'completed',+ error: '',+ created_at: `2026-02-${String(day + 16).padStart(2, '0')}T03:00:00Z`,+ ...perDay(day),+ })) as unknown as AutoresearchRunApi[]+}++function coverageStory(coverageRunList: AutoresearchRunApi[]): Story {+ return {+ decorators: [+ mswDecorator({+ get: {+ [`/api/projects/:team_id/autoresearch/${PIPELINE_ID}/runs/`]: toPaginatedResponse(coverageRunList),+ },+ }),+ ],+ parameters: {+ pageUrl: `${urls.autoresearchPipeline(PIPELINE_ID)}?tab=predictions`,+ testOptions: { viewportWidths: ['wide', 'narrow'] },+ },+ }+}++// Everyone fits under the scoring cap, so each run rescores the whole population.+export const CoverageBelowCap: Story = coverageStory(+ coverageRuns(12, (day) => ({+ rows_scored: 48000,+ metrics: { rows_eligible: 48000 },+ coverage: {+ population: 48000,+ with_score: day === 0 ? 0 : 48000,+ never_scored: day === 0 ? 48000 : 0,+ age_days_avg: day === 0 ? null : 1,+ age_days_p50: day === 0 ? null : 1,+ age_days_p90: day === 0 ? null : 1,+ age_days_max: day === 0 ? null : 1,+ lookback_days: 30,+ },+ }))+)++// Each run scores 45,000 of 250,000 people, and the first rotation is not complete yet.+export const CoverageRollingMidCycle: Story = coverageStory(+ coverageRuns(5, (day) => ({+ rows_scored: 45000,+ metrics: { rows_eligible: 250000 },+ coverage: {+ population: 250000,+ with_score: 45000 * day,+ never_scored: 250000 - 45000 * day,+ age_days_avg: day === 0 ? null : (day - 1) / 2,+ age_days_p50: day === 0 ? null : (day - 1) / 2,+ age_days_p90: day === 0 ? null : (day - 1) * 0.9,+ age_days_max: day === 0 ? null : day - 1,+ lookback_days: 30,+ },+ }))+)++// Failed runs leave gaps, so the oldest scores are older than the daily target.+export const CoverageWithFailedRuns: Story = coverageStory(+ coverageRuns(14, (day) => {+ if ([5, 6, 10, 11, 13].includes(day)) {+ return {+ status: 'failed',+ rows_scored: null,+ metrics: {},+ coverage: null,+ error: 'The scoring query timed out.',+ }+ }+ const age = day === 7 || day === 12 ? 3 : 1+ return {+ rows_scored: 48000,+ metrics: { rows_eligible: 48000 },+ coverage: {+ population: 48000,+ with_score: day === 0 ? 0 : 48000,+ never_scored: day === 0 ? 48000 : 0,+ age_days_avg: day === 0 ? null : age,+ age_days_p50: day === 0 ? null : age,+ age_days_p90: day === 0 ? null : age,+ age_days_max: day === 0 ? null : age,+ lookback_days: 30,+ },+ }+ })+)diff --git a/products/autoresearch/frontend/autoresearchPipelineLogic.ts b/products/autoresearch/frontend/autoresearchPipelineLogic.tsindex 09695a4afd21..7f361e3abc45 100644--- a/products/autoresearch/frontend/autoresearchPipelineLogic.ts+++ b/products/autoresearch/frontend/autoresearchPipelineLogic.ts@@ -70,6 +70,7 @@ import {validatedPredictionDates,} from './onlinePerformance'import { LifecycleStep, pipelineLifecycle } from './pipelineLifecycle'+import { type CoveragePoint, type CoverageSummary, coverageHistory, coverageSummary } from './predictionCoverage'import {PREDICTION_SEGMENTS,PREDICTION_SEGMENT_THRESHOLDS,@@ -281,6 +282,8 @@ export interface autoresearchPipelineLogicValues {breadcrumbs: Breadcrumb[]champion: AutoresearchModelApi | nullchampionConfusion: PooledConfusion | null+ coverageHistory: CoveragePoint[]+ coverageSummary: CoverageSummary | nulldailyVolume: DailyVolumePoint[] | nulldailyVolumeError: booleandailyVolumeLoading: boolean@@ -749,6 +752,12 @@ export interface autoresearchPipelineLogicMeta {runs: AutoresearchRunApi[],pipeline: AutoresearchPipelineApi | null) => ScoringCoverage | null+ coverageSummary: (+ runs: AutoresearchRunApi[],+ scoringCoverage: ScoringCoverage | null,+ pipeline: AutoresearchPipelineApi | null+ ) => CoverageSummary | null+ coverageHistory: (runs: AutoresearchRunApi[]) => CoveragePoint[]latestChampionPerformance: (onlinePerformance: OnlinePerformanceRowApi[]) => OnlinePerformanceRowApi | nullrealizedAucPoints: (onlinePerformance: OnlinePerformanceRowApi[]) => RealizedAucPoint[]segmentCalibration: (latestChampionPerformance: OnlinePerformanceRowApi | null) => SegmentCalibration[]@@ -1302,6 +1311,16 @@ export const autoresearchPipelineLogic = kea<autoresearchPipelineLogicType>([(runs: AutoresearchRunApi[], pipeline: AutoresearchPipelineApi | null): ScoringCoverage | null =>scoringCoverage(runs, pipeline?.cadence_days ?? 1),],+ coverageSummary: [+ (s) => [s.runs, s.scoringCoverage, s.pipeline],+ (+ runs: AutoresearchRunApi[],+ scoringCoverage: ScoringCoverage | null,+ pipeline: AutoresearchPipelineApi | null+ ): CoverageSummary | null =>+ coverageSummary(runs, scoringCoverage?.rescoreDays ?? Math.max(pipeline?.cadence_days ?? 1, 1)),+ ],+ coverageHistory: [(s) => [s.runs], (runs: AutoresearchRunApi[]): CoveragePoint[] => coverageHistory(runs)],latestChampionPerformance: [(s) => [s.onlinePerformance],(onlinePerformance: OnlinePerformanceRowApi[]): OnlinePerformanceRowApi | null =>diff --git a/products/autoresearch/frontend/pipeline/PredictionCoverage.tsx b/products/autoresearch/frontend/pipeline/PredictionCoverage.tsxnew file mode 100644index 000000000000..e1d9b92cc971--- /dev/null+++ b/products/autoresearch/frontend/pipeline/PredictionCoverage.tsx@@ -0,0 +1,159 @@+import { useActions, useValues } from 'kea'+import { useMemo } from 'react'++import { LemonBanner, LemonButton, LemonSkeleton } from '@posthog/lemon-ui'+import { type Series, TimeSeriesLineChart, type TimeSeriesLineChartConfig } from '@posthog/quill-charts'++import { useChartConfig, useChartTheme } from 'lib/charts/hooks'+import { dayjs } from 'lib/dayjs'+import { humanFriendlyNumber } from 'lib/utils/numbers'++import { autoresearchPipelineLogic } from '../autoresearchPipelineLogic'++function formatDays(days: number): string {+ const rounded = Number.isInteger(days) ? String(days) : days.toFixed(1)+ return rounded === '1' ? '1 day' : `${rounded} days`+}++function every(days: number): string {+ return days === 1 ? 'every day' : `every ${formatDays(days)}`+}++function EstimatedCoverageBanner(): JSX.Element | null {+ const { scoringCoverage } = useValues(autoresearchPipelineLogic)+ if (!scoringCoverage) {+ return null+ }+ const { scored, eligible, rescoreDays } = scoringCoverage+ return (+ <LemonBanner type="info">+ The latest run scored {humanFriendlyNumber(scored)} of {humanFriendlyNumber(eligible)} users, starting with+ users never scored, then those scored longest ago. Everyone is rescored about every {rescoreDays} days.+ </LemonBanner>+ )+}++/** Measured coverage, never-scored count and rescore cadence. Falls back to the estimate for runs from before the measure. */+export function CoverageSummaryBanner(): JSX.Element | null {+ const { coverageSummary } = useValues(autoresearchPipelineLogic)+ if (!coverageSummary) {+ return <EstimatedCoverageBanner />+ }+ const { coverage, coveragePct, measuredAt, cutoffDate, measuredRescoreDays, targetRescoreDays, failedRunsSince } =+ coverageSummary+ const slowerThanTarget = measuredRescoreDays != null && measuredRescoreDays > targetRescoreDays+ return (+ <LemonBanner type={failedRunsSince > 0 || slowerThanTarget ? 'warning' : 'info'}>+ <div className="space-y-1" data-attr="autoresearch-coverage-summary">+ <p className="mb-0">+ Before the scoring run for {dayjs.utc(cutoffDate).format('MMM D')},{' '}+ {humanFriendlyNumber(coverage.with_score)} of {humanFriendlyNumber(coverage.population)} people (+ {Math.round(coveragePct)}%) had a score from the previous {formatDays(coverage.lookback_days)}.{' '}+ {coverage.never_scored > 0+ ? `${humanFriendlyNumber(coverage.never_scored)} people had no score in that time.`+ : 'Everyone had a score.'}+ </p>+ {coverage.age_days_p50 != null && coverage.age_days_p90 != null && (+ <p className="mb-0">+ Half of those scores were less than {formatDays(coverage.age_days_p50)} old. 90% were less than{' '}+ {formatDays(coverage.age_days_p90)} old.+ </p>+ )}+ <p className="mb-0">+ {measuredRescoreDays == null+ ? `The target is to rescore each person ${every(targetRescoreDays)}. The measured rescore interval shows once everyone has a score.`+ : measuredRescoreDays !== targetRescoreDays+ ? `Each person is rescored about ${every(measuredRescoreDays)}. The target is ${every(targetRescoreDays)}.`+ : `Each person is rescored about ${every(measuredRescoreDays)}, as planned.`}+ </p>+ {failedRunsSince > 0 && (+ <p className="mb-0">+ {failedRunsSince === 1 ? '1 scoring run' : `${failedRunsSince} scoring runs`} failed after this+ measure on {dayjs(measuredAt).format('MMM D')}, so these numbers can be out of date.+ </p>+ )}+ </div>+ </LemonBanner>+ )+}++/** Coverage and score age per scoring day, from the runs list. */+export function CoverageHistoryChart(): JSX.Element {+ const { coverageHistory, runsLoaded, runsError, runsLoading } = useValues(autoresearchPipelineLogic)+ const { loadRuns } = useActions(autoresearchPipelineLogic)+ const theme = useChartTheme()++ const series = useMemo<Series[]>(+ // Dots keep a measured day visible when failed runs leave no neighbor to draw a line to.+ () => [+ {+ key: 'coverage',+ label: 'People with a score (%)',+ color: theme.colors[0],+ data: coverageHistory.map((p) => p.coveragePct ?? NaN),+ points: { radius: 2 },+ },+ {+ key: 'age_p50',+ label: 'Median score age (days)',+ color: theme.colors[1],+ data: coverageHistory.map((p) => p.ageP50Days ?? NaN),+ points: { radius: 2 },+ yAxisId: 'age',+ },+ {+ key: 'age_p90',+ label: '90th percentile score age (days)',+ color: theme.colors[2],+ data: coverageHistory.map((p) => p.ageP90Days ?? NaN),+ points: { radius: 2 },+ yAxisId: 'age',+ },+ ],+ [coverageHistory, theme]+ )+ const config = useChartConfig<TimeSeriesLineChartConfig>(+ () => ({+ showCrosshair: true,+ xAxis: { interval: 'day', timezone: 'UTC' },+ yAxis: [+ { id: 'left', label: 'People with a score', format: 'percentage', min: 0, max: 100, showGrid: true },+ { id: 'age', position: 'right', label: 'Score age (days)', decimalPlaces: 1 },+ ],+ legend: { show: true },+ }),+ []+ )++ if (runsError) {+ return (+ <div className="flex items-center gap-2">+ <p className="text-sm text-muted mb-0">Couldn't load the scoring runs.</p>+ <LemonButton size="small" type="secondary" onClick={loadRuns} loading={runsLoading}>+ Try again+ </LemonButton>+ </div>+ )+ }+ if (!runsLoaded) {+ return <LemonSkeleton className="h-64" />+ }+ if (coverageHistory.filter((p) => p.coveragePct != null).length < 2) {+ return (+ <p className="text-sm text-muted mb-0">+ The chart needs two days of scoring runs that measured coverage. Check back after the next scoring run.+ </p>+ )+ }+ return (+ <div className="flex flex-col h-64 max-w-4xl">+ <TimeSeriesLineChart+ series={series}+ labels={coverageHistory.map((p) => p.day)}+ theme={theme}+ config={config}+ dataAttr="autoresearch-coverage-chart"+ />+ </div>+ )+}diff --git a/products/autoresearch/frontend/pipeline/PredictionsTab.tsx b/products/autoresearch/frontend/pipeline/PredictionsTab.tsxindex 58fa67f270bc..9fc66cfc6623 100644--- a/products/autoresearch/frontend/pipeline/PredictionsTab.tsx+++ b/products/autoresearch/frontend/pipeline/PredictionsTab.tsx@@ -1,15 +1,14 @@import { useValues } from 'kea'import { IconGraph } from '@posthog/icons'-import { LemonBanner, LemonCollapse, LemonSkeleton } from '@posthog/lemon-ui'--import { humanFriendlyNumber } from 'lib/utils/numbers'+import { LemonCollapse, LemonSkeleton } from '@posthog/lemon-ui'import { autoresearchPipelineLogic } from '../autoresearchPipelineLogic'import { DailyVolumeChart } from '../DailyVolumeChart'import { ProbabilityHistogram } from '../ProbabilityHistogram'import { EmptyTab } from './EmptyTab'import { PredictionActionsPanel } from './PredictionActionsPanel'+import { CoverageHistoryChart, CoverageSummaryBanner } from './PredictionCoverage'import { PredictionSegmentCards } from './PredictionSegmentCards'import { ProbabilityUsersTable } from './ProbabilityUsersTable'import { ScoreNowButton } from './ScoreNowButton'@@ -56,20 +55,6 @@ function ProbabilityDistributionPanel(): JSX.Element {return <ProbabilityHistogram buckets={probabilityHistogram} />}-function ScoringCoverageBanner(): JSX.Element | null {- const { scoringCoverage } = useValues(autoresearchPipelineLogic)- if (!scoringCoverage) {- return null- }- const { scored, eligible, rescoreDays } = scoringCoverage- return (- <LemonBanner type="info">- The latest run scored {humanFriendlyNumber(scored)} of {humanFriendlyNumber(eligible)} users, starting with- users never scored, then those scored longest ago. Everyone is rescored about every {rescoreDays} days.- </LemonBanner>- )-}-export function PredictionsTab(): JSX.Element {const { pipeline } = useValues(autoresearchPipelineLogic)if (!pipeline) {@@ -94,6 +79,8 @@ export function PredictionsTab(): JSX.Element {<code>autoresearch_prediction</code> event. These views read straight from those events.</p>+ <CoverageSummaryBanner />+<PredictionSegmentCards /><PredictionActionsPanel />@@ -112,6 +99,11 @@ export function PredictionsTab(): JSX.Element {header: 'People (latest scoring run)',content: <ProbabilityUsersTable pipelineId={pipeline.id} />,},+ {+ key: 'coverage',+ header: 'Coverage and score age',+ content: <CoverageHistoryChart />,+ },{key: 'volume',header: 'Daily scoring volume',@@ -119,8 +111,6 @@ export function PredictionsTab(): JSX.Element {},]}/>-- <ScoringCoverageBanner /></div>)}diff --git a/products/autoresearch/frontend/predictionCoverage.test.ts b/products/autoresearch/frontend/predictionCoverage.test.tsnew file mode 100644index 000000000000..bec63f36e35c--- /dev/null+++ b/products/autoresearch/frontend/predictionCoverage.test.ts@@ -0,0 +1,117 @@+import { AutoresearchPredictionCoverageApi, AutoresearchRunApi } from './generated/api.schemas'+import { coverageHistory, coverageSummary } from './predictionCoverage'++function coverage(overrides: Partial<AutoresearchPredictionCoverageApi> = {}): AutoresearchPredictionCoverageApi {+ return {+ population: 1000,+ with_score: 1000,+ never_scored: 0,+ age_days_avg: 2,+ age_days_p50: 2,+ age_days_p90: 3.5,+ age_days_max: 4.2,+ lookback_days: 30,+ ...overrides,+ }+}++function run(overrides: Partial<AutoresearchRunApi>): AutoresearchRunApi {+ return {+ id: 'run',+ pipeline: 'pipeline-1',+ run_type: 'inference',+ status: 'completed',+ rows_scored: 250,+ metrics: {},+ coverage: coverage(),+ created_at: '2026-03-01T03:00:00Z',+ ...overrides,+ } as AutoresearchRunApi+}++describe('predictionCoverage', () => {+ test.each([+ [+ 'everyone has a score',+ [run({})],+ { coveragePct: 100, measuredRescoreDays: 4, targetRescoreDays: 4, failedRunsSince: 0 },+ ],+ [+ 'part of the population was never scored',+ [run({ coverage: coverage({ with_score: 600, never_scored: 400 }) })],+ { coveragePct: 60, measuredRescoreDays: null, targetRescoreDays: 4, failedRunsSince: 0 },+ ],+ [+ 'scoring runs failed after the measure',+ [+ run({ status: 'failed', coverage: null, created_at: '2026-02-28T03:00:00Z' }),+ run({}),+ run({ status: 'failed', coverage: null, created_at: '2026-03-02T03:00:00Z' }),+ run({ status: 'failed', coverage: null, created_at: '2026-03-03T03:00:00Z' }),+ ],+ { coveragePct: 100, measuredRescoreDays: 4, targetRescoreDays: 4, failedRunsSince: 2 },+ ],+ [+ 'only shadow and backfill runs failed after the measure',+ [+ run({ metrics: { prediction_date: '2026-03-01' } }),+ run({+ status: 'failed',+ coverage: null,+ metrics: { prediction_date: '2026-03-01', shadow: true },+ created_at: '2026-03-01T04:00:00Z',+ }),+ run({+ status: 'failed',+ coverage: null,+ metrics: { prediction_date: '2026-02-20' },+ created_at: '2026-03-01T05:00:00Z',+ }),+ ],+ { coveragePct: 100, measuredRescoreDays: 4, targetRescoreDays: 4, failedRunsSince: 0 },+ ],+ ])('coverageSummary when %s', (_name, runs, expected) => {+ expect(coverageSummary(runs, 4)).toMatchObject(expected)+ })++ test('coverageSummary is null when no run measured coverage', () => {+ expect(coverageSummary([run({ coverage: null })], 4)).toBeNull()+ })++ test('coverageSummary reads the newest measured run, whatever the list order', () => {+ const summary = coverageSummary(+ [+ run({ id: 'new', coverage: coverage({ with_score: 900, never_scored: 100 }) }),+ run({ id: 'old', created_at: '2026-02-20T03:00:00Z' }),+ ],+ 1+ )+ expect(summary?.coveragePct).toEqual(90)+ expect(summary?.measuredAt).toEqual('2026-03-01T03:00:00Z')+ })++ test.each([+ ['the prediction date when the run recorded one', { prediction_date: '2026-02-28' }, '2026-02-28'],+ ['the run day when the run has no prediction date', {}, '2026-03-01'],+ ])('coverageSummary cutoff is %s', (_name, metrics, expected) => {+ expect(coverageSummary([run({ metrics })], 4)?.cutoffDate).toEqual(expected)+ })++ test('coverageHistory keeps the newest measured run per day and leaves a gap for each day without one, including trailing failed days', () => {+ const history = coverageHistory([+ run({ created_at: '2026-03-02T15:00:00Z', coverage: coverage({ with_score: 800, age_days_p50: 1 }) }),+ run({ created_at: '2026-03-01T03:00:00Z', coverage: coverage({ with_score: 500 }) }),+ run({ created_at: '2026-03-02T03:00:00Z', coverage: coverage({ with_score: 700 }) }),+ run({ created_at: '2026-03-03T03:00:00Z', status: 'failed', coverage: null }),+ run({ created_at: '2026-03-04T03:00:00Z', coverage: coverage({ with_score: 900 }) }),+ run({ created_at: '2026-03-05T03:00:00Z', status: 'failed', coverage: null }),+ ])+ expect(history).toEqual([+ { day: '2026-03-01', coveragePct: 50, ageP50Days: 2, ageP90Days: 3.5 },+ { day: '2026-03-02', coveragePct: 80, ageP50Days: 1, ageP90Days: 3.5 },+ { day: '2026-03-03', coveragePct: null, ageP50Days: null, ageP90Days: null },+ { day: '2026-03-04', coveragePct: 90, ageP50Days: 2, ageP90Days: 3.5 },+ { day: '2026-03-05', coveragePct: null, ageP50Days: null, ageP90Days: null },+ ])+ })+})diff --git a/products/autoresearch/frontend/predictionCoverage.ts b/products/autoresearch/frontend/predictionCoverage.tsnew file mode 100644index 000000000000..12d85c5d5bf1--- /dev/null+++ b/products/autoresearch/frontend/predictionCoverage.ts@@ -0,0 +1,101 @@+import { dayjs } from 'lib/dayjs'++import type { AutoresearchPredictionCoverageApi, AutoresearchRunApi } from './generated/api.schemas'++/** Measured score coverage and score age from the newest live champion run that recorded them. */+export interface CoverageSummary {+ coverage: AutoresearchPredictionCoverageApi+ coveragePct: number+ measuredAt: string+ /** Prediction date of the measured run, as YYYY-MM-DD. The measure reads scores from before midnight UTC of this date, so it excludes the run's own scores. */+ cutoffDate: string+ /** Days between rescores of the same person, from the oldest score age. Null until everyone has a score. */+ measuredRescoreDays: number | null+ targetRescoreDays: number+ /** Scoring runs that failed after the measured run, so the numbers can be out of date. */+ failedRunsSince: number+}++/** One day's coverage, from the newest measured run of that day. Null values mark a day with no measure. */+export interface CoveragePoint {+ day: string+ coveragePct: number | null+ ageP50Days: number | null+ ageP90Days: number | null+}++type MeasuredRun = AutoresearchRunApi & { coverage: AutoresearchPredictionCoverageApi }++function measuredRuns(runs: AutoresearchRunApi[]): MeasuredRun[] {+ return runs+ .filter((run): run is MeasuredRun => run.status === 'completed' && run.coverage != null)+ .sort((a, b) => a.created_at.localeCompare(b.created_at))+}++function cutoffDate(run: AutoresearchRunApi): string {+ const predictionDate = run.metrics?.prediction_date+ return typeof predictionDate === 'string' ? predictionDate : run.created_at.slice(0, 10)+}++/** Shadow runs and backfills of past dates do not refresh live coverage, so their failures do not age it. */+function isLiveChampionRun(run: AutoresearchRunApi): boolean {+ return run.run_type === 'inference' && !run.metrics?.shadow && cutoffDate(run) >= run.created_at.slice(0, 10)+}++function coveragePct(coverage: AutoresearchPredictionCoverageApi): number {+ return coverage.population > 0 ? (100 * coverage.with_score) / coverage.population : 0+}++export function coverageSummary(runs: AutoresearchRunApi[], targetRescoreDays: number): CoverageSummary | null {+ const measured = measuredRuns(runs)+ const latest = measured[measured.length - 1]+ if (!latest) {+ return null+ }+ const { coverage } = latest+ const measuredRescoreDays =+ coverage.never_scored === 0 && coverage.age_days_max != null+ ? Math.max(1, Math.round(coverage.age_days_max))+ : null+ return {+ coverage,+ coveragePct: coveragePct(coverage),+ measuredAt: latest.created_at,+ cutoffDate: cutoffDate(latest),+ measuredRescoreDays,+ targetRescoreDays,+ failedRunsSince: runs.filter(+ (run) => isLiveChampionRun(run) && run.status === 'failed' && run.created_at > latest.created_at+ ).length,+ }+}++/** Coverage and score age per day, oldest day first. Reads the runs list, so it needs no extra query. */+export function coverageHistory(runs: AutoresearchRunApi[]): CoveragePoint[] {+ const byDay = new Map<string, CoveragePoint>()+ for (const run of measuredRuns(runs)) {+ const day = run.created_at.slice(0, 10)+ byDay.set(day, {+ day,+ coveragePct: coveragePct(run.coverage),+ ageP50Days: run.coverage.age_days_p50,+ ageP90Days: run.coverage.age_days_p90,+ })+ }+ const days = [...byDay.keys()]+ if (days.length === 0) {+ return []+ }+ // Failed live runs after the last measure extend the axis, so trailing failed days show as gaps too.+ const lastDay = runs+ .filter((run) => isLiveChampionRun(run) && run.status === 'failed')+ .map((run) => run.created_at.slice(0, 10))+ .reduce((latest, day) => (day > latest ? day : latest), days[days.length - 1])+ // A day with no measured run stays on the axis as a gap, so failed or skipped runs stay visible.+ const points: CoveragePoint[] = []+ for (let day = dayjs.utc(days[0]); !day.isAfter(dayjs.utc(lastDay)); day = day.add(1, 'day')) {+ const key = day.format('YYYY-MM-DD')+ points.push(byDay.get(key) ?? { day: key, coveragePct: null, ageP50Days: null, ageP90Days: null })+ }+ return points+}