: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 day on the activity chart (#66605)
Paul D'Ambra5d50cb7e7118
diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsxindex 66b409a51b7e..82e43348551f 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx@@ -30,6 +30,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {harnessRows,harnessRowsLoading,dailyActivity,+ activityIncompleteTail,activityRowsLoading,toolDailySeries,toolDailyRowsLoading,@@ -93,6 +94,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {theme={theme}timezone={timezone}interval={interval}+ incompleteTail={activityIncompleteTail}/></div><HarnessDonut rows={harnessRows} loading={harnessRowsLoading} theme={theme} />diff --git a/products/mcp_analytics/frontend/dashboard/ActivityChart.tsx b/products/mcp_analytics/frontend/dashboard/ActivityChart.tsxindex b0751c93bb9f..8292e10dcdae 100644--- a/products/mcp_analytics/frontend/dashboard/ActivityChart.tsx+++ b/products/mcp_analytics/frontend/dashboard/ActivityChart.tsx@@ -18,20 +18,28 @@ export function ActivityChart({theme,timezone,interval,+ incompleteTail,}: {daily: DailyActivityloading: booleantheme: ChartThemetimezone: stringinterval: TimeInterval+ // When true, the final bucket is the current in-progress interval — dash that segment so the+ // partial period reads as "not finished yet" rather than a drop in tool calls.+ incompleteTail?: boolean}): JSX.Element {const series = useMemo<Series[]>(() => {const totals = daily.successes.map((s, i) => s + (daily.errors[i] ?? 0))+ // `incompleteTail` is only true when the window has ≥2 buckets (lastBucketIsInProgress owns+ // that rule), and `daily` is zero-filled to the bucket count — so the final segment exists.+ // The renderer also clamps fromIndex, so a stray single-point series can't go out of range.+ const partialStroke = incompleteTail ? { partial: { fromIndex: totals.length - 1 } } : undefinedreturn [- { key: 'calls', label: 'Tool calls', color: theme.colors[0], data: totals },- { key: 'errors', label: 'Errors', color: theme.colors[4], data: daily.errors },+ { key: 'calls', label: 'Tool calls', color: theme.colors[0], data: totals, stroke: partialStroke },+ { key: 'errors', label: 'Errors', color: theme.colors[4], data: daily.errors, stroke: partialStroke },]- }, [daily, theme])+ }, [daily, theme, incompleteTail])// quill's built-in date tick formatter only kicks in when both interval and timezone are set.const config = useMemo<TimeSeriesLineChartConfig>(() => ({diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex a539d53d3663..6894611f6d27 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -20,6 +20,7 @@ import {buildKpiWindow,buildToolDailySeries,deltaPct,+ lastBucketIsInProgress,mcpDashboardOverviewLogic,normalizeBucket,pickNotableSessions,@@ -227,6 +228,43 @@ describe('mcpDashboardOverviewLogic', () => {errors: [0, 0, 0],})})++ // The in-progress-tail dash applies `fromIndex = successes.length - 1` to line up with the+ // last bucket key, so the series must stay exactly bucketKeys-length — including when rows+ // fall outside the window. If this drifts, the dashed segment lands on the wrong point.+ it('keeps series length equal to bucketKeys, ignoring rows outside the window', () => {+ const bucketKeys = ['2024-01-01 00:00:00', '2024-01-02 00:00:00', '2024-01-03 00:00:00']+ const rows: ActivityRow[] = [+ { day: '2024-01-02 00:00:00', successes: 5, errors: 1 },+ { day: '2023-12-31 00:00:00', successes: 9, errors: 9 }, // outside bucketKeys — must be dropped+ ]+ const result = buildDailyActivity(rows, bucketKeys)+ expect(result.labels).toHaveLength(bucketKeys.length)+ expect(result.successes).toHaveLength(bucketKeys.length)+ expect(result.errors).toHaveLength(bucketKeys.length)+ expect(result.successes).toEqual([0, 5, 0])+ })+ })++ describe('lastBucketIsInProgress', () => {+ const tz = 'UTC'+ const keys = ['2026-06-27 00:00:00', '2026-06-28 00:00:00', '2026-06-29 00:00:00']++ it('flags the tail when the last bucket is the interval containing now', () => {+ const now = dayjs.tz('2026-06-29 09:15:00', tz)+ expect(lastBucketIsInProgress(keys, tz, 'day', now)).toBe(true)+ })++ it('leaves the tail solid when the window ends in the past', () => {+ const now = dayjs.tz('2026-07-05 09:15:00', tz)+ expect(lastBucketIsInProgress(keys, tz, 'day', now)).toBe(false)+ })++ it('does not dash when there is no segment to dash', () => {+ const now = dayjs.tz('2026-06-29 09:15:00', tz)+ expect(lastBucketIsInProgress(['2026-06-29 00:00:00'], tz, 'day', now)).toBe(false)+ expect(lastBucketIsInProgress([], tz, 'day', now)).toBe(false)+ })})describe('normalizeBucket', () => {diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex e9245c7c9328..04dfa15d873c 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -281,6 +281,10 @@ function startOfBucket(d: dayjs.Dayjs, interval: IntervalType): dayjs.Dayjs {return d.startOf(interval)}+// The one format for bucket keys — must match ClickHouse dateTrunc's DateTime output so the+// zero-fill join and the in-progress-tail comparison line up. Change it here, nowhere else.+const BUCKET_FORMAT = 'YYYY-MM-DD HH:mm:ss'+// Every bucket key across the resolved window [start, end] at the active interval, formatted to// match dateTrunc's DateTime output ('YYYY-MM-DD HH:mm:ss'). The activity and tool-usage series are// zero-filled against these so the x-axis spans the whole selected range instead of clipping to the@@ -292,15 +296,31 @@ export function buildBucketKeys(dateFilter: DateFilter, timezone: string, intervlet cursor = startOfBucket(start, interval)// Bounded dashboard windows keep this small; the cap is just a guard against a pathological range.for (let i = 0; cursor.valueOf() <= last && i < 100000; i++) {- keys.push(cursor.format('YYYY-MM-DD HH:mm:ss'))+ keys.push(cursor.format(BUCKET_FORMAT))cursor = cursor.add(1, interval)}return keys}+// True when the final bucket is the current, still-running interval (open-ended window), so the+// chart can dash that segment as "in progress" rather than letting the partial period read as data+// loss. Needs ≥2 buckets to have a segment to dash; `now` is injectable so the logic stays testable.+export function lastBucketIsInProgress(+ bucketKeys: string[],+ timezone: string,+ interval: IntervalType,+ now: dayjs.Dayjs = dayjs()+): boolean {+ if (bucketKeys.length < 2) {+ return false+ }+ const currentBucket = startOfBucket(now.tz(timezone), interval).format(BUCKET_FORMAT)+ return bucketKeys[bucketKeys.length - 1] === currentBucket+}+export function normalizeBucket(raw: unknown, timezone: string): string {const s = String(raw ?? '')- return s ? dayjs(s).tz(timezone).format('YYYY-MM-DD HH:mm:ss') : ''+ return s ? dayjs(s).tz(timezone).format(BUCKET_FORMAT) : ''}// Project the daily success/error rows onto the full set of buckets, defaulting empty buckets to 0.@@ -333,7 +353,7 @@ export function buildKpiWindow(dateFilter: DateFilter, timezone: string, intervareturn {dateFrom: priorStart.toISOString(),dateTo: end.toISOString(),- currentStartBucket: start.startOf(interval).format('YYYY-MM-DD HH:mm:ss'),+ currentStartBucket: start.startOf(interval).format(BUCKET_FORMAT),}}@@ -586,6 +606,13 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([(dateFilter: DateFilter, timezone: string, interval: IntervalType): string[] =>buildBucketKeys(dateFilter, timezone, interval),],+ // Whether the activity chart's final bucket is the current, still-running interval — the+ // chart dashes that segment so a partial period doesn't read as a drop in tool calls.+ activityIncompleteTail: [+ (s) => [s.bucketKeys, s.timezone, s.interval],+ (bucketKeys: string[], timezone: string, interval: IntervalType): boolean =>+ lastBucketIsInProgress(bucketKeys, timezone, interval),+ ],dailyActivity: [(s) => [s.activityRows, s.bucketKeys],(rows: ActivityRow[], bucketKeys: string[]): DailyActivity => buildDailyActivity(rows, bucketKeys),