Skip to content

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

fix(annotation-queues): Don't reset trace expansion state between traces (#16417)

Ben Bachem7bf1b976c76d
diff --git a/web/src/features/traces/components/Trace.tsx b/web/src/features/traces/components/Trace.tsx
index 62df6ec73f..838cf14aab 100644
--- a/web/src/features/traces/components/Trace.tsx
+++ b/web/src/features/traces/components/Trace.tsx
@@ -45,16 +45,42 @@ export type TraceProps = {
truncatedAtObservations?: number;
};
+const DESKTOP_LAYOUT_BY_CONTEXT = {
+ fullscreen: {
+ groupId: "trace-layout-v3",
+ defaultNavigationCollapsed: false,
+ expandDetailOnMount: false,
+ },
+ peek: {
+ groupId: "trace-layout-peek-v1",
+ defaultNavigationCollapsed: false,
+ expandDetailOnMount: false,
+ },
+ annotation: {
+ groupId: "trace-layout-annotation-v1",
+ defaultNavigationCollapsed: true,
+ expandDetailOnMount: true,
+ },
+} as const;
+
+type DesktopLayout =
+ (typeof DESKTOP_LAYOUT_BY_CONTEXT)[keyof typeof DESKTOP_LAYOUT_BY_CONTEXT];
+
/**
* SelectionProvider sits ABOVE the trace data so the selected observation can be
* resolved before the tree is built: past the observation cap the selected row is
* missing from the loaded list and has to be fetched and merged in.
*/
export function Trace({ context, ...props }: TraceProps) {
+ const traceContext = context ?? "fullscreen";
+
return (
- <ViewPreferencesProvider traceContext={context}>
+ <ViewPreferencesProvider traceContext={traceContext}>
<SelectionProvider>
- <TraceWithSelection {...props} />
+ <TraceWithSelection
+ {...props}
+ desktopLayout={DESKTOP_LAYOUT_BY_CONTEXT[traceContext]}
+ />
</SelectionProvider>
</ViewPreferencesProvider>
);
@@ -67,7 +93,10 @@ function TraceWithSelection({
corrections,
projectId,
truncatedAtObservations,
-}: Omit<TraceProps, "context">) {
+ desktopLayout,
+}: Omit<TraceProps, "context"> & {
+ desktopLayout: DesktopLayout;
+}) {
const { selectedNodeId } = useSelection();
// Fetch comment counts using existing hook
@@ -136,7 +165,7 @@ function TraceWithSelection({
<SearchProvider>
<JsonExpansionProvider>
<PlayheadProvider>
- <TraceContent />
+ <TraceContent desktopLayout={desktopLayout} />
</PlayheadProvider>
</JsonExpansionProvider>
</SearchProvider>
@@ -158,7 +187,7 @@ function TraceWithSelection({
* - useViewPreferences() - for graph toggle state
* - useTraceGraphData() - for graph availability
*/
-function TraceContent() {
+function TraceContent({ desktopLayout }: { desktopLayout: DesktopLayout }) {
const isMobile = useIsMobile();
const { showGraph } = useViewPreferences();
const { isGraphViewAvailable } = useTraceGraphData();
@@ -167,7 +196,10 @@ function TraceContent() {
return isMobile ? (
<MobileTraceContent shouldShowGraph={shouldShowGraph} />
) : (
- <DesktopTraceContent shouldShowGraph={shouldShowGraph} />
+ <DesktopTraceContent
+ shouldShowGraph={shouldShowGraph}
+ desktopLayout={desktopLayout}
+ />
);
}
@@ -181,11 +213,13 @@ function TraceContent() {
*/
function DesktopTraceContent({
shouldShowGraph,
+ desktopLayout,
}: {
shouldShowGraph: boolean;
+ desktopLayout: DesktopLayout;
}) {
return (
- <TraceLayoutDesktop>
+ <TraceLayoutDesktop key={desktopLayout.groupId} {...desktopLayout}>
<TraceLayoutDesktop.NavigationPanel>
<TracePanelNavigationLayoutDesktop
secondaryContent={shouldShowGraph ? <TraceGraphView /> : undefined}
diff --git a/web/src/features/traces/components/TraceLayoutDesktop.tsx b/web/src/features/traces/components/TraceLayoutDesktop.tsx
index 1b70443e74..9098abc3cf 100644
--- a/web/src/features/traces/components/TraceLayoutDesktop.tsx
+++ b/web/src/features/traces/components/TraceLayoutDesktop.tsx
@@ -23,16 +23,6 @@ import { useViewPreferences } from "@/src/features/traces/contexts/ViewPreferenc
import { useSelection } from "@/src/features/traces/contexts/SelectionContext";
import { resolveEffectiveWidthFraction } from "@/src/components/table/peek/store/peekPanelStore";
-// Full-page trace view's layout group. v3: the full-page view gets the same
-// computed info-favoring default + localStorage persistence as the peek
-// (LFE-10729); bumped from v2 so stale saved layouts from the old 60/40-share
-// era don't mask the new default.
-const RESIZABLE_PANEL_GROUP_ID = "trace-layout-v3";
-// Peek keeps a distinct group id so the two surfaces remember their sizes
-// independently — a split dragged in a ~50vw peek is rarely right for a
-// full-page trace, and vice versa. Same panels, different layout scope
-// (LFE-10601).
-const PEEK_RESIZABLE_PANEL_GROUP_ID = "trace-layout-peek-v1";
const RESIZABLE_PANEL_HANDLE_ID = "trace-layout-handle";
const RESIZABLE_PANEL_NAVIGATION_ID = "trace-layout-panel-navigation";
const RESIZABLE_PANEL_PREVIEW_ID = "trace-layout-panel-preview";
@@ -180,36 +170,29 @@ export function useDesktopLayoutContextOptional() {
return useContext(LayoutContext);
}
-export function TraceLayoutDesktop({ children }: { children: ReactNode }) {
+export function TraceLayoutDesktop({
+ children,
+ groupId,
+ defaultNavigationCollapsed,
+ expandDetailOnMount,
+}: {
+ children: ReactNode;
+ groupId: string;
+ defaultNavigationCollapsed: boolean;
+ expandDetailOnMount: boolean;
+}) {
// Get current view mode from URL
const [viewMode] = useQueryParam("view", StringParam);
const isTimelineView = viewMode === "timeline";
- // Get annotation mode + peek mode from context. Peek scopes the layout to its
- // own group so a split dragged there doesn't leak into the full-page view and
- // vice versa (LFE-10601).
- const { isAnnotationMode, isPeekMode } = useViewPreferences();
-
- const groupId = isPeekMode
- ? PEEK_RESIZABLE_PANEL_GROUP_ID
- : RESIZABLE_PANEL_GROUP_ID;
- // Both views persist their split in localStorage (like the peek's outer
- // width), so a resized tree/info ratio sticks across tabs and reloads instead
- // of resetting per tab (the peek's old sessionStorage behavior, fixed in
- // LFE-10601; the full-page's in LFE-10729). Guarded so SSR / DOM-less tests
- // fall back to a no-op store instead of throwing on the bare global.
- //
- // Annotation mode is an opinionated workspace — nav on its rail, detail
- // full-width — that never SAVES a layout (onLayoutChanged below), so it must
- // not INHERIT one either: it shares the full-page group id, and a full-page
- // session that parked the detail panel on its 40px rail would otherwise open
- // annotation with BOTH panels collapsed (trace-level queue items have no
- // selection to auto-expand the detail panel). No-op storage keeps it on the
- // computed default.
+ // Peek sizing depends on the drawer width; persistence scope is caller-owned.
+ const { isPeekMode } = useViewPreferences();
+
+ // The caller owns the persistence scope and first-use default. Keeping that
+ // policy outside this layout lets annotation queues retain their workspace
+ // across keyed trace remounts without inheriting the full-page trace layout.
const storage =
- typeof window === "undefined" || isAnnotationMode
- ? NOOP_LAYOUT_STORAGE
- : window.localStorage;
+ typeof window === "undefined" ? NOOP_LAYOUT_STORAGE : window.localStorage;
// The width the trace container actually opens at, driving the computed
// default split. Peek: the drawer width — when expanded (a shared/reloaded
@@ -262,7 +245,7 @@ export function TraceLayoutDesktop({ children }: { children: ReactNode }) {
const [isNavigationPanelCollapsed, setIsNavigationPanelCollapsed] = useState(
() =>
- isAnnotationMode ||
+ (defaultNavigationCollapsed && !defaultLayout) ||
isPanelCollapsedInLayout(
defaultLayout,
RESIZABLE_PANEL_NAVIGATION_ID,
@@ -411,21 +394,23 @@ export function TraceLayoutDesktop({ children }: { children: ReactNode }) {
};
// Selecting another node (timeline/tree) while the detail panel is collapsed
- // reopens it. This covers selection CHANGES (incl. the search list); re-
+ // reopens it. Annotation items also reopen it on mount so a collapsed layout
+ // cannot hide the trace overview on the next trace-level queue item. Re-
// selecting the same node is handled at the row click via expandDetailPanel,
// since the URL param — and thus this effect — doesn't change on re-click.
const { selectedNodeId } = useSelection();
useEffect(() => {
// Guard on selectedNodeId so a deliberately-collapsed panel isn't reopened
// on mount/refresh when there's no selection (effects always run once).
- if (selectedNodeId) expandDetailPanel();
+ if (selectedNodeId || expandDetailOnMount) expandDetailPanel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedNodeId]);
- // Collapse panel on initial mount if in annotation mode
+ // Apply the caller's first-use default. A restored layout always wins.
useEffect(() => {
if (
- isAnnotationMode &&
+ defaultNavigationCollapsed &&
+ !defaultLayout &&
panelRef.current &&
!panelRef.current.isCollapsed()
) {
@@ -492,7 +477,7 @@ export function TraceLayoutDesktop({ children }: { children: ReactNode }) {
id={groupId}
groupRef={groupRef}
defaultLayout={defaultLayout ?? computedDefaultLayout}
- onLayoutChanged={isAnnotationMode ? undefined : onLayoutChanged}
+ onLayoutChanged={onLayoutChanged}
className={bothPanelsOpen ? undefined : "min-w-0"}
style={
bothPanelsOpen