Skip to content

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

fix(dashboard): exclude v3 trace presets from widget suggestions (LFE-14444) (#15885)

Nikita Kabardinb116a8439609
diff --git a/packages/shared/src/features/query/types.ts b/packages/shared/src/features/query/types.ts
index 820fef8b85..a169f82b5b 100644
--- a/packages/shared/src/features/query/types.ts
+++ b/packages/shared/src/features/query/types.ts
@@ -129,6 +129,20 @@ export const viewsV2 = z.enum([
"scores-boolean",
]);
+/**
+ * Persisted dashboard-widget view ids → query view ids. Lives here (not with
+ * the server-only DashboardService types) so client code can classify a stored
+ * widget; DashboardService's Prisma-keyed map is this constant, so the two
+ * cannot drift.
+ */
+export const persistedWidgetViewToQueryView = {
+ TRACES: "traces",
+ OBSERVATIONS: "observations",
+ SCORES_NUMERIC: "scores-numeric",
+ SCORES_BOOLEAN: "scores-boolean",
+ SCORES_CATEGORICAL: "scores-categorical",
+} as const satisfies Record<string, z.infer<typeof views>>;
+
export const viewVersions = z.enum(["v1", "v2"]);
export type ViewVersion = z.infer<typeof viewVersions>;
diff --git a/packages/shared/src/features/query/widgetVersion.test.ts b/packages/shared/src/features/query/widgetVersion.test.ts
index 00eaccb3f7..01af1bcf33 100644
--- a/packages/shared/src/features/query/widgetVersion.test.ts
+++ b/packages/shared/src/features/query/widgetVersion.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
getWidgetRequiredVersion,
+ isSuggestedWidgetView,
resolveWidgetEditorVersion,
resolveWidgetRenderVersion,
type WidgetQueryShape,
@@ -55,6 +56,20 @@ describe("widget query version selection", () => {
},
);
+ // v4 suggestions must not offer v3 trace-based widgets (LFE-14444), in
+ // either the persisted (Prisma) or query view spelling.
+ it.each([
+ ["traces", "v2", false],
+ ["TRACES", "v2", false],
+ ["observations", "v2", true],
+ ["OBSERVATIONS", "v2", true],
+ ["SCORES_NUMERIC", "v2", true],
+ ["traces", "v1", true],
+ ["TRACES", "v1", true],
+ ] as const)("suggests %s in %s: %s", (view, version, expected) => {
+ expect(isSuggestedWidgetView(view, version)).toBe(expected);
+ });
+
it.each([
["v1 editor", v1Shape, 1, "v1", "v1"],
["frozen v2 editor floor", v1Shape, 2, "v1", "v2"],
diff --git a/packages/shared/src/features/query/widgetVersion.ts b/packages/shared/src/features/query/widgetVersion.ts
index caf9b82513..41341d2f23 100644
--- a/packages/shared/src/features/query/widgetVersion.ts
+++ b/packages/shared/src/features/query/widgetVersion.ts
@@ -1,5 +1,9 @@
import { requiresV2 } from "./dataModel";
-import type { ViewVersion } from "./types";
+import {
+ persistedWidgetViewToQueryView,
+ viewsV2,
+ type ViewVersion,
+} from "./types";
export type WidgetQueryVersion = 1 | 2;
export type WidgetQueryShape = Parameters<typeof requiresV2>[0];
@@ -15,6 +19,25 @@ export function getWidgetRequiredVersion(
return requiresV2(shape) ? 2 : 1;
}
+/**
+ * Whether a widget view may be *offered* for a target version. v2 derives
+ * traces at read time from the events model, so `viewsV2` — already the
+ * allowlist for new v4 widget definitions — is also the suggestion allowlist.
+ * Existing `traces` widgets stay readable (v2 has an events-backed traces
+ * declaration); they are just not suggested. (LFE-14444)
+ */
+export function isSuggestedWidgetView(
+ view: string,
+ targetVersion: ViewVersion,
+): boolean {
+ if (targetVersion !== "v2") return true;
+ const queryView =
+ persistedWidgetViewToQueryView[
+ view as keyof typeof persistedWidgetViewToQueryView
+ ] ?? view;
+ return viewsV2.safeParse(queryView).success;
+}
+
function resolveEffectiveWidgetVersion(params: {
shape: WidgetQueryShape;
versionFloor?: number;
diff --git a/packages/shared/src/server/services/DashboardService/types.ts b/packages/shared/src/server/services/DashboardService/types.ts
index 248781129a..eeb359bb29 100644
--- a/packages/shared/src/server/services/DashboardService/types.ts
+++ b/packages/shared/src/server/services/DashboardService/types.ts
@@ -1,16 +1,21 @@
import { DashboardWidgetChartType, DashboardWidgetViews } from "@prisma/client";
import { z } from "zod";
import { singleFilter } from "../../../";
-import { type views } from "../../../features/query";
-
-/** Maps the persisted Prisma enum to the query model's public view id. */
-export const dashboardWidgetViewToQueryView = {
- [DashboardWidgetViews.TRACES]: "traces",
- [DashboardWidgetViews.OBSERVATIONS]: "observations",
- [DashboardWidgetViews.SCORES_NUMERIC]: "scores-numeric",
- [DashboardWidgetViews.SCORES_BOOLEAN]: "scores-boolean",
- [DashboardWidgetViews.SCORES_CATEGORICAL]: "scores-categorical",
-} as const satisfies Record<DashboardWidgetViews, z.infer<typeof views>>;
+import {
+ persistedWidgetViewToQueryView,
+ type views,
+} from "../../../features/query";
+
+/**
+ * Maps the persisted Prisma enum to the query model's public view id. The map
+ * itself is client-safe (`persistedWidgetViewToQueryView`); the `satisfies`
+ * here is what keeps it exhaustive against the Prisma enum.
+ */
+export const dashboardWidgetViewToQueryView =
+ persistedWidgetViewToQueryView satisfies Record<
+ DashboardWidgetViews,
+ z.infer<typeof views>
+ >;
/** Maps the query model's public view id to the persisted Prisma enum. */
export const queryViewToDashboardWidgetView = {
diff --git a/web/src/features/dashboard/components/home-preset-registry.tsx b/web/src/features/dashboard/components/home-preset-registry.tsx
index 798c8ce142..91f7e7862c 100644
--- a/web/src/features/dashboard/components/home-preset-registry.tsx
+++ b/web/src/features/dashboard/components/home-preset-registry.tsx
@@ -1,5 +1,9 @@
import { type ReactNode } from "react";
-import { type FilterState, type HomeDashboardPresetId } from "@langfuse/shared";
+import {
+ HOME_DASHBOARD_PRESET_IDS,
+ type FilterState,
+ type HomeDashboardPresetId,
+} from "@langfuse/shared";
import { type ViewVersion } from "@langfuse/shared/query";
import { type DashboardDateRangeAggregationOption } from "@/src/utils/date-range-utils";
import { TracesBarListChart } from "@/src/features/dashboard/components/TracesBarListChart";
@@ -205,11 +209,19 @@ const HOME_PRESETS: Record<
/**
* Display metadata for the preset picker (Add Widget dialog). `illustration`
- * keys into ChartTypeIllustration.
+ * keys into ChartTypeIllustration. `queriesTracesView` marks a preset whose
+ * query still targets the legacy `traces` view under v2, so it is not
+ * suggested to v4 users (LFE-14444) — every other card branches to the events
+ * model on its own.
*/
export const HOME_PRESET_METADATA: Record<
HomeDashboardPresetId,
- { name: string; description: string; illustration: string }
+ {
+ name: string;
+ description: string;
+ illustration: string;
+ queriesTracesView?: true;
+ }
> = {
"home-traces": {
name: "Traces",
@@ -250,6 +262,8 @@ export const HOME_PRESET_METADATA: Record<
name: "Trace Latency Percentiles",
description: "p50–p99 latencies per trace name",
illustration: "PIVOT_TABLE",
+ // LatencyTable kind="traces" has no v2 branch: always `view: "traces"`.
+ queriesTracesView: true,
},
"home-latency-table-generations": {
name: "Generation Latency Percentiles",
@@ -273,6 +287,16 @@ export const HOME_PRESET_METADATA: Record<
},
};
+/** Home cards offered in the Add Widget dialog for a metrics version. */
+export function getSuggestedHomePresetIds(
+ version: ViewVersion,
+): HomeDashboardPresetId[] {
+ return HOME_DASHBOARD_PRESET_IDS.filter(
+ (presetId) =>
+ version !== "v2" || !HOME_PRESET_METADATA[presetId].queriesTracesView,
+ );
+}
+
export function getHomePreset(
presetId: string,
): ((ctx: PresetWidgetContext) => ReactNode) | undefined {
diff --git a/web/src/features/dashboard/components/homePresetSuggestions.clienttest.ts b/web/src/features/dashboard/components/homePresetSuggestions.clienttest.ts
new file mode 100644
index 0000000000..abcd3f660d
--- /dev/null
+++ b/web/src/features/dashboard/components/homePresetSuggestions.clienttest.ts
@@ -0,0 +1,12 @@
+import { describe, expect, it } from "vitest";
+import { HOME_DASHBOARD_PRESET_IDS } from "@langfuse/shared";
+import { getSuggestedHomePresetIds } from "@/src/features/dashboard/components/home-preset-registry";
+
+describe("Add Widget home-card suggestions", () => {
+ it("drops presets that still query the legacy traces view on v4", () => {
+ expect(getSuggestedHomePresetIds("v2")).not.toContain(
+ "home-latency-table-traces",
+ );
+ expect(getSuggestedHomePresetIds("v1")).toEqual(HOME_DASHBOARD_PRESET_IDS);
+ });
+});
diff --git a/web/src/features/widgets/components/SelectWidgetDialog.tsx b/web/src/features/widgets/components/SelectWidgetDialog.tsx
index be35d84e0f..2e1b5aace5 100644
--- a/web/src/features/widgets/components/SelectWidgetDialog.tsx
+++ b/web/src/features/widgets/components/SelectWidgetDialog.tsx
@@ -20,11 +20,16 @@ import {
import startCase from "lodash/startCase";
import { getChartTypeDisplayName } from "@/src/features/widgets/chart-library/utils";
import { ChartTypeIllustration } from "@/src/features/widgets/components/ChartTypeIllustration";
+import { type HomeDashboardPresetId } from "@langfuse/shared";
import {
- HOME_DASHBOARD_PRESET_IDS,
- type HomeDashboardPresetId,
-} from "@langfuse/shared";
-import { HOME_PRESET_METADATA } from "@/src/features/dashboard/components/home-preset-registry";
+ isSuggestedWidgetView,
+ type ViewVersion,
+} from "@langfuse/shared/query";
+import {
+ getSuggestedHomePresetIds,
+ HOME_PRESET_METADATA,
+} from "@/src/features/dashboard/components/home-preset-registry";
+import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
import { type DashboardWidgetChartType } from "@langfuse/shared/src/db";
import { InAppAgentWidgetComposer } from "@/src/features/in-app-agent/components/InAppAgentWidgetComposer";
@@ -130,7 +135,23 @@ export function SelectWidgetDialog({
},
);
- const projectWidgets = widgets.data?.widgets ?? [];
+ // Suggestions obey the same view allowlist the widget editor uses for new
+ // definitions, so v4 users are never offered a v3 trace-based widget.
+ // Legacy trace widgets stay listed and editable under /widgets. (LFE-14444)
+ const { isBetaEnabled, isInitializing } = useV4Beta();
+ const suggestedVersion: ViewVersion = isBetaEnabled ? "v2" : "v1";
+ const allProjectWidgets = widgets.data?.widgets ?? [];
+ const projectWidgets = allProjectWidgets.filter((widget) =>
+ isSuggestedWidgetView(widget.view, suggestedVersion),
+ );
+ const hiddenWidgetCount = allProjectWidgets.length - projectWidgets.length;
+ const suggestedPresetIds = getSuggestedHomePresetIds(suggestedVersion);
+ // Replaces the generic empty state when it hid every widget, so the two can
+ // never contradict each other.
+ const hiddenWidgetsNote =
+ hiddenWidgetCount > 0
+ ? `${hiddenWidgetCount} trace-based widget${hiddenWidgetCount === 1 ? "" : "s"} hidden — the Traces view is not available for new charts. Manage them under Widgets.`
+ : null;
const selectWidget = (widget: WidgetItem) => {
capture("dashboard:widget_added", {
@@ -152,7 +173,9 @@ export function SelectWidgetDialog({
</DialogHeader>
<DialogBody>
- {widgets.isPending ? (
+ {/* isInitializing: an unresolved session reads as v1, which would
+ briefly offer the unfiltered list to a v4 user. */}
+ {widgets.isPending || isInitializing ? (
<div className="py-8 text-center">Loading widgets...</div>
) : widgets.isError ? (
<div className="text-destructive py-8 text-center">
@@ -186,8 +209,12 @@ export function SelectWidgetDialog({
</button>
<Tabs
+ // Open on the project tab when it has something to say — a
+ // hidden-widget note included, so it is not missed.
defaultValue={
- projectWidgets.length > 0 ? "project" : "home-cards"
+ projectWidgets.length > 0 || hiddenWidgetsNote
+ ? "project"
+ : "home-cards"
}
onValueChange={(tab) =>
capture("dashboard:add_widget_tab_switch", { tab })
@@ -199,32 +226,35 @@ export function SelectWidgetDialog({
</TabsTrigger>
{onSelectPreset && (
<TabsTrigger value="home-cards">
- Home cards ({HOME_DASHBOARD_PRESET_IDS.length})
+ Home cards ({suggestedPresetIds.length})
</TabsTrigger>
)}
</TabsList>
<TabsContent value="project">
<div className="flex max-h-[360px] flex-col gap-2 overflow-y-auto p-1">
+ {projectWidgets.map((widget) => (
+ <WidgetRow
+ key={widget.id}
+ widget={widget as WidgetItem}
+ onClick={() => selectWidget(widget as WidgetItem)}
+ />
+ ))}
{projectWidgets.length === 0 ? (
<div className="text-muted-foreground py-8 text-center text-sm">
- No saved widgets in this project yet — build one with
- Custom Chart.
+ {hiddenWidgetsNote ??
+ "No saved widgets in this project yet — build one with Custom Chart."}
+ </div>
+ ) : hiddenWidgetsNote ? (
+ <div className="text-muted-foreground px-1 py-2 text-xs">
+ {hiddenWidgetsNote}
</div>
- ) : (
- projectWidgets.map((widget) => (
- <WidgetRow
- key={widget.id}
- widget={widget as WidgetItem}
- onClick={() => selectWidget(widget as WidgetItem)}
- />
- ))
- )}
+ ) : null}
</div>
</TabsContent>
{onSelectPreset && (
<TabsContent value="home-cards">
<div className="flex max-h-[360px] flex-col gap-2 overflow-y-auto p-1">
- {HOME_DASHBOARD_PRESET_IDS.map((presetId) => {
+ {suggestedPresetIds.map((presetId) => {
const meta = HOME_PRESET_METADATA[presetId];
return (
<button