: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): flag only sessions that clear a notable rule (#73979)
Georgis Andonis805c4300f070
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b4aeafb510b7..835995e19140 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6439,9 +6439,9 @@ snapshots:scenes-app-mcp-analytics--dashboard--light:hash: v1.k794b7964.49f850b518aa783296b3d178c4335a14048651a65980d230e22f2d140176b149.GdW1N70CXyKtRCe88ML3fwlrrHTXrIJ58dXsp7VIN6gscenes-app-mcp-analytics--dashboard-with-menu-bar--dark:- hash: v1.k794b7964.ec3c0249491cc08c6b3e36e6a6f8a237e16a0742a26bec7bf5ec94cc658071e7.ttVOYlABA3PeTBJKCxXvYWlrLij8JlGo50fy0kJSC1A+ hash: v1.k794b7964.f63d8772f7410e4065ac9a8ee9306c79d1fb3134209487ef591303a9d1ea0440.VdOMnTgvJfutwOLw66yEukrkA4AJhyjqzWGVgI-USj8scenes-app-mcp-analytics--dashboard-with-menu-bar--light:- hash: v1.k794b7964.64aa035890ac3ad11d7c4d7a7edcd9fd677462780b05db60c1777ced89c90371.M9V8SQPjfYBEjJfl54ow7GhayKAiOaPoGE-j1ZU3ouI+ hash: v1.k794b7964.0f359fcdf0a972c5b0d3cbcbd78a85fa8c9c6566a88f9c837ab50e43b943de56.GkvbpbIp2w0itq_jj4opjc9-TYiLI-CR5HiCZKA46nYscenes-app-mcp-analytics--intent-clustering--dark:hash: v1.k794b7964.93cb428637db03234a4d0d09b51ef886d95ab801bb3e4dc6ca0f1ba3824b9fe3.JeUzojRsSPumu87KUEx7WXtojxL5GEF98Ps9CVS7WAYscenes-app-mcp-analytics--intent-clustering--light:@@ -6467,9 +6467,9 @@ snapshots:scenes-app-mcp-analytics-dashboard-cards--error-rate-by-tool--light:hash: v1.k794b7964.fb19ba2710284a3445ca8b3fd35276da7ed57ca13d22470ae362e1a7789bc032.BN2AkhljnBC-tp086Cjl4KxQATZ2wivmeSPAthlLtoQscenes-app-mcp-analytics-dashboard-cards--flagged-sessions--dark:- hash: v1.k794b7964.dc02dfd2e4364ca89f870b23872f749248a128f7f6b55d5ad862dfa63840d419.Q8O9ETB70piBnPcnMZe4xey80IEDXeeG8sqyFYg4Dlg+ hash: v1.k794b7964.d3f4ab762ad6e50234a032dc3912ddad0792b64bffa8c236bedb03c5e6e91416.OJfegOAGDyyHGvjiPacJqKP7m3_q-azP9GVbQfVta34scenes-app-mcp-analytics-dashboard-cards--flagged-sessions--light:- hash: v1.k794b7964.594333649b8b6be4e2af262bb606f164e5ed9b72271f7226668af76653013150.BYJ6q_JJ2ZGGSCxOs4SoGDb1E9BNWRk9Yo5lrIFdzW8+ hash: v1.k794b7964.2df0892a30e3bd13942ef30abc61e1ef094cde73028eccb5f94f2964c563e0f9.ybT8Hty9V0j8OB1T431TxBH-AwznCNplBoiIOl_BI6Yscenes-app-mcp-analytics-dashboard-cards--key-metrics--dark:hash: v1.k794b7964.c43bf4fc139c60f91e2bbe9f160077ebe7678b23bfbb86cc23ffb7e610cf510a.cYi4muc-vdYm66DM_ooUC9daJDJ7FJlH9dgETasyR68scenes-app-mcp-analytics-dashboard-cards--key-metrics--light:diff --git a/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx b/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsxindex 7c8a6116828c..24479e02211f 100644--- a/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx+++ b/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx@@ -71,7 +71,7 @@ const NOTABLE_SESSIONS: NotableSession[] = [},{rule: 'all_fail',- label: 'Every call failed — likely auth scope',+ label: 'Every call failed, likely an auth scope issue',session: {session_id: '0193f2a1aaaabbbbcccc000000000002',tool_calls: 6,@@ -84,7 +84,7 @@ const NOTABLE_SESSIONS: NotableSession[] = [},{rule: 'exemplar',- label: 'Exemplar — concise success',+ label: 'Concise success',session: {session_id: '0193f2a1aaaabbbbcccc000000000003',tool_calls: 31,diff --git a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsxindex 859ba4cd11de..000b70e0afe7 100644--- a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx+++ b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx@@ -79,7 +79,7 @@ function SessionRows({)}if (sessions.length === 0) {- return <TableEmpty className="py-6 text-secondary">No notable sessions in the last 30 days.</TableEmpty>+ return <TableEmpty className="py-6 text-secondary">No sessions were flagged in this period.</TableEmpty>}return (<TableBody>@@ -133,13 +133,11 @@ export function NotableSessionsTable({</TableHeader><SessionRows sessions={sessions} loading={loading} searchParams={searchParams} /></Table>- {sessions.length > 0 && (- <CardFooter className="justify-end">- <Link to={sessionsUrl(searchParams)} className="text-[10px]">- Open in Sessions tab ↗- </Link>- </CardFooter>- )}+ <CardFooter className="justify-end">+ <Link to={sessionsUrl(searchParams)} className="text-[10px]">+ Open in Sessions tab ↗+ </Link>+ </CardFooter></Card>)}diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex cd6f321f2eca..8618bfa9ed9d 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -326,7 +326,7 @@ describe('mcpDashboardOverviewLogic', () => {expect(pickNotableSessions([])).toEqual([])})- it('picks one session per rule, then tops up with the busiest, capped and deduped', () => {+ it('picks one session per rule', () => {const rows: SessionRow[] = [session({session_id: 'A',@@ -369,17 +369,47 @@ describe('mcpDashboardOverviewLogic', () => {distinct_tools: 2,}),]- const picked = pickNotableSessions(rows)- expect(picked.map((p) => ({ id: p.session.session_id, rule: p.rule }))).toEqual([+ // A is the busiest, but it is already listed under worst_error_rate, so no high_activity row.+ expect(pickNotableSessions(rows).map((p) => ({ id: p.session.session_id, rule: p.rule }))).toEqual([{ id: 'A', rule: 'worst_error_rate' },{ id: 'B', rule: 'all_fail' },{ id: 'C', rule: 'most_exploratory' },{ id: 'D', rule: 'exemplar' },- { id: 'E', rule: 'high_activity' },])- // never more than the cap, never the same session twice- expect(picked).toHaveLength(5)- expect(new Set(picked.map((p) => p.session.session_id)).size).toBe(5)+ })++ it('lists a session that satisfies two rules once, under the first that matched', () => {+ const rows: SessionRow[] = [+ session({ session_id: 'both', tool_calls: 50, distinct_tools: 8, duration_seconds: 100 }),+ session({ session_id: 'filler-a', tool_calls: 2, distinct_tools: 1 }),+ session({ session_id: 'filler-b', tool_calls: 2, distinct_tools: 1 }),+ ]+ // 'both' is the most exploratory session and the volume outlier. Two rows would mean a+ // duplicate session_id, which is the table's React key.+ expect(pickNotableSessions(rows).map((p) => ({ id: p.session.session_id, rule: p.rule }))).toEqual([+ { id: 'both', rule: 'most_exploratory' },+ ])+ })++ it('returns nothing when every session is small, rather than reaching for a filler row', () => {+ const rows: SessionRow[] = [+ session({ session_id: 'errored', tool_calls: 2, errors: 1, error_rate_pct: 50, distinct_tools: 2 }),+ session({ session_id: 'clean', tool_calls: 2, distinct_tools: 2 }),+ ]+ expect(pickNotableSessions(rows)).toEqual([])+ })++ it('flags a genuine volume outlier and leaves unremarkable sessions out entirely', () => {+ const rows: SessionRow[] = [+ session({ session_id: 'firehose', tool_calls: 40, distinct_tools: 2, duration_seconds: 100 }),+ session({ session_id: 'explorer', tool_calls: 4, distinct_tools: 6, duration_seconds: 10 }),+ session({ session_id: 'single-a', tool_calls: 1, distinct_tools: 1 }),+ session({ session_id: 'single-b', tool_calls: 1, distinct_tools: 1 }),+ ]+ expect(pickNotableSessions(rows).map((p) => ({ id: p.session.session_id, rule: p.rule }))).toEqual([+ { id: 'explorer', rule: 'most_exploratory' },+ { id: 'firehose', rule: 'high_activity' },+ ])})})diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex 2786e24c52f7..625d4e5de072 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -216,8 +216,13 @@ export interface SessionRow {export type NotableRule = 'worst_error_rate' | 'all_fail' | 'most_exploratory' | 'exemplar' | 'high_activity'-// Fill the table out to this many rows: the rule-based picks first, then the busiest remaining sessions.-const NOTABLE_SESSION_TARGET = 8+// Calls the busiest session needs before it is worth flagging. Absolute rather than relative to the+// median, because the query returns the 500 busiest sessions, so the median of what we get is not the+// account's median.+const MIN_OUTLIER_CALLS = 5++// Below this, a session is an ordinary task rather than an exploration.+const MIN_JOURNEY_TOOLS = 4export interface NotableSession {rule: NotableRule@@ -1003,8 +1008,8 @@ function median(values: number[]): number {return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2}-// Pick at most one session per rule. Thresholds relax automatically when the-// data is small so something demo-worthy always shows.+// Pick at most one session per rule, so every row has a reason to be there. Deliberately returns+// short, or empty, when nothing qualifies.export function pickNotableSessions(rows: SessionRow[]): NotableSession[] {if (rows.length === 0) {return []@@ -1012,6 +1017,7 @@ export function pickNotableSessions(rows: SessionRow[]): NotableSession[] {const medianCalls = median(rows.map((r) => r.tool_calls))const medianDuration = median(rows.map((r) => r.duration_seconds))+ const busyThreshold = Math.max(medianCalls, 3)const used = new Set<string>()const picked: NotableSession[] = []@@ -1024,7 +1030,7 @@ export function pickNotableSessions(rows: SessionRow[]): NotableSession[] {}// 1. Worst error rate at high volume — top err% among above-median-volume sessions- const highVolume = rows.filter((r) => r.tool_calls >= Math.max(medianCalls, 3) && r.error_rate_pct > 0)+ const highVolume = rows.filter((r) => r.tool_calls >= busyThreshold && r.error_rate_pct > 0)take('worst_error_rate','Worst error rate at high volume',@@ -1035,32 +1041,29 @@ export function pickNotableSessions(rows: SessionRow[]): NotableSession[] {const allFail = rows.filter((r) => r.error_rate_pct >= 100 && r.tool_calls >= 3)take('all_fail',- 'Every call failed — likely auth scope',+ 'Every call failed, likely an auth scope issue',[...allFail].sort((a, b) => b.tool_calls - a.tool_calls)[0])- // 3. Most exploratory — highest distinct_tools count (multi-step journey)+ // 3. Most exploratory — highest distinct_tools count, among sessions that are journeys at all+ const journeys = rows.filter((r) => r.distinct_tools >= MIN_JOURNEY_TOOLS)take('most_exploratory','Most exploratory journey',- [...rows].sort((a, b) => b.distinct_tools - a.distinct_tools || b.tool_calls - a.tool_calls)[0]+ [...journeys].sort((a, b) => b.distinct_tools - a.distinct_tools || b.tool_calls - a.tool_calls)[0])// 4. Exemplar — zero errors, above-median calls, faster than median durationconst exemplars = rows.filter(- (r) =>- r.error_rate_pct === 0 && r.tool_calls >= Math.max(medianCalls, 3) && r.duration_seconds <= medianDuration+ (r) => r.error_rate_pct === 0 && r.tool_calls >= busyThreshold && r.duration_seconds <= medianDuration)- take('exemplar', 'Exemplar — concise success', [...exemplars].sort((a, b) => b.tool_calls - a.tool_calls)[0])+ take('exemplar', 'Concise success', [...exemplars].sort((a, b) => b.tool_calls - a.tool_calls)[0])- // Top up to the target with the busiest sessions not already chosen, so the table reads as a- // fuller list rather than a sparse handful.- const byVolume = [...rows].sort((a, b) => b.tool_calls - a.tool_calls)- for (const candidate of byVolume) {- if (picked.length >= NOTABLE_SESSION_TARGET) {- break- }- take('high_activity', 'High activity', candidate)+ // 5. High activity — the busiest session, once it is busy enough to be worth reading. Being the+ // largest of a small set is not notable: on a quiet account that can be a single tool call.+ const busiest = [...rows].sort((a, b) => b.tool_calls - a.tool_calls)[0]+ if (busiest && busiest.tool_calls >= MIN_OUTLIER_CALLS) {+ take('high_activity', 'High activity', busiest)}return picked