: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(mcp-analytics): dash the in-progress bucket on the tool quality charts (#75887)
Georgis Andonisd2343d823f5c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex df4236a0078d..3edcd72c8f9c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6506,6 +6506,14 @@ snapshots:hash: v1.k794b7964.a4f65ae92d92d3600674689dc61f5ba834aac470154fb26b82821cb17b12cada.vAYLkto1-GBp1WeHETUeB5R0Pljn-RwHDW9h3bib1KQscenes-app-mcp-analytics-dashboard-cards--share-by-harness--light:hash: v1.k794b7964.c5eae070d2b0728ce676a8248650123f9a153ec8a9b9052f119d28b82e112e75.CdS-40DZGyT0t1Th9qh7g6Cc9Dgt__lEEujO7OXp4IM+ scenes-app-mcp-analytics-tool-quality-charts--in-progress-bucket--dark:+ hash: v1.k794b7964.cb575879ad1044413db6602a42cdd55d8325c1b7a86618bbf61c6f0027f8d396.VwV3uapTtM35cAwkGPx28mCWFl03HVcTxa4tdtqQQZE+ scenes-app-mcp-analytics-tool-quality-charts--in-progress-bucket--light:+ hash: v1.k794b7964.bf8496b4a7103103ec3a4b31efe1ec4828079f3b5b8d5abe472c16bb9303ccba.MA0W6oUfi1mfyPbNaC8VX3cXB5qWI1cp9q7Pk0tt82E+ scenes-app-mcp-analytics-tool-quality-charts--settled-window--dark:+ hash: v1.k794b7964.9f5b5cf95369d8822ac8b995151ff5386e5588d27a8a5fa0e1e2a70e8ca0ef27.5AywKm-JhISINz7_bggX38c9vtYVpCCUgeiJ5Yrukho+ scenes-app-mcp-analytics-tool-quality-charts--settled-window--light:+ hash: v1.k794b7964.ffd727aeabfa7614a64378cfe84563a23dcfb016cef6257fa51b8f5b01318f3a.Izt8TRdp_Kl4BruaSpc2ZRXgd5Qdc_36oM7pWPH_E28scenes-app-notebooks--bullet-list--dark:hash: v1.k794b7964.ff3b99437db7b9bcc36ff7530f42aa5c397f0e4d3ef300b741a84914afb3083c.5niOTwV3qBfjQba0L2N6T6HHEDSltopfXj1A5COVdbQscenes-app-notebooks--bullet-list--light:diff --git a/products/mcp_analytics/frontend/MCPAnalyticsToolQuality.tsx b/products/mcp_analytics/frontend/MCPAnalyticsToolQuality.tsxindex a3140e4fb6f6..b9f375ff2526 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsToolQuality.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsToolQuality.tsx@@ -93,7 +93,7 @@ function ChartsScopeHeader(): JSX.Element {}export function MCPAnalyticsToolQuality(): JSX.Element {- const { dailyChartData, dailyStatsLoading, interval } = useValues(mcpAnalyticsToolQualityLogic)+ const { dailyChartData, dailyStatsLoading, interval, incompleteTail } = useValues(mcpAnalyticsToolQualityLogic)const { timezone } = useValues(teamLogic)const theme = useChartTheme()@@ -108,6 +108,7 @@ export function MCPAnalyticsToolQuality(): JSX.Element {theme={theme}timezone={timezone}interval={interval}+ incompleteTail={incompleteTail}/><ToolQualityTable /></div>diff --git a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.test.ts b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.test.tsindex 91bc5f355872..f46050ca6054 100644--- a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.test.ts@@ -71,6 +71,29 @@ describe('mcpAnalyticsToolQualityLogic', () => {})})+ describe('incompleteTail', () => {+ beforeEach(() => {+ jest.clearAllMocks()+ initKeaTests()+ jest.spyOn(mockApi, 'query').mockResolvedValue({ results: [] })+ })++ // An open-ended relative window always ends in the bucket that is still collecting, and a+ // window that closed in the past never does, so this holds whenever the suite runs.+ it.each([+ ['an open-ended window', '-7d', null, true],+ ['a window that already closed', '2026-06-01', '2026-06-10', false],+ ])('is %s: %s', async (_label, dateFrom, dateTo, expected) => {+ const logic = mcpAnalyticsToolQualityLogic()+ logic.mount()+ await expectLogic(logic, () => {+ logic.actions.setDateFilter(dateFrom, dateTo)+ }).toFinishAllListeners()++ expect(logic.values.incompleteTail).toBe(expected)+ })+ })+describe('date range and tool filters', () => {beforeEach(() => {jest.clearAllMocks()diff --git a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.tsindex c11241801df8..8a05ae60a912 100644--- a/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts+++ b/products/mcp_analytics/frontend/mcpAnalyticsToolQualityLogic.ts@@ -16,7 +16,7 @@ import {} from '~/queries/schema/schema-general'import { IntervalType } from '~/types'-import { buildBucketKeys, normalizeBucket } from './timeBuckets'+import { buildBucketKeys, lastBucketIsInProgress, normalizeBucket } from './timeBuckets'export interface CategoryCount {category: string@@ -146,6 +146,7 @@ export interface mcpAnalyticsToolQualityLogicValues {dateFilter: DateFilterdateRangeLabel: stringfilteredRows: ToolQualityRow[]+ incompleteTail: booleaninterval: IntervalTypescopeShare: ScopeSharesearchTerm: string@@ -259,6 +260,7 @@ export interface mcpAnalyticsToolQualityLogicMeta {interval: IntervalType,timezone: string) => DailyChartData+ incompleteTail: (dailyChartData: DailyChartData, interval: IntervalType, timezone: string) => boolean}}@@ -439,6 +441,13 @@ export const mcpAnalyticsToolQualityLogic = kea<mcpAnalyticsToolQualityLogicTypereturn buildDailyChartData(dailyStats, bucketKeys)},],+ // The charts dash the final segment when it is the current, still-collecting interval, so a+ // partial day doesn't read as a fall in calls or a latency improvement.+ incompleteTail: [+ (s) => [s.dailyChartData, s.interval, teamLogic.selectors.timezone],+ (dailyChartData: DailyChartData, interval: IntervalType, timezone: string): boolean =>+ lastBucketIsInProgress(dailyChartData.labels, timezone, interval),+ ],}),listeners(({ actions, values }) => ({diff --git a/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.stories.tsx b/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.stories.tsxnew file mode 100644index 000000000000..0178fdd057a4--- /dev/null+++ b/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.stories.tsx@@ -0,0 +1,82 @@+import { Meta, StoryObj } from '@storybook/react'++import { type ChartTheme } from '@posthog/quill-charts'++import { buildTheme } from 'lib/charts/utils/theme'++import { type DailyChartData } from '../mcpAnalyticsToolQualityLogic'+import { ToolQualityCharts } from './ToolQualityCharts'++const LABELS = [+ '2026-06-01 00:00:00',+ '2026-06-02 00:00:00',+ '2026-06-03 00:00:00',+ '2026-06-04 00:00:00',+ '2026-06-05 00:00:00',+ '2026-06-06 00:00:00',+ '2026-06-07 00:00:00',+]++const DAILY: DailyChartData = {+ labels: LABELS,+ calls: [820, 910, 880, 940, 1010, 990, 1060],+ errors: [24, 31, 27, 33, 30, 28, 35],+ successRate: [97.1, 96.6, 96.9, 96.5, 97.0, 97.2, 96.7],+ p50: [180, 176, 190, 184, 178, 182, 188],+ p95: [900, 940, 980, 920, 960, 910, 970],+ p99: [2100, 2200, 2350, 2180, 2260, 2140, 2300],+}++// The shape the in-progress story exists for: the last bucket is a few hours into the day, so its+// counts sit far below its neighbours and its percentiles are computed off a thin sample.+const DAILY_PARTIAL_TAIL: DailyChartData = {+ ...DAILY,+ calls: [820, 910, 880, 940, 1010, 990, 310],+ errors: [24, 31, 27, 33, 30, 28, 6],+ successRate: [97.1, 96.6, 96.9, 96.5, 97.0, 97.2, 98.1],+ p50: [180, 176, 190, 184, 178, 182, 140],+ p95: [900, 940, 980, 920, 960, 910, 620],+ p99: [2100, 2200, 2350, 2180, 2260, 2140, 1180],+}++const meta: Meta = {+ title: 'Scenes-App/MCP Analytics/Tool Quality Charts',+ // The tab lays the three charts side by side from `lg` up, so at the default 1280 snapshot+ // viewport each one is barely 400px wide and the dashed tail is hard to read. Snapshot wide.+ parameters: { layout: 'padded', testOptions: { viewport: { width: 1920, height: 720 } } },+}+export default meta++type Story = StoryObj++function withTheme(render: (theme: ChartTheme) => JSX.Element): () => JSX.Element {+ return function Render() {+ return <div data-quill>{render(buildTheme())}</div>+ }+}++export const SettledWindow: Story = {+ render: withTheme((theme) => (+ <ToolQualityCharts+ data={DAILY}+ loading={false}+ theme={theme}+ timezone="UTC"+ interval="day"+ incompleteTail={false}+ />+ )),+}++export const InProgressBucket: Story = {+ render: withTheme((theme) => (+ <ToolQualityCharts+ data={DAILY_PARTIAL_TAIL}+ loading={false}+ theme={theme}+ timezone="UTC"+ interval="day"+ incompleteTail+ />+ )),+}diff --git a/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.tsx b/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.tsxindex ddba0812fc5e..06737412eea3 100644--- a/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.tsx+++ b/products/mcp_analytics/frontend/tool-quality/ToolQualityCharts.tsx@@ -73,33 +73,53 @@ export function ToolQualityCharts({theme,timezone,interval,+ incompleteTail,}: {data: DailyChartDataloading: booleantheme: ChartThemetimezone: stringinterval: TimeInterval+ // When true, the final bucket is the current in-progress interval — dash that segment so a+ // partial period doesn't read as a fall in calls or an improvement in latency. Required rather+ // than optional: an omitted prop silently renders the partial bucket as settled data.+ incompleteTail: boolean}): JSX.Element {const isEmpty = data.labels.length === 0+ // `incompleteTail` is only true when the window has ≥2 buckets (lastBucketIsInProgress owns that+ // rule), and every series is filled to the bucket count, so the final segment exists.+ const partialStroke = useMemo(+ () => (incompleteTail ? { partial: { fromIndex: data.labels.length - 1 } } : undefined),+ [incompleteTail, data.labels.length]+ )+const callsSeries = useMemo<Series[]>(() => [- { key: 'calls', label: 'Calls', color: theme.colors[0], data: data.calls },- { key: 'errors', label: 'Errors', color: theme.colors[4], data: data.errors },+ { key: 'calls', label: 'Calls', color: theme.colors[0], data: data.calls, stroke: partialStroke },+ { key: 'errors', label: 'Errors', color: theme.colors[4], data: data.errors, stroke: partialStroke },],- [data, theme]+ [data, theme, partialStroke])const successSeries = useMemo<Series[]>(- () => [{ key: 'successRate', label: 'Success rate', color: theme.colors[2], data: data.successRate }],- [data, theme]+ () => [+ {+ key: 'successRate',+ label: 'Success rate',+ color: theme.colors[2],+ data: data.successRate,+ stroke: partialStroke,+ },+ ],+ [data, theme, partialStroke])const latencySeries = useMemo<Series[]>(() => [- { key: 'p50', label: 'p50', color: theme.colors[1], data: data.p50 },- { key: 'p95', label: 'p95', color: theme.colors[0], data: data.p95 },- { key: 'p99', label: 'p99', color: theme.colors[4], data: data.p99 },+ { key: 'p50', label: 'p50', color: theme.colors[1], data: data.p50, stroke: partialStroke },+ { key: 'p95', label: 'p95', color: theme.colors[0], data: data.p95, stroke: partialStroke },+ { key: 'p99', label: 'p99', color: theme.colors[4], data: data.p99, stroke: partialStroke },],- [data, theme]+ [data, theme, partialStroke])const countsConfig = useChartConfig(() => buildConfig(timezone, interval), [timezone, interval])