Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): show non-default environment values in the filter bar (#16893)

Nikita Kabardinf6c78e0f0d93
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index 6fb91c42fb..18d82301f4 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -321,7 +321,7 @@ export default function SessionsTable({
projectId,
tableName: sessionsFilterConfig.tableName,
enabled: sessionsSearchBarEnabled,
- filterState: queryFilter.explicitFilterState,
+ filterState: queryFilter.searchBarFilterState,
searchQuery: null,
searchType: DEFAULT_SEARCH_TYPE,
observed: observedOptions,
diff --git a/web/src/features/events/components/EventsTable.tsx b/web/src/features/events/components/EventsTable.tsx
index b7df3f7717..524bae2a0a 100644
--- a/web/src/features/events/components/EventsTable.tsx
+++ b/web/src/features/events/components/EventsTable.tsx
@@ -672,6 +672,7 @@ export default function ObservationsEventsTable({
isV4: true,
},
);
+ const projectFiltersForSearchBar = queryFilter.projectFiltersForSearchBar;
// Lazy filter-options: load a facet's values when its sidebar section is
// expanded (also covers active filters, which auto-expand on mount). The
@@ -743,7 +744,7 @@ export default function ObservationsEventsTable({
projectId,
tableName: eventsFilterConfig.tableName,
enabled: searchBarMode,
- filterState: queryFilter.explicitFilterState,
+ filterState: queryFilter.searchBarFilterState,
searchQuery,
searchType,
observed: observedOptions,
@@ -762,12 +763,15 @@ export default function ObservationsEventsTable({
if (!searchBarMode) return;
const { actions } = searchBarStore.getState();
if (state) {
- actions.setPreview(filterStateToQueryText(state.filters).text);
+ actions.setPreview(
+ filterStateToQueryText(projectFiltersForSearchBar(state.filters))
+ .text,
+ );
} else {
actions.clearPreview();
}
},
- [searchBarMode, searchBarStore],
+ [searchBarMode, searchBarStore, projectFiltersForSearchBar],
);
// Disabled for now because perhaps confusing
diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.ts
index 035dca62e9..9f0ec3614c 100644
--- a/web/src/features/filters/filter-integration.clienttest.ts
+++ b/web/src/features/filters/filter-integration.clienttest.ts
@@ -38,7 +38,8 @@ import {
buildManagedEnvironmentPolicyConfig,
buildImplicitEnvironmentFilter,
buildEffectiveEnvironmentFilter,
- stripImplicitEnvironmentFilterFromExplicitState,
+ canonicalizeExplicitEnvironmentFilters,
+ toSearchBarEnvironmentFilters,
} from "./lib/managedEnvironmentPolicy";
import { astToFilterState } from "@/src/features/search-bar/lib/adapter";
import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-state-to-query";
@@ -1271,8 +1272,8 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
managedEnvironmentColumn: "environment",
hiddenEnvironments,
});
- const strip = (explicitFilters: FilterState) =>
- stripImplicitEnvironmentFilterFromExplicitState({
+ const canonicalize = (explicitFilters: FilterState) =>
+ canonicalizeExplicitEnvironmentFilters({
explicitFilters,
config: managedEnvironmentConfig,
});
@@ -1317,8 +1318,9 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
it("strips only the system-shaped implicit default, keeping user-authored selections", () => {
// The implicit default the sidebar auto-derives β€” and that the facet
// re-creates when the user clears back to the default selection β€” is the
- // `none of [hidden]` shape. That is the ONLY env filter we strip before
- // persistence, so returning to default leaves a clean URL.
+ // `none of [hidden]` shape. That default is stripped before persistence,
+ // so returning to default leaves a clean URL. Extra exclusions on top of
+ // that default stay as `none of [hidden βˆͺ extras]`.
const explicitWithExactDefault: FilterState = [
{
column: "environment",
@@ -1334,7 +1336,7 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
},
];
- expect(strip(explicitWithExactDefault)).toEqual([
+ expect(canonicalize(explicitWithExactDefault)).toEqual([
{
column: "name",
type: "stringOptions",
@@ -1355,7 +1357,9 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
value: ["production", "staging"],
},
];
- expect(strip(userAuthoredDefaultSet)).toEqual(userAuthoredDefaultSet);
+ expect(canonicalize(userAuthoredDefaultSet)).toEqual(
+ userAuthoredDefaultSet,
+ );
});
it("keeps explicit overrides that enable hidden environments", () => {
@@ -1374,7 +1378,9 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
},
];
- expect(strip(explicitWithHiddenEnabled)).toEqual(explicitWithHiddenEnabled);
+ expect(canonicalize(explicitWithHiddenEnabled)).toEqual(
+ explicitWithHiddenEnabled,
+ );
const explicitAll: FilterState = [
{
@@ -1385,12 +1391,12 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
},
];
- expect(strip(explicitAll)).toEqual(explicitAll);
+ expect(canonicalize(explicitAll)).toEqual(explicitAll);
});
it("keeps hidden-only explicit selection as explicit override", () => {
expect(
- strip([
+ canonicalize([
{
column: "environment",
type: "stringOptions",
@@ -1430,4 +1436,164 @@ describe("Implicit Environment Defaults (sidebar only)", () => {
},
]);
});
+
+ it("keeps the full none-of exclusion set in explicit state", () => {
+ // Unchecking a default-included environment (production) from the implicit
+ // `none of [hidden]` default produces `none of [hidden βˆͺ production]`.
+ // Persist the full set so this cannot collapse with "enabled every hidden
+ // env and left production unchecked".
+ const fullExclusion: FilterState = [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: [...hiddenEnvironments, "production"],
+ },
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["trace-a"],
+ },
+ ];
+
+ expect(canonicalize(fullExclusion)).toEqual(fullExclusion);
+ });
+
+ it("expands extras-only none-of to the full exclusion set on persist", () => {
+ // A search-bar commit of the displayed chip (`-environment:production`)
+ // lowers to extras-only none-of. Treat that as default-plus-extra-exclusion.
+ const stripped = canonicalize([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production"],
+ },
+ ]);
+
+ expect(stripped).toEqual([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: [...hiddenEnvironments, "production"],
+ },
+ ]);
+ expect(
+ buildEffectiveEnvironmentFilter({
+ explicitFilters: stripped,
+ config: managedEnvironmentConfig,
+ }),
+ ).toEqual(stripped);
+ });
+
+ it("shows only extras in the search-bar projection of a full none-of", () => {
+ expect(
+ toSearchBarEnvironmentFilters({
+ explicitFilters: [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: [...hiddenEnvironments, "production"],
+ },
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["trace-a"],
+ },
+ ],
+ config: managedEnvironmentConfig,
+ }),
+ ).toEqual([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production"],
+ },
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["trace-a"],
+ },
+ ]);
+ });
+
+ it("does not fold extras-only none-of in effective state", () => {
+ // Effective state uses the persisted form as-is. Extras-only is expanded
+ // on persist/read of explicit state first; callers must strip before
+ // building effective state so hidden envs stay excluded.
+ expect(
+ buildEffectiveEnvironmentFilter({
+ explicitFilters: [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production"],
+ },
+ ],
+ config: managedEnvironmentConfig,
+ }),
+ ).toEqual([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production"],
+ },
+ ]);
+ });
+
+ it("does not strip a none-of that enables a hidden environment", () => {
+ // Checking one hidden env leaves `none of [hidden βˆ’ that env]`. That is
+ // not the implicit default and must stay explicit so the enabled env
+ // is not silently re-hidden.
+ const remainingHidden = hiddenEnvironments.filter(
+ (environment) => environment !== "langfuse-evaluation",
+ );
+
+ expect(
+ canonicalize([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: remainingHidden,
+ },
+ ]),
+ ).toEqual([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: remainingHidden,
+ },
+ ]);
+
+ expect(
+ buildEffectiveEnvironmentFilter({
+ explicitFilters: [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: remainingHidden,
+ },
+ ],
+ config: managedEnvironmentConfig,
+ }),
+ ).toEqual([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: remainingHidden,
+ },
+ ]);
+ });
});
diff --git a/web/src/features/filters/hooks/useSidebarFilterState.tsx b/web/src/features/filters/hooks/useSidebarFilterState.tsx
index f46f284baa..bcd945da10 100644
--- a/web/src/features/filters/hooks/useSidebarFilterState.tsx
+++ b/web/src/features/filters/hooks/useSidebarFilterState.tsx
@@ -31,7 +31,8 @@ import { normalizeFilterColumnNames } from "../lib/filter-transform";
import {
buildEffectiveEnvironmentFilter,
buildManagedEnvironmentPolicyConfig,
- stripImplicitEnvironmentFilterFromExplicitState,
+ canonicalizeExplicitEnvironmentFilters,
+ toSearchBarEnvironmentFilters,
type ManagedEnvironmentPolicyInput,
} from "../lib/managedEnvironmentPolicy";
import { useKeyedSessionStorageState } from "./useKeyedSessionStorageState";
@@ -690,19 +691,34 @@ export function useSidebarFilterStateCore(
? memoryFilterState
: urlFilterState;
+ const managedEnvironmentPolicyConfig = useMemo(
+ () => buildManagedEnvironmentPolicyConfig(implicitDefaultConfig),
+ [implicitDefaultConfig],
+ );
+
const explicitFilterState = useMemo(() => {
const defaultFilters = hookOptions.defaultExplicitFilterState ?? [];
- if (defaultFilters.length === 0) return persistedExplicitFilterState;
+ const merged = (() => {
+ if (defaultFilters.length === 0) return persistedExplicitFilterState;
+ const explicitlyOwnedColumns = new Set(
+ persistedExplicitFilterState.map((filter) => filter.column),
+ );
+ return persistedExplicitFilterState.concat(
+ defaultFilters.filter(
+ (filter) => !explicitlyOwnedColumns.has(filter.column),
+ ),
+ );
+ })();
- const explicitlyOwnedColumns = new Set(
- persistedExplicitFilterState.map((filter) => filter.column),
- );
- return persistedExplicitFilterState.concat(
- defaultFilters.filter(
- (filter) => !explicitlyOwnedColumns.has(filter.column),
- ),
- );
- }, [hookOptions.defaultExplicitFilterState, persistedExplicitFilterState]);
+ return canonicalizeExplicitEnvironmentFilters({
+ explicitFilters: merged,
+ config: managedEnvironmentPolicyConfig,
+ });
+ }, [
+ hookOptions.defaultExplicitFilterState,
+ persistedExplicitFilterState,
+ managedEnvironmentPolicyConfig,
+ ]);
// LFE-10164: When arriving via a URL/deep link that already carries applied
// filters, expand the sidebar sections that have an active filter. Sidebar
@@ -772,11 +788,6 @@ export function useSidebarFilterStateCore(
});
}
- const managedEnvironmentPolicyConfig = useMemo(
- () => buildManagedEnvironmentPolicyConfig(implicitDefaultConfig),
- [implicitDefaultConfig],
- );
-
const managedEnvironmentColumn =
managedEnvironmentPolicyConfig.managedEnvironmentColumn;
@@ -801,6 +812,23 @@ export function useSidebarFilterStateCore(
],
);
+ // Display projection for the search bar: persist the full
+ // `none of [hidden βˆͺ extras]` exclusion, but show only extras
+ // (`-environment:production`) so implicit hidden envs stay off the chip.
+ const projectFiltersForSearchBar = useCallback(
+ (filters: FilterState) =>
+ toSearchBarEnvironmentFilters({
+ explicitFilters: filters,
+ config: managedEnvironmentPolicyConfig,
+ }),
+ [managedEnvironmentPolicyConfig],
+ );
+
+ const searchBarFilterState: FilterState = useMemo(
+ () => projectFiltersForSearchBar(explicitFilterState),
+ [explicitFilterState, projectFiltersForSearchBar],
+ );
+
// `options.updateType` controls the history semantics of the URL write:
// user-initiated filter edits keep the default (push β€” a Back-able step);
// programmatic writes (e.g. the session default-view auto-apply) pass
@@ -815,7 +843,7 @@ export function useSidebarFilterStateCore(
},
) => {
const explicitFilters = stripOmittedColumns(
- stripImplicitEnvironmentFilterFromExplicitState({
+ canonicalizeExplicitEnvironmentFilters({
explicitFilters: newFilters,
config: managedEnvironmentPolicyConfig,
}),
@@ -980,6 +1008,8 @@ export function useSidebarFilterStateCore(
/** Effective applied filters: explicit + defaults + managed-env policy. */
filterState,
explicitFilterState,
+ searchBarFilterState,
+ projectFiltersForSearchBar,
setFilterState,
expandedState,
onExpandedChange,
@@ -1013,6 +1043,8 @@ export function useSidebarFilterPresentation(
const {
filterState,
explicitFilterState,
+ searchBarFilterState,
+ projectFiltersForSearchBar,
setFilterState,
expandedState,
onExpandedChange,
@@ -1033,6 +1065,10 @@ export function useSidebarFilterPresentation(
managedEnvironmentPolicyConfig.hiddenEnvironments.length > 0
? managedEnvironmentColumn
: undefined,
+ hiddenEnvironments:
+ managedEnvironmentPolicyConfig.hiddenEnvironments.length > 0
+ ? managedEnvironmentPolicyConfig.hiddenEnvironments
+ : undefined,
}),
[
config.facets,
@@ -1854,11 +1890,13 @@ export function useSidebarFilterPresentation(
// A user-authored environment filter lives in EXPLICIT state; the
// implicit hidden-env default (`none of [hidden]`) is added to EFFECTIVE
// state only and stripped from explicit state by the managed-environment
- // policy. So "explicit env filter present" is exactly "the user committed
- // to an environment selection" β€” including `environment:default` (any-of
- // the default set), which now persists. Keying the facet's active state
- // off this keeps it in sync with the search bar, which renders any
- // explicit env filter as a chip.
+ // policy. Extra exclusions on top of that default persist as
+ // `none of [hidden βˆͺ extras]`; the search bar display projection shows
+ // only extras. So "explicit env filter present" is exactly
+ // "the user committed to an environment selection" β€” including
+ // `environment:default` (any-of the default set), which now persists.
+ // Keying the facet's active state off this keeps it in sync with the
+ // search bar, which renders any explicit env filter as a chip.
const hasExplicitManagedEnvironmentFilter =
isManagedEnvironmentFacet &&
explicitFilterState.some(
@@ -1983,6 +2021,8 @@ export function useSidebarFilterPresentation(
filterState,
effectiveFilterState: filterState,
explicitFilterState,
+ searchBarFilterState,
+ projectFiltersForSearchBar,
setFilterState,
updateFilter,
updateFilterOnly,
diff --git a/web/src/features/filters/lib/managedEnvironmentPolicy.ts b/web/src/features/filters/lib/managedEnvironmentPolicy.ts
index 069d1bd962..b5edee4bf6 100644
--- a/web/src/features/filters/lib/managedEnvironmentPolicy.ts
+++ b/web/src/features/filters/lib/managedEnvironmentPolicy.ts
@@ -1,5 +1,4 @@
import type { FilterState } from "@langfuse/shared";
-import { areStringSetsEqual } from "./stringSetUtils";
type EnvironmentFilter = Extract<
FilterState[number],
@@ -25,6 +24,29 @@ export function buildManagedEnvironmentPolicyConfig(
};
}
+export function partitionNoneOfEnvironmentValues(params: {
+ values: readonly string[];
+ hiddenEnvironments: readonly string[];
+}): {
+ extras: string[];
+ hiddenInValues: string[];
+ excludesAllHidden: boolean;
+} {
+ const { values, hiddenEnvironments } = params;
+ const hiddenSet = new Set(hiddenEnvironments);
+ const extras = values.filter((value) => !hiddenSet.has(value));
+ const hiddenInValues = values.filter((value) => hiddenSet.has(value));
+ const valueSet = new Set(values);
+
+ return {
+ extras,
+ hiddenInValues,
+ excludesAllHidden:
+ hiddenEnvironments.length > 0 &&
+ hiddenEnvironments.every((environment) => valueSet.has(environment)),
+ };
+}
+
// Only the SYSTEM-shaped implicit default β€” the `none of [hidden]` filter the
// sidebar auto-derives, and that the facet re-creates when the user clears back
// to the default selection β€” counts as "no real filter" and is stripped before
@@ -33,21 +55,51 @@ export function buildManagedEnvironmentPolicyConfig(
// happens to select exactly the current default set: if the user committed to a
// value we keep it explicit and visible. Returning to the default is the user's
// action (remove the filter / uncheck back to default), not something we infer.
-function isEquivalentToImplicitEnvironmentDefault(params: {
+//
+// A `none of [hidden βˆͺ extras]` exclusion is the same default plus extra
+// unchecked values (unchecking production from the implicit default). Persist
+// the full exclusion set so the two intents that both look like
+// `none of [production]` cannot collapse:
+// 1. default + uncheck production β†’ `none of [hidden βˆͺ production]`
+// 2. enable every hidden env and leave production unchecked β†’ sidebar stores
+// `any of [checked]`, never extras-only none-of
+// The search bar still shows only extras (`-environment:production`) via
+// `toSearchBarEnvironmentFilters`. A bar commit of that extras-only chip is
+// expanded back to the full exclusion set on write.
+function canonicalizeNoneOfEnvironmentFilter(params: {
envFilter: EnvironmentFilter;
hiddenEnvironments: string[];
-}): boolean {
+}): EnvironmentFilter | null {
const { envFilter, hiddenEnvironments } = params;
- if (hiddenEnvironments.length === 0) return false;
+ if (envFilter.operator !== "none of") {
+ return envFilter;
+ }
+
+ if (hiddenEnvironments.length === 0) {
+ return envFilter.value.length === 0 ? null : envFilter;
+ }
- return (
- envFilter.operator === "none of" &&
- areStringSetsEqual(envFilter.value, hiddenEnvironments)
- );
+ const { extras, hiddenInValues, excludesAllHidden } =
+ partitionNoneOfEnvironmentValues({
+ values: envFilter.value,
+ hiddenEnvironments,
+ });
+
+ if (excludesAllHidden && extras.length === 0) {
+ return null;
+ }
+
+ // Bar commit of the displayed extras-only chip (`-environment:production`)
+ // means intent (1): keep hidden environments excluded.
+ if (hiddenInValues.length === 0 && extras.length > 0) {
+ return { ...envFilter, value: [...hiddenEnvironments, ...extras] };
+ }
+
+ return envFilter;
}
-export function stripImplicitEnvironmentFilterFromExplicitState(params: {
+export function canonicalizeExplicitEnvironmentFilters(params: {
explicitFilters: FilterState;
config: ManagedEnvironmentPolicyConfig;
}): FilterState {
@@ -69,17 +121,60 @@ export function stripImplicitEnvironmentFilterFromExplicitState(params: {
}
const envFilter = managedColumnFilters[0] as EnvironmentFilter;
- const otherFilters = explicitFilters.filter((filter) => filter !== envFilter);
+ const canonical = canonicalizeNoneOfEnvironmentFilter({
+ envFilter,
+ hiddenEnvironments,
+ });
+
+ if (canonical === envFilter) {
+ return explicitFilters;
+ }
+
+ return explicitFilters.flatMap((filter) => {
+ if (filter !== envFilter) return [filter];
+ return canonical === null ? [] : [canonical];
+ });
+}
+
+export function toSearchBarEnvironmentFilters(params: {
+ explicitFilters: FilterState;
+ config: ManagedEnvironmentPolicyConfig;
+}): FilterState {
+ const { explicitFilters, config } = params;
+ const { managedEnvironmentColumn, hiddenEnvironments } = config;
+
+ if (hiddenEnvironments.length === 0) return explicitFilters;
+
+ const managedColumnFilters = explicitFilters.filter(
+ (filter) => filter.column === managedEnvironmentColumn,
+ );
if (
- isEquivalentToImplicitEnvironmentDefault({
- envFilter,
- hiddenEnvironments,
- })
+ managedColumnFilters.length !== 1 ||
+ managedColumnFilters[0]?.type !== "stringOptions"
) {
- return otherFilters;
+ return explicitFilters;
+ }
+
+ const envFilter = managedColumnFilters[0] as EnvironmentFilter;
+ if (envFilter.operator !== "none of") {
+ return explicitFilters;
}
- return explicitFilters;
+
+ const { extras, excludesAllHidden } = partitionNoneOfEnvironmentValues({
+ values: envFilter.value,
+ hiddenEnvironments,
+ });
+
+ if (!excludesAllHidden) {
+ return explicitFilters;
+ }
+
+ return explicitFilters.flatMap((filter) => {
+ if (filter !== envFilter) return [filter];
+ if (extras.length === 0) return [];
+ return [{ ...envFilter, value: extras }];
+ });
}
export function buildImplicitEnvironmentFilter(params: {
@@ -132,6 +227,5 @@ export function buildEffectiveEnvironmentFilter(params: {
return managedColumnFilters;
}
- const envFilter = managedColumnFilters[0] as EnvironmentFilter;
- return [envFilter];
+ return [managedColumnFilters[0] as EnvironmentFilter];
}
diff --git a/web/src/features/filters/lib/sidebar-filter-actions.clienttest.ts b/web/src/features/filters/lib/sidebar-filter-actions.clienttest.ts
index e9f8b2edcf..c1f98bbd3d 100644
--- a/web/src/features/filters/lib/sidebar-filter-actions.clienttest.ts
+++ b/web/src/features/filters/lib/sidebar-filter-actions.clienttest.ts
@@ -111,6 +111,131 @@ describe("applySelection", () => {
]);
});
+ it("keeps none-of when unchecking a default env while hidden stay excluded", () => {
+ const hidden = ["langfuse-evaluation", "sdk-experiment"];
+ const managedCtx: SidebarFilterActionContext = {
+ ...ctx,
+ managedEnvironmentColumn: "env",
+ hiddenEnvironments: hidden,
+ options: {
+ ...ctx.options,
+ env: ["production", "staging", ...hidden],
+ },
+ };
+
+ expect(applySelection(managedCtx, [], "env", ["staging"])).toEqual([
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production", ...hidden],
+ },
+ ]);
+ });
+
+ it("stores any-of when every hidden env is checked and a default env is not", () => {
+ const hidden = ["langfuse-evaluation", "sdk-experiment"];
+ const managedCtx: SidebarFilterActionContext = {
+ ...ctx,
+ managedEnvironmentColumn: "env",
+ hiddenEnvironments: hidden,
+ options: {
+ ...ctx.options,
+ env: ["production", "staging", ...hidden],
+ },
+ };
+ const existing: FilterState = [
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production", ...hidden],
+ },
+ ];
+ const checked = ["staging", ...hidden];
+
+ expect(applySelection(managedCtx, existing, "env", checked)).toEqual([
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "any of",
+ value: checked,
+ },
+ ]);
+ });
+
+ it("stores any-of when a hidden environment is enabled from the default", () => {
+ const hidden = ["langfuse-evaluation", "sdk-experiment"];
+ const managedCtx: SidebarFilterActionContext = {
+ ...ctx,
+ managedEnvironmentColumn: "env",
+ hiddenEnvironments: hidden,
+ options: {
+ ...ctx.options,
+ env: ["production", "staging", ...hidden],
+ },
+ };
+ const checked = ["production", "staging", "langfuse-evaluation"];
+
+ expect(applySelection(managedCtx, [], "env", checked)).toEqual([
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "any of",
+ value: checked,
+ },
+ ]);
+ });
+
+ it("promotes extras-only none-of from the explicit-operator path to any-of", () => {
+ const hidden = ["langfuse-evaluation", "sdk-experiment"];
+ const managedCtx: SidebarFilterActionContext = {
+ ...ctx,
+ managedEnvironmentColumn: "env",
+ hiddenEnvironments: hidden,
+ options: {
+ ...ctx.options,
+ env: ["production", "staging", ...hidden],
+ },
+ };
+
+ expect(
+ applySelection(managedCtx, [], "env", ["production"], "none of"),
+ ).toEqual([
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["production"],
+ },
+ ]);
+ });
+
+ it("keeps an explicit none-of that already excludes every hidden env", () => {
+ const hidden = ["langfuse-evaluation", "sdk-experiment"];
+ const managedCtx: SidebarFilterActionContext = {
+ ...ctx,
+ managedEnvironmentColumn: "env",
+ hiddenEnvironments: hidden,
+ options: {
+ ...ctx.options,
+ env: ["production", "staging", ...hidden],
+ },
+ };
+ const exclusions = ["production", ...hidden];
+
+ expect(
+ applySelection(managedCtx, [], "env", exclusions, "none of"),
+ ).toEqual([
+ {
+ column: "env",
+ type: "stringOptions",
+ operator: "none of",
+ value: exclusions,
+ },
+ ]);
+ });
+
it("treats an explicit empty none-of as a no-op reset", () => {
const current: FilterState = [
{
diff --git a/web/src/features/filters/lib/sidebar-filter-actions.ts b/web/src/features/filters/lib/sidebar-filter-actions.ts
index ebe0be3357..0b5c99beba 100644
--- a/web/src/features/filters/lib/sidebar-filter-actions.ts
+++ b/web/src/features/filters/lib/sidebar-filter-actions.ts
@@ -4,6 +4,7 @@ import type {
SingleValueOption,
} from "@langfuse/shared";
import type { FilterConfig } from "./filter-config";
+import { partitionNoneOfEnvironmentValues } from "./managedEnvironmentPolicy";
// Pure FilterState transitions behind the sidebar's facet interactions.
// No React: every function maps (context, current state, user input) to the
@@ -31,6 +32,12 @@ export type SidebarFilterActionContext = {
* enable-all-environments override in applySelection.
*/
managedEnvironmentColumn?: string;
+ /**
+ * Hidden environments for the managed-environment policy. Required to
+ * distinguish "default plus extra exclusions" (stay in none-of) from
+ * "user enabled at least one hidden env" (store as any-of [checked]).
+ */
+ hiddenEnvironments?: readonly string[];
};
// Represents one active filter row in the key-value facet UI
@@ -303,6 +310,28 @@ export function applySelection(
}
}
+ // Managed environment: a none-of that does not exclude every hidden env
+ // means the user enabled at least one hidden environment. Store that as
+ // a positive any-of of the checked set so it cannot be confused with
+ // "default plus extra exclusions" (`none of [hidden βˆͺ extras]`). Shared
+ // by checkbox writes and the explicit-operator path (Only / operator
+ // toggle) so the sidebar never persists extras-only none-of.
+ const hiddenEnvironments = ctx.hiddenEnvironments ?? [];
+ if (
+ isManagedEnvironmentColumn &&
+ finalOperator === "none of" &&
+ hiddenEnvironments.length > 0
+ ) {
+ const { excludesAllHidden } = partitionNoneOfEnvironmentValues({
+ values: finalValues,
+ hiddenEnvironments,
+ });
+ if (!excludesAllHidden) {
+ finalOperator = "any of";
+ finalValues = values;
+ }
+ }
+
const filterType: "arrayOptions" | "stringOptions" =
colType === "arrayOptions" ? "arrayOptions" : "stringOptions";
diff --git a/web/src/features/filters/lib/stringSetUtils.ts b/web/src/features/filters/lib/stringSetUtils.ts
deleted file mode 100644
index 834a0d32dc..0000000000
--- a/web/src/features/filters/lib/stringSetUtils.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export function areStringSetsEqual(left: string[], right: string[]): boolean {
- if (left.length !== right.length) return false;
- const leftSet = new Set(left);
- if (leftSet.size !== new Set(right).size) return false;
- return right.every((value) => leftSet.has(value));
-}
diff --git a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
index 05dbafed05..9eefbfdae1 100644
--- a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
+++ b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx
@@ -15,6 +15,12 @@ import { useState } from "react";
import { useSidebarFilterState } from "./hooks/useSidebarFilterState";
import type { FilterConfig } from "./lib/filter-config";
import { useTableViewManager } from "../../components/table/table-view-presets/hooks/useTableViewManager";
+import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-state-to-query";
+import { EVENTS_FIELD_REGISTRY } from "@/src/features/search-bar/lib/fields";
+import {
+ buildManagedEnvironmentPolicyConfig,
+ toSearchBarEnvironmentFilters,
+} from "./lib/managedEnvironmentPolicy";
const mockUseRouter = vi.fn();
const mockCapture = vi.fn();
@@ -216,6 +222,9 @@ function SavedViewHarness({
<pre data-testid="explicit-state">
{JSON.stringify(queryFilter.explicitFilterState)}
</pre>
+ <pre data-testid="search-bar-state">
+ {JSON.stringify(queryFilter.searchBarFilterState)}
+ </pre>
<pre data-testid="effective-state">
{JSON.stringify(queryFilter.filterState)}
</pre>
@@ -683,6 +692,162 @@ describe("Saved view restore with implicit environment defaults", () => {
expect.objectContaining({ enabled: false }),
);
});
+
+ it("surfaces only non-default environment exclusions from a saved view in the search bar", async () => {
+ savedViewFilters = [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: [...HIDDEN_ENVIRONMENTS, "production"],
+ },
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["checkout"],
+ },
+ ];
+ mockGetByIdUseQuery.mockReturnValue({
+ data: {
+ id: "view-1",
+ name: "View excluding production",
+ tableName: TableViewPresetTableName.Traces,
+ projectId: "project-1",
+ orderBy: null,
+ filters: savedViewFilters,
+ columnOrder: null,
+ columnVisibility: null,
+ searchQuery: "",
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
+ updatedAt: new Date("2026-01-01T00:00:00.000Z"),
+ createdBy: "user-1",
+ createdByUser: null,
+ },
+ error: null,
+ });
+
+ render(<SavedViewHarness />);
+
+ await waitFor(() => {
+ expect(screen.getByTestId("loading-state").textContent).toBe("ready");
+ });
+
+ const explicit = JSON.parse(
+ screen.getByTestId("explicit-state").textContent ?? "[]",
+ ) as FilterState;
+ const searchBar = JSON.parse(
+ screen.getByTestId("search-bar-state").textContent ?? "[]",
+ ) as FilterState;
+ const effective = JSON.parse(
+ screen.getByTestId("effective-state").textContent ?? "[]",
+ ) as FilterState;
+
+ expect(explicit).toEqual(
+ expect.arrayContaining([
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: [...HIDDEN_ENVIRONMENTS, "production"],
+ },
+ {
+ column: "name",
+ type: "stringOptions",
+ operator: "any of",
+ value: ["checkout"],
+ },
+ ]),
+ );
+ expect(
+ explicit.find((filter) => filter.column === "environment")?.value,
+ ).toEqual(expect.arrayContaining([...HIDDEN_ENVIRONMENTS, "production"]));
+
+ const envEffective = effective.find(
+ (filter) => filter.column === "environment",
+ );
+ expect(envEffective).toEqual(
+ expect.objectContaining({
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ }),
+ );
+ expect(
+ envEffective && "value" in envEffective ? envEffective.value : [],
+ ).toEqual(expect.arrayContaining([...HIDDEN_ENVIRONMENTS, "production"]));
+
+ expect(
+ searchBar.find((filter) => filter.column === "environment")?.value,
+ ).toEqual(["production"]);
+ expect(
+ filterStateToQueryText(
+ toSearchBarEnvironmentFilters({
+ explicitFilters: explicit,
+ config: buildManagedEnvironmentPolicyConfig({
+ hiddenEnvironments: HIDDEN_ENVIRONMENTS,
+ }),
+ }),
+ {},
+ EVENTS_FIELD_REGISTRY,
+ ).text,
+ ).toContain("-environment:production");
+ });
+
+ it("expands a legacy extras-only saved view to the full exclusion set", async () => {
+ savedViewFilters = [
+ {
+ column: "environment",
+ type: "stringOptions",
+ operator: "none of",
+ value: ["production"],
+ },
+ ];
+ mockGetByIdUseQuery.mockReturnValue({
+ data: {
+ id: "view-1",
+ name: "View excluding production",
+ tableName: TableViewPresetTableName.Traces,
+ projectId: "project-1",
+ orderBy: null,
+ filters: savedViewFilters,
+ columnOrder: null,
+ columnVisibility: null,
+ searchQuery: "",
+ createdAt: new Date("2026-01-01T00:00:00.000Z"),
+ updatedAt: new Date("2026-01-01T00:00:00.000Z"),
+ createdBy: "user-1",
+ createdByUser: null,
+ },
+ error: null,
+ });
+
+ render(<SavedViewHarness />);
+
+ await waitFor(() => {
+ expect(screen.getByTestId("loading-state").textContent).toBe("ready");
+ });
+
+ const explicit = JSON.parse(
+ screen.getByTestId("explicit-state").textContent ?? "[]",
+ ) as FilterState;
+ const searchBar = JSON.parse(
+ screen.getByTestId("search-bar-state").textContent ?? "[]",
+ ) as FilterState;
+ const effective = JSON.parse(
+ screen.getByTestId("effective-state").textContent ?? "[]",
+ ) as FilterState;
+
+ expect(
+ explicit.find((filter) => filter.column === "environment")?.value,
+ ).toEqual(expect.arrayContaining([...HIDDEN_ENVIRONMENTS, "production"]));
+ expect(
+ effective.find((filter) => filter.column === "environment")?.value,
+ ).toEqual(expect.arrayContaining([...HIDDEN_ENVIRONMENTS, "production"]));
+ expect(
+ searchBar.find((filter) => filter.column === "environment")?.value,
+ ).toEqual(["production"]);
+ });
});
describe("Explicit filter in URL without viewId", () => {
diff --git a/web/src/features/search-bar/README.md b/web/src/features/search-bar/README.md
index 88500f677b..4d7a87a590 100644
--- a/web/src/features/search-bar/README.md
+++ b/web/src/features/search-bar/README.md
@@ -154,13 +154,19 @@ committedText ──resetTo──▢ store.draft ──(type/pick/remove)──
on a `textSearch` field β€” `-name:=v` β€” is representable: it lowers to a
`stringOptions none of`, the exact-inequality form the facet emits when one
value is unchecked. It is NOT `does not contain`.)
-- **User-authored filters are never auto-removed.** The bar reads the sidebar's
- **explicit** `FilterState`, so the managed-environment implicit default
- (`environment none of [hidden internal envs]`, derived into _effective_ state
- by `features/filters/lib/managedEnvironmentPolicy.ts`) never shows as a token.
- That policy strips exactly one shape from explicit state β€” that same implicit
- `none of [hidden]` default (which the facet also re-creates on "clear back to
- default"). A user-authored positive selection (`environment:default`, typed or
+- **User-authored filters are never auto-removed.** The bar reads a display
+ projection of the sidebar's **explicit** `FilterState`, so the
+ managed-environment implicit default (`environment none of [hidden internal
+envs]`, derived into _effective_ state by
+ `features/filters/lib/managedEnvironmentPolicy.ts`) never shows as a token.
+ That policy strips the implicit `none of [hidden]` default (which the facet
+ also re-creates on "clear back to default") and keeps
+ `none of [hidden βˆͺ extras]` in persisted/effective state so queries still
+ exclude the hidden set. The search-bar projection shows only extras
+ (`-environment:production`). A bar commit of that extras-only chip expands
+ back to the full exclusion set. Enabling any hidden environment stores a
+ positive `any of [checked]` instead, so it cannot be remasked as extras-only
+ none-of. A user-authored positive selection (`environment:default`, typed or
saved) is kept explicit even when it equals the current default set; the user
returns to the default by removing the filter, never by us inferring it.
diff --git a/web/src/features/search-bar/hooks/useEventsSearchBar.ts b/web/src/features/search-bar/hooks/useEventsSearchBar.ts
index c297b3459d..593f3a4c3e 100644
--- a/web/src/features/search-bar/hooks/useEventsSearchBar.ts
+++ b/web/src/features/search-bar/hooks/useEventsSearchBar.ts
@@ -90,7 +90,7 @@ export function useEventsSearchBar({
/** Table this bar filters β€” the `tableName` analytics dimension. */
tableName: string;
enabled: boolean;
- /** The user's explicit facet filters (sidebar `explicitFilterState`). */
+ /** Search-bar projection of the user's explicit facet filters. */
filterState: FilterState;
searchQuery: string | null;
searchType: TracingSearchType[];