Skip to content

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

feat(session): Timeline UI improvements (#17313)

Ben Bachemff097a5f2bf5
diff --git a/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx b/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx
index 41af049970..d8c1fc6b9e 100644
--- a/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx
+++ b/web/src/features/sessions/ConnectedModernSessionBodyTimeline.tsx
@@ -1,4 +1,4 @@
-import { useRef, useState } from "react";
+import { useEffect, useEffectEvent, useRef, useState } from "react";
import { type FilterState } from "@langfuse/shared";
import {
@@ -241,6 +241,7 @@ export function ConnectedModernSessionBodyTimeline({
}
const sidebarTraces: ModernSessionSidebarTrace[] = [];
+ const incompleteTimelineTraceIds = new Set<string>();
for (const [index, trace] of traces.entries()) {
const chunkIndex = Math.floor(index / SIDEBAR_TRACE_CHUNK_SIZE);
const chunkKey = `browse:${filterMeasurementKey}:${chunkIndex}`;
@@ -267,6 +268,7 @@ export function ConnectedModernSessionBodyTimeline({
const mayHaveMoreObservations = Boolean(
lastRelevantQuery?.isPending || lastRelevantQuery?.data?.hasMore,
);
+ if (mayHaveMoreObservations) incompleteTimelineTraceIds.add(trace.id);
const observations =
isPending && !hasLoadedObservations
? undefined
@@ -324,6 +326,12 @@ export function ConnectedModernSessionBodyTimeline({
return next;
});
};
+ const autoLoadMoreObservations = useEffectEvent(loadMoreObservations);
+
+ useEffect(() => {
+ if (!hasMoreObservations || isLoadingMoreObservations) return;
+ autoLoadMoreObservations();
+ }, [hasMoreObservations, isLoadingMoreObservations]);
const handleVisibleTraceIdsChange = (nextTraceIds: string[]) => {
const highestVisibleTraceIndex = nextTraceIds.reduce(
@@ -373,7 +381,8 @@ export function ConnectedModernSessionBodyTimeline({
const observations =
sidebarTrace?.observations === null
? null
- : sidebarTrace?.observations === undefined
+ : sidebarTrace?.observations === undefined ||
+ incompleteTimelineTraceIds.has(trace.id)
? undefined
: (timelineObservationsByTraceId.get(trace.id) ?? []);
diff --git a/web/src/features/sessions/ModernSessionSidebar.stories.tsx b/web/src/features/sessions/ModernSessionSidebar.stories.tsx
index 36723698b5..6c5d2fc9ed 100644
--- a/web/src/features/sessions/ModernSessionSidebar.stories.tsx
+++ b/web/src/features/sessions/ModernSessionSidebar.stories.tsx
@@ -494,6 +494,7 @@ export const TestSelectsFilteredTurnByStableNumber = meta.story({
const canvas = within(canvasElement);
await expect(canvas.getByText("3")).toBeInTheDocument();
await expect(canvas.getByText("Matching observation")).toBeInTheDocument();
+ await expect(canvas.queryByText(/idle$/)).not.toBeInTheDocument();
await userEvent.click(
canvas.getByRole("button", { name: /Summarize findings/i }),
diff --git a/web/src/features/sessions/ModernSessionSidebar.tsx b/web/src/features/sessions/ModernSessionSidebar.tsx
index 5140210163..a92222c9a2 100644
--- a/web/src/features/sessions/ModernSessionSidebar.tsx
+++ b/web/src/features/sessions/ModernSessionSidebar.tsx
@@ -665,7 +665,8 @@ export function ModernSessionSidebar(
virtualItem={virtualItem}
virtualizer={virtualizer}
>
- {gap !== null &&
+ {search.trim() === "" &&
+ gap !== null &&
gap !== undefined &&
gap >= IDLE_GAP_THRESHOLD_SECONDS ? (
<div className="my-0.5 mb-2 flex items-center bg-[repeating-linear-gradient(315deg,hsl(var(--foreground)/0.07)_0_1px,transparent_1px_5px)] px-3 py-[5px]">
diff --git a/web/src/features/sessions/SessionConversationTimeline/SessionConversationTimeline.stories.tsx b/web/src/features/sessions/SessionConversationTimeline/SessionConversationTimeline.stories.tsx
index 30e57eef8b..3eab0bd173 100644
--- a/web/src/features/sessions/SessionConversationTimeline/SessionConversationTimeline.stories.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/SessionConversationTimeline.stories.tsx
@@ -1695,15 +1695,32 @@ Active filter: level is ERROR
],
});
const generationOutput = JSON.stringify(
- action.tools.length > 0
+ actionIndex === inAppAgentActions.length - 1
? {
- tool_calls: action.tools.map((tool, toolIndex) => ({
- args: tool.input,
- toolCallId: `error-analysis-call-${actionIndex + 1}-${toolIndex + 1}`,
- toolName: tool.name,
- })),
+ role: "assistant",
+ content: [
+ {
+ taxonomy: {
+ primaryIssue: "tool-timeout",
+ affectedWorkflow: "booking-assistant",
+ recommendedFix: "Add bounded retries with backoff",
+ },
+ tracking: {
+ metric: "tool_error_rate",
+ owner: "agent-platform",
+ },
+ },
+ ],
}
- : { text: action.summary },
+ : action.tools.length > 0
+ ? {
+ tool_calls: action.tools.map((tool, toolIndex) => ({
+ args: tool.input,
+ toolCallId: `error-analysis-call-${actionIndex + 1}-${toolIndex + 1}`,
+ toolName: tool.name,
+ })),
+ }
+ : { text: action.summary },
);
return [
@@ -2064,7 +2081,7 @@ export const RenderLoadedConversation = meta.story({
await expect(
within(
generation?.closest("[data-session-observation-depth]") as HTMLElement,
- ).queryByRole("button", { name: "Show 1 tool" }),
+ ).queryByRole("button", { name: /^Show .*tool/ }),
).not.toBeInTheDocument();
await expect(
canvas.queryByRole("button", { name: "get_order" }),
@@ -2134,6 +2151,61 @@ export const TruncatedObservation = meta.story({
},
});
+export const ObservationIssues = meta.story({
+ name: "(Test) Renders Observation Issues",
+ args: {
+ ...loadedArgs,
+ traces: [
+ {
+ trace,
+ turnNumber: 1,
+ observations: [
+ {
+ ...observations[0]!,
+ level: "WARNING",
+ statusMessage:
+ "TimeoutError: Model response exceeded 30s\n at generateResponse (src/agent.ts:42:11)\n at async runTurn (src/session.ts:18:5)",
+ },
+ {
+ ...observations[1]!,
+ level: "ERROR",
+ statusMessage: JSON.stringify(
+ {
+ code: "TOOL_TIMEOUT",
+ tool: "get_order",
+ retryable: true,
+ },
+ null,
+ 2,
+ ),
+ },
+ ],
+ },
+ ],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const warning = canvas.getByRole("img", {
+ name: /WARNING: TimeoutError: Model response exceeded 30s/,
+ });
+ const error = canvas.getByRole("img", {
+ name: /ERROR:.*TOOL_TIMEOUT/s,
+ });
+
+ await expect(warning).toHaveClass("bg-light-yellow", "text-dark-yellow");
+ await expect(error).toHaveClass("bg-light-red", "text-dark-red");
+ await userEvent.hover(warning);
+ await expect(
+ await within(canvasElement.ownerDocument.body).findByRole("tooltip"),
+ ).toHaveTextContent("at generateResponse (src/agent.ts:42:11)");
+ await userEvent.unhover(warning);
+ await userEvent.hover(error);
+ await expect(
+ await within(canvasElement.ownerDocument.body).findByRole("tooltip"),
+ ).toHaveTextContent('"code": "TOOL_TIMEOUT"');
+ },
+});
+
export const UseObservationFilters = meta.story({
name: "(Test) Uses Observation Filters",
args: {
@@ -2275,6 +2347,11 @@ export const ExpandToolObservation = meta.story({
await expect(toolPreviews).toHaveLength(2);
await expect(toolPreviews[0]).toHaveTextContent('{"orderId":"LF-20481"}');
await expect(toolPreviews[1]).toHaveTextContent('"status":"processing"');
+ await expect(
+ expandButton
+ .closest("[data-session-observation-depth]")
+ ?.querySelector("[data-session-observation-rail-end]"),
+ ).not.toBeInTheDocument();
await userEvent.click(
canvas.getByRole("button", { name: "Collapse Get order" }),
@@ -2303,7 +2380,7 @@ export const ExpandRolledUpTool = meta.story({
?.closest("[data-session-observation-depth]");
await userEvent.click(
within(generation as HTMLElement).getByRole("button", {
- name: "Show 1 tool",
+ name: "Show tools: get_order",
}),
);
const expandButton = canvas.getByRole("button", {
@@ -2322,13 +2399,10 @@ export const ExpandRolledUpTool = meta.story({
"data-session-observation-depth",
"1",
);
- await expect(toolRow).toHaveStyle({ paddingLeft: "24px" });
+ await expect(toolRow).not.toHaveAttribute("style");
await expect(
toolRow?.querySelector('[data-session-observation-rail-depth="0"]'),
- ).toBeInTheDocument();
- await expect(
- toolRow?.querySelector('[data-session-observation-rail-depth="1"]'),
- ).not.toBeInTheDocument();
+ ).toHaveClass("left-[7px]");
await expect(toolIcon).not.toBeNull();
await userEvent.hover(unavailableActionsIcon);
await expect(
@@ -2339,10 +2413,38 @@ export const ExpandRolledUpTool = meta.story({
await userEvent.click(expandButton);
await expect(
- toolRow?.querySelector('[data-session-observation-rail-depth="1"]'),
- ).toBeInTheDocument();
+ toolRow?.querySelectorAll("[data-session-observation-rail-depth]"),
+ ).toHaveLength(1);
await expect(
toolRow?.querySelector("[data-session-observation-rail-end]"),
+ ).not.toBeInTheDocument();
+ },
+});
+
+export const ExpandFinalToolObservation = meta.story({
+ name: "(Test) Ends Rail After Final Expanded Tool",
+ args: {
+ ...loadedArgs,
+ traces: [
+ {
+ trace: { ...trace, observationCount: 1 },
+ turnNumber: 1,
+ observations: [observations[1]!],
+ },
+ ],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const expandButton = canvas.getByRole("button", {
+ name: "Expand Get order",
+ });
+
+ await userEvent.click(expandButton);
+
+ await expect(
+ expandButton
+ .closest("[data-session-observation-depth]")
+ ?.querySelector("[data-session-observation-rail-end]"),
).toBeInTheDocument();
},
});
@@ -2425,6 +2527,9 @@ export const ExpandNestedObservations = meta.story({
const rootToggle = canvas.getByRole("button", {
name: "Show 2 generations and 5 tools",
});
+ await expect(
+ canvas.getByText("2 generations and 5 tools"),
+ ).toBeInTheDocument();
const rootStart = rootToggle.closest("[data-session-observation-depth]");
await expect(
rootStart?.querySelector('[data-session-observation-rail-depth="0"]'),
@@ -2438,22 +2543,30 @@ export const ExpandNestedObservations = meta.story({
await expect(
rootToggle.querySelector(".lucide-chevrons-up-down"),
).not.toBeNull();
+ await userEvent.hover(rootToggle);
+ await expect(
+ rootStart?.querySelector('[data-session-observation-rail-depth="0"]'),
+ ).toHaveClass("bg-border");
+ await userEvent.unhover(rootToggle);
const initialRootToggleTop = rootToggle.getBoundingClientRect().top;
// Expanding a parent reveals its direct children, but nested groups remain collapsed.
await userEvent.click(rootToggle);
- // Expanding the rail must not move the toggle the user just clicked.
+ // Message content leaves room to move the collapse control up one row.
await expect(rootToggle.getBoundingClientRect().top).toBe(
- initialRootToggleTop,
+ initialRootToggleTop - 28,
);
await expect(canvas.getByText("generation-1")).toBeInTheDocument();
await expect(canvas.getByText("generation-2")).toBeInTheDocument();
await expect(canvas.queryByText("tool-1")).not.toBeInTheDocument();
await expect(rootToggle.parentElement).toHaveClass("h-0");
await expect(
- rootToggle.querySelector(".lucide-chevrons-down-up"),
+ rootToggle.querySelector(".lucide-chevron-down"),
).not.toBeNull();
+ await expect(
+ rootStart?.querySelector('[data-session-observation-rail-depth="0"]'),
+ ).toHaveClass("bg-border");
const nestedGeneration = canvasElement
.querySelector('[data-session-observation-id="generation-1"]')
?.closest("[data-session-observation-depth]");
@@ -2461,31 +2574,44 @@ export const ExpandNestedObservations = meta.story({
"data-session-observation-depth",
"1",
);
- await expect(nestedGeneration).toHaveStyle({ paddingLeft: "24px" });
+ await expect(nestedGeneration).not.toHaveAttribute("style");
await expect(
nestedGeneration?.querySelectorAll(
"[data-session-observation-rail-depth]",
),
- ).toHaveLength(2);
+ ).toHaveLength(1);
const nestedObservationIcon = nestedGeneration?.querySelector(
'[data-session-observation-id="generation-1"] button svg',
);
await expect(nestedObservationIcon).not.toBeNull();
- const rootToggleRect = rootToggle.getBoundingClientRect();
- const nestedObservationIconRect = (
- nestedObservationIcon as SVGElement
- ).getBoundingClientRect();
- // The rail toggle stays vertically centered with the child observation icon beside it.
- await expect(rootToggleRect.top + rootToggleRect.height / 2).toBe(
- nestedObservationIconRect.top + nestedObservationIconRect.height / 2,
- );
- const nestedToggle = canvas.getByRole("button", { name: "Show 3 tools" });
+ rootToggle.blur();
+ await userEvent.hover(rootToggle);
+ await expect(
+ rootToggle.parentElement?.querySelector(
+ "[data-session-collapse-rail-highlight]",
+ ),
+ ).toBeInTheDocument();
+ await expect(
+ rootStart?.querySelector('[data-session-observation-rail-depth="0"]'),
+ ).toHaveClass("bg-border");
+ await expect(
+ nestedGeneration?.querySelector("[data-session-observation-rail-depth]"),
+ ).toHaveClass("bg-primary/60");
+ await expect(
+ closingRailEnd
+ ?.closest("[data-session-observation-depth]")
+ ?.querySelector("[data-session-observation-rail-depth]"),
+ ).toHaveClass("bg-border");
+ await userEvent.unhover(rootToggle);
+ const nestedToggle = canvas.getByRole("button", {
+ name: "Show tools: tool-1, tool-2, and tool-3",
+ });
const initialNestedToggleTop = nestedToggle.getBoundingClientRect().top;
// Nested observations expand independently from their ancestors.
await userEvent.click(nestedToggle);
- // Expanding a nested rail must keep its toggle anchored too.
+ // A message-less observation retains its control row to avoid its icon.
await expect(nestedToggle.getBoundingClientRect().top).toBe(
initialNestedToggleTop,
);
@@ -2497,30 +2623,40 @@ export const ExpandNestedObservations = meta.story({
"data-session-observation-depth",
"2",
);
- await expect(nestedTool).toHaveStyle({ paddingLeft: "48px" });
+ await expect(nestedTool).not.toHaveAttribute("style");
await expect(
nestedTool?.querySelectorAll("[data-session-observation-rail-depth]"),
- ).toHaveLength(2);
+ ).toHaveLength(1);
await expect(
- nestedTool?.querySelector('[data-session-observation-rail-depth="2"]'),
- ).not.toBeInTheDocument();
+ nestedTool?.querySelector("[data-session-observation-rail-depth]"),
+ ).toHaveClass("left-[7px]");
+
+ nestedToggle.blur();
+ await userEvent.hover(nestedToggle);
+ await expect(
+ nestedTool?.querySelector("[data-session-observation-rail-depth]"),
+ ).toHaveClass("bg-primary/60");
+ await userEvent.unhover(nestedToggle);
+ await expect(
+ nestedTool?.querySelector("[data-session-observation-rail-depth]"),
+ ).toHaveClass("bg-border");
await userEvent.click(
canvas.getByRole("button", { name: "Expand tool-1" }),
);
await expect(
- nestedTool?.querySelector('[data-session-observation-rail-depth="2"]'),
- ).toHaveClass("top-[22px]");
+ nestedTool?.querySelectorAll("[data-session-observation-rail-depth]"),
+ ).toHaveLength(1);
await expect(
nestedTool?.querySelector("[data-session-observation-rail-end]"),
- ).toBeInTheDocument();
+ ).not.toBeInTheDocument();
await userEvent.click(
canvas.getByRole("button", { name: "Collapse tool-1" }),
);
await expect(
- nestedTool?.querySelector('[data-session-observation-rail-depth="2"]'),
- ).not.toBeInTheDocument();
+ nestedTool?.querySelectorAll("[data-session-observation-rail-depth]"),
+ ).toHaveLength(1);
await expect(
nestedTool?.querySelector("[data-session-observation-rail-end]"),
).not.toBeInTheDocument();
@@ -2529,13 +2665,15 @@ export const ExpandNestedObservations = meta.story({
await userEvent.click(nestedToggle);
- // Collapsing the nested rail must not move the toggle either.
+ // Collapsing returns the expand control to its summary row.
await expect(nestedToggle.getBoundingClientRect().top).toBe(
initialNestedToggleTop,
);
await expect(canvas.queryByText("tool-1")).not.toBeInTheDocument();
await expect(
- canvas.getByRole("button", { name: "Show 3 tools" }),
+ canvas.getByRole("button", {
+ name: "Show tools: tool-1, tool-2, and tool-3",
+ }),
).toBeInTheDocument();
},
});
@@ -2586,7 +2724,11 @@ export const ToolObservationDataOnly = meta.story({
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- await userEvent.click(canvas.getByRole("button", { name: "Show 1 tool" }));
+ await userEvent.click(
+ canvas.getByRole("button", {
+ name: "Show tools: get_subscription_details",
+ }),
+ );
await expect(
canvas.getAllByRole("button", { name: "get_subscription_details" }),
).toHaveLength(1);
@@ -2611,7 +2753,11 @@ export const GenerationToolDataOnly = meta.story({
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- await userEvent.click(canvas.getByRole("button", { name: "Show 1 tool" }));
+ await userEvent.click(
+ canvas.getByRole("button", {
+ name: "Show tools: get_subscription_details",
+ }),
+ );
await expect(
canvas.getAllByRole("button", { name: "get_subscription_details" }),
).toHaveLength(1);
@@ -2645,7 +2791,11 @@ export const DeduplicateMatchingToolData = meta.story({
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- await userEvent.click(canvas.getByRole("button", { name: "Show 1 tool" }));
+ await userEvent.click(
+ canvas.getByRole("button", {
+ name: "Show tools: get_subscription_details",
+ }),
+ );
await expect(
canvas.getAllByRole("button", { name: "get_subscription_details" }),
).toHaveLength(1);
@@ -2684,7 +2834,11 @@ export const KeepDifferentToolData = meta.story({
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- await userEvent.click(canvas.getByRole("button", { name: "Show 2 tools" }));
+ await userEvent.click(
+ canvas.getByRole("button", {
+ name: "Show tools: search_documentation and get_customer_profile",
+ }),
+ );
await expect(
canvas.getAllByRole("button", { name: "search_documentation" }),
).toHaveLength(1);
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
index b6d488c436..e2f7df6056 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
@@ -75,7 +75,7 @@ describe("SessionConversationTimelineTrace", () => {
expect(screen.getByText("grandchild")).toBeInTheDocument();
const parentToggle = screen.getByRole("button", {
- name: "Hide 1 tool",
+ name: "Hide tools: grandchild",
});
fireEvent.click(parentToggle);
expect(screen.queryByText("grandchild")).not.toBeInTheDocument();
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
index 88cfc68801..dae486e625 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
@@ -1,11 +1,13 @@
-import { useState } from "react";
+import { useMemo, useState } from "react";
import {
ChevronDown,
- ChevronsDownUp,
ChevronsUpDown,
+ CircleAlert,
FileWarning,
+ Info,
MessageSquareOff,
MoreHorizontal,
+ TriangleAlert,
} from "lucide-react";
import { renderFilterIcon } from "@/src/components/ItemBadge";
import {
@@ -33,6 +35,7 @@ import {
import { type RouterOutputs } from "@/src/utils/api";
import { formatIntervalSeconds } from "@/src/utils/dates";
import { cn } from "@/src/utils/tailwind";
+import { getLevelColors } from "@/src/components/level-colors";
type EventObservation = RouterOutputs["events"]["all"]["observations"][number];
type EventObservationIO = RouterOutputs["events"]["batchIO"][number];
@@ -66,6 +69,41 @@ export type SessionObservationActions = {
onFilterByName: (name: string, operator: "any of" | "none of") => void;
};
+function SessionTimelineStatusIndicator({
+ observation,
+}: {
+ observation: SessionObservation;
+}) {
+ const Icon =
+ observation.level === "ERROR"
+ ? CircleAlert
+ : observation.level === "WARNING"
+ ? TriangleAlert
+ : Info;
+ const colors = getLevelColors(observation.level);
+
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span
+ className={cn(
+ "flex h-5 w-5 shrink-0 items-center justify-center rounded-md",
+ colors.bg,
+ colors.text,
+ )}
+ role="img"
+ aria-label={`${observation.level}: ${observation.statusMessage}`}
+ >
+ <Icon className="h-3.5 w-3.5" aria-hidden="true" />
+ </span>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm whitespace-pre-wrap">
+ {observation.statusMessage}
+ </TooltipContent>
+ </Tooltip>
+ );
+}
+
const toPreviewText = (value: unknown) =>
typeof value === "string"
? value
@@ -123,9 +161,31 @@ function SessionTimelineRailEnd() {
const NESTED_OBSERVATION_TYPE_ORDER = ["GENERATION", "TOOL"];
-const formatNestedObservationCounts = (
- counts: Readonly<Record<string, number>>,
-) => {
+function getNestedObservationSummary(
+ observations: readonly PreparedSessionTimelineItem<SessionObservation>[],
+) {
+ const seenObservationIds = new Set<string>();
+ const toolNames = new Set<string>();
+ const counts: Record<string, number> = {};
+
+ for (const item of observations) {
+ if (item.type === "tool") {
+ counts.TOOL = (counts.TOOL ?? 0) + 1;
+ toolNames.add(item.toolCall.toolName);
+ continue;
+ }
+
+ const observationKey = `${item.observation.traceId ?? ""}:${item.observation.id}`;
+ if (seenObservationIds.has(observationKey)) continue;
+
+ seenObservationIds.add(observationKey);
+ const type = item.observation.type ?? "EVENT";
+ counts[type] = (counts[type] ?? 0) + 1;
+ if (type === "TOOL" && item.observation.name) {
+ toolNames.add(item.observation.name);
+ }
+ }
+
const labels = Object.entries(counts)
.filter(([, count]) => count > 0)
.sort(([left], [right]) => {
@@ -136,22 +196,36 @@ const formatNestedObservationCounts = (
if (rightIndex !== -1) return 1;
return left.localeCompare(right);
})
- .map(
- ([type, count]) =>
- `${count} ${type.toLowerCase()}${count === 1 ? "" : "s"}`,
- );
+ .map(([type, count]) => {
+ if (type !== "TOOL") {
+ return `${count} ${type.toLowerCase()}${count === 1 ? "" : "s"}`;
+ }
+
+ const names = count <= 3 ? Array.from(toolNames) : [];
+ const namesSummary =
+ names.length < 2
+ ? (names[0] ?? "")
+ : names.length === 2
+ ? `${names[0]} and ${names[1]}`
+ : `${names.slice(0, -1).join(", ")}, and ${names.at(-1)}`;
+ if (names.length === count) return `tools: ${namesSummary}`;
+
+ return `${count} tool${count === 1 ? "" : "s"}${namesSummary ? ` using ${namesSummary}` : ""}`;
+ });
if (labels.length < 2) return labels[0] ?? "nested observations";
if (labels.length === 2) return `${labels[0]} and ${labels[1]}`;
return `${labels.slice(0, -1).join(", ")}, and ${labels.at(-1)}`;
-};
+}
function TruncatedObservation({
observation,
phase,
+ showRailEnd,
}: {
observation: SessionObservation;
phase: "complete" | "start" | "end";
+ showRailEnd: boolean;
}) {
return (
<div className="flex flex-col gap-5">
@@ -162,7 +236,9 @@ function TruncatedObservation({
parts={[{ type: "text", text: toPreviewText(observation.input) }]}
senderName={undefined}
/>
- {phase === "complete" && !hasPreviewValue(observation.output) ? (
+ {showRailEnd &&
+ phase === "complete" &&
+ !hasPreviewValue(observation.output) ? (
<SessionTimelineRailEnd />
) : null}
</div>
@@ -174,7 +250,7 @@ function TruncatedObservation({
parts={[{ type: "text", text: toPreviewText(observation.output) }]}
senderName={undefined}
/>
- <SessionTimelineRailEnd />
+ {showRailEnd ? <SessionTimelineRailEnd /> : null}
</div>
) : null}
</div>
@@ -191,6 +267,7 @@ function SessionTimelineToolRow({
inputTruncated,
outputTruncated,
isExpanded,
+ showRailEnd,
onExpandedChange,
onOpenInTraceView,
observation,
@@ -205,6 +282,7 @@ function SessionTimelineToolRow({
inputTruncated?: boolean;
outputTruncated?: boolean;
isExpanded: boolean;
+ showRailEnd: boolean;
onExpandedChange: (isExpanded: boolean) => void;
onOpenInTraceView: () => void;
observation?: SessionObservation;
@@ -247,6 +325,9 @@ function SessionTimelineToolRow({
/>
</button>
<span className="ml-auto flex shrink-0 items-center gap-2">
+ {observation?.statusMessage && observation.level !== "DEFAULT" ? (
+ <SessionTimelineStatusIndicator observation={observation} />
+ ) : null}
{latency !== null ? (
<span className="text-muted-foreground font-mono text-[11px]">
{formatIntervalSeconds(latency)}
@@ -301,7 +382,9 @@ function SessionTimelineToolRow({
<pre className="bg-muted/30 max-h-48 overflow-auto rounded-md border p-3 font-mono text-xs break-all whitespace-pre-wrap">
{toPreviewText(input)}
</pre>
- {!hasPreviewValue(output) ? <SessionTimelineRailEnd /> : null}
+ {!hasPreviewValue(output) && showRailEnd ? (
+ <SessionTimelineRailEnd />
+ ) : null}
</div>
) : null}
{hasPreviewValue(output) ? (
@@ -312,7 +395,7 @@ function SessionTimelineToolRow({
<pre className="bg-muted/30 max-h-48 overflow-auto rounded-md border p-3 font-mono text-xs break-all whitespace-pre-wrap">
{toPreviewText(output)}
</pre>
- <SessionTimelineRailEnd />
+ {showRailEnd ? <SessionTimelineRailEnd /> : null}
</div>
) : null}
{!hasPreviewValue(input) && !hasPreviewValue(output) ? (
@@ -320,7 +403,7 @@ function SessionTimelineToolRow({
<span className="text-muted-foreground text-xs">
No input or output
</span>
- <SessionTimelineRailEnd />
+ {showRailEnd ? <SessionTimelineRailEnd /> : null}
</div>
) : null}
</div>
@@ -334,6 +417,7 @@ function SessionTimelineConversationObservation({
parsed,
processedMessages,
phase,
+ showRailEnd,
onOpenInTraceView,
actions,
}: {
@@ -341,6 +425,7 @@ function SessionTimelineConversationObservation({
parsed: ParsedSessionTimelineObservation | null;
processedMessages: PreparedSessionTimelineMessages;
phase: "complete" | "start" | "end";
+ showRailEnd: boolean;
onOpenInTraceView: () => void;
actions?: SessionObservationActions;
}) {
@@ -387,6 +472,9 @@ function SessionTimelineConversationObservation({
</span>
</button>
<span className="ml-auto flex shrink-0 items-center gap-2">
+ {observation.statusMessage && observation.level !== "DEFAULT" ? (
+ <SessionTimelineStatusIndicator observation={observation} />
+ ) : null}
{isTruncated ? (
<span
className="bg-muted text-muted-foreground shrink-0 rounded-md p-1"
@@ -452,7 +540,11 @@ function SessionTimelineConversationObservation({
) : null}
<div className="flex min-w-0 flex-col gap-5 pl-[22px]">
{isTruncated ? (
- <TruncatedObservation observation={observation} phase={phase} />
+ <TruncatedObservation
+ observation={observation}
+ phase={phase}
+ showRailEnd={showRailEnd}
+ />
) : showNonMessageBody && parsed?.type === "error" ? (
<div className="border-destructive/40 bg-destructive/5 flex items-center justify-between gap-3 rounded-lg border p-3">
<span className="text-destructive text-xs">
@@ -484,7 +576,9 @@ function SessionTimelineConversationObservation({
className="relative"
>
{messageContent}
- {phase !== "start" && index === visibleMessages.length - 1 ? (
+ {showRailEnd &&
+ phase !== "start" &&
+ index === visibleMessages.length - 1 ? (
<SessionTimelineRailEnd />
) : null}
</div>
@@ -502,6 +596,7 @@ function SessionTimelineObservation({
processedMessages,
phase,
isToolExpanded,
+ showRailEnd,
onToolExpandedChange,
onOpenInTraceView,
actions,
@@ -511,6 +606,7 @@ function SessionTimelineObservation({
processedMessages: PreparedSessionTimelineMessages;
phase: "complete" | "start" | "end";
isToolExpanded: boolean;
+ showRailEnd: boolean;
onToolExpandedChange: (isExpanded: boolean) => void;
onOpenInTraceView: () => void;
actions?: SessionObservationActions;
@@ -527,6 +623,7 @@ function SessionTimelineObservation({
inputTruncated={observation.inputTruncated}
outputTruncated={observation.outputTruncated}
isExpanded={isToolExpanded}
+ showRailEnd={showRailEnd}
onExpandedChange={onToolExpandedChange}
onOpenInTraceView={onOpenInTraceView}
observation={observation}
@@ -541,6 +638,7 @@ function SessionTimelineObservation({
parsed={parsed}
processedMessages={processedMessages}
phase={phase}
+ showRailEnd={showRailEnd}
onOpenInTraceView={onOpenInTraceView}
actions={actions}
/>
@@ -577,6 +675,33 @@ function LoadedSessionConversationTimeline({
const [expandedToolObservationIds, setExpandedToolObservationIds] = useState(
() => new Set<string>(),
);
+ const [hoveredSubsectionId, setHoveredSubsectionId] = useState<string | null>(
+ null,
+ );
+ const [focusedSubsectionId, setFocusedSubsectionId] = useState<string | null>(
+ null,
+ );
+ const highlightedSubsectionId = hoveredSubsectionId ?? focusedSubsectionId;
+ const nestedObservationSummaries = useMemo(() => {
+ const observationsByAncestorId = new Map<
+ string,
+ PreparedSessionTimelineItem<SessionObservation>[]
+ >();
+ for (const item of observations) {
+ for (const ancestorId of item.ancestorObservationIds) {
+ const nestedObservations = observationsByAncestorId.get(ancestorId);
+ if (nestedObservations) nestedObservations.push(item);
+ else observationsByAncestorId.set(ancestorId, [item]);
+ }
+ }
+
+ return new Map(
+ Array.from(observationsByAncestorId, ([observationId, nestedItems]) => [
+ observationId,
+ getNestedObservationSummary(nestedItems),
+ ]),
+ );
+ }, [observations]);
let collapsedObservationIds = collapseState.observationIds;
if (
scrollTarget &&
@@ -594,10 +719,30 @@ function LoadedSessionConversationTimeline({
});
}
+ const visibleObservations = observations.filter((item) => {
+ if (
+ item.ancestorObservationIds.some((ancestorId) =>
+ collapsedObservationIds.has(ancestorId),
+ )
+ ) {
+ return false;
+ }
+ if (item.type === "tool") return true;
+ if (item.observation.type === "TOOL" && item.phase === "start") {
+ return Object.keys(item.nestedObservationCounts).length > 0;
+ }
+ if (item.phase !== "end") return true;
+ if (item.processedMessages.messages.length > 0) return true;
+ return Boolean(
+ item.observation.outputTruncated &&
+ hasPreviewValue(item.observation.output),
+ );
+ });
+
return (
<TooltipProvider>
<div className="flex flex-col gap-1">
- {observations.map((item) => {
+ {visibleObservations.map((item, index) => {
const {
observation,
parsed,
@@ -606,14 +751,6 @@ function LoadedSessionConversationTimeline({
ancestorObservationIds,
nestedObservationCounts,
} = item;
- if (
- ancestorObservationIds.some((ancestorId) =>
- collapsedObservationIds.has(ancestorId),
- )
- ) {
- return null;
- }
-
const isToolStart =
item.type === "observation" &&
observation.type === "TOOL" &&
@@ -627,6 +764,9 @@ function LoadedSessionConversationTimeline({
);
const hasNestedObservations =
Object.keys(nestedObservationCounts).length > 0;
+ const nestedObservationSummary = hasNestedObservations
+ ? (nestedObservationSummaries.get(observation.id) ?? "")
+ : "";
const isCollapsed = collapsedObservationIds.has(observation.id);
const itemId = item.type === "tool" ? item.id : observation.id;
const isToolExpanded = expandedToolObservationIds.has(itemId);
@@ -637,6 +777,12 @@ function LoadedSessionConversationTimeline({
? (phase !== "end" && hasPreviewValue(observation.input)) ||
(phase !== "start" && hasPreviewValue(observation.output))
: processedMessages.messages.length > 0);
+ const moveCollapseControlUp = !isCollapsed && hasChatBubbles;
+ const isHighlightedSubsection =
+ highlightedSubsectionId === observation.id && phase === "start";
+ const isHighlightedDescendant = highlightedSubsectionId
+ ? ancestorObservationIds.includes(highlightedSubsectionId)
+ : false;
const depth = ancestorObservationIds.length;
@@ -647,34 +793,35 @@ function LoadedSessionConversationTimeline({
}
data-session-observation-depth={depth}
className="relative"
- style={{ paddingLeft: `${depth * 24}px` }}
>
- {ancestorObservationIds.map((ancestorId, ancestorDepth) => (
+ {ancestorObservationIds.length > 0 ? (
<span
- key={ancestorId}
- data-session-observation-rail-depth={ancestorDepth}
- className="bg-border pointer-events-none absolute -top-1 -bottom-1 w-px"
- style={{ left: `${ancestorDepth * 24 + 7}px` }}
+ data-session-observation-rail-depth={depth - 1}
+ className={cn(
+ "pointer-events-none absolute -top-1 -bottom-1 left-[7px] w-px transition-colors",
+ isHighlightedDescendant ? "bg-primary/60" : "bg-border",
+ )}
aria-hidden="true"
/>
- ))}
- {(phase === "start" && !isToolStart) ||
- (phase === "complete" && (hasChatBubbles || isToolExpanded)) ? (
+ ) : null}
+ {depth === 0 &&
+ ((phase === "start" && !isToolStart) ||
+ (phase === "complete" &&
+ (hasChatBubbles || isToolExpanded))) ? (
<span
data-session-observation-rail-depth={depth}
className={cn(
- "bg-border pointer-events-none absolute top-[22px] w-px",
+ "pointer-events-none absolute top-[22px] left-[7px] w-px transition-colors",
+ "bg-border",
phase === "start" ? "-bottom-1" : "bottom-0",
)}
- style={{ left: `${depth * 24 + 7}px` }}
aria-hidden="true"
/>
) : null}
- {phase === "end" ? (
+ {depth === 0 && phase === "end" ? (
<span
data-session-observation-rail-depth={depth}
- className="bg-border pointer-events-none absolute -top-1 bottom-0 w-px"
- style={{ left: `${depth * 24 + 7}px` }}
+ className="bg-border pointer-events-none absolute -top-1 bottom-0 left-[7px] w-px"
aria-hidden="true"
/>
) : null}
@@ -687,6 +834,7 @@ function LoadedSessionConversationTimeline({
input={item.toolCall.input}
output={undefined}
isExpanded={isToolExpanded}
+ showRailEnd={false}
onExpandedChange={(isExpanded) =>
setExpandedToolObservationIds((current) => {
const next = new Set(current);
@@ -704,6 +852,11 @@ function LoadedSessionConversationTimeline({
processedMessages={processedMessages}
phase={phase}
isToolExpanded={isToolExpanded}
+ showRailEnd={
+ depth === 0 &&
+ (observation.type !== "TOOL" ||
+ index === visibleObservations.length - 1)
+ }
onToolExpandedChange={(isExpanded) =>
setExpandedToolObservationIds((current) => {
const next = new Set(current);
@@ -717,47 +870,68 @@ function LoadedSessionConversationTimeline({
/>
) : null}
{phase === "start" && hasNestedObservations ? (
- <div className={cn("relative", isCollapsed ? "h-7" : "h-0")}>
- <Tooltip>
- <TooltipTrigger asChild>
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- className="bg-background text-muted-foreground hover:text-foreground absolute top-5 z-[1] -translate-x-1/2 -translate-y-1/2 rounded-full"
- style={{ left: "7.5px" }}
- aria-expanded={!isCollapsed}
- aria-label={`${isCollapsed ? "Show" : "Hide"} ${formatNestedObservationCounts(nestedObservationCounts)}`}
- onClick={() =>
- setCollapseState((current) => {
- const observationIds = new Set(
- current.observationIds,
- );
- if (isCollapsed) {
- observationIds.delete(observation.id);
- } else observationIds.add(observation.id);
- return { ...current, observationIds };
- })
- }
- >
- {isCollapsed ? (
- <ChevronsUpDown
- className="h-3 w-3"
- aria-hidden="true"
- />
- ) : (
- <ChevronsDownUp
- className="h-3 w-3"
- aria-hidden="true"
- />
- )}
- </Button>
- </TooltipTrigger>
- <TooltipContent side="right">
- {isCollapsed ? "Show" : "Hide"}{" "}
- {formatNestedObservationCounts(nestedObservationCounts)}
- </TooltipContent>
- </Tooltip>
+ <div
+ className={cn(
+ "relative",
+ moveCollapseControlUp ? "h-0" : "h-7",
+ )}
+ >
+ {isHighlightedSubsection ? (
+ <span
+ data-session-collapse-rail-highlight
+ className={cn(
+ "bg-primary/60 pointer-events-none absolute -bottom-1 left-[7px] w-px",
+ moveCollapseControlUp ? "-top-2" : "top-5",
+ )}
+ aria-hidden="true"
+ />
+ ) : null}
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ className={cn(
+ "bg-background text-muted-foreground hover:text-foreground absolute z-[1] -translate-x-1/2 -translate-y-1/2 rounded-full",
+ moveCollapseControlUp ? "-top-2" : "top-5",
+ )}
+ style={{ left: "7.5px" }}
+ aria-expanded={!isCollapsed}
+ aria-label={`${isCollapsed ? "Show" : "Hide"} ${nestedObservationSummary}`}
+ onMouseEnter={() => {
+ if (!isCollapsed) {
+ setHoveredSubsectionId(observation.id);
+ }
+ }}
+ onMouseLeave={() => setHoveredSubsectionId(null)}
+ onFocus={() => {
+ if (!isCollapsed) {
+ setFocusedSubsectionId(observation.id);
+ }
+ }}
+ onBlur={() => setFocusedSubsectionId(null)}
+ onClick={() => {
+ setHoveredSubsectionId(null);
+ setFocusedSubsectionId(null);
+ setCollapseState((current) => {
+ const observationIds = new Set(current.observationIds);
+ if (isCollapsed) {
+ observationIds.delete(observation.id);
+ } else observationIds.add(observation.id);
+ return { ...current, observationIds };
+ });
+ }}
+ >
+ {isCollapsed ? (
+ <ChevronsUpDown className="h-3 w-3" aria-hidden="true" />
+ ) : (
+ <ChevronDown className="h-3 w-3" aria-hidden="true" />
+ )}
+ </Button>
+ {isCollapsed ? (
+ <span className="text-muted-foreground absolute top-5 left-5 -translate-y-1/2 text-xs">
+ {nestedObservationSummary}
+ </span>
+ ) : null}
</div>
) : null}
</div>
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.stories.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.stories.tsx
index 28b8874153..4c4b50a4d9 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.stories.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.stories.tsx
@@ -44,6 +44,7 @@ export const Tool = meta.story({
});
export const StructuredData = meta.story({
+ name: "(Test) Collapses JSON-only Message",
args: {
role: "tool",
parts: [
@@ -51,6 +52,41 @@ export const StructuredData = meta.story({
{ type: "custom", kind: "citation", value: 7 },
],
},
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const toggle = canvas.getByRole("button", {
+ name: "JSON-only message detected",
+ });
+
+ await expect(toggle).toHaveAttribute("aria-expanded", "false");
+ await expect(canvas.queryAllByRole("table")).toHaveLength(0);
+ await userEvent.click(toggle);
+ await expect(toggle).toHaveAttribute("aria-expanded", "true");
+ await expect(canvas.getAllByRole("table")).toHaveLength(2);
+ await userEvent.click(toggle);
+ await expect(canvas.queryAllByRole("table")).toHaveLength(0);
+ },
+});
+
+export const MixedTextAndData = meta.story({
+ name: "(Test) Keeps Mixed Message Expanded",
+ args: {
+ role: "assistant",
+ parts: [
+ { type: "text", text: "The structured result follows." },
+ { type: "data", value: { confidence: 0.9 } },
+ ],
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ await expect(
+ canvas.queryByRole("button", { name: "JSON-only message detected" }),
+ ).not.toBeInTheDocument();
+ await expect(
+ canvas.getByText("The structured result follows."),
+ ).toBeVisible();
+ await expect(canvasElement).toHaveTextContent("confidence");
+ },
});
export const Reasoning = meta.story({
@@ -183,6 +219,12 @@ export const RenderSupportedParts = meta.story({
await userEvent.click(canvas.getByRole("button", { name: "Reasoning" }));
await expect(canvas.getByText("Think")).toBeVisible();
+ await expect(
+ canvas.getByRole("button", { name: "JSON-only message detected" }),
+ ).toHaveAttribute("aria-expanded", "false");
+ await userEvent.click(
+ canvas.getByRole("button", { name: "JSON-only message detected" }),
+ );
await expect(canvasElement).toHaveTextContent("confidence");
await expect(canvasElement).toHaveTextContent("citation");
},
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.tsx
index 764e3188b0..a620c1a8c9 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelineContentMessage/SessionTimelineContentMessage.tsx
@@ -1,5 +1,5 @@
-import React from "react";
-import { Bot, UserRound, Wrench } from "lucide-react";
+import React, { useState } from "react";
+import { Bot, ChevronDown, UserRound, Wrench } from "lucide-react";
import { type ReasoningPart } from "@langfuse/shared/src/utils/normalized-io";
import { type SessionTimelineConversationMessage } from "@/src/features/sessions/SessionConversationTimeline/fns/processTimelineMessages";
@@ -47,6 +47,9 @@ export function SessionTimelineContentMessage({
const presentation = rolePresentation[role];
const Icon = presentation.icon;
const showSender = Boolean(senderName && senderName !== presentation.label);
+ const [expandedJsonGroupIndices, setExpandedJsonGroupIndices] = useState(
+ () => new Set<number>(),
+ );
type MessagePart = SessionTimelineConversationMessage["parts"][number];
type ContentPart = Exclude<MessagePart, ReasoningPart>;
const groups: Array<
@@ -95,6 +98,11 @@ export function SessionTimelineContentMessage({
);
}
+ const isJsonOnly = group.parts.every(
+ (part) => part.type === "data" || part.type === "custom",
+ );
+ const isJsonExpanded = expandedJsonGroupIndices.has(groupIndex);
+
return (
<div
key={`content-${groupIndex}`}
@@ -114,14 +122,45 @@ export function SessionTimelineContentMessage({
</span>
</div>
) : null}
- <div className="flex flex-col gap-2 text-sm leading-6">
- {group.parts.map((part, partIndex) => (
- <SessionTimelinePart
- key={`${part.type}-${partIndex}`}
- part={part}
+ {isJsonOnly ? (
+ <button
+ type="button"
+ className="text-muted-foreground hover:text-foreground flex w-full items-center gap-1.5 text-left font-mono text-xs transition-colors"
+ aria-expanded={isJsonExpanded}
+ onClick={() =>
+ setExpandedJsonGroupIndices((current) => {
+ const next = new Set(current);
+ if (isJsonExpanded) next.delete(groupIndex);
+ else next.add(groupIndex);
+ return next;
+ })
+ }
+ >
+ <ChevronDown
+ className={cn(
+ "h-3 w-3 shrink-0 transition-transform",
+ !isJsonExpanded && "-rotate-90",
+ )}
+ aria-hidden="true"
/>
- ))}
- </div>
+ JSON-only message detected
+ </button>
+ ) : null}
+ {!isJsonOnly || isJsonExpanded ? (
+ <div
+ className={cn(
+ "flex flex-col gap-2 text-sm leading-6",
+ isJsonOnly && "mt-2",
+ )}
+ >
+ {group.parts.map((part, partIndex) => (
+ <SessionTimelinePart
+ key={`${part.type}-${partIndex}`}
+ part={part}
+ />
+ ))}
+ </div>
+ ) : null}
</article>
</div>
);