🪢 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): Show saved corrections in session observations (#19501)
Ben Bachemf43e71bbf91a
diff --git a/web/src/features/sessions/SessionObservationIO.tsx b/web/src/features/sessions/SessionObservationIO.tsxindex 07cee10903..24073a5880 100644--- a/web/src/features/sessions/SessionObservationIO.tsx+++ b/web/src/features/sessions/SessionObservationIO.tsx@@ -14,7 +14,7 @@ import { showErrorToast } from "@/src/features/notifications";import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import { compactNumberFormatter } from "@/src/utils/numbers";import { decodeUnicodeEscapesOnly } from "@/src/utils/unicode";-import { parseJsonIfString } from "@langfuse/shared";+import { parseJsonIfString, type ScoreDomain } from "@langfuse/shared";import { classifyTrpcToastError } from "@/src/utils/trpcErrorClassification";export type SessionTraceObservation =@@ -97,6 +97,7 @@ export const SessionObservationIO = ({traceId,environment,showCorrections,+ outputCorrection,onOpenInTraceView,contentMode = "all",showSystemPrompt,@@ -112,6 +113,7 @@ export const SessionObservationIO = ({traceId: string;environment?: string;showCorrections: boolean;+ outputCorrection?: ScoreDomain;onOpenInTraceView: (observationId: string) => void;contentMode?: IOPreviewContentMode;showSystemPrompt?: boolean;@@ -192,9 +194,12 @@ export const SessionObservationIO = ({media={observationMedia.data}projectId={projectId}traceId={traceId}- observationId={observation.id}+ observationId={+ observation.id === `t-${traceId}` ? undefined : observation.id+ }environment={environment}showCorrections={showCorrections}+ outputCorrection={outputCorrection}contentMode={contentMode}showSystemPrompt={showSystemPrompt}currentView={currentView}diff --git a/web/src/features/sessions/TraceEventsRow.tsx b/web/src/features/sessions/TraceEventsRow.tsxindex b5f93699d7..ef3066b902 100644--- a/web/src/features/sessions/TraceEventsRow.tsx+++ b/web/src/features/sessions/TraceEventsRow.tsx@@ -8,6 +8,7 @@ import React from "react";import { ItemBadge } from "@/src/components/ItemBadge";import { deepParseJson, type FilterState } from "@langfuse/shared";import { SessionObservationIO } from "@/src/features/sessions/SessionObservationIO";+import { useObservationCorrections } from "@/src/features/sessions/useObservationCorrections";import { FilterX } from "@langfuse/icons";import { SESSION_DETAIL_VIEW_TRIGGER_ID } from "@/src/features/sessions/session-detail-presets";import { SessionTraceActionButtons } from "@/src/features/sessions/SessionTraceActionButtons";@@ -34,6 +35,7 @@ const ModernSessionObservation = ({traceId,environment,showCorrections,+ outputCorrection,contentMode,showSystemPrompt,onOpenInTraceView,@@ -44,6 +46,9 @@ const ModernSessionObservation = ({traceId: string;environment?: string;showCorrections: boolean;+ outputCorrection?: React.ComponentProps<+ typeof SessionObservationIO+ >["outputCorrection"];contentMode: IOPreviewContentMode;showSystemPrompt?: boolean;onOpenInTraceView: (observationId: string) => void;@@ -100,6 +105,7 @@ const ModernSessionObservation = ({traceId={traceId}environment={environment}showCorrections={showCorrections}+ outputCorrection={outputCorrection}onOpenInTraceView={onOpenInTraceView}contentMode={isConversation ? contentMode : "all"}showSystemPrompt={showSystemPrompt}@@ -303,6 +309,13 @@ export const TraceEventsRow = React.memo(const { visibleObservations, hasMoreObservations } =visibleObservationState;+ const correctionsByObservation = useObservationCorrections({+ projectId,+ traceId: trace.id,+ showCorrections,+ visibleObservations,+ });+const Frame = surface === "card" ? Card : "div";const showTracePanel = surface === "card" && !hideTracePanel;@@ -376,6 +389,9 @@ export const TraceEventsRow = React.memo(undefined}showCorrections={showCorrections}+ outputCorrection={correctionsByObservation.get(+ observation.id,+ )}contentMode={contentMode}showSystemPrompt={showSystemPrompt}onOpenInTraceView={openObservationInTraceView}@@ -397,6 +413,9 @@ export const TraceEventsRow = React.memo(undefined}showCorrections={showCorrections}+ outputCorrection={correctionsByObservation.get(+ observation.id,+ )}onOpenInTraceView={openObservationInTraceView}contentMode={contentMode}showSystemPrompt={showSystemPrompt}diff --git a/web/src/features/sessions/useObservationCorrections.ts b/web/src/features/sessions/useObservationCorrections.tsnew file mode 100644index 0000000000..901e8aaa53--- /dev/null+++ b/web/src/features/sessions/useObservationCorrections.ts@@ -0,0 +1,56 @@+import { useMemo } from "react";+import {+ filterAndValidateDbScoreList,+ ScoreDataTypeEnum,+ type ScoreDomain,+} from "@langfuse/shared";+import { getMostRecentCorrection } from "@/src/features/corrections";+import { type SessionTraceObservation } from "./SessionObservationIO";+import { api } from "@/src/utils/api";++export function useObservationCorrections({+ projectId,+ traceId,+ showCorrections,+ visibleObservations,+}: {+ projectId: string;+ traceId: string;+ showCorrections: boolean;+ visibleObservations: readonly SessionTraceObservation[] | undefined;+}) {+ const scoresQuery = api.events.scoresForTrace.useQuery(+ { projectId, traceId },+ {+ enabled:+ showCorrections &&+ !!visibleObservations?.some(+ (observation) =>+ !observation.inputTruncated && !observation.outputTruncated,+ ),+ staleTime: 60 * 1000,+ },+ );++ return useMemo(() => {+ const corrections = filterAndValidateDbScoreList({+ scores: scoresQuery.data ?? [],+ dataTypes: [ScoreDataTypeEnum.CORRECTION],+ });+ const grouped = new Map<string, ScoreDomain[]>();+ for (const correction of corrections) {+ // Synthetic session rows display trace I/O, whose corrections have no observation ID.+ const observationId = correction.observationId ?? `t-${traceId}`;+ const group = grouped.get(observationId) ?? [];+ group.push(correction);+ grouped.set(observationId, group);+ }++ const latestByObservation = new Map<string, ScoreDomain>();+ for (const [observationId, group] of grouped) {+ const latest = getMostRecentCorrection(group);+ if (latest) latestByObservation.set(observationId, latest);+ }+ return latestByObservation;+ }, [scoresQuery.data, traceId]);+}