Skip to content

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

feat(topics): internal users don't need feature flag (#19155)

Nimar38a36b97a756
diff --git a/web/AGENTS.md b/web/AGENTS.md
index bf184b4745..5454540ede 100644
--- a/web/AGENTS.md
+++ b/web/AGENTS.md
@@ -27,8 +27,8 @@
history drawer shows execution status, errors and retry controls.
`LANGFUSE_TOPICS_ENABLED` gates all routes and effective session flags.
Trigger/retry also requires `LANGFUSE_TOPICS_ENABLED_PROJECT_IDS`; reads/configuration
- use the `langfuseTopics` flag and project permissions. Storage, retry and setup
- details: `../worker/src/features/topics/README.md`. Preview and trigger
+ use internal view or the `langfuseTopics` flag, plus project permissions.
+ Storage, retry and setup details: `../worker/src/features/topics/README.md`. Preview and trigger
selection share `topics/server`'s bounded trace selector with worker
backfills; preserve sampling and the frozen submission range. Models come
from the project's LLM connections (`TopicModelSettings.tsx`,
diff --git a/web/src/__tests__/server/unit/topics.servertest.ts b/web/src/__tests__/server/unit/topics.servertest.ts
index b34d72a607..e15a636df6 100644
--- a/web/src/__tests__/server/unit/topics.servertest.ts
+++ b/web/src/__tests__/server/unit/topics.servertest.ts
@@ -301,18 +301,23 @@ describe("Topics visibility gate", () => {
const session = ({
admin = false,
langfuseTopics = true,
+ internalFeatures = true,
+ enableExperimentalFeatures = false,
role = "VIEWER",
}: {
admin?: boolean;
langfuseTopics?: boolean;
+ internalFeatures?: boolean;
+ enableExperimentalFeatures?: boolean;
role?: string | null;
}) =>
({
expires: "1",
+ environment: { enableExperimentalFeatures },
user: {
id: "user-a",
admin,
- featureFlags: testFeatureFlags({ langfuseTopics }),
+ featureFlags: testFeatureFlags({ langfuseTopics, internalFeatures }),
organizations: role
? [{ id: "org-a", role, projects: [{ id: projectId, role }] }]
: [],
@@ -323,12 +328,45 @@ describe("Topics visibility gate", () => {
it.each([
["a member on an allowlisted project", {}, true, true],
["a project outside the allowlist", {}, false, false],
- ["the feature preview turned off", { langfuseTopics: false }, true, false],
- ["a role without topics:read", { role: "NONE" }, true, false],
- ["an admin outside the project", { admin: true, role: null }, true, true],
+ [
+ "a non-internal user without the flag",
+ { langfuseTopics: false },
+ true,
+ false,
+ ],
+ [
+ "internal view without the Topics flag",
+ { admin: true, langfuseTopics: false, role: null },
+ true,
+ true,
+ ],
+ [
+ "internal view opted out without the Topics flag",
+ { admin: true, internalFeatures: false, langfuseTopics: false },
+ true,
+ false,
+ ],
+ [
+ "internal view opted out with the Topics flag",
+ { admin: true, internalFeatures: false },
+ true,
+ true,
+ ],
+ [
+ "experimental internal view without the Topics flag",
+ { enableExperimentalFeatures: true, langfuseTopics: false },
+ true,
+ true,
+ ],
+ [
+ "internal view without topics:read",
+ { enableExperimentalFeatures: true, langfuseTopics: false, role: "NONE" },
+ true,
+ false,
+ ],
[
"an admin outside a non-allowlisted project",
- { admin: true, role: null },
+ { admin: true, langfuseTopics: false, role: null },
false,
false,
],
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsx
index b62f91b6a9..7377fb4291 100644
--- a/web/src/components/layouts/routes.tsx
+++ b/web/src/components/layouts/routes.tsx
@@ -37,6 +37,10 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { CloudStatusMenu } from "@/src/features/cloud-status-notification/components/CloudStatusMenu";
import { type ProductModule } from "@/src/ee/features/ui-customization/productModuleSchema";
import { matchesPathname } from "@/src/components/layouts/app-layout/utils/pathClassification";
+import {
+ InternalFeatureBadge,
+ useInternalFeaturesEnabled,
+} from "@/src/features/feature-flags";
export enum RouteSection {
Main = "main",
@@ -154,6 +158,7 @@ export const ROUTES: Route[] = [
title: "Topics",
href: "/project/[projectId]/topics",
icon: Grid2X2,
+ label: <TopicsInternalBadge />,
show: ({ canViewTopics }) => canViewTopics,
group: RouteGroup.Observability,
section: RouteSection.Main,
@@ -316,6 +321,11 @@ export const ROUTES: Route[] = [
},
];
+function TopicsInternalBadge() {
+ const internalFeaturesEnabled = useInternalFeaturesEnabled();
+ return internalFeaturesEnabled ? <InternalFeatureBadge /> : null;
+}
+
function CommandMenuTrigger() {
const { setOpen } = useCommandMenu();
const capture = usePostHogClientCapture();
diff --git a/web/src/features/feature-flags/README.md b/web/src/features/feature-flags/README.md
index 292e65d187..f3c93e5285 100644
--- a/web/src/features/feature-flags/README.md
+++ b/web/src/features/feature-flags/README.md
@@ -19,12 +19,16 @@ User-controlled previews may pass `{ enableForAdmins: false }` so an
administrator can opt in or out like any other user. The deployment-wide
`LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES` override still forces flags on.
-`langfuseTopics` ("Langfuse Topics") requires explicit personal opt-in. Only
-platform administrators (`user.admin`) see or may change this preview toggle;
-organization administrator roles do not grant toggle access. Admin and global
-experimental overrides do not enable Topics. It is deliberately excluded from
-public previews, organization defaults, and member preview management. Its
-runtime availability remains controlled separately by the Topics server gate.
+Topics is available through internal view or the `langfuseTopics` ("Langfuse
+Topics") personal flag. Internal view follows the shared internal eligibility
+and opt-out rules; its sidebar entry carries the Internal badge. Only platform
+administrators (`user.admin`) see or may change the personal preview toggle;
+organization administrator roles do not grant toggle access. The flag is
+excluded from public previews, organization defaults, and member preview
+management. Both access paths still require the Topics project/deployment gate
+and `topics:read` permission.
+While Internal view is on, the Topics preview toggle shows as enabled and
+cannot be changed. Switch to External view to manage the personal flag.
Admin-only personal previews are registered in `adminOnlyFeaturePreviewFlags`;
the personal modal and self-toggle mutation use `personalFeaturePreviewFlags`.
diff --git a/web/src/features/feature-flags/hooks/useIsFeatureEnabled.ts b/web/src/features/feature-flags/hooks/useIsFeatureEnabled.ts
index 98ac146aed..de6bbab79e 100644
--- a/web/src/features/feature-flags/hooks/useIsFeatureEnabled.ts
+++ b/web/src/features/feature-flags/hooks/useIsFeatureEnabled.ts
@@ -1,12 +1,15 @@
import { useSession } from "next-auth/react";
import {
isAdminOnlyFeaturePreviewFlag,
- INTERNAL_FEATURE_FLAG,
isInternalFlag,
isRestrictedFlag,
} from "../available-flags";
import type { Flag } from "../types";
-import { getContextualFeatureFlags, hasInternalAccess } from "../utils";
+import {
+ getContextualFeatureFlags,
+ hasInternalAccess,
+ isInternalViewEnabled,
+} from "../utils";
export default function useIsFeatureEnabled(
feature: Flag,
@@ -34,10 +37,7 @@ export default function useIsFeatureEnabled(
})?.[feature] ?? false;
if (isInternalFlag(feature)) {
- return (
- hasInternalAccess({ isAdmin, isExperimentalFeaturesEnabled }) &&
- session.data?.user?.featureFlags[INTERNAL_FEATURE_FLAG] !== false
- );
+ return isInternalViewEnabled(session.data);
}
if (isRestrictedFlag(feature) || isAdminOnlyFeaturePreviewFlag(feature)) {
diff --git a/web/src/features/feature-flags/utils.ts b/web/src/features/feature-flags/utils.ts
index b6bc8c229d..d70102018d 100644
--- a/web/src/features/feature-flags/utils.ts
+++ b/web/src/features/feature-flags/utils.ts
@@ -1,4 +1,5 @@
/* eslint-disable no-nested-ternary */
+import type { Session } from "next-auth";
import {
availableFlags,
defaultOnFeaturePreviewFlags,
@@ -10,6 +11,7 @@ import {
isOrganizationOnlyFeaturePreviewFlag,
isFeaturePreviewAvailable,
isAdminOnlyFeaturePreviewFlag,
+ INTERNAL_FEATURE_FLAG,
type FeaturePreviewAvailabilityContext,
type UserFeatureFlag,
} from "./available-flags";
@@ -30,6 +32,13 @@ export const hasInternalAccess = ({
isExperimentalFeaturesEnabled: boolean;
}) => isExperimentalFeaturesEnabled || isAdmin;
+export const isInternalViewEnabled = (session: Session | null | undefined) =>
+ hasInternalAccess({
+ isAdmin: session?.user?.admin === true,
+ isExperimentalFeaturesEnabled:
+ session?.environment?.enableExperimentalFeatures === true,
+ }) && session?.user?.featureFlags[INTERNAL_FEATURE_FLAG] !== false;
+
const receivesFeaturePreviewsByDefault = (email: string | null | undefined) => {
const normalizedEmail = email?.toLowerCase();
return (
diff --git a/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx b/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx
index 0344660516..17895fe5df 100644
--- a/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx
+++ b/web/src/features/feature-previews/components/ControlledFeaturePreviewModal.tsx
@@ -3,7 +3,10 @@ import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { useSession } from "next-auth/react";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import { useReadPath, V4_PREVIEW_LABEL } from "@/src/features/events";
-import { featurePreviewLabels } from "@/src/features/feature-flags";
+import {
+ featurePreviewLabels,
+ useInternalFeaturesEnabled,
+} from "@/src/features/feature-flags";
import { api } from "@/src/utils/api";
import { classifyTrpcToastError } from "@/src/utils/trpcErrorClassification";
@@ -23,6 +26,7 @@ export function ControlledFeaturePreviewModal({
onOpenChange,
}: ControlledFeaturePreviewModalProps) {
const authSession = useSession();
+ const internalViewEnabled = useInternalFeaturesEnabled();
const { isV4 } = useReadPath();
const capture = usePostHogClientCapture();
const setFeaturePreviewEnabled =
@@ -52,8 +56,9 @@ export function ControlledFeaturePreviewModal({
setFeaturePreviewEnabled.mutate({ flag, enabled });
const isModernSessionEnabled =
- authSession.data?.user?.featureFlags.sessionViewV2 === true ||
- authSession.data?.environment.enableExperimentalFeatures === true;
+ isV4 &&
+ (authSession.data?.user?.featureFlags.sessionViewV2 === true ||
+ authSession.data?.environment.enableExperimentalFeatures === true);
const state: Partial<Record<PreviewFlag, PreviewState>> = {
skillManagement: {
@@ -75,7 +80,13 @@ export function ControlledFeaturePreviewModal({
...(authSession.data?.user?.admin === true
? {
langfuseTopics: {
- enabled: authSession.data.user.featureFlags.langfuseTopics === true,
+ enabled:
+ internalViewEnabled ||
+ authSession.data.user.featureFlags.langfuseTopics === true,
+ disabled: internalViewEnabled,
+ warningReason: internalViewEnabled
+ ? "Topics is enabled by Internal view. Switch to External view to manage this preview separately."
+ : undefined,
onToggle: onToggle("langfuseTopics"),
isToggling: setFeaturePreviewEnabled.isPending,
},
@@ -96,8 +107,9 @@ export function ControlledFeaturePreviewModal({
},
sessionViewV2Timeline: {
enabled:
- authSession.data?.user?.featureFlags.sessionViewV2Timeline === true ||
- authSession.data?.environment.enableExperimentalFeatures === true,
+ isModernSessionEnabled &&
+ (authSession.data?.user?.featureFlags.sessionViewV2Timeline === true ||
+ authSession.data?.environment.enableExperimentalFeatures === true),
disabled:
!isV4 ||
!isModernSessionEnabled ||
diff --git a/web/src/features/feature-previews/components/FeaturePreviewModal.clienttest.tsx b/web/src/features/feature-previews/components/FeaturePreviewModal.clienttest.tsx
index ebd6b49cf2..eb152c433b 100644
--- a/web/src/features/feature-previews/components/FeaturePreviewModal.clienttest.tsx
+++ b/web/src/features/feature-previews/components/FeaturePreviewModal.clienttest.tsx
@@ -1,13 +1,114 @@
/* eslint-disable @repo/prefer-stories-over-client-tests */
import { fireEvent, render, screen } from "@testing-library/react";
+import type { Session } from "next-auth";
+import { useSession } from "next-auth/react";
+import { testFeatureFlags } from "@/src/__tests__/fixtures/feature-flags";
+import { ControlledFeaturePreviewModal } from "./ControlledFeaturePreviewModal";
import { FeaturePreviewModal } from "./FeaturePreviewModal";
+const mocks = vi.hoisted(() => ({ mutate: vi.fn(), isV4: true }));
+
+vi.mock("next-auth/react", () => ({ useSession: vi.fn() }));
+vi.mock("@/src/features/events", () => ({
+ useReadPath: () => ({ isV4: mocks.isV4 }),
+ V4_PREVIEW_LABEL: "Fast (Preview)",
+}));
+vi.mock("@/src/features/posthog-analytics", () => ({
+ usePostHogClientCapture: () => vi.fn(),
+}));
+vi.mock("@/src/utils/api", () => ({
+ api: {
+ userAccount: {
+ setFeaturePreviewEnabled: {
+ useMutation: () => ({ mutate: mocks.mutate, isPending: false }),
+ },
+ },
+ },
+}));
+
vi.mock("next/image", () => ({
default: ({ alt }: { alt: string }) => <span role="img" aria-label={alt} />,
}));
describe("FeaturePreviewModal", () => {
+ beforeEach(() => {
+ mocks.isV4 = true;
+ });
+
+ it("locks Topics on in internal view and restores the personal toggle after opting out", () => {
+ const session = {
+ user: {
+ admin: true,
+ featureFlags: testFeatureFlags({
+ internalFeatures: true,
+ langfuseTopics: false,
+ }),
+ },
+ environment: { enableExperimentalFeatures: false },
+ } as Session;
+ vi.mocked(useSession).mockReturnValue({
+ data: session,
+ status: "authenticated",
+ update: vi.fn(),
+ });
+ const modal = <ControlledFeaturePreviewModal open onOpenChange={vi.fn()} />;
+ const { rerender } = render(modal);
+ fireEvent.click(screen.getByRole("button", { name: /Langfuse Topics/ }));
+
+ const toggle = screen.getByRole("switch", {
+ name: "Toggle Langfuse Topics",
+ });
+ expect(toggle).toBeChecked();
+ expect(toggle).toBeDisabled();
+ expect(
+ screen.getByRole("button", { name: "Langfuse Topics Enabled" }),
+ ).toBeInTheDocument();
+ fireEvent.click(toggle);
+ expect(mocks.mutate).not.toHaveBeenCalled();
+
+ session.user!.featureFlags.internalFeatures = false;
+ rerender(<ControlledFeaturePreviewModal open onOpenChange={vi.fn()} />);
+ expect(toggle).not.toBeChecked();
+ expect(toggle).not.toBeDisabled();
+ fireEvent.click(toggle);
+ expect(mocks.mutate).toHaveBeenCalledWith({
+ flag: "langfuseTopics",
+ enabled: true,
+ });
+ });
+
+ it("keeps session previews unavailable on the legacy read path despite stored opt-ins", () => {
+ mocks.isV4 = false;
+ vi.mocked(useSession).mockReturnValue({
+ data: {
+ user: {
+ featureFlags: testFeatureFlags({
+ sessionViewV2: true,
+ sessionViewV2Timeline: true,
+ }),
+ },
+ environment: { enableExperimentalFeatures: false },
+ } as Session,
+ status: "authenticated",
+ update: vi.fn(),
+ });
+ render(<ControlledFeaturePreviewModal open onOpenChange={vi.fn()} />);
+ fireEvent.click(
+ screen.getByRole("button", {
+ name: "Redesigned Session View Unavailable",
+ }),
+ );
+ for (const name of [
+ "Toggle Redesigned Session View",
+ "Toggle Session Timeline",
+ ]) {
+ const toggle = screen.getByRole("switch", { name });
+ expect(toggle).not.toBeChecked();
+ expect(toggle).toBeDisabled();
+ }
+ });
+
it("lets users opt into Skill Management without other previews", () => {
const onToggle = vi.fn();
diff --git a/web/src/features/feature-previews/components/FeaturePreviewModal.tsx b/web/src/features/feature-previews/components/FeaturePreviewModal.tsx
index 8dc8a8122b..931628cfa5 100644
--- a/web/src/features/feature-previews/components/FeaturePreviewModal.tsx
+++ b/web/src/features/feature-previews/components/FeaturePreviewModal.tsx
@@ -1,4 +1,4 @@
-/* eslint-disable no-nested-ternary, @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
+/* eslint-disable @typescript-eslint/no-deprecated -- Legacy UI usage retained during migration to design-system components. */
import Image from "next/image";
import { useState } from "react";
@@ -148,11 +148,7 @@ export function FeaturePreviewModal({
{featurePreviewLabels[item.flag]}
</span>
<span className="text-muted-foreground mt-1 line-clamp-2 block text-xs">
- {state[item.flag]?.disabled
- ? "Unavailable"
- : state[item.flag]?.enabled
- ? "Enabled"
- : "Available"}
+ {getPreviewStatusLabel(state[item.flag])}
</span>
</span>
</button>
@@ -246,6 +242,12 @@ export function FeaturePreviewModal({
);
}
+function getPreviewStatusLabel(state: PreviewState | undefined) {
+ if (state?.enabled) return "Enabled";
+ if (state?.disabled) return "Unavailable";
+ return "Available";
+}
+
function PreviewMockupPanel({
illustration,
}: {
diff --git a/web/src/features/topics/topicsAccess.ts b/web/src/features/topics/topicsAccess.ts
index e95d4ea14f..15a290bdee 100644
--- a/web/src/features/topics/topicsAccess.ts
+++ b/web/src/features/topics/topicsAccess.ts
@@ -1,12 +1,15 @@
import { type Session } from "next-auth";
import { useSession } from "next-auth/react";
-import { getContextualFeatureFlags } from "@/src/features/feature-flags/utils";
+import {
+ getContextualFeatureFlags,
+ isInternalViewEnabled,
+} from "@/src/features/feature-flags/utils";
import { useProject } from "@/src/features/projects/hooks";
import { hasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
type TopicsProject = { id: string; topicsEnabled?: boolean };
-/** Visibility gate for every Topics surface: project gate, the user's feature preview and topics:read. */
+/** Visibility gate for every Topics surface: project gate, internal view or feature preview, and topics:read. */
export function canViewTopics(
session: Session | null,
project: TopicsProject | null | undefined,
@@ -14,8 +17,9 @@ export function canViewTopics(
return (
!!project &&
isTopicsEnabledForProject(project) &&
- getContextualFeatureFlags(session?.user, { projectId: project.id })
- ?.langfuseTopics === true &&
+ (isInternalViewEnabled(session) ||
+ getContextualFeatureFlags(session?.user, { projectId: project.id })
+ ?.langfuseTopics === true) &&
hasProjectAccess({ session, projectId: project.id, scope: "topics:read" })
);
}