: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): open the clicked notable session in sessions view (#68701)
Georgis Andonisf4e88811bd63
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e84b80507fe2..84df267c0fd4 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6205,9 +6205,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.d97cedf2d117fe2e285f939cc13ce5fdf683ed7de4e18a3c4eb9f28fff983a34.CfkZnIjZc2LqUixiNp67M-oYSgm9RZo5S_j710llXos+ hash: v1.k794b7964.dc02dfd2e4364ca89f870b23872f749248a128f7f6b55d5ad862dfa63840d419.Q8O9ETB70piBnPcnMZe4xey80IEDXeeG8sqyFYg4Dlgscenes-app-mcp-analytics-dashboard-cards--flagged-sessions--light:- hash: v1.k794b7964.3564655474c6001d48e81c691e1339dc5413f96073ca97ab730d45c1f098a9d9.nHOM1CoYHMaZRiMpFANM8CPeuiPQp4Lysxq6m1uCs-w+ hash: v1.k794b7964.594333649b8b6be4e2af262bb606f164e5ed9b72271f7226668af76653013150.BYJ6q_JJ2ZGGSCxOs4SoGDb1E9BNWRk9Yo5lrIFdzW8scenes-app-mcp-analytics-dashboard-cards--key-metrics--dark:hash: v1.k794b7964.539a2481d273c0043468cca5c575d2b1b597b6a7ebdb985da1692f8a02c9bb43.bFQjFUi7S6EomB8-kxn_lUjRaN4pfI6uzsu4_HnReYgscenes-app-mcp-analytics-dashboard-cards--key-metrics--light:diff --git a/products/mcp_analytics/frontend/MCPAnalyticsScene.tsx b/products/mcp_analytics/frontend/MCPAnalyticsScene.tsxindex 7c13ffc03b4b..60b14dc829a5 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsScene.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsScene.tsx@@ -42,12 +42,15 @@ function MCPAnalyticsSceneContent(): JSX.Element {const { activeTab } = useValues(mcpAnalyticsSceneLogic)const { onboardingState, signals } = useValues(mcpAnalyticsOnboardingLogic)+ // search is Sessions-only — drop it when leaving the tab; the date range stays shared.+ const { search: _search, ...sharedParams } = searchParams+const tabs: LemonTab<MCPAnalyticsTab>[] = [{key: 'dashboard',label: 'Dashboard',content: <MCPAnalyticsDashboard />,- link: combineUrl(urls.mcpAnalyticsDashboard(), searchParams).url,+ link: combineUrl(urls.mcpAnalyticsDashboard(), sharedParams).url,'data-attr': 'mcp-analytics-dashboard-tab',},{@@ -61,14 +64,14 @@ function MCPAnalyticsSceneContent(): JSX.Element {key: 'tool-quality',label: 'Tool quality',content: <MCPAnalyticsToolQuality />,- link: combineUrl(urls.mcpAnalyticsToolQuality(), searchParams).url,+ link: combineUrl(urls.mcpAnalyticsToolQuality(), sharedParams).url,'data-attr': 'mcp-analytics-tool-quality-tab',},{key: 'intent-clustering',label: 'Intent clustering',content: <MCPAnalyticsClustering />,- link: combineUrl(urls.mcpAnalyticsIntentClustering(), searchParams).url,+ link: combineUrl(urls.mcpAnalyticsIntentClustering(), sharedParams).url,'data-attr': 'mcp-analytics-intent-clustering-tab',},]diff --git a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsxindex 35ced240dccc..859ba4cd11de 100644--- a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx+++ b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx@@ -1,3 +1,6 @@+import { useValues } from 'kea'+import { combineUrl, router } from 'kea-router'+import { Link } from '@posthog/lemon-ui'import {Badge,@@ -21,6 +24,14 @@ import { urls } from 'scenes/urls'import { type NotableSession } from '../mcpDashboardOverviewLogic'import { formatDuration, truncateSessionId } from './formatters'+// Link to the Sessions tab, keeping the dashboard's date range so a linked session resolves in the+// same window. A sessionId becomes the search term (filtering the list to it and selecting it);+// without one, opens the full list.+function sessionsUrl(searchParams: Record<string, any>, sessionId?: string): string {+ const { search: _search, ...rest } = searchParams+ return combineUrl(urls.mcpAnalyticsSessions(), sessionId ? { ...rest, search: sessionId } : rest).url+}+const DESTRUCTIVE_ERROR_PCT = 5const WARNING_ERROR_PCT = 1@@ -43,7 +54,15 @@ function StatusPill({ errorRatePct }: { errorRatePct: number }): JSX.Element {)}-function SessionRows({ sessions, loading }: { sessions: NotableSession[]; loading: boolean }): JSX.Element {+function SessionRows({+ sessions,+ loading,+ searchParams,+}: {+ sessions: NotableSession[]+ loading: boolean+ searchParams: Record<string, any>+}): JSX.Element {if (loading && sessions.length === 0) {return (<TableBody>@@ -67,7 +86,11 @@ function SessionRows({ sessions, loading }: { sessions: NotableSession[]; loadin{sessions.map((entry) => (<TableRow key={entry.session.session_id}><TableCell className="whitespace-nowrap">- <Link to={urls.mcpAnalyticsSessions()} className="font-mono" title={entry.session.session_id}>+ <Link+ to={sessionsUrl(searchParams, entry.session.session_id)}+ className="font-mono"+ title={entry.session.session_id}+ >{truncateSessionId(entry.session.session_id)}</Link></TableCell>@@ -92,6 +115,7 @@ export function NotableSessionsTable({sessions: NotableSession[]loading: boolean}): JSX.Element {+ const { searchParams } = useValues(router)return (<Card size="sm" className="gap-0"><CardHeader className="border-b border-border pb-3">@@ -107,12 +131,12 @@ export function NotableSessionsTable({<TableHead expand>Why notable</TableHead></TableRow></TableHeader>- <SessionRows sessions={sessions} loading={loading} />+ <SessionRows sessions={sessions} loading={loading} searchParams={searchParams} /></Table>{sessions.length > 0 && (<CardFooter className="justify-end">- <Link to={urls.mcpAnalyticsSessions()} className="text-[10px]">- Open all flagged sessions in Sessions tab ↗+ <Link to={sessionsUrl(searchParams)} className="text-[10px]">+ Open in Sessions tab ↗</Link></CardFooter>)}diff --git a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.tsindex 0fa22e6a803f..ddaf9b5eba1a 100644--- a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts+++ b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts@@ -367,26 +367,30 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([}},})),- // date_from / date_to are shared with the dashboard via the URL: the scene's tab links- // carry searchParams across tabs, so a range picked on either tab follows to the other.+ // Mirror the filters to the URL so they survive a refresh and follow across tabs (date_from /+ // date_to are shared with the dashboard; search is Sessions-only and also lets the dashboard+ // deep-link a session by pre-filling its id).actionToUrl(({ values }) => {const syncUrl = (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => {const { currentLocation } = router.valuesconst searchParams = { ...currentLocation.searchParams }- if (values.dateFilter.dateFrom) {- searchParams.date_from = values.dateFilter.dateFrom- } else {- delete searchParams.date_from+ const params: Record<string, string | null> = {+ date_from: values.dateFilter.dateFrom,+ date_to: values.dateFilter.dateTo,+ search: values.filters.search || null,}- if (values.dateFilter.dateTo) {- searchParams.date_to = values.dateFilter.dateTo- } else {- delete searchParams.date_to+ for (const [key, value] of Object.entries(params)) {+ if (value) {+ searchParams[key] = value+ } else {+ delete searchParams[key]+ }}return [currentLocation.pathname, searchParams, currentLocation.hashParams, { replace: true }]}return {setDateFilter: syncUrl,+ setFilters: syncUrl,}}),urlToAction(({ actions, values, cache }) => ({@@ -395,22 +399,33 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([typeof searchParams.date_from === 'string' ? searchParams.date_from : DEFAULT_DATE_FILTER.dateFromconst dateTo = typeof searchParams.date_to === 'string' ? searchParams.date_to : nullconst dateChanged = dateFrom !== values.dateFilter.dateFrom || dateTo !== values.dateFilter.dateTo- // setDateFilter reloads via its listener; only load directly when nothing changed.++ const search = typeof searchParams.search === 'string' ? searchParams.search : ''+ const searchChanged = search !== values.filters.search++ // setFilters / setDateFilter each reload via their listener; only load directly when+ // neither changed and we haven't loaded yet.+ if (searchChanged) {+ actions.setFilters({ search })+ }if (dateChanged) {actions.setDateFilter(dateFrom, dateTo)- } else if (!cache.hasLoaded) {+ } else if (!searchChanged && !cache.hasLoaded) {actions.loadSessions()}cache.hasLoaded = true},})),afterMount(({ actions, cache }) => {- // urlToAction owns the initial load when the sessions URL carries date params; this is the- // fallback for a param-less mount (and off-route mounts in tests, where urlToAction never- // fires). The cache.hasLoaded guard keeps a deep-linked load from firing twice.+ // urlToAction owns the initial load when the sessions URL carries date or search params; this+ // is the fallback for a param-less mount (and off-route mounts in tests, where urlToAction+ // never fires). The cache.hasLoaded guard keeps a deep-linked load from firing twice.const { searchParams } = router.values- const hasUrlDates = typeof searchParams.date_from === 'string' || typeof searchParams.date_to === 'string'- if (!hasUrlDates && !cache.hasLoaded) {+ const hasUrlParams =+ typeof searchParams.date_from === 'string' ||+ typeof searchParams.date_to === 'string' ||+ typeof searchParams.search === 'string'+ if (!hasUrlParams && !cache.hasLoaded) {cache.hasLoaded = trueactions.loadSessions()}