πͺ’ 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
feat(experiments): add persistent resizable charts (#18216)
marliessophie718e7d878756
diff --git a/web/src/components/ui/resizable-split-layout.tsx b/web/src/components/ui/resizable-split-layout.tsxindex 8f493c2ad9..631f47122d 100644--- a/web/src/components/ui/resizable-split-layout.tsx+++ b/web/src/components/ui/resizable-split-layout.tsx@@ -40,11 +40,6 @@ interface ResizableSplitLayoutProps {const PRIMARY_PANEL_ID = "primary";const SECONDARY_PANEL_ID = "secondary";-const NOOP_LAYOUT_STORAGE = {- getItem: () => null,- setItem: () => {},-};-/*** Horizontal split layout with a collapsible secondary panel.*@@ -75,11 +70,6 @@ export function ResizableSplitLayout({? `resizable-layout-${persistId}`: `resizable-layout-${instanceId}`;- const storage =- persistId && typeof window !== "undefined"- ? sessionStorage- : NOOP_LAYOUT_STORAGE;-const renderSecondaryPanel = keepSecondaryMounted || open;const panelIds = (() => {if (renderSecondaryPanel) {@@ -96,7 +86,7 @@ export function ResizableSplitLayout({const { defaultLayout, onLayoutChanged } = useDefaultLayout({id: groupId,panelIds,- storage,+ storage: persistId ? "session" : false,});useLayoutEffect(() => {diff --git a/web/src/components/ui/resizable.tsx b/web/src/components/ui/resizable.tsxindex 65d9ee91a6..a1e9b616ab 100644--- a/web/src/components/ui/resizable.tsx+++ b/web/src/components/ui/resizable.tsx@@ -51,7 +51,27 @@ function ResizableHandle({}const usePanelRef = ResizablePrimitive.usePanelRef;-const useDefaultLayout = ResizablePrimitive.useDefaultLayout;+const NOOP_LAYOUT_STORAGE = { getItem: () => null, setItem: () => {} };++function useDefaultLayout({+ storage,+ ...options+}: Pick<+ Parameters<typeof ResizablePrimitive.useDefaultLayout>[0],+ "debounceSaveMs" | "panelIds"+> & {+ id: string;+ storage: "local" | "session" | false;+}) {+ const browserStorage = (() => {+ if (!storage || typeof window === "undefined") return NOOP_LAYOUT_STORAGE;+ return storage === "local" ? localStorage : sessionStorage;+ })();+ return ResizablePrimitive.useDefaultLayout({+ ...options,+ storage: browserStorage,+ });+}export {ResizableHandle,diff --git a/web/src/features/experiments/components/ExperimentChartsLayout.tsx b/web/src/features/experiments/components/ExperimentChartsLayout.tsxnew file mode 100644index 0000000000..905776f327--- /dev/null+++ b/web/src/features/experiments/components/ExperimentChartsLayout.tsx@@ -0,0 +1,188 @@+import { MAX_EXPERIMENT_CHARTS } from "../constants/charts";+import { type ReactNode } from "react";+import { Plus } from "lucide-react";+import { IconButton } from "@/src/components/design-system/IconButton/IconButton";+import { Button } from "@/src/components/design-system/Button/Button";+import {+ ResizableHandle,+ ResizablePanel,+ ResizablePanelGroup,+ useDefaultLayout,+} from "@/src/components/ui/resizable";+import {+ type ExperimentChartSlot,+ useExperimentCharts,+} from "@/src/features/experiments/hooks/useExperimentCharts";+import { ExperimentMetricStrip } from "./ExperimentMetricStrip";+import {+ type MetricOption,+ type ScoreCoverageByLevel,+} from "@/src/features/experiments/types/charts";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics";+import { chartMetricChangedProps } from "@/src/features/experiments/lib/analytics";++const PANEL_IDS = ["charts", "table"];+type Props = {+ projectId: string;+ experiments: Array<{ id: string; name: string; startTime: Date }>;+ fromTimestamp?: Date;+ toTimestamp?: Date;+ isExternalLoading?: boolean;+ scoreCoverage?: ScoreCoverageByLevel;+ availableMetricOptions: MetricOption[];+ isMetricOptionsLoading: boolean;+ metricOptionsError: string | null;+ onRetryMetricOptions: () => void;+ children: ReactNode;+};++export function ExperimentChartsLayout(props: Props) {+ if (!props.fromTimestamp || !props.toTimestamp) return <>{props.children}</>;+ return (+ <ChartsLayout+ key={props.projectId}+ {...props}+ fromTimestamp={props.fromTimestamp}+ toTimestamp={props.toTimestamp}+ />+ );+}++function ChartsLayout({+ children,+ projectId,+ availableMetricOptions,+ scoreCoverage,+ isExternalLoading,+ isMetricOptionsLoading,+ metricOptionsError,+ onRetryMetricOptions,+ ...chartProps+}: Props & { fromTimestamp: Date; toTimestamp: Date }) {+ const { charts, canAdd, addChart, removeChart, updateChart } =+ useExperimentCharts({ projectId, availableMetricOptions, scoreCoverage });+ const capture = usePostHogClientCapture();+ const { defaultLayout, onLayoutChanged } = useDefaultLayout({+ id: `experiment-charts-size-${projectId}`,+ panelIds: PANEL_IDS,+ storage: "local",+ });+ const isLoading = isExternalLoading || isMetricOptionsLoading;+ const addChartTitle = (() => {+ if (canAdd) return "Add chart";+ if (charts.length >= MAX_EXPERIMENT_CHARTS)+ return `Maximum of ${MAX_EXPERIMENT_CHARTS} charts`;+ return "All available metrics are already shown";+ })();+ const handleAddChart = () => {+ addChart();+ capture("experiment:chart_added", {+ isV4: true,+ tableName: "experiments",+ chartCount: charts.length + 1,+ });+ };+ const renderChart = (slot: ExperimentChartSlot & { metricId: string }) => {+ const handleRemove = () => {+ removeChart(slot.id);+ capture("experiment:chart_removed", {+ isV4: true,+ tableName: "experiments",+ chartCount: charts.length - 1,+ });+ };+ const handleMetricChange = (metricId: string) => {+ if (metricId === slot.metricId) return;+ updateChart(slot.id, { metricId });+ capture(+ "experiment:chart_metric_changed",+ chartMetricChangedProps({+ tableName: "experiments",+ metricId,+ }),+ );+ };+ const handleChartTypeChange = (chartType: "line" | "bar") => {+ if (chartType === slot.chartType) return;+ updateChart(slot.id, { chartType });+ capture("experiment:chart_type_changed", {+ isV4: true,+ tableName: "experiments",+ chartType,+ });+ };+ return (+ <ExperimentMetricStrip+ key={slot.id}+ {...chartProps}+ projectId={projectId}+ availableMetricOptions={availableMetricOptions}+ slot={slot}+ canRemove={charts.length > 1}+ onRemove={handleRemove}+ onMetricChange={handleMetricChange}+ onChartTypeChange={handleChartTypeChange}+ />+ );+ };+ const renderCharts = () => {+ if (metricOptionsError)+ return (+ <div className="flex h-full items-center justify-center gap-2 text-xs">+ <span>Could not load chart metrics.</span>+ <Button+ text="Retry"+ variant="ghost"+ size="sm"+ onClick={onRetryMetricOptions}+ />+ </div>+ );+ if (isLoading)+ return (+ <div+ className="bg-muted h-full animate-pulse"+ aria-label="Loading charts"+ />+ );+ return (+ <div className="flex h-full min-h-0">+ <div className="grid min-w-0 flex-1 auto-cols-[minmax(260px,1fr)] grid-flow-col divide-x overflow-x-auto overflow-y-hidden">+ {charts.map(renderChart)}+ </div>+ <div className="shrink-0 border-l pt-1" title={addChartTitle}>+ <IconButton+ icon={Plus}+ label="Add chart"+ size="sm"+ disabled={!canAdd}+ onClick={handleAddChart}+ />+ </div>+ </div>+ );+ };+ return (+ <ResizablePanelGroup+ orientation="vertical"+ defaultLayout={defaultLayout}+ onLayoutChanged={onLayoutChanged}+ className="min-h-0 flex-1"+ >+ <ResizablePanel+ id="charts"+ defaultSize="150px"+ minSize="130px"+ maxSize="70%"+ >+ <div className="h-full border-t">{renderCharts()}</div>+ </ResizablePanel>+ <ResizableHandle withHandle aria-label="Resize charts and table" />+ <ResizablePanel id="table" minSize="150px">+ <div className="flex h-full min-h-0 flex-col overflow-hidden">+ {children}+ </div>+ </ResizablePanel>+ </ResizablePanelGroup>+ );+}diff --git a/web/src/features/experiments/components/ExperimentMetricStrip.tsx b/web/src/features/experiments/components/ExperimentMetricStrip.tsxindex 5def965184..94366abd43 100644--- a/web/src/features/experiments/components/ExperimentMetricStrip.tsx+++ b/web/src/features/experiments/components/ExperimentMetricStrip.tsx@@ -1,6 +1,7 @@-/* eslint-disable no-nested-ternary */import { useMemo } from "react";+import { X } from "lucide-react";import { DropdownIndicator } from "@/src/components/design-system/DropdownIndicator/DropdownIndicator";+import { IconButton } from "@/src/components/design-system/IconButton/IconButton";import {Select,SelectContent,@@ -10,138 +11,46 @@ import {SelectTrigger,SelectValue,} from "@/src/components/ui/select";-import DocPopup from "@/src/components/layouts/doc-popup";-import { ScoreTag, SCORE_LEVEL_LABELS } from "@/src/components/score-tag";+import { ScoreTag } from "@/src/components/score-tag";import { WidgetContent } from "@/src/features/widgets";import { type QueryType } from "@langfuse/shared/query";-import type {- MetricOption,- ScoreCoverageByLevel,-} from "@/src/features/experiments/types/charts";+import { type MetricOption } from "@/src/features/experiments/types/charts";import { buildWidgetConfigFromId } from "@/src/features/experiments/utils/charts";import { SCORE_LEVEL_TAGS } from "@/src/features/experiments/constants/charts";-import { cn } from "@/src/utils/tailwind";-import {- MetricStripBand,- MetricStripHeaderRow,- MetricStripMessage,- type MetricStripStatus,-} from "@/src/components/metric-strip/MetricStripBand";+import { MetricStripMessage } from "@/src/components/metric-strip/MetricStripBand";import {METRIC_STRIP_TRIGGER_CLASS,metricStripTriggerClasses,} from "@/src/components/metric-strip/MetricStripTrigger";-import { useExperimentStripMetric } from "@/src/features/experiments/hooks/useExperimentStripMetric";-import { usePostHogClientCapture } from "@/src/features/posthog-analytics";-import { chartMetricChangedProps } from "@/src/features/experiments/lib/analytics";--/**- * Stable node: `Chart` is memoized, so a fresh element on every render would- * defeat it. Says which half is missing β the metric, not the experiments.- */-const EMPTY_PLOT = <MetricStripMessage message="No values for this metric" />;--/**- * Leave room for the experiment names on the x-axis without shrinking the- * plot below the neighboring strips' height.- */-const PLOT_WITH_LABELS_HEIGHT_CLASS = "h-[100px]";--/**- * What this strip's ready content occupies, for the band's loading and empty- * box: the 13px header row (a `leading-none` 13px trigger), the 6px gap under- * it, and the plot with its labels. Taller than the band's default, and a- * placeholder of the wrong height drops the table by the difference the moment- * the data arrives.- */-const CONTENT_HEIGHT_CLASS = "h-[119px]";--const AXIS_EXPLANATION =- "One bar per experiment in view, oldest on the left and newest on the right, so a metric that improved over time climbs. The bars are a set of runs in start order, not a timeline β nothing is implied between two of them. The table below stays newest-first; filtering it changes which experiments are plotted, not their left-to-right order. Experiments with no value for this metric are left out. Experiment names appear on the x-axis; hovering a bar reveals its full name. Which metric opens by default is data-driven: the numeric score recorded on the most items across these experiments, with ties settled by name, falling back to cost only when none of them carry a score. Pick any metric from the dropdown and that choice is kept instead.";--/**- * Which columns carry the experiment, keyed by the chart's entity dimension.- * A score's level decides this: an observation-level score reads the experiment- * off its observation, a trace-level score off the scored trace's root event,- * and a run-level score is keyed by dataset run id alone.- */-const EXPERIMENT_SCOPE_COLUMNS: Record<- string,- { nameColumn?: string; idColumn: string }-> = {- experimentName: { nameColumn: "experimentName", idColumn: "experimentId" },- datasetRunId: { idColumn: "datasetRunId" },-};--const buildExperimentScopeFilters = ({- entityDimensionField,- experimentNames,- experimentIds,-}: {- entityDimensionField?: string;- experimentNames: string[];- experimentIds: string[];-}) => {- const scope = entityDimensionField- ? EXPERIMENT_SCOPE_COLUMNS[entityDimensionField]- : undefined;- if (!scope) return [];-- return [- ...(scope.nameColumn && experimentNames.length > 0- ? [- {- column: scope.nameColumn,- operator: "any of" as const,- value: experimentNames,- type: "stringOptions" as const,- },- ]- : []),- {- column: scope.idColumn,- operator: "any of" as const,- value: experimentIds,- type: "stringOptions" as const,- },- ];-};--type ExperimentMetricStripProps = {- projectId: string;- /** The experiments in view, in any order; the strip re-orders by start time. */- experiments: Array<{ id: string; name: string; startTime: Date }>;- fromTimestamp: Date;- toTimestamp: Date;- isExternalLoading?: boolean;- /**- * Values recorded per score name across the experiments in view, from the- * table's own rows. Decides the default metric (`pickDefaultStripMetric`);- * undefined until the row metrics land.- */- scoreCoverage?: ScoreCoverageByLevel;-};+import { cn } from "@/src/utils/tailwind";+import { type ExperimentChartSlot } from "@/src/features/experiments/hooks/useExperimentCharts";-/**- * The compact metric strip above the experiments table β one chart in the band- * the 4Γ224px chart grid used to occupy, modelled on the events table's- * outlier strip. It plots one metric across the experiments in view, defaulting- * to the best-recorded numeric score rather than cost, as one bar per- * experiment on a chronological- * x-axis (oldest left) so an improving metric climbs. The axis is a set of- * discrete runs, not a timeline β hence bars, not a line. Long experiment names- * stay off the axis; the legend and the hover tooltip carry identity.- */+const EMPTY_PLOT = (+ <MetricStripMessage message="No values for these experiments" />+);export function ExperimentMetricStrip({projectId,experiments,fromTimestamp,toTimestamp,- isExternalLoading = false,- scoreCoverage,-}: ExperimentMetricStripProps) {- // Chronological, oldest first: an improving metric has to read left-to-right.- // The table stays newest-first, so this is deliberately not the table order.+ availableMetricOptions,+ slot,+ onMetricChange,+ onChartTypeChange,+ onRemove,+ canRemove,+}: {+ projectId: string;+ experiments: Array<{ id: string; name: string; startTime: Date }>;+ fromTimestamp: Date;+ toTimestamp: Date;+ availableMetricOptions: MetricOption[];+ slot: ExperimentChartSlot & { metricId: string };+ onMetricChange: (metricId: string) => void;+ onChartTypeChange: (chartType: "line" | "bar") => void;+ onRemove: () => void;+ canRemove: boolean;+}) {const orderedExperiments = useMemo(() =>[...experiments].sort(@@ -149,45 +58,31 @@ export function ExperimentMetricStrip({),[experiments],);-- const experimentIds = useMemo(- () => orderedExperiments.map((experiment) => experiment.id),- [orderedExperiments],+ const selectedOption = availableMetricOptions.find(+ (option) => option.id === slot.metricId,);-- const { metricId, setMetricId, availableMetricOptions, isLoading } =- useExperimentStripMetric({ projectId, experimentIds, scoreCoverage });- const capture = usePostHogClientCapture();-- // Do people move the strip off its score-first default, and onto which score- // LEVEL? Trace-level is where an LLM-as-judge on a dataset run writes, so the- // level is the interesting half. The score's NAME is user content and is- // never sent. Reuses `chart_metric_changed` from the chart grid this strip- // replaced, so the metric-choice history is continuous.- const handleMetricChange = (newMetricId: string) => {- if (newMetricId === metricId) return;- capture(- "experiment:chart_metric_changed",- chartMetricChangedProps({- tableName: "experiments",- metricId: newMetricId,- }),- );- setMetricId(newMetricId);- };-- const { selectedMetricOption, widgetConfig } = useMemo(- () => ({- selectedMetricOption: availableMetricOptions.find(- (option) => option.id === metricId,- ),- widgetConfig: buildWidgetConfigFromId(metricId),- }),- [availableMetricOptions, metricId],+ const widgetConfig = useMemo(+ () => buildWidgetConfigFromId(slot.metricId),+ [slot.metricId],);-- // Presentation-only names for the entity axis; their insertion order is what- // InlineWidget orders the x-axis by, so it carries the chronological order.+ const label =+ selectedOption?.label ??+ slot.metricId.substring(slot.metricId.indexOf(":") + 1);+ const isCategorical =+ selectedOption?.valueKind === "categorical" ||+ slot.metricId.includes("-score-categorical:");+ const showLevels =+ new Set(+ availableMetricOptions.flatMap((option) =>+ option.level ? [option.level] : [],+ ),+ ).size > 1;+ const chartType = (() => {+ if (isCategorical) return "BAR_TIME_SERIES" as const;+ return slot.chartType === "bar"+ ? ("VERTICAL_BAR" as const)+ : ("LINE_TIME_SERIES" as const);+ })();const entityDimensionLabelMap = useMemo(() =>Object.fromEntries(@@ -198,182 +93,166 @@ export function ExperimentMetricStrip({),[orderedExperiments],);-- const query: QueryType | null = useMemo(() => {+ const query = useMemo((): QueryType | null => {if (!widgetConfig) return null;-- const experimentNames = Array.from(- new Set(- orderedExperiments- .map((experiment) => experiment.name)- .filter((name) => name.length > 0),- ),- );- const entityDimensionField = widgetConfig.entityDimension?.field;-return {view: widgetConfig.view,dimensions: [...widgetConfig.dimensions],- orderBy: widgetConfig.orderBy ? [...widgetConfig.orderBy] : null,+ orderBy: null,timeDimension: widgetConfig.timeDimension,entityDimension: widgetConfig.entityDimension,- metrics: widgetConfig.metrics.map((m) => ({- measure: m.measure,- aggregation: m.agg,+ metrics: widgetConfig.metrics.map((metric) => ({+ measure: metric.measure,+ aggregation: metric.agg,})),filters: [- ...(widgetConfig.filters ?? []),- ...buildExperimentScopeFilters({- entityDimensionField,- experimentNames,- experimentIds,- }),+ ...widgetConfig.filters,+ ...(widgetConfig.entityDimension.field === "experimentName"+ ? [+ {+ column: "experimentName",+ operator: "any of" as const,+ type: "stringOptions" as const,+ value: orderedExperiments.map((experiment) => experiment.name),+ },+ ]+ : []),+ {+ column:+ widgetConfig.entityDimension.field === "datasetRunId"+ ? "datasetRunId"+ : "experimentId",+ operator: "any of",+ type: "stringOptions",+ value: orderedExperiments.map((experiment) => experiment.id),+ },],fromTimestamp: fromTimestamp.toISOString(),toTimestamp: toTimestamp.toISOString(),};- }, [- widgetConfig,- orderedExperiments,- experimentIds,- fromTimestamp,- toTimestamp,- ]);+ }, [widgetConfig, orderedExperiments, fromTimestamp, toTimestamp]);- const groupedOptions = useMemo(() => {- const groups = new Map<MetricOption["group"], MetricOption[]>();-- for (const option of availableMetricOptions) {- const existing = groups.get(option.group) ?? [];- existing.push(option);- groups.set(option.group, existing);- }-- return groups;- }, [availableMetricOptions]);-- // A stored metric can name a score the experiments in view don't carry; show- // its name rather than a blank trigger.- const selectedLabel =- selectedMetricOption?.label ?? metricId.split(":").pop() ?? metricId;-- // Every dropdown row is tagged with its level; the header only needs the tag- // when the name alone doesn't say which series is drawn β the same score name- // can exist at two levels and the chart plots exactly one of them. A- // selected name that is unique reads plain, as in the tracing tables'- // filter picker.- const selectedLevel = selectedMetricOption?.level;- const isSelectedNameAmbiguous =- Boolean(selectedLevel) &&- availableMetricOptions.filter(- (option) => option.label === selectedMetricOption?.label,- ).length > 1;-- const isChartEnabled =- Boolean(selectedMetricOption) && orderedExperiments.length > 0;- const status: MetricStripStatus =- isExternalLoading || isLoading- ? "loading"- : isChartEnabled- ? "ready"- : "empty";+ const handleChartTypeChange = (value: string) => {+ if (value === "line" || value === "bar") onChartTypeChange(value);+ };return (- <MetricStripBand- status={status}- contentHeightClass={CONTENT_HEIGHT_CLASS}- // The band's own voice, in place of a 144px dashed card clipped by a- // 63px band: say which half is missing.- emptyMessage="No experiments in view"- header={- <MetricStripHeaderRow>- <Select value={metricId} onValueChange={handleMetricChange}>+ <section+ className="group/chart flex h-full min-h-[130px] min-w-0 flex-col"+ aria-label={`Chart: ${label}`}+ >+ <div className="flex min-h-8 min-w-0 items-center gap-1.5 pl-2">+ <div className="min-w-0 flex-1">+ <Select value={slot.metricId} onValueChange={onMetricChange}><SelectTrigger- aria-label={- selectedLevel- ? `Chart metric: ${selectedLabel} (${SCORE_LEVEL_LABELS[SCORE_LEVEL_TAGS[selectedLevel]]})`- : `Chart metric: ${selectedLabel}`- }- // The band's own bold trigger (`MetricStripTrigger`), on a- // Select rather than a DropdownMenu: this list is long (every- // score name, at every level), so it needs the scrolling and- // type-to-find a Select brings.+ aria-label="Chart metric"className={cn(METRIC_STRIP_TRIGGER_CLASS,metricStripTriggerClasses.metric,- "h-auto w-auto border-0 bg-transparent p-0 shadow-none focus:ring-0 focus:ring-offset-0",+ "h-auto w-auto max-w-full justify-start border-0 bg-transparent p-0 shadow-none focus:ring-0 focus:ring-offset-0",)}hideDownIcon>- <SelectValue placeholder="Select metric...">- {selectedLabel}+ <SelectValue>+ <span className="truncate" title={label}>+ {label}+ </span></SelectValue>- {isSelectedNameAmbiguous && selectedLevel && (- <ScoreTag level={SCORE_LEVEL_TAGS[selectedLevel]} />+ {showLevels && selectedOption?.level && (+ <ScoreTag level={SCORE_LEVEL_TAGS[selectedOption.level]} />)}<DropdownIndicator size="sm" nudge /></SelectTrigger><SelectContent>- {Array.from(groupedOptions.entries()).map(([group, options]) => (+ {!selectedOption && (+ <SelectItem value={slot.metricId} disabled>+ {label} (unavailable)+ </SelectItem>+ )}+ {(["Scores", "Base Metrics"] as const).map((group) => (<SelectGroup key={group}><SelectLabel className="text-xs font-bold">{group}</SelectLabel>- {options.map((option) => (- <SelectItem- key={option.id}- value={option.id}- // Type-to-find stays on the score name, so the level tag- // can't swallow a keystroke.- textValue={option.label}- >- <span className="flex items-center gap-1.5">- {option.label}- {option.level && (- <ScoreTag level={SCORE_LEVEL_TAGS[option.level]} />- )}- </span>- </SelectItem>- ))}+ {availableMetricOptions+ .filter((option) => option.group === group)+ .map((option) => (+ <SelectItem+ key={option.id}+ value={option.id}+ textValue={option.label}+ >+ <span className="flex items-center gap-1.5">+ {showLevels && option.level && (+ <ScoreTag level={SCORE_LEVEL_TAGS[option.level]} />+ )}+ {option.label}+ </span>+ </SelectItem>+ ))}</SelectGroup>))}</SelectContent></Select>- <span className="text-muted-foreground flex items-baseline text-xs leading-none">- oldest to newest- <DocPopup description={AXIS_EXPLANATION} />- </span>- </MetricStripHeaderRow>- }- >- <div- className={cn("mt-1.5 flex flex-col", PLOT_WITH_LABELS_HEIGHT_CLASS)}- >- {query && widgetConfig && (+ </div>+ {!isCategorical && (+ <Select value={slot.chartType} onValueChange={handleChartTypeChange}>+ <SelectTrigger+ aria-label="Chart type"+ className="h-6 w-auto gap-1 border-0 px-1 text-xs opacity-0 shadow-none group-focus-within/chart:opacity-100 group-hover/chart:opacity-100 data-[state=open]:opacity-100 [@media(hover:none)]:opacity-100"+ >+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="line">Line</SelectItem>+ <SelectItem value="bar">Bar</SelectItem>+ </SelectContent>+ </Select>+ )}+ {canRemove && (+ <div className="opacity-0 group-focus-within/chart:opacity-100 group-hover/chart:opacity-100 [@media(hover:none)]:opacity-100">+ <IconButton+ icon={X}+ label={`Remove ${label} chart`}+ size="sm"+ onClick={onRemove}+ />+ </div>+ )}+ </div>+ <div className="flex min-h-0 flex-1 flex-col">+ {selectedOption && query && widgetConfig && experiments.length > 0 ? (<WidgetContentprojectId={projectId}query={query}version={widgetConfig.minVersion}- chartType={widgetConfig.chartType}- chartConfig={widgetConfig.chartConfig}+ chartType={chartType}+ chartConfig={+ chartType === "LINE_TIME_SERIES"+ ? { type: chartType, show_data_point_dots: true }+ : { type: chartType }+ }metrics={[...widgetConfig.metrics]}dimensions={[...widgetConfig.dimensions]}view={widgetConfig.view}- schedulerId={`experiments-strip-${metricId}`}- isExternalLoading={isExternalLoading}+ schedulerId={`experiments-chart-${slot.id}`}layoutHint="tight"entityDimensionLabelMap={entityDimensionLabelMap}- // The band is 63px: the chart's own "No data" card is taller than- // that and clips its own text inside it.emptyState={EMPTY_PLOT}- // The axis shows shortened names; hover restores the full name.legendPosition="none"- colorBarsByCategory- // Bars are compared by length, so they have to start at zero.- zeroBaseline+ colorBarsByCategory={chartType === "VERTICAL_BAR"}+ zeroBaseline={chartType !== "LINE_TIME_SERIES"}+ />+ ) : (+ <MetricStripMessage+ message={+ experiments.length === 0+ ? "No experiments in view"+ : "No values for these experiments"+ }/>)}</div>- </MetricStripBand>+ </section>);}diff --git a/web/src/features/experiments/components/table/ExperimentsTable.tsx b/web/src/features/experiments/components/table/ExperimentsTable.tsxindex 68cefaaf5e..78fe299f60 100644--- a/web/src/features/experiments/components/table/ExperimentsTable.tsx+++ b/web/src/features/experiments/components/table/ExperimentsTable.tsx@@ -76,7 +76,8 @@ import { type ExperimentsTableRow, type ExperimentsTableProps } from "./types";import { useExperimentFilterOptions } from "../../hooks/useExperimentFilterOptions";import { RunEvaluationDialog } from "@/src/features/batch-actions";import { useHasProjectAccess } from "@/src/features/rbac";-import { ExperimentMetricStrip } from "../ExperimentMetricStrip";+import { ExperimentChartsLayout } from "../ExperimentChartsLayout";+import { metricOptionsFromScoreColumns } from "../../fns/metricOptionsFromScoreColumns";import {createExperimentsTableStore,type ExperimentsTableStore,@@ -441,8 +442,11 @@ export default function ExperimentsTable({totalCount,dataUpdatedAt,metricsLoading,+ metricsError,+ refetchMetrics,isShowingMostRecent,mostRecentCount,+ fallbackDateRange,} = useExperimentsTableData({projectId,filterState,@@ -515,6 +519,9 @@ export default function ExperimentsTable({const {scoreColumns: observationItemScoreColumns,isLoading: isObservationItemScoreLoading,+ scoreDefinitions: observationScoreDefinitions,+ error: observationScoreOptionsError,+ refetch: refetchObservationScoreOptions,} = useScoreColumns<ExperimentsTableRow>({rawKey: true,displayFormat: "aggregate",@@ -535,6 +542,9 @@ export default function ExperimentsTable({const {scoreColumns: experimentScoreColumns,isLoading: isExperimentScoreColumnLoading,+ scoreDefinitions: experimentScoreDefinitions,+ error: experimentScoreOptionsError,+ refetch: refetchExperimentScoreOptions,} = useScoreColumns<ExperimentsTableRow>({scoreColumnKey: "experimentScores",projectId,@@ -550,6 +560,16 @@ export default function ExperimentsTable({presentKeys: presentScoreKeys?.experiment,});+ const availableMetricOptions = useMemo(+ () =>+ metricOptionsFromScoreColumns(+ observationScoreDefinitions,+ experimentScoreDefinitions,+ ),+ [observationScoreDefinitions, experimentScoreDefinitions],+ );+ const chartDateRange = fallbackDateRange ?? tableDateRange;+const { selectActionColumn } = TableSelectionManager<ExperimentsTableRow>({projectId,tableName: "experiments",@@ -1043,80 +1063,96 @@ export default function ExperimentsTable({{/* Table-width, like the events table's pulse strip: inside thelayout so the facet sidebar keeps its full height and thestrip resizes with the table. */}- {tableDateRange && (- <ExperimentMetricStrip- projectId={projectId}- experiments={chartExperiments}- fromTimestamp={tableDateRange.from}- toTimestamp={tableDateRange.to}- isExternalLoading={experiments.status === "loading"}- scoreCoverage={scoreCoverage}- />- )}- <DataTable- key={`experiments-table-${dataUpdatedAt}`}- tableName="experiments"- columns={columns}- data={- experiments.status === "loading" || isViewLoading- ? { isLoading: true, isError: false }- : experiments.status === "error"- ? {- isLoading: false,- isError: true,- error: "",- }- : {- isLoading: false,- isError: false,- data: rows,- }+ <ExperimentChartsLayout+ projectId={projectId}+ experiments={chartExperiments}+ fromTimestamp={chartDateRange?.from}+ toTimestamp={chartDateRange?.to}+ isExternalLoading={experiments.status === "loading"}+ scoreCoverage={scoreCoverage}+ availableMetricOptions={availableMetricOptions}+ isMetricOptionsLoading={+ metricsLoading ||+ isObservationItemScoreLoading ||+ isExperimentScoreColumnLoading+ }+ metricOptionsError={+ metricsError?.message ??+ observationScoreOptionsError?.message ??+ experimentScoreOptionsError?.message ??+ null}- pagination={{- totalCount,- onChange: (updater) => {- const newState =- typeof updater === "function"- ? updater({- pageIndex: paginationState.page - 1,- pageSize: paginationState.limit,- })- : updater;- setPaginationState({- page: newState.pageIndex + 1,- limit: newState.pageSize,- });- },- state: {- pageIndex: paginationState.page - 1,- pageSize: paginationState.limit,- },+ onRetryMetricOptions={() => {+ refetchMetrics();+ refetchObservationScoreOptions();+ refetchExperimentScoreOptions();}}- selectionStore={experimentsTableStore}- setOrderBy={handleOrderByChange}- orderBy={orderByState}- columnOrder={columnOrder}- onColumnOrderChange={handleColumnOrderChange}- columnVisibility={columnVisibility}- onColumnVisibilityChange={handleColumnVisibilityChange}- rowHeight={rowHeight}- onRowClick={(row, event) => {- // Handle Command/Ctrl+click to open experiment in new tab- if (event && (event.metaKey || event.ctrlKey)) {- event.preventDefault();- const experimentId = row.id;- const experimentUrl = `/project/${projectId}/experiments/results?baseline=${encodeURIComponent(experimentId)}`;- const fullUrl = `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${experimentUrl}`;- window.open(fullUrl, "_blank");- }- // For normal clicks, navigate to experiment detail page- else {- router.push(- `/project/${projectId}/experiments/results?baseline=${encodeURIComponent(row.id)}`,- );+ >+ <DataTable+ key={`experiments-table-${dataUpdatedAt}`}+ tableName="experiments"+ columns={columns}+ data={+ experiments.status === "loading" || isViewLoading+ ? { isLoading: true, isError: false }+ : experiments.status === "error"+ ? {+ isLoading: false,+ isError: true,+ error: "",+ }+ : {+ isLoading: false,+ isError: false,+ data: rows,+ }}- }}- />+ pagination={{+ totalCount,+ onChange: (updater) => {+ const newState =+ typeof updater === "function"+ ? updater({+ pageIndex: paginationState.page - 1,+ pageSize: paginationState.limit,+ })+ : updater;+ setPaginationState({+ page: newState.pageIndex + 1,+ limit: newState.pageSize,+ });+ },+ state: {+ pageIndex: paginationState.page - 1,+ pageSize: paginationState.limit,+ },+ }}+ selectionStore={experimentsTableStore}+ setOrderBy={handleOrderByChange}+ orderBy={orderByState}+ columnOrder={columnOrder}+ onColumnOrderChange={handleColumnOrderChange}+ columnVisibility={columnVisibility}+ onColumnVisibilityChange={handleColumnVisibilityChange}+ rowHeight={rowHeight}+ onRowClick={(row, event) => {+ // Handle Command/Ctrl+click to open experiment in new tab+ if (event && (event.metaKey || event.ctrlKey)) {+ event.preventDefault();+ const experimentId = row.id;+ const experimentUrl = `/project/${projectId}/experiments/results?baseline=${encodeURIComponent(experimentId)}`;+ const fullUrl = `${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}${experimentUrl}`;+ window.open(fullUrl, "_blank");+ }+ // For normal clicks, navigate to experiment detail page+ else {+ router.push(+ `/project/${projectId}/experiments/results?baseline=${encodeURIComponent(row.id)}`,+ );+ }+ }}+ />+ </ExperimentChartsLayout></div></StickySearchableTableFilterLayout></div>diff --git a/web/src/features/experiments/constants/charts.ts b/web/src/features/experiments/constants/charts.tsindex 5fefc6b895..88e01d0f2c 100644--- a/web/src/features/experiments/constants/charts.ts+++ b/web/src/features/experiments/constants/charts.ts@@ -6,6 +6,8 @@ import type {import type { WidgetDimensionConfig } from "@/src/features/widgets";import type { FilterCondition } from "@langfuse/shared";+export const MAX_EXPERIMENT_CHARTS = 4;+// Base chart IDsexport const BASE_CHART_IDS = {COST: "base:cost",@@ -64,12 +66,8 @@ const BASE_EXPERIMENT_WIDGET_CONFIG = {// Entity (x-axis) order follows the experiments table order, applied// client-side in InlineWidget, so no query-side ordering is needed.orderBy: null,- // Bars, not a line: the axis is a set of discrete experiments, so a segment- // drawn between two of them claims a continuity that does not exist. A bar- // also makes a metric that only some runs recorded read as absent rather- // than as a long line across every other run.- chartType: "VERTICAL_BAR",- chartConfig: { type: "VERTICAL_BAR" },+ chartType: "LINE_TIME_SERIES",+ chartConfig: { type: "LINE_TIME_SERIES" },timeDimension: null,entityDimension: { field: "experimentName" },filters: [],@@ -114,9 +112,8 @@ export const NUMERIC_SCORE_CHART_CONFIG = {dimensions: [],metrics: [{ measure: "value", agg: "avg" }],filters: [],- // See BASE_EXPERIMENT_WIDGET_CONFIG: one bar per experiment, not a line.- chartType: "VERTICAL_BAR",- chartConfig: { type: "VERTICAL_BAR" },+ chartType: "LINE_TIME_SERIES",+ chartConfig: { type: "LINE_TIME_SERIES" },} as const;export const CATEGORICAL_SCORE_CHART_CONFIG = {diff --git a/web/src/features/experiments/fns/metricOptionsFromScoreColumns.ts b/web/src/features/experiments/fns/metricOptionsFromScoreColumns.tsnew file mode 100644index 0000000000..47221b4860--- /dev/null+++ b/web/src/features/experiments/fns/metricOptionsFromScoreColumns.ts@@ -0,0 +1,37 @@+import { buildMetricOptions } from "../utils/charts";++type ScoreColumn = { name: string; dataType: string };++/** Chart identities combine sources, matching the widget query aggregation. */+export function metricOptionsFromScoreColumns(+ observation: ScoreColumn[],+ experiment: ScoreColumn[],+) {+ const groupScoreNamesByDataType = (columns: ScoreColumn[]) => {+ const numeric = new Set(+ columns.filter((c) => c.dataType === "NUMERIC").map((c) => c.name),+ );+ const booleans = new Set(+ columns.filter((c) => c.dataType === "BOOLEAN").map((c) => c.name),+ );+ return {+ numeric: [...new Set([...numeric, ...booleans])],+ boolean: [...booleans].filter((name) => !numeric.has(name)),+ categorical: Object.fromEntries(+ columns+ .filter((c) => c.dataType === "CATEGORICAL")+ .map((c) => [c.name, [] as string[]]),+ ),+ };+ };+ const obs = groupScoreNamesByDataType(observation);+ const run = groupScoreNamesByDataType(experiment);+ return buildMetricOptions({+ obs_scores_avg: obs.numeric,+ obs_score_booleans: obs.boolean,+ obs_score_categories: obs.categorical,+ experiment_scores_avg: run.numeric,+ experiment_score_booleans: run.boolean,+ experiment_score_categories: run.categorical,+ });+}diff --git a/web/src/features/experiments/fns/pickDefaultStripMetric.ts b/web/src/features/experiments/fns/pickDefaultStripMetric.tsindex 69bfa531ed..eea4511ec5 100644--- a/web/src/features/experiments/fns/pickDefaultStripMetric.ts+++ b/web/src/features/experiments/fns/pickDefaultStripMetric.ts@@ -6,9 +6,9 @@ import type {import { normalizeScoreName } from "@/src/features/scores";/** Score chart ids are `${level}-score-${dataType}:${scoreName}`. */-const NUMERIC_SCORE_ID = /^(obs|trace|experiment)-score-numeric:/;+const NUMERIC_SCORE_ID = /^(obs|experiment)-score-numeric:/;-/** Numeric first: only a numeric average reads as a bar in a 63px band. */+/** Prefer a numeric quality metric over boolean or categorical distributions. */const VALUE_KIND_RANK: Record<NonNullable<MetricOption["valueKind"]>,number@@ -40,7 +40,7 @@ const valueKindOf = (** Coverage is unknown until the row metrics land; until then the order falls* through to the name. A user's explicit pick always wins β see- * `useExperimentStripMetric`.+ * `useExperimentCharts`.*/export function pickDefaultStripMetric(options: MetricOption[],diff --git a/web/src/features/experiments/hooks/useExperimentCharts.clienttest.tsx b/web/src/features/experiments/hooks/useExperimentCharts.clienttest.tsxnew file mode 100644index 0000000000..a66a6133e8--- /dev/null+++ b/web/src/features/experiments/hooks/useExperimentCharts.clienttest.tsx@@ -0,0 +1,63 @@+import { act, renderHook } from "@testing-library/react";+import { useExperimentCharts } from "./useExperimentCharts";+import { type MetricOption } from "../types/charts";++const cost: MetricOption = {+ id: "base:cost",+ label: "Cost ($)",+ group: "Base Metrics",+};+const latency: MetricOption = {+ id: "base:latency",+ label: "Latency (ms)",+ group: "Base Metrics",+};+const accuracy: MetricOption = {+ id: "obs-score-numeric:accuracy",+ label: "accuracy",+ group: "Scores",+ level: "obs",+ valueKind: "numeric",+};+const quality: MetricOption = {+ ...accuracy,+ id: "obs-score-numeric:quality",+ label: "quality",+};+const options = [cost, latency, accuracy, quality];++beforeEach(() => localStorage.clear());++it("keeps an explicit metric and chart type across filters and remounts", () => {+ const { result, rerender, unmount } = renderHook(+ ({ availableMetricOptions }) =>+ useExperimentCharts({ projectId: "p1", availableMetricOptions }),+ { initialProps: { availableMetricOptions: options } },+ );+ act(() =>+ result.current.updateChart("initial", {+ metricId: accuracy.id,+ chartType: "bar",+ }),+ );+ rerender({ availableMetricOptions: [cost, latency] });+ expect(result.current.charts[0]).toMatchObject({+ metricId: accuracy.id,+ chartType: "bar",+ });+ unmount();+ const restored = renderHook(() =>+ useExperimentCharts({ projectId: "p1", availableMetricOptions: options }),+ );+ expect(restored.result.current.charts[0]).toMatchObject({+ metricId: accuracy.id,+ chartType: "bar",+ });+ const otherProject = renderHook(() =>+ useExperimentCharts({ projectId: "p2", availableMetricOptions: [cost] }),+ );+ expect(otherProject.result.current.charts[0]).toMatchObject({+ metricId: cost.id,+ chartType: "line",+ });+});diff --git a/web/src/features/experiments/hooks/useExperimentCharts.ts b/web/src/features/experiments/hooks/useExperimentCharts.tsnew file mode 100644index 0000000000..1acf9d4dd3--- /dev/null+++ b/web/src/features/experiments/hooks/useExperimentCharts.ts@@ -0,0 +1,96 @@+import { MAX_EXPERIMENT_CHARTS } from "../constants/charts";+import useLocalStorage from "@/src/components/useLocalStorage";+import { pickDefaultStripMetric } from "@/src/features/experiments/fns/pickDefaultStripMetric";+import {+ type MetricOption,+ type ScoreCoverageByLevel,+} from "@/src/features/experiments/types/charts";++export type ExperimentChartSlot = {+ id: string;+ /** Null keeps the score-first automatic default until the user chooses. */+ metricId: string | null;+ chartType: "line" | "bar";+};+const INITIAL_CHARTS: ExperimentChartSlot[] = [+ { id: "initial", metricId: null, chartType: "line" },+];++export function useExperimentCharts({+ projectId,+ availableMetricOptions,+ scoreCoverage,+}: {+ projectId: string;+ availableMetricOptions: MetricOption[];+ scoreCoverage?: ScoreCoverageByLevel;+}) {+ const [storedCharts, setCharts] = useLocalStorage<ExperimentChartSlot[]>(+ `experiment-charts-v1-${projectId}`,+ INITIAL_CHARTS,+ );+ const charts = validSlots(storedCharts) ? storedCharts : INITIAL_CHARTS;+ const defaultMetricId = pickDefaultStripMetric(+ availableMetricOptions,+ scoreCoverage,+ );+ const resolvedCharts = charts.map((chart) => ({+ ...chart,+ metricId: chart.metricId ?? defaultMetricId,+ }));+ const unusedOptions = availableMetricOptions.filter(+ (option) => !resolvedCharts.some((chart) => chart.metricId === option.id),+ );++ return {+ charts: resolvedCharts,+ canAdd: charts.length < MAX_EXPERIMENT_CHARTS && unusedOptions.length > 0,+ addChart: () => {+ if (charts.length >= MAX_EXPERIMENT_CHARTS || unusedOptions.length === 0)+ return;+ setCharts([+ ...charts,+ {+ id: crypto.randomUUID(),+ metricId:+ unusedOptions.find(+ (option) =>+ option.id ===+ pickDefaultStripMetric(unusedOptions, scoreCoverage),+ )?.id ?? unusedOptions[0].id,+ chartType: "line",+ },+ ]);+ },+ removeChart: (id: string) => {+ if (charts.length > 1)+ setCharts(charts.filter((chart) => chart.id !== id));+ },+ updateChart: (+ id: string,+ update: Partial<Pick<ExperimentChartSlot, "metricId" | "chartType">>,+ ) => {+ setCharts(+ charts.map((chart) =>+ chart.id === id ? { ...chart, ...update } : chart,+ ),+ );+ },+ };+}++function validSlots(value: unknown): value is ExperimentChartSlot[] {+ return (+ Array.isArray(value) &&+ value.length > 0 &&+ value.length <= MAX_EXPERIMENT_CHARTS &&+ new Set(value.map((slot) => slot?.id)).size === value.length &&+ value.every(+ (slot) =>+ slot &&+ typeof slot.id === "string" &&+ (slot.metricId === null || typeof slot.metricId === "string") &&+ (slot.chartType === "line" || slot.chartType === "bar"),+ )+ );+}diff --git a/web/src/features/experiments/hooks/useExperimentStripMetric.clienttest.tsx b/web/src/features/experiments/hooks/useExperimentStripMetric.clienttest.tsxdeleted file mode 100644index f3a60338eb..0000000000--- a/web/src/features/experiments/hooks/useExperimentStripMetric.clienttest.tsx+++ /dev/null@@ -1,157 +0,0 @@-import { render, screen } from "@testing-library/react";-import { useExperimentStripMetric } from "./useExperimentStripMetric";-import { type ScoreCoverageByLevel } from "@/src/features/experiments/types/charts";--const scoreOptionsQuery = vi.fn();--vi.mock("@/src/utils/api", () => ({- api: {- experiments: {- scoreOptions: {- useQuery: (...args: unknown[]) => scoreOptionsQuery(...args),- },- },- },-}));--const SCORE_OPTIONS_DATA = {- obs_scores_avg: ["groundedness"],- obs_score_categories: [],- experiment_scores_avg: [],- experiment_score_categories: [],-};--/**- * Two observation-level scores as the score-options endpoint returns them:- * booleans are listed under `*_scores_avg` too, and only `*_score_columns`- * says which they are.- */-const MIXED_SCORE_OPTIONS_DATA = {- ...SCORE_OPTIONS_DATA,- obs_scores_avg: ["answered_in_right_language", "groundedness"],- obs_score_columns: [- {- name: "answered_in_right_language",- dataType: "BOOLEAN",- source: "EVAL",- },- { name: "groundedness", dataType: "NUMERIC", source: "EVAL" },- ],-};--function Harness({- experimentIds,- scoreCoverage,-}: {- experimentIds: string[];- scoreCoverage?: ScoreCoverageByLevel;-}) {- const { metricId, isLoading } = useExperimentStripMetric({- projectId: "p1",- experimentIds,- scoreCoverage,- });- return (- <div data-testid="state">{`${isLoading ? "loading" : "ready"}:${metricId}`}</div>- );-}--const state = () => screen.getByTestId("state").textContent;--describe("useExperimentStripMetric", () => {- beforeEach(() => {- sessionStorage.clear();- scoreOptionsQuery.mockReset();- });-- // The bug: a pending options query left the hook "ready" on the Cost- // fallback, so a project full of scores opened on "Cost ($)". The fallback- // asserts that the experiments in view carry no scores β it may only be- // reached once the query can say so.- it("stays loading while the score options are unknown", () => {- scoreOptionsQuery.mockReturnValue({- data: undefined,- isSuccess: false,- isError: false,- });- render(<Harness experimentIds={["e1"]} />);- expect(state()).toBe("loading:base:cost");- });-- it("opens on a score once the options arrive", () => {- scoreOptionsQuery.mockReturnValue({- data: SCORE_OPTIONS_DATA,- isSuccess: true,- isError: false,- });- render(<Harness experimentIds={["e1"]} />);- expect(state()).toBe("ready:obs-score-numeric:groundedness");- });-- // Nothing to ask about: the strip renders its empty band, so it must not be- // held on a skeleton by a query that never runs.- it("is not loading when no experiments are in view", () => {- scoreOptionsQuery.mockReturnValue({- data: undefined,- isSuccess: false,- isError: false,- });- render(<Harness experimentIds={[]} />);- expect(state()).toBe("ready:base:cost");- });-- // The reviewer's question: why this score? Because it is the numeric score- // with the most values recorded across the runs in view β not the first name.- it("opens on the best-recorded numeric score", () => {- scoreOptionsQuery.mockReturnValue({- data: {- ...SCORE_OPTIONS_DATA,- obs_scores_avg: ["accuracy", "groundedness"],- },- isSuccess: true,- isError: false,- });- render(- <Harness- experimentIds={["e1"]}- scoreCoverage={{- obs: new Map([- ["accuracy", 4],- ["groundedness", 88],- ]),- }}- />,- );- expect(state()).toBe("ready:obs-score-numeric:groundedness");- });-- it("does not open on a boolean score while a numeric one exists", () => {- scoreOptionsQuery.mockReturnValue({- data: MIXED_SCORE_OPTIONS_DATA,- isSuccess: true,- isError: false,- });- render(- <Harness- experimentIds={["e1"]}- scoreCoverage={{- obs: new Map([- ["answered_in_right_language", 300],- ["groundedness", 30],- ]),- }}- />,- );- expect(state()).toBe("ready:obs-score-numeric:groundedness");- });-- it("falls back to cost when the options query fails", () => {- scoreOptionsQuery.mockReturnValue({- data: undefined,- isSuccess: false,- isError: true,- });- render(<Harness experimentIds={["e1"]} />);- expect(state()).toBe("ready:base:cost");- });-});diff --git a/web/src/features/experiments/hooks/useExperimentStripMetric.ts b/web/src/features/experiments/hooks/useExperimentStripMetric.tsdeleted file mode 100644index fe39af0f35..0000000000--- a/web/src/features/experiments/hooks/useExperimentStripMetric.ts+++ /dev/null@@ -1,123 +0,0 @@-import { useMemo } from "react";-import useSessionStorage from "@/src/components/useSessionStorage";-import { buildMetricOptions } from "@/src/features/experiments/utils/charts";-import { pickDefaultStripMetric } from "@/src/features/experiments/fns/pickDefaultStripMetric";-import { api } from "@/src/utils/api";-import {- type ScoreCoverageByLevel,- type ScoreFilterOptions,-} from "@/src/features/experiments/types/charts";--const processCategoricalScoreOptions = (- categories: Array<{ label: string; values: string[] }>,-): Record<string, string[]> =>- Object.fromEntries(categories.map(({ label, values }) => [label, values]));--/**- * The score names whose values are booleans at this level. Booleans are also- * listed as numeric (they are stored as 0/1), so a name that is numeric- * anywhere at this level is left out: the strip's default ranks a boolean below- * a true numeric, and a share of true reads nothing like an average.- */-const booleanOnlyScoreNames = (- columns: Array<{ name: string; dataType: string }> | undefined,-): string[] => {- if (!columns) return [];- const numericNames = new Set(- columns.filter((c) => c.dataType === "NUMERIC").map((c) => c.name),- );- return Array.from(- new Set(- columns- .filter((c) => c.dataType === "BOOLEAN" && !numericNames.has(c.name))- .map((c) => c.name),- ),- );-};--/**- * The metric the experiments strip plots, persisted per project in session- * storage. Nothing is persisted until the user picks one, so the coverage-first- * default (`pickDefaultStripMetric`) keeps applying as the score options- * arrive β and a stored metric that the experiments in view no longer carry- * falls back to it instead of rendering an empty chart.- *- * `isLoading` covers "we do not know the options yet", not just "a request is- * in flight". `pickDefaultStripMetric`'s Cost fallback asserts something β- * that the experiments in view carry no scores β and only the score-options- * query can assert it. Until it has, the strip must show its loading state:- * reporting ready would put "Cost ($)" in the header of a project full of- * scores.- */-export function useExperimentStripMetric({- projectId,- experimentIds,- scoreCoverage,-}: {- projectId: string;- experimentIds: string[];- /** See `pickDefaultStripMetric`: coverage decides the default metric. */- scoreCoverage?: ScoreCoverageByLevel;-}) {- // `projectId` arrives with `router.query` after hydration; without it in the- // guard the query can fire with `undefined` and zod rejects it. With no- // experiments in view there is nothing to ask about.- const canLoadScoreOptions = Boolean(projectId) && experimentIds.length > 0;-- const scoreOptions = api.experiments.scoreOptions.useQuery(- { projectId, experimentIds },- { enabled: canLoadScoreOptions },- );-- const [selectedMetricId, setSelectedMetricId] = useSessionStorage<- string | null- >(`experiment-strip-metric-${projectId}`, null);-- const transformedScoreOptions = useMemo((): ScoreFilterOptions => {- if (!scoreOptions.data) {- return {};- }- return {- obs_scores_avg: scoreOptions.data.obs_scores_avg,- obs_score_categories: processCategoricalScoreOptions(- scoreOptions.data.obs_score_categories,- ),- obs_score_booleans: booleanOnlyScoreNames(- scoreOptions.data.obs_score_columns,- ),- experiment_scores_avg: scoreOptions.data.experiment_scores_avg,- experiment_score_categories: processCategoricalScoreOptions(- scoreOptions.data.experiment_score_categories,- ),- experiment_score_booleans: booleanOnlyScoreNames(- scoreOptions.data.experiment_score_columns,- ),- };- }, [scoreOptions.data]);-- const availableMetricOptions = useMemo(- () => buildMetricOptions(transformedScoreOptions),- [transformedScoreOptions],- );-- const metricId = useMemo(() => {- if (- selectedMetricId &&- availableMetricOptions.some((option) => option.id === selectedMetricId)- ) {- return selectedMetricId;- }- return pickDefaultStripMetric(availableMetricOptions, scoreCoverage);- }, [selectedMetricId, availableMetricOptions, scoreCoverage]);-- return {- metricId,- setMetricId: setSelectedMetricId,- availableMetricOptions,- // A disabled query is "pending" forever, so settle on the query's own- // outcome rather than on `isLoading`, which a not-yet-started fetch- // reports as false.- isLoading:- canLoadScoreOptions && !scoreOptions.isSuccess && !scoreOptions.isError,- };-}diff --git a/web/src/features/experiments/hooks/useExperimentsTableData.ts b/web/src/features/experiments/hooks/useExperimentsTableData.tsindex 9819eac2be..acc7ea8453 100644--- a/web/src/features/experiments/hooks/useExperimentsTableData.ts+++ b/web/src/features/experiments/hooks/useExperimentsTableData.ts@@ -187,8 +187,13 @@ export function useExperimentsTableData({dataUpdatedAt,totalCount,metricsLoading: metricsQuery.isLoading,+ metricsError: metricsQuery.error,+ refetchMetrics: metricsQuery.refetch,/** The rows shown are the most recent runs, not the selected time range. */isShowingMostRecent,+ fallbackDateRange: isShowingMostRecent+ ? mostRecentQuery.data?.dateRange+ : undefined,/*** How many fallback runs are actually on screen. The cap is what was asked* for, not what came back, so a project with fewer runs than the cap mustdiff --git a/web/src/features/experiments/lib/analytics.ts b/web/src/features/experiments/lib/analytics.tsindex fc5fca53ea..db41b59b70 100644--- a/web/src/features/experiments/lib/analytics.ts+++ b/web/src/features/experiments/lib/analytics.ts@@ -116,16 +116,7 @@ export function baselineChangedProps({};}-/**- * `chart_metric_changed` β the metric behind the list's compact metric strip.- * Inherited from the four-slot chart grid this replaced, so the event name and- * its history carry over; `chartIndex`/`slotCount` are gone with the slots.- *- * The score's NAME is user content and never leaves the client β only which- * family of metric it is, at which score level, of which type. The level is the- * interesting half: trace-level is where an LLM-as-judge on a dataset run- * writes, and it only became selectable here at all in this change.- */+/** Metric selection metadata: score names never leave the client. */export function chartMetricChangedProps({tableName,metricId,diff --git a/web/src/features/experiments/server/router.ts b/web/src/features/experiments/server/router.tsindex b2260d9044..87847d289c 100644--- a/web/src/features/experiments/server/router.ts+++ b/web/src/features/experiments/server/router.ts@@ -348,6 +348,10 @@ export const experimentsRouter = createTRPCRouter({scope: "promptExperiments:read",});+ // Return the server-resolved window so widgets share it without adding+ // a render-time timestamp to the fallback query input.+ const to = new Date();+ const from = addDays(to, -MOST_RECENT_LOOKBACK_DAYS);const filter: FilterState = [// The selected window is the one that came back empty; every other// filter the user applied still holds.@@ -356,7 +360,7 @@ export const experimentsRouter = createTRPCRouter({column: "startTime",type: "datetime",operator: ">=",- value: addDays(new Date(), -MOST_RECENT_LOOKBACK_DAYS),+ value: from,},];@@ -368,7 +372,7 @@ export const experimentsRouter = createTRPCRouter({limit: input.limit,});- return { data: experiments };+ return { data: experiments, dateRange: { from, to } };}),byId: protectedProjectProcedurediff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex d617cf22a1..12d6a0026d 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -342,18 +342,15 @@ const events = {// distinguishes picker vs table-selection vs url (deep link / redirect) vs// auto β so the auto-selected comparison stays out of "users who compare".//- // Two events from the original plan went away with the surfaces they- // measured: `analytics_tab_opened` (the Analytics route is- // deleted) and `charts_section_toggled` (the charts accordion is replaced by- // an always-on metric strip). `chart_metric_changed` now belongs to that- // strip and `item_regression_filter_applied` to the score-comparison filter:- // same question, same name, so the event history stays continuous.experiment: ["comparison_changed","comparison_picker_opened","baseline_changed","auto_comparison_preference_changed","chart_metric_changed",+ "chart_added",+ "chart_removed",+ "chart_type_changed","layout_changed","diff_mode_changed","score_column_scope_toggled",diff --git a/web/src/features/scores/hooks/useScoreColumns.ts b/web/src/features/scores/hooks/useScoreColumns.tsindex 358d7d539d..8918a99aa5 100644--- a/web/src/features/scores/hooks/useScoreColumns.ts+++ b/web/src/features/scores/hooks/useScoreColumns.ts@@ -129,14 +129,18 @@ export function useScoreColumns<T extends Record<string, any>>({},);- const scoreColumns = useMemo(() => {- if (!scoreColumnsQuery.data?.scoreColumns) return [];-- return createScoreColumns<T>({- scoreColumns: withPresentScoreKeys(- toOrderedScoresList(scoreColumnsQuery.data.scoreColumns),+ const scoreDefinitions = useMemo(+ () =>+ withPresentScoreKeys(+ toOrderedScoresList(scoreColumnsQuery.data?.scoreColumns ?? []),presentKeys,),+ [scoreColumnsQuery.data?.scoreColumns, presentKeys],+ );++ const scoreColumns = useMemo(() => {+ return createScoreColumns<T>({+ scoreColumns: scoreDefinitions,scoreColumnKey,displayFormat,prefix,@@ -145,18 +149,19 @@ export function useScoreColumns<T extends Record<string, any>>({rawKey,});}, [- scoreColumnsQuery.data?.scoreColumns,+ scoreDefinitions,scoreColumnKey,prefix,headerPrefix,displayFormat,defaultHidden,rawKey,- presentKeys,]);return {scoreColumns,+ scoreDefinitions,+ refetch: scoreColumnsQuery.refetch,isLoading: scoreColumnsQuery.isPending,error: scoreColumnsQuery.error,};diff --git a/web/src/features/traces/components/TraceLayoutDesktop.tsx b/web/src/features/traces/components/TraceLayoutDesktop.tsxindex 72809b4876..c3b483fde7 100644--- a/web/src/features/traces/components/TraceLayoutDesktop.tsx+++ b/web/src/features/traces/components/TraceLayoutDesktop.tsx@@ -1,3 +1,4 @@+import { useDefaultLayout } from "@/src/components/ui/resizable";import { useRouter } from "next/router";import { StringParam, useQueryParam } from "use-query-params";import {@@ -6,7 +7,6 @@ import {Panel,usePanelRef,useGroupRef,- useDefaultLayout,type PanelImperativeHandle,} from "react-resizable-panels";import {@@ -92,14 +92,6 @@ const COLLAPSED_PANEL_PX = 40;const BOTH_PANELS_MIN_WIDTH_PX =NAVIGATION_PANEL_MIN_PX + DETAIL_PANEL_MIN_PX + RESIZE_HANDLE_PX;-// A no-op layout storage so `useDefaultLayout` never touches a real Storage-// during SSR / DOM-less tests (its default `= localStorage` is a bare global-// that would throw). Mirrors the pattern in `ui/resizable-split-layout.tsx`.-const NOOP_LAYOUT_STORAGE = {- getItem: () => null,- setItem: () => {},-};-// Detect whether a panel is sitting on its collapsed rail in a RESTORED layout.// `useDefaultLayout` returns a `{ [panelId]: number }` map of flexGrow shares// that sum to ~100 (percentages of the group). A collapsed panel is exactly its@@ -229,12 +221,6 @@ function TraceNavigationDetailLayout({// 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" ? 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// `?peekView=expanded` link) the panel renders at ~viewport width, NOT the@@ -274,7 +260,7 @@ function TraceNavigationDetailLayout({const { defaultLayout, onLayoutChanged } = useDefaultLayout({id: groupId,panelIds: [RESIZABLE_PANEL_NAVIGATION_ID, RESIZABLE_PANEL_PREVIEW_ID],- storage,+ storage: "local",});// Collapse-seed threshold: width-aware, so a small-share-but-open nav on adiff --git a/web/src/features/widgets/chart-library/utils.clienttest.ts b/web/src/features/widgets/chart-library/utils.clienttest.tsindex d323f4730b..37a050d1ee 100644--- a/web/src/features/widgets/chart-library/utils.clienttest.ts+++ b/web/src/features/widgets/chart-library/utils.clienttest.ts@@ -8,6 +8,19 @@ import {import { type DataPoint } from "@/src/features/widgets/chart-library/chart-props";describe("formatMetric", () => {+ it("keeps sub-millisecond duration ticks distinct", () => {+ expect(+ [0, 0.002, 0.004, 0.006, 0.008, 0.01].map((value) =>+ formatMetric(value, { unit: "millisecond", style: "compact" }),+ ),+ ).toEqual(+ ["0", "0.002", "0.004", "0.006", "0.008", "0.01"].map((main) => ({+ main,+ suffix: "ms",+ })),+ );+ });+it("keeps compact numeric formatting within maxCharacters", () => {expect(formatMetric(12_345, { style: "compact", maxCharacters: 4 }),diff --git a/web/src/features/widgets/chart-library/utils.ts b/web/src/features/widgets/chart-library/utils.tsindex a550909803..28f5ccb5b9 100644--- a/web/src/features/widgets/chart-library/utils.ts+++ b/web/src/features/widgets/chart-library/utils.ts@@ -383,12 +383,16 @@ export function formatMetric();const normalizedValue = absValue / durationDivisors[tier];+ const maxFractionDigits =+ normalizedValue > 0 && normalizedValue < 1+ ? Math.min(20, 2 - Math.floor(Math.log10(normalizedValue)))+ : 2;return applyNegative(formatWithConstrainedDecimals({value: normalizedValue,maxCharacters: magnitudeMaxCharacters,- maxFractionDigits: 2,+ maxFractionDigits,createFormatter: (fractionDigits) =>new Intl.NumberFormat("en-US", {style: "unit",