🪢 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(filters): sort tag filter values alphabetically (LFE-14382) (#15879)
Nikita Kabardin2f131e85ad2a
diff --git a/.agents/skills/seed-test-data/SKILL.md b/.agents/skills/seed-test-data/SKILL.mdindex 81d6588999..f5097b71ec 100644--- a/.agents/skills/seed-test-data/SKILL.md+++ b/.agents/skills/seed-test-data/SKILL.md@@ -41,6 +41,7 @@ this.| Long-window v4 traffic with cost/latency/token OUTLIERS (outlier chart strip, LFE-14451) | `pnpm run seed -- outlier-traffic --days 90` (diurnal base load + deterministic spikes + hour-long ×8-latency incidents; root AGENT + GENERATION carrying cost + TOOL per trace; v4 on by default) || Scores with spaces in the name (filter/grammar testing) | `pnpm run seed -- scored-traces --traces 24 --v4` || Lots of scores on every node (dense score badges, tree-row overflow testing) | add `--scores-per-node 12` to `trace-tree` (N distinct scores per observation; try `--depth 2 --breadth 44` for many tall sibling rows) |+| Extra trace tags, incl. mixed case/accents (tag filter ordering) | add `--tags "Zebra,apple,Ärger"` to `trace-tree` (comma-separated, appended to the scenario's own tags) || Varied human-annotation queues (annotate UI / keyboard testing) | `pnpm run seed -- annotation-queue --core-items 12` (creates a "core types" queue covering every score-field render path + an "edge cases" queue with archived/stale/partial scores and observation/session/deleted/completed items) || Huge/malformed/unicode payloads | `pnpm run seed -- trace-tree --payload-bytes 1000000 --payload-style malformed` (styles: json, text, malformed, unicode, bignum, base64) || Big integers beyond 2^53-1 (number-precision testing) | `pnpm run seed -- trace-tree --observations 1 --payload-style bignum` |diff --git a/packages/shared/scripts/seeder/AGENTS.md b/packages/shared/scripts/seeder/AGENTS.mdindex 819d890d1c..a16c35632d 100644--- a/packages/shared/scripts/seeder/AGENTS.md+++ b/packages/shared/scripts/seeder/AGENTS.md@@ -10,6 +10,7 @@ pnpm run seed -- doctor # check the stack; prints the fix per failurepnpm run seed -- list # scenarios and flags (--json for machines)pnpm run seed -- trace-tree --observations 5000 --breadth 500 --v4pnpm run seed -- trace-tree --observations 12 --plain --v4 # SPAN/GENERATION/EVENT only (collapsed-by-default graph panel)+pnpm run seed -- trace-tree --observations 12 --v4 --tags "Zebra,apple,Ärger" # extra trace tags (alphabetical tag filter ordering)pnpm run seed -- deep-chain --v4 # 1401 sequential generations in ONE parent chain (depth = count; LFE-10959 layout stress)pnpm run seed -- agent-timeline --turns 6 --v4 # realistic agent flow-with-loop over a timeline (graph view)pnpm run seed -- support-agent --v4 --id-prefix <hex> # demo-grade handcrafted support-copilot run (videos/screenshots)diff --git a/packages/shared/scripts/seeder/scenarios/trace-tree.ts b/packages/shared/scripts/seeder/scenarios/trace-tree.tsindex 89a7a790bd..7ad296a66e 100644--- a/packages/shared/scripts/seeder/scenarios/trace-tree.ts+++ b/packages/shared/scripts/seeder/scenarios/trace-tree.ts@@ -160,6 +160,12 @@ const run = async (// "lots of scores" shape from LFE-10591 that overflows fixed/virtualized tree// rows — many distinct score names wrap into several badge lines per node.const scoresPerNode = params["scores-per-node"] as number;+ // Extra trace tags on top of the scenario's own. Default "" keeps the+ // historic tag list, so unflagged output stays byte-identical.+ const extraTags = (params["tags"] as string)+ .split(",")+ .map((tag) => tag.trim())+ .filter((tag) => tag.length > 0);if (!PAYLOAD_STYLES.includes(payloadStyle)) {throw new SeedError(@@ -257,7 +263,7 @@ const run = async (session_id: null,release: "seed-1.0.0",version: "seed-v2",- tags: ["seed", "trace-tree", payloadStyle],+ tags: ["seed", "trace-tree", payloadStyle, ...extraTags],public: false,bookmarked: false,metadata: {@@ -731,6 +737,13 @@ export const traceTreeScenario: ScenarioDefinition = {description:"attach N distinct scores to every observation (the LFE-10591 'lots of scores' shape; try 12), 0-100",},+ {+ flag: "tags",+ type: "string",+ default: "",+ description:+ 'comma-separated extra trace tags, e.g. "Zebra,apple,Ärger" — mixed case/accents exercise alphabetical tag filter ordering (LFE-14382)',+ },],run,};diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsxindex 3e72e7281c..6b1fc747da 100644--- a/web/src/components/table/use-cases/observations.tsx+++ b/web/src/components/table/use-cases/observations.tsx@@ -42,6 +42,7 @@ import {type ScoreAggregate,} from "@langfuse/shared";import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { formatIntervalSeconds } from "@/src/utils/dates";import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";import {@@ -454,11 +455,13 @@ export default function ObservationsTable({value: pn.value,count: pn.count !== undefined ? Number(pn.count) : undefined,})) ?? undefined,- tags:+ // tags read A→Z+ tags: sortOptionValues(filterOptions.data?.tags?.map((t) => ({value: t.value,count: t.count !== undefined ? Number(t.count) : undefined,- })) ?? undefined,+ })),+ ),toolNames:filterOptions.data?.toolNames?.map((tn) => ({value: tn.value,diff --git a/web/src/components/table/use-cases/scores.tsx b/web/src/components/table/use-cases/scores.tsxindex 5a4adbd7d8..212e5c35db 100644--- a/web/src/components/table/use-cases/scores.tsx+++ b/web/src/components/table/use-cases/scores.tsx@@ -37,6 +37,7 @@ import {type TimeFilter,} from "@langfuse/shared";import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { isNumericDataType } from "@/src/features/scores/lib/helpers";import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";import { useTableDateRange } from "@/src/hooks/useTableDateRange";@@ -329,7 +330,8 @@ export default function ScoresTable({value: u.value,count: u.count !== undefined ? Number(u.count) : undefined,})) ?? undefined,- tags: filterOptions.data?.tags?.map((t) => t.value) ?? undefined, // tags don't have counts+ // tags don't have counts; they read A→Z+ tags: sortOptionValues(filterOptions.data?.tags?.map((t) => t.value)),environment: environmentOptions,}),[filterOptions.data, environmentOptions],diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsxindex eaa1c35d9c..d797a5c177 100644--- a/web/src/components/table/use-cases/sessions.tsx+++ b/web/src/components/table/use-cases/sessions.tsx@@ -36,6 +36,7 @@ import {type ScoreAggregate,} from "@langfuse/shared";import { transformFiltersForBackend } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";import { api } from "@/src/utils/api";@@ -246,7 +247,8 @@ export default function SessionsTable({value: u.value,count: Number(u.count),})) ?? undefined,- tags: filterOptions.data?.tags.map((t) => t.value) ?? undefined, // tags don't have counts+ // tags don't have counts; they read A→Z+ tags: sortOptionValues(filterOptions.data?.tags.map((t) => t.value)),sessionDuration: [],countTraces: [],inputTokens: [],diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsxindex 4339ba15df..c4c3339dfc 100644--- a/web/src/components/table/use-cases/traces.tsx+++ b/web/src/components/table/use-cases/traces.tsx@@ -88,6 +88,7 @@ import {getTraceFilterConfig,type TraceOmittableFilterColumn,} from "@/src/features/filters/config/traces-config";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { TablePeekViewTraceDetail } from "@/src/components/table/peek/peek-trace-detail";import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";@@ -325,9 +326,10 @@ export default function TracesTable({value: n.value,count: Number(n.count),})) ?? undefined,- // tags don't have counts- traceTags:- traceFilterOptionsResponse.data?.tags?.map((t) => t.value) ?? undefined,+ // tags don't have counts; they read A→Z+ traceTags: sortOptionValues(+ traceFilterOptionsResponse.data?.tags?.map((t) => t.value),+ ),environment:environmentFilterOptions.data?.map((value) => value.environment) ??undefined,diff --git a/web/src/features/evals/hooks/useEvalConfigFilterOptions.ts b/web/src/features/evals/hooks/useEvalConfigFilterOptions.tsindex 7e929a4d76..2203847b20 100644--- a/web/src/features/evals/hooks/useEvalConfigFilterOptions.ts+++ b/web/src/features/evals/hooks/useEvalConfigFilterOptions.ts@@ -1,3 +1,4 @@+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { api } from "@/src/utils/api";import {type ExperimentEvalOptions,@@ -77,9 +78,11 @@ export function useEvalConfigFilterOptions({scores_avg: traceFilterOptionsResponse.data.scores_avg,score_categories: traceFilterOptionsResponse.data.score_categories,score_booleans: traceFilterOptionsResponse.data.score_booleans,- traceTags: traceFilterOptionsResponse.data.tags?.map((t) => ({- value: t.value,- })),+ traceTags: sortOptionValues(+ traceFilterOptionsResponse.data.tags?.map((t) => ({+ value: t.value,+ })),+ ),}: {};@@ -123,9 +126,11 @@ export function useEvalConfigFilterOptions({environment: environmentFilterOptionsResponse.data?.map((e) => ({value: e.environment,})),- tags: traceFilterOptionsResponse.data?.tags?.map((t) => ({- value: t.value,- })),+ tags: sortOptionValues(+ traceFilterOptionsResponse.data?.tags?.map((t) => ({+ value: t.value,+ })),+ ),traceName: traceFilterOptionsResponse.data?.name?.map((n) => ({value: n.value,})),diff --git a/web/src/features/events/hooks/useEventsFilterOptions.clienttest.ts b/web/src/features/events/hooks/useEventsFilterOptions.clienttest.tsindex 4abc4a551d..575ca17457 100644--- a/web/src/features/events/hooks/useEventsFilterOptions.clienttest.ts+++ b/web/src/features/events/hooks/useEventsFilterOptions.clienttest.ts@@ -132,6 +132,29 @@ describe("useEventsFilterOptions filtered facet counts (LFE-14489)", () => {expect(envQuery.startTimeFilter).toEqual([START_TIME]);});+ it("serves tag options alphabetically, whatever order the server sent (LFE-14382)", () => {+ mocks.perColumnData.traceTags = {+ traceTags: [{ value: "urgent" }, { value: "Billing" }, { value: "beta" }],+ };++ const { result } = renderHook(() =>+ useEventsFilterOptions({+ projectId: "p",+ startTimeFilter: [START_TIME],+ refiningFilter: [],+ lazy: true,+ }),+ );++ act(() => result.current.requestColumns(["traceTags"]));++ expect(result.current.filterOptions.traceTags).toEqual([+ { value: "beta" },+ { value: "Billing" },+ { value: "urgent" },+ ]);+ });+it("loads release options when the Release facet is opened", () => {const releaseOptions = [{ value: "181", count: 2 }];mocks.perColumnData.release = { release: releaseOptions };diff --git a/web/src/features/events/hooks/useEventsFilterOptions.ts b/web/src/features/events/hooks/useEventsFilterOptions.tsindex 2d849770c8..34a2164c9f 100644--- a/web/src/features/events/hooks/useEventsFilterOptions.ts+++ b/web/src/features/events/hooks/useEventsFilterOptions.ts@@ -5,6 +5,7 @@ import {planEventFacetQueries,splitFacetFilter,} from "@/src/features/events/lib/facet-query-plan";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";type EventFilterOptionColumnsInput =RouterInputs["events"]["filterOptions"]["columns"];@@ -324,7 +325,8 @@ export function useEventsFilterOptions({providedModelName: rawData.providedModelName ?? undefined,modelId: rawData.modelId ?? undefined,promptName: rawData.promptName ?? undefined,- traceTags: rawData.traceTags ?? undefined,+ // Tags read A→Z; every other facet keeps its count-descending order.+ traceTags: sortOptionValues(rawData.traceTags),traceName: rawData.traceName ?? undefined,userId: rawData.userId ?? undefined,sessionId: rawData.sessionId ?? undefined,diff --git a/web/src/features/filters/lib/option-sort.clienttest.ts b/web/src/features/filters/lib/option-sort.clienttest.tsnew file mode 100644index 0000000000..f68ccb0fb4--- /dev/null+++ b/web/src/features/filters/lib/option-sort.clienttest.ts@@ -0,0 +1,30 @@+import { describe, expect, it } from "vitest";++import { sortOptionValues } from "@/src/features/filters/lib/option-sort";++describe("sortOptionValues", () => {+ it("orders values alphabetically, case-insensitively and locale-aware", () => {+ // Bytewise (ClickHouse `ORDER BY value ASC`) would yield+ // ["Zebra", "apple", "banana", "Ärger"] — uppercase first, accents last.+ expect(sortOptionValues(["Zebra", "banana", "Ärger", "apple"])).toEqual([+ "apple",+ "Ärger",+ "banana",+ "Zebra",+ ]);+ });++ it("sorts option objects by value and passes undefined through", () => {+ expect(+ sortOptionValues([+ { value: "prod", count: 2 },+ { value: "dev", count: 9 },+ ]),+ ).toEqual([+ { value: "dev", count: 9 },+ { value: "prod", count: 2 },+ ]);+ // undefined means "not loaded yet" for the facet consumers — keep it.+ expect(sortOptionValues(undefined)).toBeUndefined();+ });+});diff --git a/web/src/features/filters/lib/option-sort.ts b/web/src/features/filters/lib/option-sort.tsnew file mode 100644index 0000000000..a3556f4705--- /dev/null+++ b/web/src/features/filters/lib/option-sort.ts@@ -0,0 +1,32 @@+// Alphabetical ordering for tag filter options (LFE-14382).+//+// Tag values arrive in backend order, which is not alphabetical: the legacy+// traces query has no ORDER BY at all, and ClickHouse's ORDER BY is bytewise+// ("Zebra" before "apple"). Sorting in the browser also gets the viewer's own+// locale. Other facets keep their count-descending order on purpose.+//+// Relevance still wins while typing: rankFilter/rankFacetOptions are stable, so+// this only decides the idle list and the order within each rank group.++type OptionValue = string | { value: string };++const valueOf = (option: OptionValue): string =>+ typeof option === "string" ? option : option.value;++/**+ * A→Z copy of an option list, `string[]` or `{ value, … }[]`. `undefined` passes+ * through — callers distinguish it from `[]` as "not loaded yet".+ */+export function sortOptionValues<T extends OptionValue>(+ options: readonly T[],+): T[];+export function sortOptionValues<T extends OptionValue>(+ options: readonly T[] | undefined,+): T[] | undefined;+export function sortOptionValues<T extends OptionValue>(+ options: readonly T[] | undefined,+): T[] | undefined {+ return options+ ? [...options].sort((a, b) => valueOf(a).localeCompare(valueOf(b)))+ : options;+}diff --git a/web/src/features/monitors/components/MonitorForm.tsx b/web/src/features/monitors/components/MonitorForm.tsxindex 7424c0257f..fa51093a15 100644--- a/web/src/features/monitors/components/MonitorForm.tsx+++ b/web/src/features/monitors/components/MonitorForm.tsx@@ -54,6 +54,7 @@ import {getWidgetFilterColumns,} from "@/src/features/widgets/components/widgetFilterColumns";import { normalizeSingleValueOptions } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { cn } from "@/src/utils/tailwind";import {@@ -185,7 +186,7 @@ const buildFilterColumnsParams = ({environmentOptions: filterOptions?.environment ?? [],nameOptions: normalizeSingleValueOptions(filterOptions?.traceName),observationNameOptions: normalizeSingleValueOptions(filterOptions?.name),- tagsOptions: filterOptions?.traceTags ?? [],+ tagsOptions: sortOptionValues(filterOptions?.traceTags ?? []),modelOptions: filterOptions?.providedModelName ?? [],toolNamesOptions: filterOptions?.toolNames ?? [],calledToolNamesOptions: filterOptions?.calledToolNames ?? [],diff --git a/web/src/features/widgets/components/WidgetForm.tsx b/web/src/features/widgets/components/WidgetForm.tsxindex 78ba9056ae..de10e664a6 100644--- a/web/src/features/widgets/components/WidgetForm.tsx+++ b/web/src/features/widgets/components/WidgetForm.tsx@@ -60,6 +60,7 @@ import {type DashboardDateRangeOptions,} from "@/src/utils/date-range-utils";import { normalizeSingleValueOptions } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import { Chart } from "@/src/features/widgets/chart-library/Chart";import { type DataPoint } from "@/src/features/widgets/chart-library/chart-props";import { Button } from "@/src/components/ui/button";@@ -502,10 +503,11 @@ export function WidgetForm({viewVersion === "v2"? normalizeSingleValueOptions(eventsFilterOptions.data?.name): normalizeSingleValueOptions(generationsFilterOptions.data?.name);- const tagsOptions =+ const tagsOptions = sortOptionValues(viewVersion === "v2"? eventsFilterOptions.data?.traceTags || []- : traceFilterOptions.data?.tags || [];+ : traceFilterOptions.data?.tags || [],+ );const modelOptions =viewVersion === "v2"? eventsFilterOptions.data?.providedModelName || []diff --git a/web/src/hooks/useDashboardFilterOptions.ts b/web/src/hooks/useDashboardFilterOptions.tsindex 5b1627d30d..4b49c648cf 100644--- a/web/src/hooks/useDashboardFilterOptions.ts+++ b/web/src/hooks/useDashboardFilterOptions.ts@@ -1,6 +1,7 @@import { useMemo } from "react";import { api } from "@/src/utils/api";import { normalizeSingleValueOptions } from "@/src/features/filters/lib/filter-transform";+import { sortOptionValues } from "@/src/features/filters/lib/option-sort";import {toAbsoluteTimeRange,type TimeRange,@@ -105,9 +106,11 @@ export function useDashboardFilterOptions({],);- const tagsOptions = isBetaEnabled- ? (eventsFilterOptions.data?.traceTags ?? [])- : (traceFilterOptions.data?.tags ?? []);+ const tagsOptions = sortOptionValues(+ isBetaEnabled+ ? (eventsFilterOptions.data?.traceTags ?? [])+ : (traceFilterOptions.data?.tags ?? []),+ );return { nameOptions, tagsOptions };}