πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(trace): compact timeline, first round of review feedback (#16352)
Nikita Kabardine17abfe6ee49
diff --git a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.stories.tsx b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.stories.tsxindex afca6982a5..d75278b58b 100644--- a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.stories.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.stories.tsx@@ -1677,3 +1677,454 @@ export const TheTooltipEscapesTheSurface = meta.story({);},});++/** The shared args for the feedback-round stories: names visible, one trace. */+const READABLE = {+ roots: deepNesting(6),+ box: DESKTOP,+ gutter: "expanded" as const,+ pointer: "fine" as const,+ barColor: "type" as const,+ compress: false,+ showReadout: true,+ selectedId: null,+};++/**+ * A row is one thing. The tooltip used to be gated on the pointer being past the+ * gutter β so hovering a span's NAME, the most obvious way to ask what it is,+ * told you nothing, while the row highlighted across its full width anyway.+ */+export const TheTooltipCoversTheWholeRow = meta.story({+ name: "(Test) The Tooltip Covers The Whole Row",+ args: { ...READABLE, onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ const rect = surface.getBoundingClientRect();+ // Over the NAME, well inside the gutter.+ surface.dispatchEvent(+ new PointerEvent("pointermove", {+ bubbles: true,+ pointerType: "mouse",+ clientX: rect.left + 30,+ clientY: rect.top + 40,+ }),+ );+ const tooltip = await waitFor(() => {+ const el = document.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-tooltip"]',+ );+ if (!el) throw new Error("hovering a name said nothing");+ return el;+ });+ await expect(tooltip.innerText).toContain("level-");+ },+});++/**+ * Hue means observation type and nothing else. Focus used to repaint the bar in+ * the accent β which is the same blue that means SPAN β so a hovered generation+ * changed species under the cursor.+ */+export const HoverDoesNotRecolourTheBar = meta.story({+ name: "(Test) Hover Does Not Recolour The Bar",+ args: {+ ...READABLE,+ roots: manySpans(40),+ selectedId: "n0",+ onSelect: fn(),+ onHover: fn(),+ },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ const bars = () => [+ ...canvasElement.querySelectorAll<HTMLElement>(+ '[data-testid="timeline-dense-bar"]',+ ),+ ];+ const hueOf = (bar: HTMLElement) =>+ [...bar.classList].find((name) => name.startsWith("bg-")) ?? "";++ const before = bars().map(hueOf);+ await expect(before.length).toBeGreaterThan(3);++ const rect = surface.getBoundingClientRect();+ surface.dispatchEvent(+ new PointerEvent("pointermove", {+ bubbles: true,+ pointerType: "mouse",+ clientX: rect.left + rect.width * 0.7,+ clientY: rect.top + 60,+ }),+ );+ await waitFor(() =>+ expect(+ document.querySelector('[data-testid="timeline-dense-tooltip"]'),+ ).not.toBeNull(),+ );++ // Same hues, hovered or not β and the accent never paints a bar at all.+ await expect(bars().map(hueOf)).toEqual(before);+ await expect(before.some((hue) => hue.includes("primary-accent"))).toBe(+ false,+ );+ // Selection still reads, as a ring rather than a repaint.+ const ringed = bars().filter((bar) =>+ [...bar.classList].some((name) => name.startsWith("ring-")),+ );+ await expect(ringed.length).toBe(1);+ },+});++/** A control that can do nothing should say so rather than look broken. */+export const FitIsDisabledWhenItWouldDoNothing = meta.story({+ name: "(Test) Fit Is Disabled When It Would Do Nothing",+ args: { ...READABLE, roots: manySpans(40), onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const fit = () =>+ canvasElement.querySelector<HTMLButtonElement>(+ 'button[aria-label*="fits"], button[aria-label="Fit whole trace"]',+ );+ const button = fit();+ if (!button) throw new Error("no fit button");+ // At rest the whole trace already fits.+ await expect(button.disabled).toBe(true);++ const zoomIn = canvasElement.querySelector<HTMLButtonElement>(+ 'button[aria-label="Zoom in"]',+ );+ if (!zoomIn) throw new Error("no zoom button");+ await userEvent.click(zoomIn);+ await waitFor(() => expect(fit()?.disabled).toBe(false));+ },+});++/** Collapse in the tree means collapse here: the same set, honoured. */+export const CollapsedRowsAreNotDrawn = meta.story({+ name: "(Test) Collapsed Rows Are Not Drawn",+ args: {+ ...READABLE,+ collapsed: new Set(["n0"]),+ onSelect: fn(),+ onHover: fn(),+ },+ play: async ({ canvasElement }) => {+ // A six-deep chain with its root collapsed is one row.+ await expect(+ canvasElement.querySelectorAll('[data-testid="timeline-dense-row"]')+ .length,+ ).toBe(1);+ },+});++/**+ * The tooltip does not say when a span started. The bar's position on the axis+ * already says it, and in words it was one more number to read past: `@0ms` on a+ * root means nothing, and a row that starts 11m 52s in and runs 11m 52s put two+ * identical unlabelled durations side by side.+ */+export const TheTooltipDoesNotRepeatTheAxis = meta.story({+ name: "(Test) The Tooltip Does Not Repeat The Axis",+ args: { ...READABLE, onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ const rect = surface.getBoundingClientRect();+ const hover = (offsetY: number) =>+ surface.dispatchEvent(+ new PointerEvent("pointermove", {+ bubbles: true,+ pointerType: "mouse",+ clientX: rect.left + rect.width * 0.7,+ clientY: rect.top + offsetY,+ }),+ );+ const tooltip = () =>+ document.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-tooltip"]',+ );++ // The root, which starts the trace...+ hover(6);+ await waitFor(() => expect(tooltip()).not.toBeNull());+ const rootText = tooltip()!.innerText;+ await expect(rootText).not.toContain("@");+ await expect(rootText).not.toContain("starts at");++ // ...and a row that starts well into it. Neither mentions when.+ hover(6 + 26 * 3);+ await waitFor(() => expect(tooltip()!.innerText).not.toBe(rootText));+ await expect(tooltip()!.innerText).not.toContain("@");+ await expect(tooltip()!.innerText).not.toContain("starts at");+ // What it DOES say: the name, and how long it took.+ await expect(tooltip()!.innerText).toMatch(/\d/);+ },+});++/** Drag draws the zoom box β no modifier, because scroll already pans. */+export const DragZoomsWithoutAModifier = meta.story({+ name: "(Test) Drag Zooms Without A Modifier",+ args: { ...READABLE, roots: manySpans(150), onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ // Spy rather than stub: WHEN the pointer is captured is the contract here.+ // Capture retargets the click that follows to the capturing element, so+ // taking it on pointerdown kills click-to-select on every row β and no+ // synthetic event in a test can observe the retargeting itself, which is+ // exactly how that shipped once already.+ const captures: number[] = [];+ surface.setPointerCapture = (pointerId: number) => {+ captures.push(pointerId);+ };+ surface.releasePointerCapture = () => undefined;+ const readout = () =>+ canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-readout"]',+ )?.textContent ?? "";+ await expect(readout()).toContain("fitted");++ const rect = surface.getBoundingClientRect();+ const drag = (type: string, x: number, y: number) =>+ surface.dispatchEvent(+ new PointerEvent(type, {+ bubbles: true,+ cancelable: true,+ pointerId: 1,+ pointerType: "mouse",+ buttons: type === "pointerup" ? 0 : 1,+ clientX: x,+ clientY: y,+ }),+ );+ drag("pointerdown", rect.left + rect.width * 0.3, rect.top + 100);+ // A press is not a drag yet, so nothing is captured and no box exists.+ await expect(captures).toEqual([]);+ await expect(+ canvasElement.querySelector('[data-testid="timeline-dense-marquee"]'),+ ).toBeNull();++ drag("pointermove", rect.left + rect.width * 0.6, rect.top + 240);+ // Past the threshold it is a drag, and only now does it take the pointer.+ await expect(captures).toEqual([1]);++ drag("pointerup", rect.left + rect.width * 0.6, rect.top + 240);+ await waitFor(() => expect(readout()).toContain("zoomed"));+ },+});++/** ...but a finger still pans, because a finger has no scroll wheel. */+export const AFingerDragStillPans = meta.story({+ name: "(Test) A Finger Drag Still Pans",+ args: {+ ...READABLE,+ // More rows than the box holds, or there is no window left to pan.+ roots: manySpans(3000),+ pointer: "coarse" as const,+ onSelect: fn(),+ onHover: fn(),+ },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ surface.setPointerCapture = () => undefined;+ surface.releasePointerCapture = () => undefined;+ const rowsLabel = () =>+ canvasElement.querySelector<HTMLElement>('[data-testid="dense-rows"]')+ ?.textContent ?? "";++ const rect = surface.getBoundingClientRect();+ const before = rowsLabel();+ const heightBefore =+ canvasElement.querySelector<HTMLElement>(+ '[data-testid="dense-rowheight"]',+ )?.textContent ?? "";+ touch(+ surface,+ "pointerdown",+ 1,+ rect.left + rect.width * 0.5,+ rect.top + 400,+ );+ touch(+ surface,+ "pointermove",+ 1,+ rect.left + rect.width * 0.5,+ rect.top + 120,+ );+ touch(+ surface,+ "pointerup",+ 1,+ rect.left + rect.width * 0.5,+ rect.top + 120,+ );++ // The window MOVED...+ await waitFor(() => expect(rowsLabel()).not.toBe(before));+ // ...and did not resize: a box zoom would have changed the row height.+ await expect(+ canvasElement.querySelector<HTMLElement>(+ '[data-testid="dense-rowheight"]',+ )?.textContent,+ ).toBe(heightBefore);+ },+});++/**+ * The cursor should not promise a gesture the surface does not perform. It was a+ * grab hand, from when drag meant pan; drag draws a zoom box now, so the surface+ * says nothing at rest and the bars carry the only real affordance β a click+ * that selects.+ */+export const TheCursorMatchesTheGesture = meta.story({+ name: "(Test) The Cursor Matches The Gesture",+ args: { ...READABLE, roots: manySpans(40), onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ await expect(getComputedStyle(surface).cursor).toBe("default");++ const bar = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-bar"]',+ );+ if (!bar) throw new Error("no bar");+ await expect(getComputedStyle(bar).cursor).toBe("pointer");+ },+});++/**+ * The toolbar does not explain the surface. Every gesture it supports is one you+ * would have tried anyway, and the space is better spent saying where you ARE β+ * which is worth saying only once you are somewhere other than the whole trace.+ */+export const TheToolbarDoesNotExplainItself = meta.story({+ name: "(Test) The Toolbar Does Not Explain Itself",+ args: { ...READABLE, roots: manySpans(40), onSelect: fn(), onHover: fn() },+ play: async ({ canvasElement }) => {+ const toolbar = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-toolbar"]',+ );+ if (!toolbar) throw new Error("no toolbar");++ // At rest: no tutorial, and nothing about where you are β you are nowhere in+ // particular, you are looking at all of it.+ for (const word of ["drag", "scroll", "pinch", "double-click", "window"]) {+ await expect(toolbar.innerText.toLowerCase()).not.toContain(word);+ }++ // Three controls, all of them about the view: out, in, fit. No colour+ // reference card (the tooltip names a type where you are asking) and no+ // names toggle (`auto` decides, and the rail peeks when you want a look).+ const labels = [+ ...toolbar.querySelectorAll<HTMLButtonElement>("button"),+ ].map((button) => button.getAttribute("aria-label"));+ await expect(labels).toEqual([+ "Zoom out",+ "Zoom in",+ "Whole trace already fits",+ ]);++ const zoomIn = canvasElement.querySelector<HTMLButtonElement>(+ 'button[aria-label="Zoom in"]',+ );+ if (!zoomIn) throw new Error("no zoom button");+ await userEvent.click(zoomIn);++ // Zoomed: it says where you are, and still explains nothing.+ await waitFor(() =>+ expect(toolbar.innerText.toLowerCase()).toContain("window"),+ );+ await expect(toolbar.innerText.toLowerCase()).not.toContain("drag");+ },+});++/**+ * A second finger abandons a box the first one had started. Every release commits+ * whatever box it finds, so a rectangle left behind by an interrupted drag flies+ * the viewport somewhere nobody asked to go β one pinch later, on a release that+ * had nothing to do with it.+ */+export const APinchAbandonsAnUnfinishedBox = meta.story({+ name: "(Test) A Pinch Abandons An Unfinished Box",+ args: {+ ...READABLE,+ roots: manySpans(150),+ pointer: "coarse" as const,+ onSelect: fn(),+ onHover: fn(),+ },+ play: async ({ canvasElement }) => {+ const surface = canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-surface"]',+ );+ if (!surface) throw new Error("dense surface not found");+ surface.setPointerCapture = () => undefined;+ surface.releasePointerCapture = () => undefined;+ const readout = () =>+ canvasElement.querySelector<HTMLElement>(+ '[data-testid="timeline-dense-readout"]',+ )?.textContent ?? "";+ const marquee = () =>+ canvasElement.querySelector('[data-testid="timeline-dense-marquee"]');+ const rect = surface.getBoundingClientRect();+ await expect(readout()).toContain("fitted");++ // A finger WITH shift draws a box β the one way touch asks for one.+ const shifted = (type: string, x: number, y: number) =>+ surface.dispatchEvent(+ new PointerEvent(type, {+ bubbles: true,+ cancelable: true,+ pointerId: 1,+ pointerType: "touch",+ isPrimary: true,+ shiftKey: true,+ buttons: type === "pointerup" ? 0 : 1,+ clientX: x,+ clientY: y,+ }),+ );+ shifted("pointerdown", rect.left + rect.width * 0.3, rect.top + 100);+ shifted("pointermove", rect.left + rect.width * 0.6, rect.top + 260);+ await waitFor(() => expect(marquee()).not.toBeNull());++ // A second finger arrives: that is a pinch now, and the box is abandoned.+ touch(+ surface,+ "pointerdown",+ 2,+ rect.left + rect.width * 0.5,+ rect.top + 300,+ );+ await waitFor(() => expect(marquee()).toBeNull());++ // Releasing must not fly anywhere: there is no box left to fly to.+ shifted("pointerup", rect.left + rect.width * 0.6, rect.top + 260);+ let flew = false;+ try {+ await waitFor(() => expect(readout()).toContain("zoomed"), {+ timeout: 600,+ });+ flew = true;+ } catch {+ // Still fitted, which is the point.+ }+ await expect(flew).toBe(false);+ },+});diff --git a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsxindex 76d499d4dd..90a50fff17 100644--- a/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TimelineDense.tsx@@ -25,7 +25,7 @@* BOTH axes about the cursor, so the time window narrows and the rows grow* together. Zoom is exponential in a zoom level and deltas accumulate per* frame, as in mapping libraries β see the rate constants below.- * - Drag pans both axes too, and SHIFT-drag draws a box to zoom into β the one+ * - Drag pans both axes too, and drag draws a box to zoom into β the one* gesture where the user has stated the window on both axes, so it goes* straight there. There are no scrollbars by design: a map has none, and the* viewport clamps to the content so there is nowhere to get lost.@@ -57,13 +57,7 @@ import {type PointerEvent as ReactPointerEvent,type ReactNode,} from "react";-import {- Maximize2,- Minus,- PanelLeftClose,- PanelLeftOpen,- Plus,-} from "lucide-react";+import { Scan, Minus, Plus } from "lucide-react";import { ItemBadge, type LangfuseItemType } from "@/src/components/ItemBadge";import {tooltipPlacement,@@ -120,17 +114,31 @@ const TYPE_COLOR: Record<string, string> = {GUARDRAIL: "bg-red-600",};const FALLBACK_COLOR = "bg-muted-gray";-/** Neutral mode's bar, and the accent a selected or hovered bar takes. */+/** Neutral mode's bar, when colour is not carrying type. */const NEUTRAL_COLOR = "bg-muted-foreground/60";-const ACCENT_COLOR = "bg-primary-accent";-/** Every colour a bar can be β the set whose contrast has to be resolved. */+/**+ * Every colour a bar can be β the set whose contrast has to be resolved. The+ * accent used to be in here, and it was the one tone the picker read as dark+ * enough for a black label while looking mid-violet to a person.+ */const BAR_COLORS = [...Object.values(TYPE_COLOR),FALLBACK_COLOR,NEUTRAL_COLOR,- ACCENT_COLOR,];+/**+ * `GENERATION` β `Generation`. The palette is by observation type, and the type+ * has to be readable wherever its colour is: nothing in the view said what the+ * colours meant, so the only way to learn was to ask someone.+ */+function typeLabel(type: string): string {+ return (type.charAt(0).toUpperCase() + type.slice(1).toLowerCase()).replace(+ /_/g,+ " ",+ );+}+const RAIL_INDENT = 2;const RAIL_MAX_DEPTH = 4;/** Biggest the closed rail's type square gets, however tall the row is. */@@ -201,7 +209,7 @@ const FOCUS_ANIMATION_MS = 320;const PEEK_MARGIN_PX = 6;/** A collapsed-gap band narrower than this has no room to name itself. */const GAP_LABEL_MIN_WIDTH = 14;-/** Below this in both axes a shift-drag was a stray click, not a box. */+/** Below this in both axes a drag was a stray click, not a box. */const MARQUEE_MIN_PX = 6;/** Two taps within this long, and this close, are one double-tap. */const DOUBLE_TAP_MS = 320;@@ -226,6 +234,13 @@ export type TimelineDenseProps = {* this layout.*/gutter: GutterMode;+ /**+ * Ids whose descendants are hidden β the SAME set the tree view collapses+ * with, so "collapse all" in the header means the same thing in both. The pure+ * core has always taken it; this view simply never passed it on, so the button+ * moved the store and nothing here moved.+ */+ collapsed?: ReadonlySet<string>;/*** Input modality. `fine` peeks the gutter on hover; `coarse` has no hover, so* it toggles on a tap of the rail.@@ -300,6 +315,7 @@ export function TimelineDense({roots,box,gutter,+ collapsed,pointer,barColor,compress,@@ -321,7 +337,7 @@ export function TimelineDense({} | null>(null);const [dragging, setDragging] = useState(false);/**- * Shift-drag box, in surface coordinates, while it is being drawn. The REF is+ * Zoom box, in surface coordinates, while it is being drawn. The REF is* the authority and the state is only for drawing it: a gesture that read the* box back out of render scope would depend on React having re-rendered* between pointerdown and pointerup, which nothing guarantees.@@ -333,7 +349,10 @@ export function TimelineDense({setMarquee(next);};- const prepared = useMemo(() => prepareTimeline(roots), [roots]);+ const prepared = useMemo(+ () => prepareTimeline(roots, collapsed),+ [roots, collapsed],+ );// Measured in the font the labels ACTUALLY render in, read off a probe span// that carries their own size β `10px ui-sans-serif` is a guess, and the// canvas resolves it to a different face than the app's system stack, ~6px@@ -462,7 +481,6 @@ export function TimelineDense({canShowNames && !committedOpen && (peeking || override === "expanded")? wantedGutter: 0;- const gutterWidth = Math.max(railWidth, peekWidth);const presentation = presentationForRowHeight(rowHeight);const fitted = isViewportFitted(current, limits);const barHeight = Math.max(Math.min(rowHeight - 1, MAX_BAR_HEIGHT), 1);@@ -563,7 +581,17 @@ export function TimelineDense({);const surfaceRef = useRef<HTMLDivElement | null>(null);- const gesture = useRef({ down: false, dragging: false, x: 0, y: 0 });+ const gesture = useRef({+ down: false,+ dragging: false,+ x: 0,+ y: 0,+ /** What this press becomes once it moves: a zoom box, or a pan. */+ intent: "pan" as "pan" | "zoom",+ /** Where it began, in surface coordinates, for the box's own corner. */+ originX: 0,+ originY: 0,+ });/*** Every pointer currently down, and the pinch they describe.*@@ -896,27 +924,15 @@ export function TimelineDense({lastTap.current = { at: 0, x: 0, y: 0 };return;}- // Shift+drag draws a box to zoom into, which is the one gesture where the- // user states the window on BOTH axes β so it goes straight there rather- // than picking a level for them. Plain drag keeps panning; a map's primary- // gesture should not need a modifier.- if (event.shiftKey) {- const rect = event.currentTarget.getBoundingClientRect();- const point = {- x: event.clientX - rect.left,- y: event.clientY - rect.top,- };- event.currentTarget.setPointerCapture(event.pointerId);- setMarqueeBox({ from: point, to: point });- return;- }-- // A PRIMARY touch is the first contact of a new gesture, so anything left in+ // Every pointer type reaches here now: the box is decided below and drawn on+ // the first real move, so nothing returns early any more.+ //+ // A PRIMARY contact is the first of a new gesture, so anything left in// the map is stale by definition. Not every release arrives β lift two// fingers at once and a `pointerup` can go missing, or land outside the// element β and one phantom finger turns the next one-finger drag into a// pinch, which showed up as a pan that also zoomed a little.- if (event.isPrimary && event.pointerType !== "mouse") {+ if (event.isPrimary) {touches.current.points.clear();touches.current.distance = 0;}@@ -926,9 +942,13 @@ export function TimelineDense({});if (touches.current.points.size === 2) {// A second finger ends whatever the first one was doing and starts a- // pinch from where the two currently are.+ // pinch from where the two currently are β INCLUDING a box it had begun+ // to draw. Left behind, that rectangle outlives the pinch and the next+ // release flies to it, since every release commits whatever box it finds.gesture.current.down = false;gesture.current.dragging = false;+ gesture.current.intent = "pan";+ setMarqueeBox(null);setDragging(false);const [a, b] = [...touches.current.points.values()];if (a && b) {@@ -941,11 +961,26 @@ export function TimelineDense({return;}+ // Drag draws a box to zoom into: the one gesture where the user states the+ // window on BOTH axes, so it goes straight there rather than picking a level+ // for them. It needs no modifier β scroll already pans both axes, so drag is+ // free, and a modifier nobody guesses is not a gesture, it is a footnote.+ // Touch is the exception: one finger keeps panning, because a finger has no+ // scroll wheel to pan with and drawing a box with one is nobody's instinct.+ //+ // Decided here and ACTED ON in pointermove. A press is not yet a drag, and+ // capturing the pointer before it is one retargets the click that follows+ // away from the row β which silently kills click-to-select, and no synthetic+ // event in a test can see it happen. Both gestures wait for the threshold.+ const rect = event.currentTarget.getBoundingClientRect();gesture.current = {down: true,dragging: false,x: event.clientX,y: event.clientY,+ intent: event.pointerType !== "touch" || event.shiftKey ? "zoom" : "pan",+ originX: event.clientX - rect.left,+ originY: event.clientY - rect.top,};};@@ -1024,6 +1059,17 @@ export function TimelineDense({// Capture only once it really is a drag, so a click still reaches a row.event.currentTarget.setPointerCapture(event.pointerId);}+ if (state.dragging && state.intent === "zoom") {+ const surface = event.currentTarget.getBoundingClientRect();+ setMarqueeBox({+ from: { x: state.originX, y: state.originY },+ to: {+ x: event.clientX - surface.left,+ y: event.clientY - surface.top,+ },+ });+ return;+ }if (state.dragging) {releaseOverride();panBy(dx, dy);@@ -1052,7 +1098,7 @@ export function TimelineDense({});};- /** Release of a shift-drag: fly to the box, if it is big enough to mean one. */+ /** Release of a zoom drag: fly to the box, if it is big enough to mean one. */const commitMarquee = () => {const box = marqueeRef.current;if (!box) return;@@ -1090,6 +1136,9 @@ export function TimelineDense({dragging: false,x: survivor.x,y: survivor.y,+ intent: "pan",+ originX: 0,+ originY: 0,};setDragging(false);return;@@ -1230,6 +1279,7 @@ export function TimelineDense({compression.toRealMs(current.time.start + current.time.duration) -compression.toRealMs(current.time.start),);+ const windowHint = `${rowHeight.toFixed(1)}px rows Β· ${windowLabel} window`;return (<div@@ -1239,6 +1289,7 @@ export function TimelineDense({<divclassName="border-border flex shrink-0 items-center gap-1 border-b px-1"style={{ height: `${TOOLBAR_HEIGHT}px` }}+ data-testid="timeline-dense-toolbar"><ToolbarButtonlabel="Zoom out"@@ -1253,37 +1304,25 @@ export function TimelineDense({<Plus className="h-3 w-3" /></ToolbarButton><ToolbarButton- label="Fit whole trace"+ label={fitted ? "Whole trace already fits" : "Fit whole trace"}onClick={() => flyTo(fitViewport(limits))}+ disabled={fitted}>- <Maximize2 className="h-3 w-3" />+ {/* A viewfinder, not the diagonal arrows this used to wear: those read+ as "fullscreen", so a control that was merely spent looked broken. */}+ <Scan className="h-3 w-3" /></ToolbarButton>- {/* Hidden when there is nothing to expand: a control that cannot do- anything is worse than no control. */}- {canShowNames ? (- <ToolbarButton- label={isOpen ? "Collapse names" : "Show names"}- onClick={() => setOverride(isOpen ? "collapsed" : "expanded")}- >- {isOpen ? (- <PanelLeftClose className="h-3 w-3" />- ) : (- <PanelLeftOpen className="h-3 w-3" />- )}- </ToolbarButton>- ) : null}+ {/* Where you are, when you are somewhere β and nothing at all when the+ whole trace is in view. This carried a list of gestures once. Every+ way of interacting with this surface is one you would have tried:+ drag, scroll, pinch, double-click, click. A caption explaining them+ is a caption nobody reads, taking the room a state readout earns. */}<spanclassName="text-muted-foreground truncate"style={{ fontSize: "10px" }}- title={- fitted- ? "scroll to pan Β· pinch to zoom Β· shift-drag a box Β· double-click to focus"- : `${rowHeight.toFixed(1)}px rows Β· ${windowLabel} window`- }+ title={fitted ? undefined : windowHint}>- {fitted- ? "scroll to pan Β· pinch to zoom Β· shift-drag a box Β· double-click to focus"- : `${rowHeight.toFixed(1)}px rows Β· ${windowLabel} window`}+ {fitted ? null : windowHint}</span></div>@@ -1336,7 +1375,10 @@ export function TimelineDense({ref={attachSurface}className={cn("relative min-h-0 flex-1 overflow-hidden",- dragging ? "cursor-grabbing" : "cursor-grab",+ // A grab hand promised panning, which drag no longer does β it draws a+ // zoom box, so the cursor says nothing until you start one and then+ // says exactly that. The rows carry the clickable cue themselves.+ dragging ? "cursor-crosshair" : "cursor-default",)}style={{ touchAction: "none" }}onPointerDown={onPointerDown}@@ -1406,12 +1448,13 @@ export function TimelineDense({const typeColor = TYPE_COLOR[node.type] ?? FALLBACK_COLOR;// One place decides the bar's colour, so the label can ask about the// exact class the bar got rather than guessing at it.- const barClass =- isFocused || isSelected- ? ACCENT_COLOR- : barColor === "type"- ? typeColor- : NEUTRAL_COLOR;+ //+ // Hue carries TYPE and nothing else. Recolouring a focused bar to the+ // accent meant a hovered generation turned the exact blue that means+ // SPAN, so the palette contradicted itself precisely when someone was+ // inspecting a row. Focus is the row's wash (full width, so it reads+ // at any density) and selection adds a ring β neither touches hue.+ const barClass = barColor === "type" ? typeColor : NEUTRAL_COLOR;return (<div@@ -1425,6 +1468,7 @@ export function TimelineDense({}),)}style={{ top: `${y}px`, height: `${rowHeight}px` }}+ data-testid="timeline-dense-row"// A double-click delivers TWO clicks, and selecting is not free:// it captures an analytics event and reopens the detail panel.// The first click of the pair already selected the row, so the@@ -1468,7 +1512,14 @@ export function TimelineDense({/>) : (<div- className={cn("absolute rounded-[1px]", barClass)}+ className={cn(+ // Clicking selects, and the bar is the part that looks+ // like it would: the row is clickable across its full+ // width, but only the bar reads as a thing.+ "absolute cursor-pointer rounded-[1px]",+ barClass,+ isSelected && "ring-foreground/80 ring-1",+ )}style={{left: `${node.x}px`,width: `${node.width}px`,@@ -1616,7 +1667,7 @@ export function TimelineDense({measuring itself: the side with room is known from the pointer alone,a size is not, and a tooltip that has to be measured before it can beplaced is a tooltip that renders once in the wrong place. */}- {focused && pointerPos && !dragging && pointerPos.x > gutterWidth ? (+ {focused && pointerPos && !dragging ? (<Layer name="tooltip"><divclassName="border-border bg-background text-foreground pointer-events-none fixed flex flex-col gap-0.5 rounded border px-1.5 py-1 shadow-md"@@ -1643,14 +1694,24 @@ export function TimelineDense({<span className="truncate" title={focused.name}>{focused.name}</span>+ {/* What the colour means, next to the colour. */}+ {focused.type ? (+ <span className="text-muted-foreground shrink-0">+ {typeLabel(focused.type)}+ </span>+ ) : null}</span>+ {/* Duration and cost. NOT the start offset: the bar's own position+ on the axis is what says when a span began, and saying it again+ in words was one more number to read past β `@0ms` on a root+ meaning nothing, and two unlabelled durations side by side+ reading as one number repeated. */}<span className="text-muted-foreground flex flex-wrap items-center gap-x-1.5 gap-y-0.5"><span>{focused.durationMs == null? "β": formatDurationMs(focused.durationMs)}</span>- <span>@{formatDurationMs(focused.startMs)}</span>{factsOf?.(focused.id).map((fact) => (<span key={fact}>{fact}</span>))}@@ -1834,10 +1895,17 @@ function GutterContent({function ToolbarButton({label,onClick,+ disabled,children,}: {label: string;onClick: () => void;+ /**+ * A control with nothing to do reads as broken rather than inert β the more so+ * when its icon suggests something dramatic. Say it instead of hiding it: the+ * button is a landmark even when it is spent.+ */+ disabled?: boolean;children: ReactNode;}) {return (@@ -1846,7 +1914,8 @@ function ToolbarButton({aria-label={label}title={label}onClick={onClick}- className="hover:bg-muted flex h-4 w-4 shrink-0 items-center justify-center rounded"+ disabled={disabled}+ className="hover:bg-muted flex h-4 w-4 shrink-0 items-center justify-center rounded disabled:pointer-events-none disabled:opacity-40">{children}</button>diff --git a/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx b/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsxindex d49702f3fb..4cbd3561cd 100644--- a/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx+++ b/web/src/features/traces/components/TraceTimelineDense/TraceTimelineCompact.tsx@@ -11,7 +11,7 @@*/import { useCallback, useMemo, useState } from "react";-import { usdFormatter, formatTokenCounts } from "@/src/utils/numbers";+import { usdFormatter } from "@/src/utils/numbers";import { useTraceData } from "@/src/features/traces/contexts/TraceDataContext";import { useSelection } from "@/src/features/traces/contexts/SelectionContext";import {@@ -26,7 +26,7 @@ import { TimelineDense } from "./TimelineDense";export function TraceTimelineCompact() {const { roots, nodeMap } = useTraceData();- const { selectedNodeId } = useSelection();+ const { selectedNodeId, collapsedNodes } = useSelection();const { handleHover } = useHandlePrefetchObservation();const selectNode = useSelectTraceNode("timeline_compact");@@ -81,26 +81,21 @@ export function TraceTimelineCompact() {[nodeMap, handleHover],);- // Cost and usage the way the tree row states them, so hovering a hairline row- // tells you what reading a tree row would. Same formatters, same order.+ /**+ * Cost, and only cost. Tokens used to come too, which put six numbers in a+ * hover β and only on the spans that HAVE usage, so the tooltip changed shape+ * from row to row. Cost is the one figure that means the same thing on every+ * kind of span; the token split is a click away in the detail panel. Same+ * formatter and the same `β` for a subtotal as the tree row uses.+ */const factsOf = useCallback((nodeId: string) => {const node = nodeMap.get(nodeId);- if (!node) return [];- const facts: string[] = [];- if (node.totalCost) {- const aggregated = node.children.length > 0 || node.type === "TRACE";- facts.push(- `${aggregated ? "β " : ""}${usdFormatter(node.totalCost.toNumber())}`,- );- }- const tokens = formatTokenCounts(- node.inputUsage,- node.outputUsage,- node.totalUsage,- );- if (tokens) facts.push(tokens);- return facts;+ if (!node?.totalCost) return [];+ const aggregated = node.children.length > 0 || node.type === "TRACE";+ return [+ `${aggregated ? "β " : ""}${usdFormatter(node.totalCost.toNumber())}`,+ ];},[nodeMap],);@@ -112,6 +107,7 @@ export function TraceTimelineCompact() {roots={roots}box={box}gutter="auto"+ collapsed={collapsedNodes}pointer={pointerModality}barColor="type"compress={false}