Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(trace): graph view polish — live framing, collapsible per-project panel, broader availability (LFE-10665) (#14767)

Nikita Kabardin24adb8621017
diff --git a/.agents/skills/seed-test-data/SKILL.md b/.agents/skills/seed-test-data/SKILL.md
index 8d800862f2..503091c649 100644
--- a/.agents/skills/seed-test-data/SKILL.md
+++ b/.agents/skills/seed-test-data/SKILL.md
@@ -35,6 +35,7 @@ this.
| The same tree readable in the v4 events UI | add `--v4` (writes `events_full`; `events_core` fills via MV) |
| Async parents whose subtree outlives their own span (subtree wall-clock duration badge) | add `--async-parents` to `trace-tree` (root + hub end immediately while children keep running) |
| A realistic agent flow over a timeline (graph view + scrubbable timeline) | `pnpm run seed -- agent-timeline --turns 6 --v4` (LangGraph refine loop planner→retriever→generator→critic→loop, staggered in time; add `--timing-only` for the pure timing fallback) |
+| A plain trace with no agentic types (collapsed-by-default graph panel) | add `--plain` to `trace-tree` (SPAN/GENERATION/EVENT only) |
| A super tough session (v3 legacy session view) | `pnpm run seed -- long-session --traces 300 --observations-per-trace 8` |
| Diverse v4 session shapes (chat / coding-agent / mixed) for the session-detail view | `pnpm run seed -- session-shapes --shape all` (the `agent` shape has I/O on AGENT/TOOL with no GENERATION — pre-LFE-10520 the "first generation" default rendered empty cards for it; the current "All observations with I/O" default renders it correctly; v4 on by default) |
| Many traces for list/filter performance | `pnpm run seed -- many-traces --count 100000 --days 14` |
diff --git a/packages/shared/scripts/seeder/AGENTS.md b/packages/shared/scripts/seeder/AGENTS.md
index 030fecefef..9aff2ee874 100644
--- a/packages/shared/scripts/seeder/AGENTS.md
+++ b/packages/shared/scripts/seeder/AGENTS.md
@@ -9,6 +9,7 @@ verification, and deep links.
pnpm run seed -- doctor # check the stack; prints the fix per failure
pnpm run seed -- list # scenarios and flags (--json for machines)
pnpm run seed -- trace-tree --observations 5000 --breadth 500 --v4
+pnpm run seed -- trace-tree --observations 12 --plain --v4 # SPAN/GENERATION/EVENT only (collapsed-by-default graph panel)
pnpm run seed -- agent-timeline --turns 6 --v4 # realistic agent flow-with-loop over a timeline (graph view)
pnpm run seed -- long-session --traces 300 --observations-per-trace 8
pnpm run seed -- session-shapes --shape all # chat / coding-agent / mixed v4 sessions
diff --git a/packages/shared/scripts/seeder/scenarios/trace-tree.ts b/packages/shared/scripts/seeder/scenarios/trace-tree.ts
index 216df59f6e..f38af2dc41 100644
--- a/packages/shared/scripts/seeder/scenarios/trace-tree.ts
+++ b/packages/shared/scripts/seeder/scenarios/trace-tree.ts
@@ -40,6 +40,11 @@ const ALL_KINDS: ObservationType[] = [
"EVENT",
];
+// The shape that historically had NO graph view: no agentic types, no
+// langgraph metadata — only qualifies via the >1-distinct-node rule (LFE-10665
+// collapsed-by-default graph panel).
+const PLAIN_KINDS: ObservationType[] = ["SPAN", "GENERATION", "EVENT"];
+
const NAME_BY_KIND: Record<string, string[]> = {
AGENT: ["router-agent", "support-agent", "planner-agent"],
CHAIN: ["rag-chain", "summarize-chain"],
@@ -128,6 +133,9 @@ const run = async (
const payloadStyle = params["payload-style"] as PayloadStyle;
const withV4 = params["v4"] as boolean;
const asyncParents = params["async-parents"] as boolean;
+ // Type restriction is index-keyed (jitter), not rng-stream-keyed, so the
+ // default (--plain absent) output stays byte-identical.
+ const kinds = (params["plain"] as boolean) ? PLAIN_KINDS : ALL_KINDS;
// Attach this many distinct scores to EVERY observation. The default 0 keeps
// the historic handful of trace-level scores. A high value (e.g. 12) is the
// "lots of scores" shape from LFE-10591 that overflows fixed/virtualized tree
@@ -209,7 +217,7 @@ const run = async (
observationCount,
depth,
breadth,
- ALL_KINDS,
+ kinds,
ctx.seed,
);
@@ -596,7 +604,7 @@ const run = async (
`Readback mismatch: expected ${observations.length} observations, found ${verified.observations}`,
);
}
- const expectedKinds = Math.min(observations.length, ALL_KINDS.length);
+ const expectedKinds = Math.min(observations.length, kinds.length);
if (verified.observationKinds < expectedKinds) {
throw new SeedError(
`Readback mismatch: expected ${expectedKinds} distinct observation kinds, found ${verified.observationKinds}`,
@@ -678,6 +686,13 @@ export const traceTreeScenario: ScenarioDefinition = {
description:
"root + hub nodes end immediately while their subtree keeps running (async/fire-and-forget shape; surfaces the subtree wall-clock duration badge)",
},
+ {
+ flag: "plain",
+ type: "boolean",
+ default: false,
+ description:
+ "restrict observation types to SPAN/GENERATION/EVENT (no agentic types) — the shape whose graph panel is collapsed by default (LFE-10665)",
+ },
{
flag: "scores-per-node",
type: "number",
diff --git a/web/src/components/trace/components/_layout/TracePanelNavigationLayoutDesktop.tsx b/web/src/components/trace/components/_layout/TracePanelNavigationLayoutDesktop.tsx
index 3ec4b82cf7..26d0ad951c 100644
--- a/web/src/components/trace/components/_layout/TracePanelNavigationLayoutDesktop.tsx
+++ b/web/src/components/trace/components/_layout/TracePanelNavigationLayoutDesktop.tsx
@@ -6,28 +6,65 @@
* - Handle panel collapse/expand state for desktop
* - Position TracePanelNavigationHiddenNotice 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
- * - useViewPreferences() - for showGraph preference
- * - useGraphData() - for isGraphViewAvailable
- *
- * Re-renders when:
- * - Panel collapse/expand state changes
- * - showGraph or isGraphViewAvailable changes
- * - Does NOT re-render when search/selection changes (isolated)
+ * - useTraceData() - for the per-project persistence key
+ * - useTraceGraphData() - for the collapsed-by-default heuristic
*/
-import { type ReactNode } from "react";
+import { useLayoutEffect, type ReactNode } from "react";
+import { ChevronDown, ChevronUp } from "lucide-react";
import {
ResizablePanel,
ResizablePanelGroup,
ResizableHandle,
+ usePanelRef,
} from "@/src/components/ui/resizable";
+import useLocalStorage from "@/src/components/useLocalStorage";
import { useDesktopLayoutContext } from "./TraceLayoutDesktop";
+import { useTraceData } from "../../contexts/TraceDataContext";
+import { useTraceGraphData } from "../../contexts/TraceGraphDataContext";
import { TracePanelNavigationHeader } from "./TracePanelNavigationHeader";
import { TracePanelNavigationHiddenNotice } from "./TracePanelNavigationHiddenNotice";
+// 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;
+
+/**
+ * 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-medium">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,
@@ -37,6 +74,27 @@ export function TracePanelNavigationLayoutDesktop({
}) {
const { isNavigationPanelCollapsed, handleTogglePanel, shouldPulseToggle } =
useDesktopLayoutContext();
+ const { trace } = useTraceData();
+ const { isAgentGraph } = useTraceGraphData();
+
+ // 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();
+
+ // 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()) panel.expand();
+ }, [graphCollapsed, graphPanelRef, secondaryContent]);
return (
<div className="flex h-full flex-col border-r">
@@ -57,8 +115,37 @@ export function TracePanelNavigationLayoutDesktop({
<div className="h-full overflow-hidden">{children}</div>
</ResizablePanel>
<ResizableHandle className="bg-border h-px" />
- <ResizablePanel defaultSize="40%" minSize="20%">
- <div className="h-full overflow-hidden">{secondaryContent}</div>
+ <ResizablePanel
+ 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>
) : (
diff --git a/web/src/components/trace/contexts/TraceGraphDataContext.tsx b/web/src/components/trace/contexts/TraceGraphDataContext.tsx
index b5a51b9ad0..584c2efb3b 100644
--- a/web/src/components/trace/contexts/TraceGraphDataContext.tsx
+++ b/web/src/components/trace/contexts/TraceGraphDataContext.tsx
@@ -17,8 +17,14 @@ const MAX_NODES_FOR_GRAPH_UI = 5000;
interface TraceGraphDataContextValue {
/** Agent graph data for visualization */
agentGraphData: AgentGraphDataResponse[];
- /** Whether graph view is available (has graphable data, not too large) */
+ /** Whether graph view is available (more than one node, not too large) */
isGraphViewAvailable: boolean;
+ /**
+ * A "real" agent graph (agentic observation types or LangGraph metadata) —
+ * shown expanded by default. Traces that only qualify via the >1-node rule
+ * get a collapsed-by-default graph panel instead.
+ */
+ isAgentGraph: boolean;
/** Whether data is currently loading */
isLoading: boolean;
}
@@ -113,40 +119,52 @@ export function TraceGraphDataProvider({
const agentGraphData = useMemo(() => query.data ?? [], [query.data]);
- const isGraphViewAvailable = useMemo(() => {
- if (agentGraphData.length === 0) {
- return false;
+ 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 };
}
- // Don't show graph UI for extremely large traces
- if (agentGraphData.length >= MAX_NODES_FOR_GRAPH_UI) {
- return false;
- }
-
- // Check if there are observations that would be included in the graph
- // (not SPAN, EVENT, or GENERATION)
+ // "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",
);
-
- // Check for LangGraph data (has step != 0)
const hasLangGraphData = agentGraphData.some(
(obs) => obs.step != null && obs.step !== 0,
);
+ const isAgentGraph = hasGraphableObservations || hasLangGraphData;
+ if (isAgentGraph) {
+ return { isGraphViewAvailable: true, isAgentGraph };
+ }
- return hasGraphableObservations || hasLangGraphData;
+ // Otherwise the graph is still available whenever it would draw more than
+ // one node — the panel just defaults to collapsed for these. Exact mirror
+ // of the timing-based inference these traces go through (buildStepData):
+ // it drops EVENT observations, then keys every node on the observation
+ // NAME (`obs.node = obs.name`), so count distinct non-EVENT names.
+ const distinctNodes = new Set(
+ agentGraphData
+ .filter((obs) => obs.observationType !== "EVENT")
+ .map((obs) => obs.name),
+ );
+ return { isGraphViewAvailable: distinctNodes.size > 1, isAgentGraph };
}, [agentGraphData]);
const value = useMemo<TraceGraphDataContextValue>(
() => ({
agentGraphData,
isGraphViewAvailable,
+ isAgentGraph,
isLoading: query.isLoading,
}),
- [agentGraphData, isGraphViewAvailable, query.isLoading],
+ [agentGraphData, isGraphViewAvailable, isAgentGraph, query.isLoading],
);
return (
diff --git a/web/src/features/trace-graph-view/components/ElkGraphRenderer.tsx b/web/src/features/trace-graph-view/components/ElkGraphRenderer.tsx
index 5f9534d413..7028871b41 100644
--- a/web/src/features/trace-graph-view/components/ElkGraphRenderer.tsx
+++ b/web/src/features/trace-graph-view/components/ElkGraphRenderer.tsx
@@ -92,8 +92,13 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
null,
undefined
> | null>(null);
- // Once the user pans/zooms, stop auto-fitting on resize.
- const userControlledRef = useRef(false);
+ // What framed the current view. Programmatic framings ("fit", "focus") stay
+ // LIVE: when the container resizes (peek panel opening/settling, divider
+ // drag, window resize) they re-apply against the new size — otherwise a
+ // deep-link focus computed against a transient early size stays frozen and
+ // the focused node ends up cropped/off-view. Only a real user gesture
+ // ("gesture") freezes the view.
+ const framingRef = useRef<"fit" | "focus" | "gesture">("fit");
// The node id (or null for an empty click) of the last in-canvas selection, so
// the focus effect re-frames only for selections from the tree/timeline.
const lastCanvasClickRef = useRef<string | null | undefined>(undefined);
@@ -143,7 +148,7 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
setLayout(null);
setLayoutError(false);
setFitted(false);
- userControlledRef.current = false;
+ framingRef.current = "fit";
// Also clear cross-graph view state so a graph change re-focuses the
// selected node on the new instance and drops stale hover highlighting.
prevSelectedRef.current = null;
@@ -183,7 +188,9 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
const zoomBehavior = createZoom<HTMLDivElement, unknown>()
.scaleExtent([SCALE_MIN, SCALE_MAX])
.on("zoom", (event: D3ZoomEvent<HTMLDivElement, unknown>) => {
- if (event.sourceEvent) userControlledRef.current = true;
+ // sourceEvent is set only for real gestures (drag/wheel/pinch) —
+ // programmatic transforms (fit/focus) keep their live framing kind.
+ if (event.sourceEvent) framingRef.current = "gesture";
const { x, y, k } = event.transform;
transformRef.current = { x, y, k };
const world = worldRef.current;
@@ -258,9 +265,10 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
};
}, [layout, size]);
- // Auto-fit on layout/size until the user takes control.
+ // Live "fit" framing: re-fit on layout/size changes until a focus or a user
+ // gesture takes over.
useEffect(() => {
- if (userControlledRef.current) return;
+ if (framingRef.current !== "fit") return;
const fit = computeFit();
if (fit) applyTransform(fit);
}, [computeFit, applyTransform]);
@@ -268,44 +276,83 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
// Reflect external selection (tree/timeline): bring the node into view at the
// current zoom (or one reveal scale when zoomed out). In-canvas clicks don't
// move the view; selecting the root/empty returns to the full-graph overview.
+ // While the view is focus-framed, container size changes re-center the node
+ // against the NEW size (translate only — the zoom stays put), so a peek panel
+ // that finishes laying out after a deep-link focus, or a divider drag, can't
+ // leave the focused node cropped against a stale frame.
useEffect(() => {
const cameFromClick = lastCanvasClickRef.current === selectedNodeName;
lastCanvasClickRef.current = undefined;
- // Only react to an actual selection change. This effect also depends on
- // `size`/`computeFit`, so without this guard a resize / panel-drag would
- // re-frame (and yank) a still-selected node.
- if (prevSelectedRef.current === selectedNodeName) return;
// Wait for layout/size before acting — and don't mark the selection as
// reflected yet, so we retry once they're ready (e.g. a deep link with a
// preselected observation that arrives before the graph lays out).
if (!layout || size.width === 0) return;
+
+ // Read d3-zoom's synchronously-updated scale (set by applyTransform before
+ // React re-renders), not a state mirror that's stale in the same commit.
+ const currentK = containerRef.current
+ ? zoomTransform(containerRef.current).k
+ : 1;
+ // Clamped focus framing: aim the node at the viewport center, but never
+ // leave blank canvas the graph could cover — on an axis where the scaled
+ // graph is larger than the viewport, clamp the pan to the graph bounds
+ // (a node near the graph's edge sits off-center rather than dragging
+ // emptiness in); where the graph is smaller, just center the whole graph.
+ // Without this, deep-link-focusing a node near the top of a small graph
+ // pushed the rest out of the panel while half the canvas sat empty.
+ const centerNode = (nodeId: string, k: number): boolean => {
+ const node = layout.nodes.find((n) => n.id === nodeId);
+ if (!node) return false;
+ const cx = node.x + node.width / 2;
+ const cy = node.y + node.height / 2;
+ const graphW = layout.width * k;
+ const graphH = layout.height * k;
+ const x =
+ graphW <= size.width
+ ? (size.width - graphW) / 2
+ : Math.min(0, Math.max(size.width - graphW, size.width / 2 - cx * k));
+ const y =
+ graphH <= size.height
+ ? (size.height - graphH) / 2
+ : Math.min(
+ 0,
+ Math.max(size.height - graphH, size.height / 2 - cy * k),
+ );
+ applyTransform({ k, x, y });
+ return true;
+ };
+
+ if (prevSelectedRef.current === selectedNodeName) {
+ // No selection change — this run is a size/layout change. Keep a live
+ // focus framing honest by re-centering at the current zoom; leave user
+ // gestures alone ("fit" re-applies via the auto-fit effect above).
+ if (framingRef.current === "focus" && selectedNodeName) {
+ centerNode(selectedNodeName, currentK);
+ }
+ return;
+ }
prevSelectedRef.current = selectedNodeName;
- // In-canvas clicks already selected the node; don't move the view.
- if (cameFromClick) return;
+ // In-canvas clicks already selected the node; don't move the view. A
+ // leftover "focus" framing must be demoted to "gesture" so a later
+ // container resize can't re-center onto the clicked node — but a live
+ // "fit" framing stays live (clicking a node in a fitted overview should
+ // not kill auto-fit-on-resize).
+ if (cameFromClick) {
+ if (framingRef.current === "focus") framingRef.current = "gesture";
+ return;
+ }
if (!selectedNodeName) {
- userControlledRef.current = false;
+ framingRef.current = "fit";
const fit = computeFit();
if (fit) applyTransform(fit);
return;
}
- const node = layout.nodes.find((n) => n.id === selectedNodeName);
- if (!node) return;
- userControlledRef.current = true;
- // Read d3-zoom's synchronously-updated scale (set by applyTransform before
- // React re-renders), not a state mirror that's stale in the same commit.
- const current = containerRef.current
- ? zoomTransform(containerRef.current).k
- : 1;
- const k = current >= LABEL_HIDE_SCALE ? current : SELECTION_REVEAL_SCALE;
- const cx = node.x + node.width / 2;
- const cy = node.y + node.height / 2;
- applyTransform({
- k,
- x: size.width / 2 - cx * k,
- y: size.height / 2 - cy * k,
- });
+ const k = currentK >= LABEL_HIDE_SCALE ? currentK : SELECTION_REVEAL_SCALE;
+ if (centerNode(selectedNodeName, k)) {
+ framingRef.current = "focus";
+ }
}, [selectedNodeName, layout, size, computeFit, applyTransform]);
const handleSelect = useCallback(
@@ -334,12 +381,14 @@ export const ElkGraphRenderer: React.FC<ElkGraphRendererProps> = ({
const selection = selectionRef.current;
const zoomBehavior = zoomRef.current;
if (!selection || !zoomBehavior) return;
- userControlledRef.current = true;
+ // Toolbar zoom is a user decision — freeze the framing like a gesture
+ // (scaleBy goes through d3 without a sourceEvent, so set it explicitly).
+ framingRef.current = "gesture";
zoomBehavior.scaleBy(selection, factor);
};
const handleFit = () => {
- userControlledRef.current = false;
+ framingRef.current = "fit";
const fit = computeFit();
if (fit) applyTransform(fit);
};