🪢 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(annotation): render session-level screens subject to fast preview mode on/off (#13178)
marliessophie8dd7b23a3e8f
diff --git a/web/src/components/session/TraceEventsRow.tsx b/web/src/components/session/TraceEventsRow.tsxindex be39143237..79c2571d41 100644--- a/web/src/components/session/TraceEventsRow.tsx+++ b/web/src/components/session/TraceEventsRow.tsx@@ -33,6 +33,7 @@ export const TraceEventsRow = React.memo(traceCommentCounts,showCorrections,filterState,+ hideTracePanel = false,}: {trace: RouterOutputs["sessions"]["tracesFromEvents"][number];projectId: string;@@ -41,6 +42,7 @@ export const TraceEventsRow = React.memo(traceCommentCounts: Map<string, number> | undefined;showCorrections: boolean;filterState: FilterState;+ hideTracePanel?: boolean;}) => {const observationsQuery =api.sessions.observationsForTraceFromEvents.useQuery(@@ -59,10 +61,20 @@ export const TraceEventsRow = React.memo(return (<Card className="border-border shadow-none">- <div className="grid md:grid-cols-[1fr_1px_358px] lg:grid-cols-[1fr_1px_30rem]">+ <div+ className={+ hideTracePanel+ ? "grid"+ : "grid md:grid-cols-[1fr_1px_358px] lg:grid-cols-[1fr_1px_30rem]"+ }+ ><div className="overflow-hidden py-4 pr-4 pl-4">{observationsQuery.isLoading ? (<JsonSkeleton className="h-full w-full" numRows={8} />+ ) : observationsQuery.isError ? (+ <div className="text-destructive p-2 text-xs">+ Failed to load observations.+ </div>) : observationsQuery.data && observationsQuery.data.length > 0 ? (<div className="flex flex-col gap-4">{observationsQuery.data.map((observation) => (@@ -110,78 +122,82 @@ export const TraceEventsRow = React.memo(</div>)}</div>- <div className="bg-border hidden md:block"></div>- <div className="flex flex-col border-t py-4 pr-4 pl-4 md:border-0">- <div className="mb-4 flex flex-col gap-2">- <Link- href={`/project/${projectId}/traces/${trace.id}`}- className="hover:bg-accent flex items-start gap-2 rounded-lg border p-2 transition-colors"- onClick={(e) => {- if (!e.metaKey && !e.ctrlKey && !e.shiftKey) {- e.preventDefault();- openPeek(trace.id, trace);- }- }}- >- <ItemBadge type="TRACE" isSmall />- <div className="flex flex-col">- <span className="text-xs font-medium">- {trace.name ?? "Trace"} ({trace.id}) ↗- </span>- <span className="text-muted-foreground text-xs">- {trace.timestamp.toLocaleString()}- </span>- </div>- </Link>- <div className="flex flex-wrap gap-2">- <NewDatasetItemFromTraceId- projectId={projectId}- traceId={trace.id}- timestamp={new Date(trace.timestamp)}- buttonVariant="outline"- />- <div className="flex items-start">- <AnnotateDrawer- key={"annotation-drawer" + trace.id}- projectId={projectId}- scoreTarget={{- type: "trace",- traceId: trace.id,- }}- scores={trace.scores}- buttonVariant="outline"- analyticsData={{- type: "trace",- source: "SessionDetail",- }}- scoreMetadata={{- projectId: projectId,- environment: trace.environment ?? undefined,+ {!hideTracePanel && (+ <>+ <div className="bg-border hidden md:block"></div>+ <div className="flex flex-col border-t py-4 pr-4 pl-4 md:border-0">+ <div className="mb-4 flex flex-col gap-2">+ <Link+ href={`/project/${projectId}/traces/${trace.id}`}+ className="hover:bg-accent flex items-start gap-2 rounded-lg border p-2 transition-colors"+ onClick={(e) => {+ if (!e.metaKey && !e.ctrlKey && !e.shiftKey) {+ e.preventDefault();+ openPeek(trace.id, trace);+ }}}- />- <CreateNewAnnotationQueueItem- projectId={projectId}- objectId={trace.id}- objectType={AnnotationQueueObjectType.TRACE}- variant="outline"- />+ >+ <ItemBadge type="TRACE" isSmall />+ <div className="flex flex-col">+ <span className="text-xs font-medium">+ {trace.name ?? "Trace"} ({trace.id}) ↗+ </span>+ <span className="text-muted-foreground text-xs">+ {trace.timestamp.toLocaleString()}+ </span>+ </div>+ </Link>+ <div className="flex flex-wrap gap-2">+ <NewDatasetItemFromTraceId+ projectId={projectId}+ traceId={trace.id}+ timestamp={new Date(trace.timestamp)}+ buttonVariant="outline"+ />+ <div className="flex items-start">+ <AnnotateDrawer+ key={"annotation-drawer" + trace.id}+ projectId={projectId}+ scoreTarget={{+ type: "trace",+ traceId: trace.id,+ }}+ scores={trace.scores}+ buttonVariant="outline"+ analyticsData={{+ type: "trace",+ source: "SessionDetail",+ }}+ scoreMetadata={{+ projectId: projectId,+ environment: trace.environment ?? undefined,+ }}+ />+ <CreateNewAnnotationQueueItem+ projectId={projectId}+ objectId={trace.id}+ objectType={AnnotationQueueObjectType.TRACE}+ variant="outline"+ />+ </div>+ <CommentDrawerButton+ projectId={projectId}+ variant="outline"+ objectId={trace.id}+ objectType="TRACE"+ count={getNumberFromMap(traceCommentCounts, trace.id)}+ />+ </div>+ </div>+ <div className="flex-1">+ <p className="mb-1 font-medium">Scores</p>+ <div className="flex flex-wrap content-start items-start gap-1">+ <GroupedScoreBadges scores={trace.scores} />+ </div></div>- <CommentDrawerButton- projectId={projectId}- variant="outline"- objectId={trace.id}- objectType="TRACE"- count={getNumberFromMap(traceCommentCounts, trace.id)}- />- </div>- </div>- <div className="flex-1">- <p className="mb-1 font-medium">Scores</p>- <div className="flex flex-wrap content-start items-start gap-1">- <GroupedScoreBadges scores={trace.scores} /></div>- </div>- </div>+ </>+ )}</div></Card>);@@ -201,6 +217,7 @@ export const LazyTraceEventsRow = React.forwardRef<traceCommentCounts: Map<string, number> | undefined;showCorrections: boolean;filterState: FilterState;+ hideTracePanel?: boolean;onLoad?: (index: number) => void;}>((props, measureRef) => {diff --git a/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx b/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsxindex 8c652500c0..e447df57e2 100644--- a/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx+++ b/web/src/features/annotation-queues/components/processors/SessionAnnotationProcessor.tsx@@ -5,7 +5,8 @@ import {import { AnnotationDrawerSection } from "../shared/AnnotationDrawerSection";import { AnnotationProcessingLayout } from "../shared/AnnotationProcessingLayout";import { SessionIO } from "@/src/components/session";-import { useState, useEffect } from "react";+import { LazyTraceEventsRow } from "@/src/components/session/TraceEventsRow";+import { useState, useMemo, useCallback } from "react";import { Button } from "@/src/components/ui/button";import { ItemBadge } from "@/src/components/ItemBadge";import { CopyIdsPopover } from "@/src/components/trace2/components/_shared/CopyIdsPopover";@@ -13,6 +14,9 @@ import { Badge } from "@/src/components/ui/badge";import { Separator } from "@/src/components/ui/separator";import Link from "next/link";import { Card } from "@/src/components/ui/card";+import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";+import { api } from "@/src/utils/api";+import { JsonSkeleton } from "@/src/components/ui/CodeJsonViewer";interface SessionAnnotationProcessorProps {item: AnnotationQueueItem & {@@ -27,39 +31,67 @@ interface SessionAnnotationProcessorProps {// some projects have thousands of traces in a session, paginate to avoid rendering all at onceconst PAGE_SIZE = 10;+// Stable empty array to avoid creating new references on every render (defeats React.memo)+const EMPTY_FILTER_STATE: [] = [];+export const SessionAnnotationProcessor: React.FC<SessionAnnotationProcessorProps> = ({ item, data, configs, projectId }) => {const [visibleTraces, setVisibleTraces] = useState(PAGE_SIZE);- const [currentTraceIndex, setCurrentTraceIndex] = useState(1);-- // Intersection observer to which trace is currently in view- useEffect(() => {- if (!data?.traces) return;+ const { isBetaEnabled } = useV4Beta();- const observer = new IntersectionObserver(- (entries) => {- entries.forEach((entry) => {- if (entry.isIntersecting && entry.intersectionRatio > 0.5) {- const index = parseInt(- entry.target.getAttribute("data-trace-index") || "0",- );- setCurrentTraceIndex(index + 1);- }- });+ // Fetch traces separately when v4 beta is enabled (events table path)+ // The byIdWithScoresFromEvents endpoint doesn't include traces array+ const tracesFromEventsQuery = api.sessions.tracesFromEvents.useQuery(+ { projectId, sessionId: item.objectId },+ {+ enabled: isBetaEnabled,+ retry(failureCount, error) {+ if (+ error.data?.code === "UNAUTHORIZED" ||+ error.data?.code === "NOT_FOUND"+ )+ return false;+ return failureCount < 3;},+ },+ );++ const traceCommentCounts =+ api.comments.getTraceCommentCountsBySessionId.useQuery({- threshold: 0.5, // Trigger when 50% of trace is visible- rootMargin: "-25% 0px -25% 0px", // Focus on center area+ projectId,+ sessionId: item.objectId,},+ { enabled: isBetaEnabled },);- // Observe all trace cards- const traceCards = document.querySelectorAll("[data-trace-index]");- traceCards.forEach((card) => observer.observe(card));+ // Unify traces from both paths:+ // - v4 beta OFF: traces come from data.traces (byIdWithScores endpoint)+ // - v4 beta ON: traces come from separate tracesFromEvents query+ const traces = useMemo(() => {+ if (isBetaEnabled) {+ return tracesFromEventsQuery.data ?? [];+ }+ return data?.traces ?? [];+ }, [isBetaEnabled, tracesFromEventsQuery.data, data?.traces]);- return () => observer.disconnect();- }, [data?.traces, visibleTraces]);+ // For the "Total traces" badge, show countTraces from session metadata when available (v4),+ // or fall back to loaded traces length+ const totalTracesForBadge = useMemo(() => {+ if (isBetaEnabled) {+ return data?.countTraces ?? traces.length;+ }+ return traces.length;+ }, [isBetaEnabled, data?.countTraces, traces.length]);++ // Stable callback to avoid creating new function reference on every render (defeats React.memo)+ const openPeek = useCallback(+ (traceId: string) => {+ window.open(`/project/${projectId}/traces/${traceId}`, "_blank");+ },+ [projectId],+ );const leftPanel = (<div className="flex h-full flex-col overflow-hidden">@@ -77,22 +109,15 @@ export const SessionAnnotationProcessor: React.FC<idItems={[{ id: item.objectId, name: "Session ID" }]}/></div>- {data?.traces && (- <div className="flex items-center">- <Badge variant="outline" className="text-xs">- Trace {currentTraceIndex} / {data.traces.length}- </Badge>- </div>- )}</div><div className="mt-2 mb-4 grid w-full min-w-0 items-center justify-between px-4"><div className="flex max-w-full min-w-0 shrink flex-col"><div className="flex max-w-full min-w-0 flex-wrap items-center gap-1">- {data.environment && (+ {data?.environment && (<Badge variant="tertiary">Env: {data.environment}</Badge>)}<Badge variant="outline">- Total traces: {data?.traces.length}+ Total traces: {totalTracesForBadge}</Badge></div></div>@@ -103,13 +128,53 @@ export const SessionAnnotationProcessor: React.FC<{/* Scrollable Content */}<div className="flex-1 overflow-y-auto"><div className="p-4">- {data?.traces- .slice(0, visibleTraces)- .map((trace: any, index: number) => (+ {/* Loading state for v4 beta traces */}+ {isBetaEnabled && tracesFromEventsQuery.isLoading && (+ <div className="space-y-4">+ {Array.from({ length: 3 }).map((_, i) => (+ <Card+ key={i}+ className="border-border mb-2 grid gap-2 p-2 shadow-none"+ >+ <JsonSkeleton+ className="h-full w-full overflow-hidden"+ numRows={4}+ />+ </Card>+ ))}+ </div>+ )}+ {/* Error state for v4 beta traces */}+ {isBetaEnabled && tracesFromEventsQuery.isError && (+ <div className="text-destructive p-2 text-sm">+ Failed to load traces for this session.+ </div>+ )}+ {/* Trace list - v4 path uses LazyTraceEventsRow for deferred loading */}+ {isBetaEnabled &&+ tracesFromEventsQuery.isSuccess &&+ traces+ .slice(0, visibleTraces)+ .map((trace: any, index: number) => (+ <LazyTraceEventsRow+ key={trace.id}+ trace={trace}+ projectId={projectId}+ sessionId={item.objectId}+ openPeek={openPeek}+ traceCommentCounts={traceCommentCounts.data ?? undefined}+ showCorrections+ filterState={EMPTY_FILTER_STATE}+ hideTracePanel+ index={index}+ />+ ))}+ {/* Trace list - v3 path uses SessionIO */}+ {!isBetaEnabled &&+ traces.slice(0, visibleTraces).map((trace: any) => (<CardclassName="border-border hover:border-ring group mb-2 grid gap-2 p-2 shadow-none"key={trace.id}- data-trace-index={index}><div className="-mt-1 p-1 pt-0 opacity-50 transition-opacity group-hover:opacity-100"><Link@@ -130,16 +195,17 @@ export const SessionAnnotationProcessor: React.FC</></Card>))}- {data?.traces && data.traces.length > visibleTraces && (- <div className="flex justify-center py-4">- <Button- onClick={() => setVisibleTraces((prev) => prev + PAGE_SIZE)}- variant="ghost"- >- {`Load ${Math.min(data.traces.length - visibleTraces, PAGE_SIZE)} More`}- </Button>- </div>- )}+ {(!isBetaEnabled || tracesFromEventsQuery.isSuccess) &&+ traces.length > visibleTraces && (+ <div className="flex justify-center py-4">+ <Button+ onClick={() => setVisibleTraces((prev) => prev + PAGE_SIZE)}+ variant="ghost"+ >+ {`Load ${Math.min(traces.length - visibleTraces, PAGE_SIZE)} More`}+ </Button>+ </div>+ )}</div></div></div>