Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(web): graph becomes a view on the tree/timeline switch (#17537)

Trang Nguyen1277bbd17c23
diff --git a/web/src/features/traces/components/PlaybackControls.clienttest.tsx b/web/src/features/traces/components/PlaybackControls.clienttest.tsx
index a7d0644b61..c04dc3e085 100644
--- a/web/src/features/traces/components/PlaybackControls.clienttest.tsx
+++ b/web/src/features/traces/components/PlaybackControls.clienttest.tsx
@@ -49,10 +49,6 @@ vi.mock("@/src/features/traces/contexts/TraceGraphDataContext", () => ({
}),
}));
-vi.mock("@/src/features/traces/contexts/ViewPreferencesContext", () => ({
- useViewPreferences: () => ({ showGraph: true }),
-}));
-
vi.mock("@/src/features/traces/contexts/SearchContext", () => ({
useSearch: () => ({ searchQuery: "" }),
}));
diff --git a/web/src/features/traces/components/PlaybackControls.tsx b/web/src/features/traces/components/PlaybackControls.tsx
index 054b0e41a8..9a0f988b93 100644
--- a/web/src/features/traces/components/PlaybackControls.tsx
+++ b/web/src/features/traces/components/PlaybackControls.tsx
@@ -30,7 +30,6 @@ import {
import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";
import { useTraceGraphData } from "@/src/features/traces/contexts/TraceGraphDataContext";
import { useSearch } from "@/src/features/traces/contexts/SearchContext";
-import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferencesContext";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { useTraceAnalyticsDimensions } from "@/src/features/traces/hooks/useTraceAnalyticsDimensions";
@@ -59,7 +58,6 @@ function useHasPlayback(): boolean {
const { traceDuration } = useTraceData();
const { isGraphViewAvailable, isLoading: isGraphDataLoading } =
useTraceGraphData();
- const { showGraph } = useViewPreferences();
const { searchQuery } = useSearch();
const [viewMode] = useQueryParam("view", StringParam);
const showPlayhead = useShowPlayhead();
@@ -67,7 +65,8 @@ function useHasPlayback(): boolean {
const isSearching = searchQuery.trim().length > 0;
const hasPlaybackSurface =
(viewMode === "timeline" && !isSearching) ||
- (showGraph && (isGraphViewAvailable || isGraphDataLoading));
+ isGraphViewAvailable ||
+ isGraphDataLoading;
return traceDuration > 0 && (hasPlaybackSurface || showPlayhead);
}
@@ -86,10 +85,14 @@ function usePlaybackClickHandlers() {
const isPlaying = useIsPlaying();
const showPlayhead = useShowPlayhead();
- // Tree is stored as a null query param; anything else is still tree.
+ // Tree is stored as a null query param; an unrecognised value reads as tree.
const props = {
viewMode:
- viewMode === "timeline" ? ("timeline" as const) : ("tree" as const),
+ viewMode === "timeline"
+ ? ("timeline" as const)
+ : viewMode === "graph"
+ ? ("graph" as const)
+ : ("tree" as const),
observationCount: observations.length,
...analyticsDimensions,
};
diff --git a/web/src/features/traces/components/Trace.tsx b/web/src/features/traces/components/Trace.tsx
index 615520d463..2caa65bc68 100644
--- a/web/src/features/traces/components/Trace.tsx
+++ b/web/src/features/traces/components/Trace.tsx
@@ -197,17 +197,13 @@ function TraceWithSelection({
*/
function TraceContent({ desktopLayout }: { desktopLayout: DesktopLayout }) {
const isMobile = useIsMobile();
- const { showGraph, isAnnotationMode } = useViewPreferences();
+ const { isAnnotationMode } = useViewPreferences();
const { isGraphViewAvailable } = useTraceGraphData();
- const shouldShowGraph = showGraph && isGraphViewAvailable;
const panels = isMobile ? (
- <MobileTraceContent shouldShowGraph={shouldShowGraph} />
+ <MobileTraceContent shouldShowGraph={isGraphViewAvailable} />
) : (
- <DesktopTraceContent
- shouldShowGraph={shouldShowGraph}
- desktopLayout={desktopLayout}
- />
+ <DesktopTraceContent desktopLayout={desktopLayout} />
);
// Annotation mode shows no trace-level metadata.
@@ -232,18 +228,14 @@ function TraceContent({ desktopLayout }: { desktopLayout: DesktopLayout }) {
* - Navigation panel (left) + Detail panel (right)
*/
function DesktopTraceContent({
- shouldShowGraph,
desktopLayout,
}: {
- shouldShowGraph: boolean;
desktopLayout: DesktopLayout;
}) {
return (
<TraceLayoutDesktop key={desktopLayout.groupId} {...desktopLayout}>
<TraceLayoutDesktop.NavigationPanel>
- <TracePanelNavigationLayoutDesktop
- secondaryContent={shouldShowGraph ? <TraceGraphView /> : undefined}
- >
+ <TracePanelNavigationLayoutDesktop>
<TracePanelNavigation />
</TracePanelNavigationLayoutDesktop>
</TraceLayoutDesktop.NavigationPanel>
diff --git a/web/src/features/traces/components/TracePanelNavigation.tsx b/web/src/features/traces/components/TracePanelNavigation.tsx
index bc28496b12..c724c74d0b 100644
--- a/web/src/features/traces/components/TracePanelNavigation.tsx
+++ b/web/src/features/traces/components/TracePanelNavigation.tsx
@@ -19,17 +19,25 @@
import { StringParam, useQueryParam } from "use-query-params";
import { useSearch } from "@/src/features/traces/contexts/SearchContext";
+import { useTraceGraphData } from "@/src/features/traces/contexts/TraceGraphDataContext";
import { TraceTree } from "./TraceTree";
import { TraceSearchList } from "./TraceSearchList";
import { TraceTimelineCompact } from "./TraceTimelineDense/TraceTimelineCompact";
+import { TraceGraphView } from "./TraceGraphView/TraceGraphView";
import { useMemo } from "react";
export function TracePanelNavigation() {
const { searchQuery } = useSearch();
+ const { isGraphViewAvailable, isLoading: isGraphLoading } =
+ useTraceGraphData();
const [viewMode] = useQueryParam("view", StringParam);
const hasQuery = searchQuery.trim().length > 0;
const isTimelineView = viewMode === "timeline";
+ // Availability is false while the graph query loads, so hold the view until it
+ // resolves. Stale ?view=graph then falls back to tree.
+ const isGraphView =
+ viewMode === "graph" && (isGraphViewAvailable || isGraphLoading);
// Memoize to prevent recreation when deps haven't changed
const content = useMemo(() => {
@@ -41,6 +49,9 @@ export function TracePanelNavigation() {
//
// The Tree still hands a query to the flat list; highlighting it is its own
// change.
+ if (isGraphView) {
+ return <TraceGraphView />;
+ }
if (isTimelineView) {
return <TraceTimelineCompact />;
}
@@ -48,7 +59,7 @@ export function TracePanelNavigation() {
return <TraceSearchList />;
}
return <TraceTree />;
- }, [hasQuery, isTimelineView]);
+ }, [hasQuery, isGraphView, isTimelineView]);
return content;
}
diff --git a/web/src/features/traces/components/TracePanelNavigationHeader/TracePanelNavigationHeader.tsx b/web/src/features/traces/components/TracePanelNavigationHeader/TracePanelNavigationHeader.tsx
index 1fa3a5e5cf..228621b8a8 100644
--- a/web/src/features/traces/components/TracePanelNavigationHeader/TracePanelNavigationHeader.tsx
+++ b/web/src/features/traces/components/TracePanelNavigationHeader/TracePanelNavigationHeader.tsx
@@ -13,6 +13,12 @@ import { useSearch } from "@/src/features/traces/contexts/SearchContext";
import { useSelection } from "@/src/features/traces/contexts/SelectionContext";
import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";
import { useTraceGraphData } from "@/src/features/traces/contexts/TraceGraphDataContext";
+import { type GraphUnavailableReason } from "@/src/features/traces/fns/graphAvailability";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/src/components/ui/tooltip";
import { useReadPath } from "@/src/features/events";
import { Command, CommandInput } from "@/src/components/ui/command";
import { Button } from "@/src/components/ui/button";
@@ -21,10 +27,7 @@ import {
UnfoldVertical,
Download,
Loader2,
- ListTree,
- GanttChartSquare,
MoreHorizontal,
- type LucideIcon,
} from "lucide-react";
import {
DropdownMenu,
@@ -93,7 +96,11 @@ function TracePanelNavigationHeaderExpanded({
useSearch();
const { expandAll, collapseAll, collapsedNodes } = useSelection();
const { roots, trace, observations } = useTraceData();
- const { isGraphViewAvailable } = useTraceGraphData();
+ const {
+ isGraphViewAvailable,
+ graphAvailability,
+ isLoading: isGraphLoading,
+ } = useTraceGraphData();
const { isV4 } = useReadPath();
const [viewMode, setViewMode] = useQueryParam("view", StringParam);
const capture = usePostHogClientCapture();
@@ -176,7 +183,19 @@ function TracePanelNavigationHeaderExpanded({
}
}, [isV4, observations, trace, capture, analyticsDimensions]);
- const isTimelineView = viewMode === "timeline";
+ // Hold the Graph segment while its query loads, else it vanishes and returns
+ // on every trace switch. Stale ?view=graph then falls back to tree.
+ const graphResolved = isGraphViewAvailable || isGraphLoading;
+ const graphDisabledReason =
+ graphAvailability.available || isGraphLoading
+ ? undefined
+ : GRAPH_UNAVAILABLE_COPY[graphAvailability.reason];
+ const activeView: TraceViewMode =
+ viewMode === "timeline"
+ ? "timeline"
+ : viewMode === "graph" && graphResolved
+ ? "graph"
+ : "tree";
return (
<Command className="flex h-auto shrink-0 flex-col gap-1 overflow-hidden rounded-none border-b">
@@ -210,12 +229,15 @@ function TracePanelNavigationHeaderExpanded({
)}
{/* Search Input */}
<div
- className={cn("relative flex-1", isDetailPanelCollapsed && "pl-1")}
+ className={cn(
+ "relative min-w-0 flex-1",
+ isDetailPanelCollapsed && "pl-1",
+ )}
>
<CommandInput
showBorder={false}
placeholder="Search"
- className="h-7 min-w-20 border-0 pr-0 focus:ring-0 @max-[300px]/navheader:min-w-10"
+ className="h-7 min-w-0 border-0 pr-0 focus:ring-0"
value={searchInputValue}
onValueChange={setSearchInputValue}
onKeyDown={handleSearchKeyDown}
@@ -223,7 +245,7 @@ function TracePanelNavigationHeaderExpanded({
</div>
<div className="flex shrink-0 flex-row items-center gap-0.5">
{/* Minor tools β€” inline when the panel is wide enough. */}
- <div className="hidden flex-row items-center gap-0.5 @min-[360px]/navheader:flex">
+ <div className="hidden flex-row items-center gap-0.5 @min-[510px]/navheader:flex">
<Button
onClick={handleToggleTreeNodes}
variant="ghost"
@@ -238,9 +260,7 @@ function TracePanelNavigationHeaderExpanded({
)}
</Button>
- <TraceSettingsDropdown
- isGraphViewAvailable={isGraphViewAvailable}
- />
+ <TraceSettingsDropdown />
<Button
variant="ghost"
@@ -266,7 +286,7 @@ function TracePanelNavigationHeaderExpanded({
size="icon"
title="More"
aria-label="More options"
- className="h-7 w-7 @min-[360px]/navheader:hidden"
+ className="h-7 w-7 @min-[510px]/navheader:hidden"
>
<MoreHorizontal className="h-3.5 w-3.5" />
</Button>
@@ -289,9 +309,7 @@ function TracePanelNavigationHeaderExpanded({
</DropdownMenuItem>
<PlaybackMenuItems />
<DropdownMenuSeparator />
- <TraceViewOptionsMenuItems
- isGraphViewAvailable={isGraphViewAvailable}
- />
+ <TraceViewOptionsMenuItems />
</DropdownMenuContent>
</DropdownMenu>
@@ -300,23 +318,22 @@ function TracePanelNavigationHeaderExpanded({
folded into the overflow menu on a narrow panel, like the tools
above it. Two more 28px buttons are what tipped this row over: the
search input collapsed to "Se" and the switch clipped. */}
- <div className="hidden flex-row items-center @min-[360px]/navheader:flex">
+ <div className="hidden flex-row items-center @min-[510px]/navheader:flex">
<PlaybackControls />
</div>
- {/* Tree / Timeline segmented switch (labels collapse to icons when
- the panel is narrow β€” see @container/navheader). */}
<ViewModeSwitch
- isTimelineView={isTimelineView}
- onSelect={(timeline) => {
+ activeView={activeView}
+ graphDisabledReason={graphDisabledReason}
+ onSelect={(view) => {
// Clicking the already-active segment is a no-op β€” don't count it.
- if (timeline !== isTimelineView) {
+ if (view !== activeView) {
capture("trace_detail:view_mode_switch", {
- viewMode: timeline ? "timeline" : "tree",
+ viewMode: view,
...analyticsDimensions,
});
}
- setViewMode(timeline ? "timeline" : null);
+ setViewMode(view === "tree" ? null : view);
}}
/>
{/* When the detail panel is closed it shows its own collapsed rail
@@ -329,30 +346,46 @@ function TracePanelNavigationHeaderExpanded({
);
}
+const GRAPH_UNAVAILABLE_COPY: Record<GraphUnavailableReason, string> = {
+ "no-data": "No graph data on this trace.",
+ "too-large": "Too many observations to graph.",
+ "no-structure": "Nothing to graph. This trace has only one node.",
+};
+
+type TraceViewMode = "tree" | "timeline" | "graph";
+
function ViewModeSwitch({
- isTimelineView,
+ activeView,
+ graphDisabledReason,
onSelect,
}: {
- isTimelineView: boolean;
- onSelect: (timeline: boolean) => void;
+ activeView: TraceViewMode;
+ /** Present when the trace has no graph: the segment renders disabled. */
+ graphDisabledReason?: string;
+ onSelect: (view: TraceViewMode) => void;
}) {
return (
<div className="bg-muted/60 ml-2 inline-flex h-7 shrink-0 items-center rounded-md border p-0.5">
<ViewModeSegment
- active={!isTimelineView}
- onClick={() => onSelect(false)}
- icon={ListTree}
+ active={activeView === "tree"}
+ onClick={() => onSelect("tree")}
label="Tree"
/>
{/* One Timeline. What it IS depends on the Compact Timeline feature
preview β€” see TracePanelNavigation β€” rather than on a third segment
the user has to understand. */}
<ViewModeSegment
- active={isTimelineView}
- onClick={() => onSelect(true)}
- icon={GanttChartSquare}
+ active={activeView === "timeline"}
+ onClick={() => onSelect("timeline")}
label="Timeline"
/>
+ <ViewModeSegment
+ active={activeView === "graph"}
+ onClick={() => onSelect("graph")}
+ label="Graph"
+ disabled={Boolean(graphDisabledReason)}
+ title={graphDisabledReason}
+ />
</div>
);
}
@@ -360,29 +393,42 @@ function ViewModeSwitch({
function ViewModeSegment({
active,
onClick,
- icon: Icon,
label,
+ disabled = false,
+ title,
}: {
active: boolean;
onClick: () => void;
- icon: LucideIcon;
label: string;
+ disabled?: boolean;
+ /** Why the view is unavailable; shown in a tooltip. */
+ title?: string;
}) {
- return (
+ const segment = (
<button
type="button"
- onClick={onClick}
+ onClick={disabled ? undefined : onClick}
+ aria-disabled={disabled || undefined}
aria-pressed={active}
- title={label}
+ title={disabled ? undefined : label}
className={cn(
"flex h-6 items-center gap-1.5 rounded-md px-2 text-xs font-bold transition-colors",
+ disabled && "cursor-not-allowed opacity-40",
active
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
- <Icon className="h-3.5 w-3.5 shrink-0" />
- <span className="@max-[440px]/navheader:hidden">{label}</span>
+ {label}
</button>
);
+
+ // A native title does not reliably surface on a segment this small.
+ if (!disabled || !title) return segment;
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>{segment}</TooltipTrigger>
+ <TooltipContent>{title}</TooltipContent>
+ </Tooltip>
+ );
}
diff --git a/web/src/features/traces/components/TracePanelNavigationLayoutDesktop/TracePanelNavigationLayoutDesktop.tsx b/web/src/features/traces/components/TracePanelNavigationLayoutDesktop/TracePanelNavigationLayoutDesktop.tsx
index f99b8353e9..7a113f1a95 100644
--- a/web/src/features/traces/components/TracePanelNavigationLayoutDesktop/TracePanelNavigationLayoutDesktop.tsx
+++ b/web/src/features/traces/components/TracePanelNavigationLayoutDesktop/TracePanelNavigationLayoutDesktop.tsx
@@ -5,160 +5,24 @@
* - Wrap navigation content with header and collapsible layout structure
* - Handle panel collapse/expand state for desktop
* - Position the truncation + hidden-observation notices above content
- * - Render graph view panel below tree/timeline when enabled
- * - Own the graph panel's collapse state: drag the divider down (or click the
- * "Graph" bar) to collapse it to a slim bar; persisted per-project. Traces
- * that only qualify for a graph via the >1-node rule start collapsed;
- * real agent graphs start expanded.
*
* Hooks:
* - useDesktopLayoutContext() - for panel collapse state
- * - useTraceData() - for the per-project persistence key
- * - useTraceGraphData() - for the collapsed-by-default heuristic
*/
-import { useLayoutEffect, useRef, type ReactNode } from "react";
-import { ChevronDown, ChevronUp } from "lucide-react";
-import { useGroupRef } from "react-resizable-panels";
-import {
- ResizablePanel,
- ResizablePanelGroup,
- ResizableHandle,
- usePanelRef,
- useDefaultLayout,
-} from "@/src/components/ui/resizable";
-import useLocalStorage from "@/src/components/useLocalStorage";
+import { type ReactNode } from "react";
import { useDesktopLayoutContext } from "../TraceLayoutDesktop";
-import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";
-import { useTraceGraphData } from "@/src/features/traces/contexts/TraceGraphDataContext";
-import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferencesContext";
import { TracePanelNavigationHeader } from "../TracePanelNavigationHeader/TracePanelNavigationHeader";
import { TracePanelNavigationHiddenNotice } from "./components/TracePanelNavigationHiddenNotice";
import { TraceTruncationNotice } from "@/src/features/traces/components/TraceTruncationNotice";
-// Height of the "Graph" bar β€” the panel's collapsed form. Must match the bar's
-// h-7 so a collapsed panel shows exactly the bar and nothing else.
-const GRAPH_BAR_PX = 28;
-
-// The tree/graph split persists in localStorage like the outer nav/detail
-// split (LFE-10601/LFE-10729 model): peek and full-page each keep their own
-// group so a ratio dragged in the short peek panel doesn't leak into the tall
-// full-page view and vice versa. The graph panel's collapse state persists
-// separately (per-project, below) β€” the saved layout is always the OPEN ratio.
-const GRAPH_SPLIT_GROUP_ID = "trace-nav-graph-split-v1";
-const PEEK_GRAPH_SPLIT_GROUP_ID = "trace-nav-graph-split-peek-v1";
-const GRAPH_SPLIT_TREE_PANEL_ID = "trace-nav-graph-split-tree";
-const GRAPH_SPLIT_GRAPH_PANEL_ID = "trace-nav-graph-split-graph";
-
-// No-op storage so `useDefaultLayout` never touches a real Storage during
-// SSR / DOM-less tests (mirrors TraceLayoutDesktop).
-const NOOP_LAYOUT_STORAGE = {
- getItem: () => null,
- setItem: () => {},
-};
-
-/**
- * Slim header strip of the graph panel β€” its collapsed form, and the
- * click-to-toggle affordance while expanded (mirrors the mobile layout's bar).
- */
-function GraphPanelBar({
- collapsed,
- onToggle,
-}: {
- collapsed: boolean;
- onToggle: () => void;
-}) {
- return (
- <button
- type="button"
- onClick={onToggle}
- title={collapsed ? "Expand graph panel" : "Collapse graph panel"}
- aria-expanded={!collapsed}
- className="text-muted-foreground hover:bg-muted/50 hover:text-foreground flex h-7 w-full shrink-0 items-center justify-between border-b px-2"
- >
- <span className="text-xs font-bold">Graph</span>
- {collapsed ? (
- <ChevronUp className="h-3.5 w-3.5" />
- ) : (
- <ChevronDown className="h-3.5 w-3.5" />
- )}
- </button>
- );
-}
-
export function TracePanelNavigationLayoutDesktop({
children,
- secondaryContent,
}: {
children: ReactNode;
- secondaryContent?: ReactNode;
}) {
const { isNavigationPanelCollapsed, handleTogglePanel, shouldPulseToggle } =
useDesktopLayoutContext();
- const { trace } = useTraceData();
- const { isAgentGraph } = useTraceGraphData();
- const { isPeekMode } = useViewPreferences();
-
- // Per-project persisted collapse. Tri-state: null = no user choice yet, so
- // the default stays reactive (agent graphs expand, >1-node-only graphs stay
- // collapsed) instead of freezing whatever loaded first into storage.
- const [storedGraphCollapsed, setStoredGraphCollapsed] = useLocalStorage<
- boolean | null
- >(`trace-graph-panel-collapsed-${trace.projectId}`, null);
- const graphCollapsed = storedGraphCollapsed ?? !isAgentGraph;
-
- const graphPanelRef = usePanelRef();
- const graphGroupRef = useGroupRef();
-
- // Persisted tree/graph ratio (see the group-id comment above).
- const { defaultLayout, onLayoutChanged } = useDefaultLayout({
- id: isPeekMode ? PEEK_GRAPH_SPLIT_GROUP_ID : GRAPH_SPLIT_GROUP_ID,
- panelIds: [GRAPH_SPLIT_TREE_PANEL_ID, GRAPH_SPLIT_GRAPH_PANEL_ID],
- storage:
- typeof window === "undefined" ? NOOP_LAYOUT_STORAGE : window.localStorage,
- });
-
- // Save only the OPEN ratio: while the graph panel sits on its 28px rail the
- // layout is the collapse state (persisted separately) β€” letting it through
- // would overwrite the user's preferred split with the rail share. The ref
- // tracks the freshest saved share for the expand-restore below (the hook's
- // `defaultLayout` is the mount-time snapshot).
- const lastOpenGraphSharePct = useRef<number | null>(
- defaultLayout?.[GRAPH_SPLIT_GRAPH_PANEL_ID] ?? null,
- );
- const handleLayoutChanged = (layout: Record<string, number>) => {
- if (graphPanelRef.current?.isCollapsed()) return;
- lastOpenGraphSharePct.current =
- layout[GRAPH_SPLIT_GRAPH_PANEL_ID] ?? lastOpenGraphSharePct.current;
- onLayoutChanged(layout);
- };
-
- // State β†’ panel: keep the imperative panel in sync (mount, storage default,
- // bar toggle). Pre-paint so an initially-collapsed panel never flashes open.
- useLayoutEffect(() => {
- const panel = graphPanelRef.current;
- if (!panel) return;
- if (graphCollapsed && !panel.isCollapsed()) {
- panel.collapse();
- } else if (!graphCollapsed && panel.isCollapsed()) {
- // A panel that mounted collapsed has no in-session pre-collapse size β€”
- // a bare expand() falls back to its minSize. Reopen at the persisted
- // open ratio instead, atomically via the GROUP (chained per-panel
- // expand()+resize() validates against a stale store and no-ops β€” the
- // TraceLayoutDesktop lesson). Bounded by the panels' 20% mins so a
- // corrupt value can't strand the layout.
- const share = lastOpenGraphSharePct.current;
- const group = graphGroupRef.current;
- if (group && share !== null && share >= 20 && share <= 80) {
- group.setLayout({
- [GRAPH_SPLIT_TREE_PANEL_ID]: 100 - share,
- [GRAPH_SPLIT_GRAPH_PANEL_ID]: share,
- });
- } else {
- panel.expand();
- }
- }
- }, [graphCollapsed, graphPanelRef, graphGroupRef, secondaryContent]);
return (
<div className="flex h-full flex-col border-r">
@@ -171,60 +35,7 @@ export function TracePanelNavigationLayoutDesktop({
<>
<TraceTruncationNotice />
<TracePanelNavigationHiddenNotice />
- {secondaryContent ? (
- <ResizablePanelGroup
- orientation="vertical"
- className="flex-1 overflow-hidden"
- id={isPeekMode ? PEEK_GRAPH_SPLIT_GROUP_ID : GRAPH_SPLIT_GROUP_ID}
- groupRef={graphGroupRef}
- defaultLayout={defaultLayout}
- onLayoutChanged={handleLayoutChanged}
- >
- <ResizablePanel
- id={GRAPH_SPLIT_TREE_PANEL_ID}
- defaultSize="60%"
- minSize="20%"
- >
- <div className="h-full overflow-hidden">{children}</div>
- </ResizablePanel>
- <ResizableHandle className="bg-border h-px" />
- <ResizablePanel
- id={GRAPH_SPLIT_GRAPH_PANEL_ID}
- defaultSize="40%"
- minSize="20%"
- collapsible
- collapsedSize={`${GRAPH_BAR_PX}px`}
- panelRef={graphPanelRef}
- onResize={(_size, _id, prevPanelSize) => {
- // Panel β†’ state: a divider drag snapped the panel
- // collapsed/open β€” persist the user's choice. Skip the
- // mount call (prevPanelSize undefined): it reports the
- // pre-sync defaultSize and would clobber a stored/default
- // collapsed state before the layout effect below applies it.
- if (prevPanelSize === undefined) return;
- const collapsed =
- graphPanelRef.current?.isCollapsed() ?? false;
- if (collapsed !== graphCollapsed) {
- setStoredGraphCollapsed(collapsed);
- }
- }}
- >
- <div className="flex h-full flex-col overflow-hidden">
- <GraphPanelBar
- collapsed={graphCollapsed}
- onToggle={() => setStoredGraphCollapsed(!graphCollapsed)}
- />
- {!graphCollapsed && (
- <div className="min-h-0 flex-1 overflow-hidden">
- {secondaryContent}
- </div>
- )}
- </div>
- </ResizablePanel>
- </ResizablePanelGroup>
- ) : (
- <div className="flex-1 overflow-hidden">{children}</div>
- )}
+ <div className="flex-1 overflow-hidden">{children}</div>
</>
)}
</div>
diff --git a/web/src/features/traces/components/TraceSettingsDropdown.tsx b/web/src/features/traces/components/TraceSettingsDropdown.tsx
index 9382967019..325abb9fe6 100644
--- a/web/src/features/traces/components/TraceSettingsDropdown.tsx
+++ b/web/src/features/traces/components/TraceSettingsDropdown.tsx
@@ -10,7 +10,6 @@
* - Color Code Metrics (dependent on duration or cost being enabled)
* - Collapse System Prompts
* - Minimum Observation Level filter
- * - Show Graph (hidden when graph view not available)
*
* All preferences are managed via ViewPreferencesContext and persisted to localStorage.
*/
@@ -34,13 +33,7 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferencesContext";
import { useTraceAnalyticsDimensions } from "@/src/features/traces/hooks/useTraceAnalyticsDimensions";
-export interface TraceSettingsDropdownProps {
- isGraphViewAvailable: boolean;
-}
-
-export function TraceSettingsDropdown({
- isGraphViewAvailable,
-}: TraceSettingsDropdownProps) {
+export function TraceSettingsDropdown() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
@@ -57,9 +50,7 @@ export function TraceSettingsDropdown({
align="center"
className="w-64 space-y-0 space-x-0 p-0 px-0"
>
- <TraceViewOptionsMenuItems
- isGraphViewAvailable={isGraphViewAvailable}
- />
+ <TraceViewOptionsMenuItems />
</DropdownMenuContent>
</DropdownMenu>
);
@@ -70,16 +61,12 @@ export function TraceSettingsDropdown({
* dropdown shell, so they can be reused inside the navigation header's overflow
* "β‹―" menu when the panel is too narrow for inline toolbar icons.
*/
-export function TraceViewOptionsMenuItems({
- isGraphViewAvailable,
-}: TraceSettingsDropdownProps) {
+export function TraceViewOptionsMenuItems() {
const capture = usePostHogClientCapture();
const analyticsDimensions = useTraceAnalyticsDimensions();
// Get all preferences directly from context
const {
- showGraph,
- setShowGraph,
showComments,
setShowComments,
showScores,
@@ -102,30 +89,6 @@ export function TraceViewOptionsMenuItems({
return (
<>
<div className="space-y-0 p-0 py-1">
- {/* Show Graph Toggle (only when available) */}
- {isGraphViewAvailable && (
- <DropdownMenuItem
- asChild
- onSelect={(e) => e.preventDefault()}
- className="space-y-0 px-2 py-1"
- >
- <div className="flex w-full items-center justify-between">
- <span className="mr-2">Show Graph</span>
- <Switch
- size="sm"
- checked={showGraph}
- onCheckedChange={(checked) => {
- capture("trace_detail:graph_view_toggle", {
- show: checked,
- ...analyticsDimensions,
- });
- setShowGraph(checked);
- }}
- />
- </div>
- </DropdownMenuItem>
- )}
-
{/* Show Comments Toggle */}
<DropdownMenuItem
asChild
diff --git a/web/src/features/traces/contexts/TraceGraphDataContext.tsx b/web/src/features/traces/contexts/TraceGraphDataContext.tsx
index bf930d8f0c..362c4681a6 100644
--- a/web/src/features/traces/contexts/TraceGraphDataContext.tsx
+++ b/web/src/features/traces/contexts/TraceGraphDataContext.tsx
@@ -11,14 +11,19 @@ import { createContext, useContext, useMemo, type ReactNode } from "react";
import { api } from "@/src/utils/api";
import { type AgentGraphDataResponse } from "@/src/features/trace-graph-view/types";
import { useReadPath } from "@/src/features/events";
-
-const MAX_NODES_FOR_GRAPH_UI = 5000;
+import {
+ MAX_NODES_FOR_GRAPH_UI,
+ resolveGraphAvailability,
+ type GraphAvailability,
+} from "@/src/features/traces/fns/graphAvailability";
interface TraceGraphDataContextValue {
/** Agent graph data for visualization */
agentGraphData: AgentGraphDataResponse[];
/** Whether graph view is available (more than one node, not too large) */
isGraphViewAvailable: boolean;
+ /** The same answer plus the reason, for the disabled Graph segment. */
+ graphAvailability: GraphAvailability;
/**
* A "real" agent graph (agentic observation types or LangGraph metadata) β€”
* shown expanded by default. Traces that only qualify via the >1-node rule
@@ -119,61 +124,29 @@ export function TraceGraphDataProvider({
const agentGraphData = useMemo(() => query.data ?? [], [query.data]);
- const { isGraphViewAvailable, isAgentGraph } = useMemo(() => {
- if (
- agentGraphData.length === 0 ||
- // Don't show graph UI for extremely large traces
- agentGraphData.length >= MAX_NODES_FOR_GRAPH_UI
- ) {
- return { isGraphViewAvailable: false, isAgentGraph: false };
- }
-
- // "Real" agent graph: observations of agentic types (not SPAN, EVENT, or
- // GENERATION) or LangGraph step metadata β€” shown expanded by default.
- const hasGraphableObservations = agentGraphData.some(
- (obs) =>
- obs.observationType !== "SPAN" &&
- obs.observationType !== "EVENT" &&
- obs.observationType !== "GENERATION",
- );
- const hasLangGraphData = agentGraphData.some(
- (obs) => obs.step != null && obs.step !== 0,
- );
- const isAgentGraph = hasGraphableObservations || hasLangGraphData;
- if (isAgentGraph) {
- return { isGraphViewAvailable: true, isAgentGraph };
- }
-
- // Otherwise the graph is still available whenever it would draw more than
- // one MEANINGFUL node β€” the panel just defaults to collapsed for these.
- // Mirrors the timing-based inference these traces go through
- // (buildStepData drops EVENTs and keys nodes on the observation NAME),
- // with one extra rule: a single parentless root doesn't count. v4 makes
- // this mandatory (the trace itself is mirrored as a root span, so EVERY
- // trace has one), and it's deliberately unconditional — a v3 root→child
- // chain is exactly as uninformative as a v4 one; the graph only earns its
- // panel when there's structure beyond the tree. Multiple parallel roots
- // ARE structure and count fully.
- const nonEvent = agentGraphData.filter(
- (obs) => obs.observationType !== "EVENT",
- );
- const parentless = nonEvent.filter((obs) => !obs.parentObservationId);
- const counted =
- parentless.length === 1
- ? nonEvent.filter((obs) => obs.parentObservationId)
- : nonEvent;
- const distinctNodes = new Set(counted.map((obs) => obs.name));
- return { isGraphViewAvailable: distinctNodes.size > 1, isAgentGraph };
- }, [agentGraphData]);
+ const graphAvailability = useMemo(
+ () => resolveGraphAvailability(agentGraphData),
+ [agentGraphData],
+ );
+ const isGraphViewAvailable = graphAvailability.available;
+ const isAgentGraph =
+ graphAvailability.available && graphAvailability.isAgentGraph;
const value = useMemo<TraceGraphDataContextValue>(
() => ({
agentGraphData,
isGraphViewAvailable,
+ graphAvailability,
isAgentGraph,
isLoading: query.isLoading,
}),
- [agentGraphData, isGraphViewAvailable, isAgentGraph, query.isLoading],
+ [
+ agentGraphData,
+ isGraphViewAvailable,
+ graphAvailability,
+ isAgentGraph,
+ query.isLoading,
+ ],
);
return (
diff --git a/web/src/features/traces/contexts/ViewPreferencesContext.tsx b/web/src/features/traces/contexts/ViewPreferencesContext.tsx
index 6a2b1e34dc..505187d86d 100644
--- a/web/src/features/traces/contexts/ViewPreferencesContext.tsx
+++ b/web/src/features/traces/contexts/ViewPreferencesContext.tsx
@@ -43,8 +43,6 @@ interface ViewPreferencesContextValue {
setColorCodeMetrics: (value: boolean) => void;
showComments: boolean;
setShowComments: (value: boolean) => void;
- showGraph: boolean;
- setShowGraph: (value: boolean) => void;
/** Graph panel build mode (aggregated vs expanded "as it ran") */
graphViewMode: GraphViewMode;
setGraphViewMode: (value: GraphViewMode) => void;
@@ -115,7 +113,6 @@ export function ViewPreferencesProvider({
true,
);
const [showComments, setShowComments] = useLocalStorage("showComments", true);
- const [showGraph, setShowGraph] = useLocalStorage("showGraph", true);
const [storedGraphViewMode, setGraphViewMode] =
useLocalStorage<GraphViewMode>("graphViewMode", "aggregated");
// Sanitize persisted values: the mode enum may evolve and a stale
@@ -166,8 +163,6 @@ export function ViewPreferencesProvider({
setColorCodeMetrics,
showComments,
setShowComments,
- showGraph,
- setShowGraph,
graphViewMode,
setGraphViewMode,
minObservationLevel,
@@ -197,8 +192,6 @@ export function ViewPreferencesProvider({
setColorCodeMetrics,
showComments,
setShowComments,
- showGraph,
- setShowGraph,
graphViewMode,
setGraphViewMode,
minObservationLevel,
diff --git a/web/src/features/traces/fns/graphAvailability.clienttest.ts b/web/src/features/traces/fns/graphAvailability.clienttest.ts
new file mode 100644
index 0000000000..5f79c0fc0f
--- /dev/null
+++ b/web/src/features/traces/fns/graphAvailability.clienttest.ts
@@ -0,0 +1,97 @@
+// @vitest-environment node
+
+import { describe, expect, it } from "vitest";
+import {
+ MAX_NODES_FOR_GRAPH_UI,
+ resolveGraphAvailability,
+} from "./graphAvailability";
+import { type AgentGraphDataResponse } from "@/src/features/trace-graph-view/types";
+
+const obs = (
+ over: Partial<AgentGraphDataResponse> = {},
+): AgentGraphDataResponse =>
+ ({
+ id: "o1",
+ name: "step",
+ observationType: "SPAN",
+ parentObservationId: "root",
+ step: null,
+ ...over,
+ }) as AgentGraphDataResponse;
+
+describe("resolveGraphAvailability", () => {
+ it("reports no data for an empty trace", () => {
+ expect(resolveGraphAvailability([])).toEqual({
+ available: false,
+ reason: "no-data",
+ });
+ });
+
+ it("refuses traces at the node cap", () => {
+ const many = Array.from({ length: MAX_NODES_FOR_GRAPH_UI }, (_, i) =>
+ obs({ id: `o${i}`, name: `step-${i}` }),
+ );
+ expect(resolveGraphAvailability(many)).toEqual({
+ available: false,
+ reason: "too-large",
+ });
+ });
+
+ it("is an agent graph when an observation is not span/event/generation", () => {
+ expect(
+ resolveGraphAvailability([obs({ observationType: "AGENT" })]),
+ ).toEqual({ available: true, isAgentGraph: true });
+ });
+
+ it("is an agent graph on LangGraph step metadata", () => {
+ expect(resolveGraphAvailability([obs({ step: 2 })])).toEqual({
+ available: true,
+ isAgentGraph: true,
+ });
+ });
+
+ it("ignores step 0, which carries no LangGraph structure", () => {
+ expect(resolveGraphAvailability([obs({ step: 0 })])).toEqual({
+ available: false,
+ reason: "no-structure",
+ });
+ });
+
+ it("needs structure beyond the tree for plain span traces", () => {
+ expect(
+ resolveGraphAvailability([
+ obs({ id: "root", name: "trace", parentObservationId: null }),
+ obs({ id: "a", name: "only-child" }),
+ ]),
+ ).toEqual({ available: false, reason: "no-structure" });
+ });
+
+ it("counts two distinct children under one root as structure", () => {
+ expect(
+ resolveGraphAvailability([
+ obs({ id: "root", name: "trace", parentObservationId: null }),
+ obs({ id: "a", name: "fetch" }),
+ obs({ id: "b", name: "rank" }),
+ ]),
+ ).toEqual({ available: true, isAgentGraph: false });
+ });
+
+ it("counts parallel roots as structure", () => {
+ expect(
+ resolveGraphAvailability([
+ obs({ id: "r1", name: "one", parentObservationId: null }),
+ obs({ id: "r2", name: "two", parentObservationId: null }),
+ ]),
+ ).toEqual({ available: true, isAgentGraph: false });
+ });
+
+ it("drops events before judging structure", () => {
+ expect(
+ resolveGraphAvailability([
+ obs({ id: "root", name: "trace", parentObservationId: null }),
+ obs({ id: "a", name: "only-child" }),
+ obs({ id: "e", name: "log", observationType: "EVENT" }),
+ ]),
+ ).toEqual({ available: false, reason: "no-structure" });
+ });
+});
diff --git a/web/src/features/traces/fns/graphAvailability.ts b/web/src/features/traces/fns/graphAvailability.ts
new file mode 100644
index 0000000000..a1e7cee413
--- /dev/null
+++ b/web/src/features/traces/fns/graphAvailability.ts
@@ -0,0 +1,51 @@
+/** Why the Graph view is or is not available for a trace. */
+
+import { type AgentGraphDataResponse } from "@/src/features/trace-graph-view/types";
+
+export const MAX_NODES_FOR_GRAPH_UI = 5000;
+
+export type GraphUnavailableReason = "no-data" | "too-large" | "no-structure";
+
+export type GraphAvailability =
+ | { available: true; isAgentGraph: boolean }
+ | { available: false; reason: GraphUnavailableReason };
+
+export function resolveGraphAvailability(
+ agentGraphData: AgentGraphDataResponse[],
+): GraphAvailability {
+ if (agentGraphData.length === 0) {
+ return { available: false, reason: "no-data" };
+ }
+ if (agentGraphData.length >= MAX_NODES_FOR_GRAPH_UI) {
+ return { available: false, reason: "too-large" };
+ }
+
+ // "Real" agent graph: agentic observation types or LangGraph step metadata.
+ const hasGraphableObservations = agentGraphData.some(
+ (obs) =>
+ obs.observationType !== "SPAN" &&
+ obs.observationType !== "EVENT" &&
+ obs.observationType !== "GENERATION",
+ );
+ const hasLangGraphData = agentGraphData.some(
+ (obs) => obs.step != null && obs.step !== 0,
+ );
+ if (hasGraphableObservations || hasLangGraphData) {
+ return { available: true, isAgentGraph: true };
+ }
+
+ // Otherwise the graph only earns its place with structure beyond the tree.
+ // A single parentless root does not count: v4 mirrors every trace as one.
+ const nonEvent = agentGraphData.filter(
+ (obs) => obs.observationType !== "EVENT",
+ );
+ const parentless = nonEvent.filter((obs) => !obs.parentObservationId);
+ const counted =
+ parentless.length === 1
+ ? nonEvent.filter((obs) => obs.parentObservationId)
+ : nonEvent;
+ const distinctNodes = new Set(counted.map((obs) => obs.name));
+ return distinctNodes.size > 1
+ ? { available: true, isAgentGraph: false }
+ : { available: false, reason: "no-structure" };
+}