Skip to content

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

fix(events): always allow v3/v4 toggle for Langfuse Cloud admins (#14435)

Nikita Kabardinb43b3eb1c545
diff --git a/web/src/features/events/lib/v4Rollout.clienttest.ts b/web/src/features/events/lib/v4Rollout.clienttest.ts
new file mode 100644
index 0000000000..95e671f0ed
--- /dev/null
+++ b/web/src/features/events/lib/v4Rollout.clienttest.ts
@@ -0,0 +1,40 @@
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import { canToggleV4 } from "./v4Rollout";
+
+describe("canToggleV4", () => {
+ const originalRegion = process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+
+ // A user/org created after the rollout date is auto-enabled, so the toggle
+ // is hidden for them under the normal date-based rollout.
+ const postRolloutContext = {
+ organizations: [
+ { id: "org-new", createdAt: new Date("2026-05-01T00:00:00.000Z") },
+ ],
+ };
+
+ beforeEach(() => {
+ // Force a non-DEV cloud region so the DEV short-circuit does not apply.
+ process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "US";
+ });
+
+ afterEach(() => {
+ process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ });
+
+ it("hides the toggle for a new (auto-enabled) non-admin user", () => {
+ expect(canToggleV4(postRolloutContext)).toBe(false);
+ });
+
+ it("always allows the toggle for a Langfuse Cloud admin, even when new", () => {
+ expect(
+ canToggleV4(postRolloutContext, { isLangfuseCloudAdmin: true }),
+ ).toBe(true);
+ });
+
+ it("does not change behavior for a non-admin when the flag is false", () => {
+ expect(
+ canToggleV4(postRolloutContext, { isLangfuseCloudAdmin: false }),
+ ).toBe(false);
+ });
+});
diff --git a/web/src/features/events/lib/v4Rollout.ts b/web/src/features/events/lib/v4Rollout.ts
index bbb3ff2782..82281753e0 100644
--- a/web/src/features/events/lib/v4Rollout.ts
+++ b/web/src/features/events/lib/v4Rollout.ts
@@ -37,10 +37,25 @@ export function shouldAutoEnableV4({
return oldestOrganizationCreatedAt >= V4_DEFAULT_ENABLED_FROM_AT;
}
-export function canToggleV4(context: V4RolloutContext): boolean {
+type CanToggleV4Options = {
+ // Langfuse Cloud staff superusers (the instance-level `User.admin` flag, not a
+ // customer's org/project ADMIN role) need the toggle on any tenant's project
+ // so they can reproduce v3/v4 behavior — even when their own account is new
+ // enough that the date-based rollout would otherwise auto-enable and lock it.
+ isLangfuseCloudAdmin?: boolean;
+};
+
+export function canToggleV4(
+ context: V4RolloutContext,
+ options: CanToggleV4Options = {},
+): boolean {
if (process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "DEV") {
return true;
}
+ if (options.isLangfuseCloudAdmin) {
+ return true;
+ }
+
return !shouldAutoEnableV4(context);
}
diff --git a/web/src/server/api/routers/userAccount.ts b/web/src/server/api/routers/userAccount.ts
index 280a5d6a74..fdb57f63c3 100644
--- a/web/src/server/api/routers/userAccount.ts
+++ b/web/src/server/api/routers/userAccount.ts
@@ -269,18 +269,21 @@ export const userAccountRouter = createTRPCRouter({
});
}
- const userCanToggleV4 = canToggleV4({
- userCreatedAt: userRolloutState.createdAt,
- organizations: userRolloutState.organizationMemberships.map(
- (membership) => ({
- id: membership.organization.id,
- createdAt: membership.organization.createdAt,
- }),
- ),
- excludedOrganizationIds: env.NEXT_PUBLIC_DEMO_ORG_ID
- ? [env.NEXT_PUBLIC_DEMO_ORG_ID]
- : [],
- });
+ const userCanToggleV4 = canToggleV4(
+ {
+ userCreatedAt: userRolloutState.createdAt,
+ organizations: userRolloutState.organizationMemberships.map(
+ (membership) => ({
+ id: membership.organization.id,
+ createdAt: membership.organization.createdAt,
+ }),
+ ),
+ excludedOrganizationIds: env.NEXT_PUBLIC_DEMO_ORG_ID
+ ? [env.NEXT_PUBLIC_DEMO_ORG_ID]
+ : [],
+ },
+ { isLangfuseCloudAdmin: ctx.session.user.admin === true },
+ );
if (!userCanToggleV4) {
return {
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 091524e27f..238875992b 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -848,20 +848,24 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {
canToggleV4:
v4WriteMode === "dual" && dualPreviewAvailable
? isLangfuseCloud
- ? canToggleV4({
- userCreatedAt: dbUser.createdAt,
- organizations: dbUser.organizationMemberships.map(
- (orgMembership) => ({
- id: orgMembership.organization.id,
- createdAt:
- orgMembership.organization.createdAt,
- }),
- ),
- excludedOrganizationIds:
- env.NEXT_PUBLIC_DEMO_ORG_ID
- ? [env.NEXT_PUBLIC_DEMO_ORG_ID]
- : [],
- })
+ ? canToggleV4(
+ {
+ userCreatedAt: dbUser.createdAt,
+ organizations:
+ dbUser.organizationMemberships.map(
+ (orgMembership) => ({
+ id: orgMembership.organization.id,
+ createdAt:
+ orgMembership.organization.createdAt,
+ }),
+ ),
+ excludedOrganizationIds:
+ env.NEXT_PUBLIC_DEMO_ORG_ID
+ ? [env.NEXT_PUBLIC_DEMO_ORG_ID]
+ : [],
+ },
+ { isLangfuseCloudAdmin: dbUser.admin },
+ )
: true
: false,
canCreateOrganizations: canCreateOrganizations(