πͺ’ 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
refactor(integrations): derive export-source availability from the v4 write mode (#16093)
Niklas Semmlerb19a2f5425e8
diff --git a/fern/apis/server/definition/blob-storage-integrations.yml b/fern/apis/server/definition/blob-storage-integrations.ymlindex ad6b0a4517..b4915aa822 100644--- a/fern/apis/server/definition/blob-storage-integrations.yml+++ b/fern/apis/server/definition/blob-storage-integrations.yml@@ -80,7 +80,7 @@ types:- `OBSERVATIONS_V2`: same data model as the `/api/public/v2/observations` endpoint, plus scores. Columns are controlled by `exportFieldGroups`.- `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS`: both sets. Observation columns of both portions are controlled by `exportFieldGroups`.- **Note:** `OBSERVATIONS_V2` and the enriched-observations portion of `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` rely on the enriched observations table (Langfuse Fast Preview / v4), which is currently available on Langfuse Cloud only. See https://langfuse.com/docs/v4.+ **Note:** which sources a deployment accepts depends on how far it has moved to the v4 data model. `OBSERVATIONS_V2` and the enriched-observations portion of `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` read the enriched observations table, so they require a deployment that already populates it. `LEGACY_TRACES_OBSERVATIONS` and the legacy portion of `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` read the legacy traces and observations tables, so they require a deployment that still populates those. A deployment part-way through the migration populates both and accepts every source. Selecting a source the deployment cannot serve is rejected with `400`, rather than exporting an empty result. See https://langfuse.com/docs/v4.enum:- LEGACY_TRACES_OBSERVATIONS- OBSERVATIONS_V2@@ -143,7 +143,7 @@ types:exportSource:type: optional<BlobStorageExportSource>docs: |- Data to export. When omitted on update, the existing value is preserved. When omitted on create: integrations on Langfuse Cloud default to `OBSERVATIONS_V2`; self-hosted deployments fall back to `LEGACY_TRACES_OBSERVATIONS`. Required when `exportFieldGroups` is provided.+ Data to export. When omitted on update, the existing value is preserved. When omitted on create, the default is `OBSERVATIONS_V2` on Langfuse Cloud, and on self-hosted deployments `LEGACY_TRACES_OBSERVATIONS` β or `OBSERVATIONS_V2` where the deployment no longer populates the legacy tables. The default is never a source the deployment cannot serve. Required when `exportFieldGroups` is provided.**Cloud-only project deprecation gate (effective 2026-05-20):** For projects created on or after 2026-05-20 on Langfuse Cloud, `LEGACY_TRACES_OBSERVATIONS` and `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` are rejected with HTTP 400. Use `OBSERVATIONS_V2` for all new integrations. Self-hosted deployments are unaffected.diff --git a/packages/shared/src/features/analytics-integrations/export-source-policy.test.ts b/packages/shared/src/features/analytics-integrations/export-source-policy.test.tsindex 60fd9f949d..208c62b350 100644--- a/packages/shared/src/features/analytics-integrations/export-source-policy.test.ts+++ b/packages/shared/src/features/analytics-integrations/export-source-policy.test.ts@@ -1,12 +1,16 @@import { describe, expect, it } from "vitest";+import * as exportSourcePolicy from "./export-source-policy";import {+ areEnrichedWritesActive,+ areLegacyWritesActive,getAvailableExportSources,isEnrichedBlobExportSource,isLegacyBlobExportSource,LEGACY_BLOB_EXPORT_CUTOFF,LEGACY_BLOB_EXPORTER_CUTOFF,validateExportSource,+ type BlobExportWriteMode,type ExportSourceContext,} from "./export-source-policy";@@ -186,6 +190,121 @@ describe("getAvailableExportSources", () => {});});+// The active write mode is the single source of truth for which export+// sources hold data. Neither the V4 frontend preview flag nor a per-user beta+// opt-in may re-enter this decision.+describe("write mode drives export-source availability", () => {+ const WRITE_MODES: readonly BlobExportWriteMode[] = [+ "legacy",+ "dual",+ "events_only",+ ];++ const ctxFor = (+ writeMode: BlobExportWriteMode,+ over: Partial<ExportSourceContext> = {},+ ): ExportSourceContext => ({+ isCloud: false,+ enrichedAvailable: areEnrichedWritesActive(writeMode),+ legacyWritesActive: areLegacyWritesActive(writeMode),+ ...over,+ });++ it("areEnrichedWritesActive: enriched rows exist in every mode but legacy", () => {+ expect(areEnrichedWritesActive("legacy")).toBe(false);+ expect(areEnrichedWritesActive("dual")).toBe(true);+ expect(areEnrichedWritesActive("events_only")).toBe(true);+ });++ it("areLegacyWritesActive: legacy rows exist in every mode but events_only", () => {+ expect(areLegacyWritesActive("legacy")).toBe(true);+ expect(areLegacyWritesActive("dual")).toBe(true);+ expect(areLegacyWritesActive("events_only")).toBe(false);+ });++ // The whole selector, per mode: legacy β legacy sources only, events_only β+ // events only, dual β both. Anything else means a surface offers a source+ // whose data is not being written.+ it.each([+ [+ "legacy",+ [+ { source: "TRACES_OBSERVATIONS" },+ {+ source: "TRACES_OBSERVATIONS_EVENTS",+ blockedReason: "enriched-unavailable",+ },+ { source: "EVENTS", blockedReason: "enriched-unavailable" },+ ],+ ],+ [+ "dual",+ [+ { source: "TRACES_OBSERVATIONS" },+ { source: "TRACES_OBSERVATIONS_EVENTS" },+ { source: "EVENTS" },+ ],+ ],+ [+ "events_only",+ [+ {+ source: "TRACES_OBSERVATIONS",+ blockedReason: "legacy-writes-disabled",+ },+ {+ source: "TRACES_OBSERVATIONS_EVENTS",+ blockedReason: "legacy-writes-disabled",+ },+ { source: "EVENTS" },+ ],+ ],+ ] as const)(+ "write mode %s yields exactly this availability",+ (mode, expected) => {+ expect(getAvailableExportSources(ctxFor(mode))).toEqual(expected);+ },+ );++ // No special case: the combined source needs both halves, so only dual can+ // offer it. A hand-rolled rule for it would drift from the two predicates.+ it("TRACES_OBSERVATIONS_EVENTS requires dual, purely from the two rules", () => {+ const ok = (mode: BlobExportWriteMode) =>+ validateExportSource("TRACES_OBSERVATIONS_EVENTS", ctxFor(mode)).ok;+ expect(ok("legacy")).toBe(false);+ expect(ok("dual")).toBe(true);+ expect(ok("events_only")).toBe(false);+ // β¦and the combination is exactly "legacy AND enriched".+ for (const mode of WRITE_MODES) {+ expect(ok(mode)).toBe(+ areLegacyWritesActive(mode) && areEnrichedWritesActive(mode),+ );+ }+ });++ // The per-user beta opt-in and the Cloud deployment flag are gone from this+ // decision: a pre-cutoff Cloud project sees exactly what self-hosted sees.+ it("availability is deployment-agnostic for pre-cutoff Cloud projects", () => {+ for (const mode of WRITE_MODES) {+ expect(+ getAvailableExportSources(+ ctxFor(mode, {+ isCloud: true,+ projectCreatedAt: PROJECT_PRE,+ integrationCreatedAt: ROW_PRE,+ }),+ ),+ ).toEqual(getAvailableExportSources(ctxFor(mode)));+ }+ });++ // Deletion guard: the old preview-flag helper must not survive as a second,+ // divergent answer to "is enriched available?".+ it("no longer exports isEnrichedBlobExportAvailable", () => {+ expect("isEnrichedBlobExportAvailable" in exportSourcePolicy).toBe(false);+ });+});+describe("isLegacyBlobExportSource", () => {it("is true for the legacy sources", () => {expect(isLegacyBlobExportSource("TRACES_OBSERVATIONS")).toBe(true);diff --git a/packages/shared/src/features/analytics-integrations/export-source-policy.ts b/packages/shared/src/features/analytics-integrations/export-source-policy.tsindex ccd96bc275..b6d14e7bc8 100644--- a/packages/shared/src/features/analytics-integrations/export-source-policy.ts+++ b/packages/shared/src/features/analytics-integrations/export-source-policy.ts@@ -17,19 +17,21 @@// only β a persisted legacy value on an old row is grandfathered, which is// why the cutoffs key on creation dates rather than the write path.// - ENRICHED AVAILABILITY ("enriched-unavailable"): sources that include the-// enriched observations path (EVENTS, TRACES_OBSERVATIONS_EVENTS) need the-// enriched read path β available on Cloud, or on self-hosted via the V4-// preview opt-in. A persisted enriched value left behind by a preview-// rollback is rejected too, instead of silently driving exports against-// unpopulated tables (LFE-10296).+// enriched observations path (EVENTS, TRACES_OBSERVATIONS_EVENTS) read the v4+// events table. Under LANGFUSE_MIGRATION_V4_WRITE_MODE=legacy that table is+// not written, so such a source would export nothing.// - LEGACY WRITE CAPABILITY ("legacy-writes-disabled"): legacy sources read// the v3 traces/observations tables. Under// LANGFUSE_MIGRATION_V4_WRITE_MODE=events_only those tables are no longer-// written, so a legacy source would silently export stale/empty data β-// blocked by data capability, deployment-agnostic, on Cloud and self-hosted-// alike (LFE-10148). Unlike the date cutoffs this also applies to persisted-// values: keeping one would not grandfather anything, it would export-// nothing.+// written, so a legacy source would silently export stale/empty data.+//+// Both are data capability, deployment-agnostic, on Cloud and self-hosted+// alike, and derived from the one write mode via areEnrichedWritesActive /+// areLegacyWritesActive. Unlike the date cutoffs+// they also apply to persisted values: keeping one would not grandfather+// anything, it would export nothing. TRACES_OBSERVATIONS_EVENTS is both+// families at once, so it needs dual β that falls out of the two rules+// rather than being special-cased.// - PERSISTED VALUES ARE NEVER SILENTLY REWRITTEN (LFE-10296): the UI keeps a// persisted-but-blocked source visible as an unavailable option and blocks// the save; forms and servers must not substitute a different source behind@@ -126,14 +128,6 @@ export function isLegacyBlobExporter(return integrationCreatedAt < LEGACY_BLOB_EXPORTER_CUTOFF;}-/** Enriched export path availability: Cloud, or self-hosted V4 preview opt-in. */-export function isEnrichedBlobExportAvailable(- isCloud: boolean,- isV4PreviewEnabled?: boolean,-): boolean {- return isCloud || isV4PreviewEnabled === true;-}-/*** Mirrors the LANGFUSE_MIGRATION_V4_WRITE_MODE env enum; kept as a literal* union so this client-safe file has no dependency on server env parsing.@@ -145,6 +139,13 @@ export function areLegacyWritesActive(writeMode: BlobExportWriteMode): boolean {return writeMode !== "events_only";}+/** Whether the deployment already writes the v4 events table. */+export function areEnrichedWritesActive(+ writeMode: BlobExportWriteMode,+): boolean {+ return writeMode !== "legacy";+}+/*** Everything the policy needs to know about a deployment/project/integration.* Adapters assemble it (env reads stay server/worker-side); optional fieldsdiff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex dd082d3fb6..5ecb141a19 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -8744,10 +8744,18 @@ components:columns of both portions are controlled by `exportFieldGroups`.- **Note:** `OBSERVATIONS_V2` and the enriched-observations portion of- `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` rely on the enriched- observations table (Langfuse Fast Preview / v4), which is currently- available on Langfuse Cloud only. See https://langfuse.com/docs/v4.+ **Note:** which sources a deployment accepts depends on how far it has+ moved to the v4 data model. `OBSERVATIONS_V2` and the+ enriched-observations portion of+ `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` read the enriched observations+ table, so they require a deployment that already populates it.+ `LEGACY_TRACES_OBSERVATIONS` and the legacy portion of+ `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` read the legacy traces and+ observations tables, so they require a deployment that still populates+ those. A deployment part-way through the migration populates both and+ accepts every source. Selecting a source the deployment cannot serve is+ rejected with `400`, rather than exporting an empty result. See+ https://langfuse.com/docs/v4.BlobStorageExportFieldGroup:title: BlobStorageExportFieldGrouptype: string@@ -8836,10 +8844,12 @@ components:nullable: truedescription: >-Data to export. When omitted on update, the existing value is- preserved. When omitted on create: integrations on Langfuse Cloud- default to `OBSERVATIONS_V2`; self-hosted deployments fall back to- `LEGACY_TRACES_OBSERVATIONS`. Required when `exportFieldGroups` is- provided.+ preserved. When omitted on create, the default is `OBSERVATIONS_V2`+ on Langfuse Cloud, and on self-hosted deployments+ `LEGACY_TRACES_OBSERVATIONS` β or `OBSERVATIONS_V2` where the+ deployment no longer populates the legacy tables. The default is+ never a source the deployment cannot serve. Required when+ `exportFieldGroups` is provided.**Cloud-only project deprecation gate (effective 2026-05-20):** Fordiff --git a/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.tsindex 03ae7dce23..19214ea808 100644--- a/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts+++ b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts@@ -717,73 +717,126 @@ describe("Blob Storage Integration tRPC Router", () => {});});- describe("get: isEnrichedExportAvailable flag", () => {+ // The write mode is server-only, so the settings page can only learn it+ // from this response. This is the durable half of the contract β the+ // derived booleans next to it go away once their consumers read writeMode.+ describe("get: writeMode", () => {const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const originalPreviewOptIn = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;afterEach(() => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;(env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =- originalV4Preview;+ originalPreviewOptIn;});- it("returns true for Cloud deployments regardless of V4 flag", async () => {- (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ it.each(["legacy", "dual", "events_only"] as const)(+ "returns the active write mode %s, independent of the preview opt-in",+ async (writeMode) => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = writeMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ const { caller, project } = await prepare();+ const result = await caller.blobStorageIntegration.get({+ projectId: project.id,+ });+ expect(result.writeMode).toBe(writeMode);+ },+ );+ });++ describe("update: enriched export source guard", () => {+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const originalPreviewOptIn = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;++ afterEach(() => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =+ originalPreviewOptIn;+ });++ it("rejects EVENTS under the legacy write mode even with the preview opt-in enabled", async () => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";const { caller, project } = await prepare();- const result = await caller.blobStorageIntegration.get({- projectId: project.id,- });- expect(result.isEnrichedExportAvailable).toBe(true);+ await expect(+ caller.blobStorageIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });});- it("returns false for self-hosted without V4 preview opt-in", async () => {+ it("allows EVENTS under the dual write mode even with the preview opt-in disabled", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";(env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";const { caller, project } = await prepare();- const result = await caller.blobStorageIntegration.get({- projectId: project.id,- });- expect(result.isEnrichedExportAvailable).toBe(false);+ await expect(+ caller.blobStorageIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).resolves.not.toThrow();});- it("returns true for self-hosted with V4 preview opt-in enabled", async () => {+ it("rejects EVENTS under the legacy write mode", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { caller, project } = await prepare();- const result = await caller.blobStorageIntegration.get({- projectId: project.id,- });- expect(result.isEnrichedExportAvailable).toBe(true);+ await expect(+ caller.blobStorageIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });});- });- describe("update: enriched export source guard", () => {- const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;-- afterEach(() => {- (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =- originalV4Preview;+ it("rejects TRACES_OBSERVATIONS_EVENTS under the legacy write mode", async () => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ const { caller, project } = await prepare();+ await prisma.project.update({+ where: { id: project.id },+ data: { createdAt: PRE_CUTOFF },+ });+ await expect(+ caller.blobStorageIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });});- it("rejects EVENTS on self-hosted without V4 preview opt-in", async () => {+ it("rejects TRACES_OBSERVATIONS_EVENTS under the events_only write mode", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "events_only";const { caller, project } = await prepare();+ await prisma.project.update({+ where: { id: project.id },+ data: { createdAt: PRE_CUTOFF },+ });await expect(caller.blobStorageIntegration.update({projectId: project.id,...baseConfig,- exportSource: "EVENTS" as const,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,}),).rejects.toMatchObject({ code: "BAD_REQUEST" });});- it("rejects TRACES_OBSERVATIONS_EVENTS on self-hosted without V4 preview opt-in", async () => {+ it("allows TRACES_OBSERVATIONS_EVENTS under the dual write mode", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";const { caller, project } = await prepare();await prisma.project.update({where: { id: project.id },@@ -795,12 +848,12 @@ describe("Blob Storage Integration tRPC Router", () => {...baseConfig,exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,}),- ).rejects.toMatchObject({ code: "BAD_REQUEST" });+ ).resolves.not.toThrow();});- it("allows EVENTS on self-hosted with V4 preview opt-in", async () => {+ it("allows EVENTS under the events_only write mode", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "events_only";const { caller, project } = await prepare();await expect(caller.blobStorageIntegration.update({@@ -811,9 +864,9 @@ describe("Blob Storage Integration tRPC Router", () => {).resolves.not.toThrow();});- it("allows EVENTS on Cloud regardless of V4 flag", async () => {+ it("allows EVENTS on Cloud under the dual write mode", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";const { caller, project } = await prepare();await expect(caller.blobStorageIntegration.update({@@ -939,19 +992,18 @@ describe("Blob Storage Integration tRPC Router", () => {// enriched source alive on a deployment without the enriched export path.describe("update: omitted exportSource", () => {const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;afterEach(() => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =- originalV4Preview;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;});const { exportSource: _ignored, ...configWithoutExportSource } = baseConfig;it("preserves a persisted enriched source when enriched export is available", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";const { caller, project } = await prepare();await createIntegration({projectId: project.id,@@ -969,9 +1021,9 @@ describe("Blob Storage Integration tRPC Router", () => {expect(row.exportSource).toBe("EVENTS");});- it("rejects an omitted exportSource over a stale enriched row on rolled-back self-hosted", async () => {+ it("rejects an omitted exportSource over a stale enriched row on a legacy-write-mode deployment", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { caller, project } = await prepare();await createIntegration({projectId: project.id,@@ -991,9 +1043,9 @@ describe("Blob Storage Integration tRPC Router", () => {expect(row.exportSource).toBe("EVENTS");});- it("preserves a persisted legacy source on rolled-back self-hosted", async () => {+ it("preserves a persisted legacy source on a legacy-write-mode deployment", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { caller, project } = await prepare();await createIntegration({projectId: project.id,@@ -1017,7 +1069,7 @@ describe("Blob Storage Integration tRPC Router", () => {// default (TRACES_OBSERVATIONS) β mirror of the REST handler's// forceEventsOnCreate behavior.(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";const { caller, project } = await prepare();await prisma.project.update({where: { id: project.id },@@ -1035,9 +1087,9 @@ describe("Blob Storage Integration tRPC Router", () => {expect(row.exportSource).toBe("EVENTS");});- it("still allows an explicit downgrade to a legacy source on rolled-back self-hosted", async () => {+ it("still allows an explicit downgrade to a legacy source on a legacy-write-mode deployment", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { caller, project } = await prepare();await createIntegration({projectId: project.id,diff --git a/web/src/__tests__/server/mixpanel-integration.servertest.ts b/web/src/__tests__/server/mixpanel-integration.servertest.tsindex b991af65ec..bb364c0f7c 100644--- a/web/src/__tests__/server/mixpanel-integration.servertest.ts+++ b/web/src/__tests__/server/mixpanel-integration.servertest.ts@@ -258,29 +258,115 @@ describe("Mixpanel Integration legacy export source cutoff gate", () => {).resolves.not.toThrow();});- it("get returns legacyWritesActive=false on events_only", async () => {+ it("get returns a null config when the project has no integration", async () => {const { caller, project } = await prepare();const result = await caller.mixpanelIntegration.get({projectId: project.id,});- expect(result.legacyWritesActive).toBe(false);expect(result.config).toBeNull();});+ });++ // The active write mode is the only input to export-source availability.+ // The V4 frontend preview flag and the per-user beta opt-in no longer+ // participate, which makes two previously-unreachable combinations behave.+ describe("enriched export sources follow the write mode alone", () => {+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const originalPreview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;++ beforeEach(() => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ });++ afterEach(() => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = originalPreview;+ });- it("get returns legacyWritesActive=true on dual, with config", async () => {+ // dual writes enriched rows, so the source works β it was hidden only+ // because the frontend preview flag was off.+ it("dual + preview opt-in disabled β EVENTS accepted", async () => {(env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";const { caller, project } = await prepare();- await caller.mixpanelIntegration.update({- projectId: project.id,- ...baseConfig,- exportSource: "EVENTS" as const,- });- const result = await caller.mixpanelIntegration.get({- projectId: project.id,- });- expect(result.legacyWritesActive).toBe(true);- expect(result.config?.exportSource).toBe("EVENTS");+ await expect(+ caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).resolves.not.toThrow();});++ it("dual + preview opt-in disabled β TRACES_OBSERVATIONS_EVENTS accepted", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ const { caller, project } = await prepare();+ await expect(+ caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,+ }),+ ).resolves.not.toThrow();+ });++ // legacy writes no enriched rows: accepting the source here only defers+ // the failure to export time.+ it("legacy + preview opt-in enabled β EVENTS rejected", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ const { caller, project } = await prepare();+ await expect(+ caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });+ });++ it("legacy + preview opt-in enabled β TRACES_OBSERVATIONS_EVENTS rejected", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ const { caller, project } = await prepare();+ await expect(+ caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });+ });++ it("legacy β TRACES_OBSERVATIONS accepted", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ const { caller, project } = await prepare();+ await expect(+ caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS" as const,+ }),+ ).resolves.not.toThrow();+ });++ // The write mode is server-only, so the settings page can only learn it+ // from this response.+ it.each(["legacy", "dual", "events_only"] as const)(+ "get returns the active write mode %s, independent of the preview opt-in",+ async (writeMode) => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = writeMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ const { caller, project } = await prepare();+ const result = await caller.mixpanelIntegration.get({+ projectId: project.id,+ });+ expect(result.writeMode).toBe(writeMode);+ },+ );});// LFE-10148 review: the form schema's zod default must not be injected into@@ -340,6 +426,10 @@ describe("Mixpanel Integration legacy export source cutoff gate", () => {expect(result.config?.exportSource).toBe("EVENTS");});+ // Router default for an omitted exportSource: legacy writes active ?+ // TRACES_OBSERVATIONS : EVENTS. It deliberately differs from the+ // settings-page default (EVENTS on dual) β a pre-existing divergence this+ // change does not touch, pinned here so a later fix has to flip it.it("create without exportSource defaults to TRACES_OBSERVATIONS on dual", async () => {const { caller, project } = await prepare();await caller.mixpanelIntegration.update({@@ -352,6 +442,19 @@ describe("Mixpanel Integration legacy export source cutoff gate", () => {expect(result.config?.exportSource).toBe("TRACES_OBSERVATIONS");});+ it("create without exportSource defaults to TRACES_OBSERVATIONS on legacy", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ const { caller, project } = await prepare();+ await caller.mixpanelIntegration.update({+ projectId: project.id,+ ...baseConfig,+ });+ const result = await caller.mixpanelIntegration.get({+ projectId: project.id,+ });+ expect(result.config?.exportSource).toBe("TRACES_OBSERVATIONS");+ });+it("Cloud + post-cutoff project + create without exportSource β BAD_REQUEST (validated default)", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";const { caller, project } = await prepare();diff --git a/web/src/__tests__/server/posthog-integration.servertest.ts b/web/src/__tests__/server/posthog-integration.servertest.tsindex d04d304e5d..57b92b7053 100644--- a/web/src/__tests__/server/posthog-integration.servertest.ts+++ b/web/src/__tests__/server/posthog-integration.servertest.ts@@ -302,29 +302,115 @@ describe("PostHog Integration legacy export source cutoff gate", () => {).resolves.not.toThrow();});- it("get returns legacyWritesActive=false on events_only", async () => {+ it("get returns a null config when the project has no integration", async () => {const { caller, project } = await prepare();const result = await caller.posthogIntegration.get({projectId: project.id,});- expect(result.legacyWritesActive).toBe(false);expect(result.config).toBeNull();});+ });++ // The active write mode is the only input to export-source availability.+ // The V4 frontend preview flag and the per-user beta opt-in no longer+ // participate, which makes two previously-unreachable combinations behave.+ describe("enriched export sources follow the write mode alone", () => {+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const originalPreview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;++ beforeEach(() => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;+ });++ afterEach(() => {+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = originalPreview;+ });- it("get returns legacyWritesActive=true on dual, with config", async () => {+ // dual writes enriched rows, so the source works β it was hidden only+ // because the frontend preview flag was off.+ it("dual + preview opt-in disabled β EVENTS accepted", async () => {(env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";const { caller, project } = await prepare();- await caller.posthogIntegration.update({- projectId: project.id,- ...baseConfig,- exportSource: "EVENTS" as const,- });- const result = await caller.posthogIntegration.get({- projectId: project.id,- });- expect(result.legacyWritesActive).toBe(true);- expect(result.config?.exportSource).toBe("EVENTS");+ await expect(+ caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).resolves.not.toThrow();});++ it("dual + preview opt-in disabled β TRACES_OBSERVATIONS_EVENTS accepted", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "dual";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ const { caller, project } = await prepare();+ await expect(+ caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,+ }),+ ).resolves.not.toThrow();+ });++ // legacy writes no enriched rows: accepting the source here only defers+ // the failure to export time.+ it("legacy + preview opt-in enabled β EVENTS rejected", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ const { caller, project } = await prepare();+ await expect(+ caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });+ });++ it("legacy + preview opt-in enabled β TRACES_OBSERVATIONS_EVENTS rejected", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "true";+ const { caller, project } = await prepare();+ await expect(+ caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS_EVENTS" as const,+ }),+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });+ });++ it("legacy β TRACES_OBSERVATIONS accepted", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ const { caller, project } = await prepare();+ await expect(+ caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ exportSource: "TRACES_OBSERVATIONS" as const,+ }),+ ).resolves.not.toThrow();+ });++ // The write mode is server-only, so the settings page can only learn it+ // from this response.+ it.each(["legacy", "dual", "events_only"] as const)(+ "get returns the active write mode %s, independent of the preview opt-in",+ async (writeMode) => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = writeMode;+ (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ const { caller, project } = await prepare();+ const result = await caller.posthogIntegration.get({+ projectId: project.id,+ });+ expect(result.writeMode).toBe(writeMode);+ },+ );});// LFE-10148 review: the form schema's zod default must not be injected into@@ -384,6 +470,10 @@ describe("PostHog Integration legacy export source cutoff gate", () => {expect(result.config?.exportSource).toBe("EVENTS");});+ // Router default for an omitted exportSource: legacy writes active ?+ // TRACES_OBSERVATIONS : EVENTS. It deliberately differs from the+ // settings-page default (EVENTS on dual) β a pre-existing divergence this+ // change does not touch, pinned here so a later fix has to flip it.it("create without exportSource defaults to TRACES_OBSERVATIONS on dual", async () => {const { caller, project } = await prepare();await caller.posthogIntegration.update({@@ -396,6 +486,19 @@ describe("PostHog Integration legacy export source cutoff gate", () => {expect(result.config?.exportSource).toBe("TRACES_OBSERVATIONS");});+ it("create without exportSource defaults to TRACES_OBSERVATIONS on legacy", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";+ const { caller, project } = await prepare();+ await caller.posthogIntegration.update({+ projectId: project.id,+ ...baseConfig,+ });+ const result = await caller.posthogIntegration.get({+ projectId: project.id,+ });+ expect(result.config?.exportSource).toBe("TRACES_OBSERVATIONS");+ });+it("Cloud + post-cutoff project + create without exportSource β BAD_REQUEST (validated default)", async () => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";const { caller, project } = await prepare();diff --git a/web/src/__tests__/server/unit/assertExportSourceAllowed.servertest.ts b/web/src/__tests__/server/unit/assertExportSourceAllowed.servertest.tsindex da3db9a179..3685461a8f 100644--- a/web/src/__tests__/server/unit/assertExportSourceAllowed.servertest.ts+++ b/web/src/__tests__/server/unit/assertExportSourceAllowed.servertest.ts@@ -1,8 +1,11 @@import { describe, it, expect } from "vitest";import { assertExportSourceAllowed } from "@/src/features/analytics-integrations/server/assertExportSourceAllowed";import {+ areEnrichedWritesActive,+ areLegacyWritesActive,InvalidRequestError,LEGACY_BLOB_EXPORT_CUTOFF,+ type BlobExportWriteMode,type ExportSourceContext,} from "@langfuse/shared";@@ -79,6 +82,61 @@ describe("assertExportSourceAllowed", () => {).toThrow(/events_only/);});+ // The write-mode gate every save path funnels through (tRPC routers and the+ // public REST PUT). It must accept exactly what the UI offers for the mode.+ describe("write mode gate", () => {+ const ctxFor = (writeMode: BlobExportWriteMode): ExportSourceContext => ({+ isCloud: false,+ enrichedAvailable: areEnrichedWritesActive(writeMode),+ legacyWritesActive: areLegacyWritesActive(writeMode),+ });++ const attempt = (+ writeMode: BlobExportWriteMode,+ nextExportSource:+ | "TRACES_OBSERVATIONS"+ | "TRACES_OBSERVATIONS_EVENTS"+ | "EVENTS",+ ) =>+ assertExportSourceAllowed({ nextExportSource, ctx: ctxFor(writeMode) });++ const cases: Array<+ [+ BlobExportWriteMode,+ "TRACES_OBSERVATIONS" | "TRACES_OBSERVATIONS_EVENTS" | "EVENTS",+ boolean,+ ]+ > = [+ ["legacy", "TRACES_OBSERVATIONS", true],+ ["legacy", "TRACES_OBSERVATIONS_EVENTS", false],+ ["legacy", "EVENTS", false],+ ["dual", "TRACES_OBSERVATIONS", true],+ ["dual", "TRACES_OBSERVATIONS_EVENTS", true],+ ["dual", "EVENTS", true],+ ["events_only", "TRACES_OBSERVATIONS", false],+ ["events_only", "TRACES_OBSERVATIONS_EVENTS", false],+ ["events_only", "EVENTS", true],+ ];++ it.each(cases)("%s + %s β allowed=%s", (writeMode, source, allowed) => {+ if (allowed) {+ expect(() => attempt(writeMode, source)).not.toThrow();+ } else {+ expect(() => attempt(writeMode, source)).toThrow(InvalidRequestError);+ }+ });++ it("keeps a persisted-but-blocked source rejected on an omitted update", () => {+ expect(() =>+ assertExportSourceAllowed({+ nextExportSource: undefined,+ persistedExportSource: "EVENTS",+ ctx: ctxFor("legacy"),+ }),+ ).toThrow(InvalidRequestError);+ });+ });+it("omitted source without a persisted row is a no-op", () => {expect(() =>assertExportSourceAllowed({diff --git a/web/src/features/analytics-integrations/components/IntegrationSettingsSkeleton.tsx b/web/src/features/analytics-integrations/components/IntegrationSettingsSkeleton.tsxnew file mode 100644index 0000000000..69ee5dc19a--- /dev/null+++ b/web/src/features/analytics-integrations/components/IntegrationSettingsSkeleton.tsx@@ -0,0 +1,12 @@+import { Skeleton } from "@/src/components/ui/skeleton";++// Placeholder for an integration settings form that is not mounted yet. The+// forms capture their defaults on first render, so each settings page holds+// this until every async input has resolved.+export const IntegrationSettingsSkeleton = () => (+ <div className="space-y-3">+ <Skeleton className="h-9 w-full" />+ <Skeleton className="h-9 w-full" />+ <Skeleton className="h-9 w-full" />+ </div>+);diff --git a/web/src/features/analytics-integrations/exportSource.clienttest.ts b/web/src/features/analytics-integrations/exportSource.clienttest.tsindex 2c0292235e..8bef098932 100644--- a/web/src/features/analytics-integrations/exportSource.clienttest.ts+++ b/web/src/features/analytics-integrations/exportSource.clienttest.ts@@ -2,10 +2,12 @@ import {AnalyticsIntegrationExportSource,LEGACY_BLOB_EXPORT_CUTOFF,LEGACY_BLOB_EXPORTER_CUTOFF,+ type BlobExportWriteMode,type ExportSourceContext,} from "@langfuse/shared";import {+ buildExportSourceContext,getExportSourceFormValue,getExportSourceOptions,getExportSourceUnavailableMessage,@@ -252,11 +254,162 @@ describe("shouldHideExportSourceSelector", () => {});});+// The settings pages (blob storage, PostHog, Mixpanel) build their context+// through buildExportSourceContext from the write mode the integration router+// reports β not from the session's beta flag and not from a frontend preview+// env var. Driving these cases through the real builder is what covers that+// wiring; the builder takes no session or beta input at all.+describe("write mode drives the settings-page selector", () => {+ const WRITE_MODES: BlobExportWriteMode[] = ["legacy", "dual", "events_only"];++ const ctxFor = (+ writeMode: BlobExportWriteMode,+ over: Partial<+ Omit<ExportSourceContext, "enrichedAvailable" | "legacyWritesActive">+ > = {},+ ): ExportSourceContext =>+ buildExportSourceContext({ writeMode, isCloud: false, ...over });++ const selectableValues = (ctx: ExportSourceContext) =>+ getExportSourceOptions(undefined, ctx)+ .filter((o) => !o.unavailable)+ .map((o) => o.value);++ const offered: Array<+ [BlobExportWriteMode, AnalyticsIntegrationExportSource[]]+ > = [+ ["legacy", [AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS]],+ [+ "dual",+ [+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,+ AnalyticsIntegrationExportSource.EVENTS,+ ],+ ],+ ["events_only", [AnalyticsIntegrationExportSource.EVENTS]],+ ];++ it.each(offered)(+ "write mode %s offers exactly the sources it still writes",+ (mode, expected) => {+ expect(selectableValues(ctxFor(mode))).toEqual(expected);+ },+ );++ const defaults: Array<+ [BlobExportWriteMode, AnalyticsIntegrationExportSource]+ > = [+ ["legacy", AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS],+ ["dual", AnalyticsIntegrationExportSource.EVENTS],+ ["events_only", AnalyticsIntegrationExportSource.EVENTS],+ ];++ // The settings-page create default: areEnrichedWritesActive(writeMode)+ // ? EVENTS : TRACES_OBSERVATIONS. The tRPC/REST routers keep their own,+ // older default for an omitted exportSource (TRACES_OBSERVATIONS on dual);+ // that divergence predates this change and is tracked separately.+ it.each(defaults)(+ "write mode %s picks %s as the settings-page create default",+ (mode, expected) => {+ expect(getExportSourceFormValue(undefined, ctxFor(mode))).toBe(expected);+ },+ );++ // Precedence: when legacy is blocked by the Cloud cutoff, the page pins+ // EVENTS even though the general rule would pick TRACES_OBSERVATIONS for a+ // write mode without enriched writes. Only this ordering distinguishes the+ // two rules; every other combination agrees.+ it("post-cutoff Cloud pins EVENTS ahead of the write-mode rule", () => {+ const ctx = ctxFor("legacy", {+ isCloud: true,+ projectCreatedAt: PROJECT_POST,+ integrationCreatedAt: ROW_PRE,+ });+ expect(ctx.enrichedAvailable).toBe(false);+ expect(+ isExportSourceSelectable(+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,+ ctx,+ ),+ ).toBe(false);+ expect(getExportSourceFormValue(undefined, ctx)).toBe(+ AnalyticsIntegrationExportSource.EVENTS,+ );+ });++ // Same pinning on the reachable Cloud configuration, where the write-mode+ // rule already agrees β this is the case real Cloud projects hit.+ it("post-cutoff Cloud on dual pins EVENTS", () => {+ expect(+ getExportSourceFormValue(+ undefined,+ ctxFor("dual", {+ isCloud: true,+ projectCreatedAt: PROJECT_POST,+ integrationCreatedAt: ROW_PRE,+ }),+ ),+ ).toBe(AnalyticsIntegrationExportSource.EVENTS);+ });++ // A source that was legal when it was saved must never silently vanish: the+ // user has to see why their save is blocked and what to switch to.+ const blockedPersisted: Array<+ [BlobExportWriteMode, AnalyticsIntegrationExportSource]+ > = [+ ["legacy", AnalyticsIntegrationExportSource.EVENTS],+ ["legacy", AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS],+ ["events_only", AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS],+ [+ "events_only",+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS_EVENTS,+ ],+ ];++ it.each(blockedPersisted)(+ "write mode %s keeps a persisted %s visible and greyed out",+ (mode, persisted) => {+ const ctx = ctxFor(mode);+ const options = getExportSourceOptions(persisted, ctx);+ expect(options.map((o) => o.value)).toContain(persisted);+ expect(options.find((o) => o.value === persisted)?.unavailable).toBe(+ true,+ );+ // The form keeps the persisted value, so the blocked-save alert has a+ // selected option to point at.+ expect(getExportSourceFormValue(persisted, ctx)).toBe(persisted);+ expect(shouldHideExportSourceSelector(options)).toBe(false);+ },+ );++ // No per-user beta gate and no Cloud-specific enriched path remain, so a+ // pre-cutoff Cloud project renders exactly what self-hosted renders.+ it.each(WRITE_MODES)(+ "pre-cutoff Cloud renders the same options as self-hosted on %s",+ (mode) => {+ expect(+ getExportSourceOptions(+ undefined,+ ctxFor(mode, {+ isCloud: true,+ projectCreatedAt: PROJECT_PRE,+ integrationCreatedAt: ROW_PRE,+ }),+ ),+ ).toEqual(getExportSourceOptions(undefined, ctxFor(mode)));+ },+ );+});+describe("getExportSourceUnavailableMessage", () => {- it("names the enriched path for enriched-unavailable", () => {+ it("names the write mode for enriched-unavailable (self-hosted operator-facing)", () => {const message = getExportSourceUnavailableMessage("enriched-unavailable");expect(message).toContain("enriched observations");- expect(message).toContain("V4 preview opt-in");+ expect(message).toContain("LANGFUSE_MIGRATION_V4_WRITE_MODE=legacy");+ // The preview opt-in no longer affects enriched availability, so pointing+ // an operator at it during a blocked save sends them to a dead end.+ expect(message).not.toContain("preview opt-in");});it("describes the Cloud cutoff for cloud-cutoff", () => {diff --git a/web/src/features/analytics-integrations/exportSource.ts b/web/src/features/analytics-integrations/exportSource.tsindex 1a4dee3ee3..d60f7e4349 100644--- a/web/src/features/analytics-integrations/exportSource.ts+++ b/web/src/features/analytics-integrations/exportSource.ts@@ -1,8 +1,11 @@import {AnalyticsIntegrationExportSource,+ areEnrichedWritesActive,+ areLegacyWritesActive,EXPORT_SOURCE_OPTIONS,getAvailableExportSources,validateExportSource,+ type BlobExportWriteMode,type ExportSourceBlockedReason,type ExportSourceContext,type ExportSourceOption,@@ -12,6 +15,28 @@ import {// PostHog, and Mixpanel settings forms. Policy and rationale live in// packages/shared/.../export-source-policy.ts.+// The write mode is server-only, so every settings page receives it from its+// tRPC get response and derives both capabilities here.+export function buildExportSourceContext({+ writeMode,+ isCloud,+ projectCreatedAt,+ integrationCreatedAt,+}: {+ writeMode: BlobExportWriteMode;+ isCloud: boolean;+ projectCreatedAt?: Date;+ integrationCreatedAt?: Date | null;+}): ExportSourceContext {+ return {+ isCloud,+ enrichedAvailable: areEnrichedWritesActive(writeMode),+ legacyWritesActive: areLegacyWritesActive(writeMode),+ projectCreatedAt,+ integrationCreatedAt,+ };+}+export function isExportSourceSelectable(source: AnalyticsIntegrationExportSource,ctx: ExportSourceContext,@@ -70,7 +95,7 @@ const EXPORT_SOURCE_UNAVAILABLE_MESSAGES: Record<string> = {"enriched-unavailable":- "This integration is configured to export enriched observations, but enriched export is not available on this deployment. Saving is blocked until you select an available export source above. To keep the current configuration instead, re-enable enriched export (V4 preview opt-in) on your deployment.",+ "This integration is configured to export enriched observations, but this deployment runs LANGFUSE_MIGRATION_V4_WRITE_MODE=legacy and does not write the enriched observations table. Saving is blocked until you select an available export source above.","cloud-cutoff":"This integration is configured to export legacy traces and observations, which is no longer available for this project. Saving is blocked until you select an available export source above.",// Self-hosted-operator-facing: naming the env var is intentional.diff --git a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts b/web/src/features/blobstorage-integration/blobstorage-integration-router.tsindex 513639cdd8..04ec2c4ba3 100644--- a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts+++ b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts@@ -27,11 +27,11 @@ import { randomUUID } from "crypto";import { decrypt } from "@langfuse/shared/encryption";import {AnalyticsIntegrationExportSource,+ areEnrichedWritesActive,areLegacyWritesActive,BlobStorageIntegrationType,BlobStorageIntegrationFileType,InvalidRequestError,- isEnrichedBlobExportAvailable,} from "@langfuse/shared";const getAuditLogErrorType = (error: unknown) =>@@ -74,16 +74,6 @@ export const blobStorageIntegrationRouter = createTRPCRouter({scope: "integrations:CRUD",});try {- const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);- const isEnrichedExportAvailable = isEnrichedBlobExportAvailable(- isCloud,- env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN === "true",- );- // Data capability for legacy sources (see export-source-policy.ts).- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );-const config = await ctx.prisma.blobStorageIntegration.findFirst({where: {projectId: input.projectId,@@ -95,8 +85,7 @@ export const blobStorageIntegrationRouter = createTRPCRouter({return {config: config ?? null,- isEnrichedExportAvailable,- legacyWritesActive,+ writeMode: env.LANGFUSE_MIGRATION_V4_WRITE_MODE,};} catch (e) {logger.error(`Failed to get blob storage integration`, e);@@ -131,8 +120,6 @@ export const blobStorageIntegrationRouter = createTRPCRouter({});const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);- const isV4PreviewEnabled =- env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN === "true";const existingIntegration =await ctx.prisma.blobStorageIntegration.findUnique({@@ -156,9 +143,8 @@ export const blobStorageIntegrationRouter = createTRPCRouter({persistedExportSource: existingIntegration?.exportSource,ctx: {isCloud,- enrichedAvailable: isEnrichedBlobExportAvailable(- isCloud,- isV4PreviewEnabled,+ enrichedAvailable: areEnrichedWritesActive(+ env.LANGFUSE_MIGRATION_V4_WRITE_MODE,),legacyWritesActive: areLegacyWritesActive(env.LANGFUSE_MIGRATION_V4_WRITE_MODE,diff --git a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsxindex 1ee6b843a9..309a6d46c3 100644--- a/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx+++ b/web/src/features/blobstorage-integration/components/BlobStorageIntegrationContainer.tsx@@ -1,14 +1,16 @@import { useMemo } from "react";import { Button } from "@/src/components/ui/button";-import { Skeleton } from "@/src/components/ui/skeleton";+import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";import { showErrorToast } from "@/src/features/notifications/showErrorToast";import { api } from "@/src/utils/api";import {+ type BlobExportWriteMode,type BlobStorageIntegration,type ExportSourceContext,} from "@langfuse/shared";+import { buildExportSourceContext } from "@/src/features/analytics-integrations/exportSource";import { type BlobStorageIntegrationFormSchema } from "@/src/features/blobstorage-integration/types";import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";import { useQueryProject } from "@/src/features/projects/hooks";@@ -25,15 +27,11 @@ import { BlobStorageIntegrationForm } from "@/src/features/blobstorage-integratiexport const BlobStorageIntegrationContainer = ({config,projectId,- isLoading,- isEnrichedExportAvailable,- legacyWritesActive,+ writeMode,}: {config: Partial<BlobStorageIntegration> | null;projectId: string;- isLoading: boolean;- isEnrichedExportAvailable: boolean;- legacyWritesActive: boolean;+ writeMode: BlobExportWriteMode;}) => {const capture = usePostHogClientCapture();const { isLangfuseCloud } = useLangfuseCloudRegion();@@ -44,24 +42,18 @@ export const BlobStorageIntegrationContainer = ({const projectCreatedAt = project?.createdAt;const integrationCreatedAt = config?.createdAt;const exportSourceCtx: ExportSourceContext = useMemo(- () => ({- isCloud: isLangfuseCloud,- enrichedAvailable: isEnrichedExportAvailable,- legacyWritesActive,- projectCreatedAt: projectCreatedAt- ? new Date(projectCreatedAt)- : undefined,- integrationCreatedAt: integrationCreatedAt- ? new Date(integrationCreatedAt)- : null,- }),- [- isLangfuseCloud,- isEnrichedExportAvailable,- legacyWritesActive,- projectCreatedAt,- integrationCreatedAt,- ],+ () =>+ buildExportSourceContext({+ writeMode,+ isCloud: isLangfuseCloud,+ projectCreatedAt: projectCreatedAt+ ? new Date(projectCreatedAt)+ : undefined,+ integrationCreatedAt: integrationCreatedAt+ ? new Date(integrationCreatedAt)+ : null,+ }),+ [isLangfuseCloud, writeMode, projectCreatedAt, integrationCreatedAt],);const utils = api.useUtils();@@ -96,15 +88,10 @@ export const BlobStorageIntegrationContainer = ({});// The form is never mounted before its inputs resolve, so there is no- // mid-flight reset to protect a draft from.- if (isLoading || !project) {- return (- <div className="space-y-3">- <Skeleton className="h-9 w-full" />- <Skeleton className="h-9 w-full" />- <Skeleton className="h-9 w-full" />- </div>- );+ // mid-flight reset to protect a draft from. The page already gates on the+ // integration query; only the separate project query can still be pending.+ if (!project) {+ return <IntegrationSettingsSkeleton />;}const handleSubmit = (values: BlobStorageIntegrationFormSchema) => {diff --git a/web/src/features/blobstorage-integration/service.ts b/web/src/features/blobstorage-integration/service.tsindex f8917fb57f..115a354393 100644--- a/web/src/features/blobstorage-integration/service.ts+++ b/web/src/features/blobstorage-integration/service.ts@@ -4,6 +4,7 @@ import {BlobStorageIntegrationType,InvalidRequestError,AnalyticsIntegrationExportSource,+ areEnrichedWritesActive,areLegacyWritesActive,validateExportSource,BlobStorageIntegrationFileType,@@ -149,9 +150,8 @@ export async function upsertBlobStorageIntegration(params: {// Under events_only a new row must never fall back to the legacy Prisma// column default; force EVENTS in-transaction, deployment-agnostic// (see export-source-policy.ts).- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );+ const writeMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const legacyWritesActive = areLegacyWritesActive(writeMode);const createExportSource =data.exportSource ??(params.forceEventsOnCreate || !legacyWritesActive@@ -200,7 +200,7 @@ export async function upsertBlobStorageIntegration(params: {// transaction back. See export-source-policy.ts.const backstop = validateExportSource(result.exportSource, {isCloud: !isSelfHosted,- enrichedAvailable: true,+ enrichedAvailable: areEnrichedWritesActive(writeMode),legacyWritesActive,integrationCreatedAt: params.refuseLegacyOnCreate? result.createdAtdiff --git a/web/src/features/mixpanel-integration/mixpanel-integration-router.ts b/web/src/features/mixpanel-integration/mixpanel-integration-router.tsindex 722669618d..00f449be19 100644--- a/web/src/features/mixpanel-integration/mixpanel-integration-router.ts+++ b/web/src/features/mixpanel-integration/mixpanel-integration-router.ts@@ -15,6 +15,7 @@ import { env } from "@/src/env.mjs";import { getDisplayCredential } from "@/src/features/analytics-integrations/server/displayCredential";import {AnalyticsIntegrationExportSource,+ areEnrichedWritesActive,areLegacyWritesActive,InvalidRequestError,LangfuseNotFoundError,@@ -30,10 +31,7 @@ export const mixpanelIntegrationRouter = createTRPCRouter({projectId: input.projectId,scope: "integrations:CRUD",});- // Data capability for legacy sources (see export-source-policy.ts).- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );+ const writeMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;try {const dbConfig = await ctx.prisma.mixpanelIntegration.findFirst({where: {@@ -42,7 +40,7 @@ export const mixpanelIntegrationRouter = createTRPCRouter({});if (!dbConfig) {- return { config: null, legacyWritesActive };+ return { config: null, writeMode };}const { encryptedMixpanelProjectToken, exportSource, ...config } =@@ -57,7 +55,7 @@ export const mixpanelIntegrationRouter = createTRPCRouter({decrypt(encryptedMixpanelProjectToken),),},- legacyWritesActive,+ writeMode,};} catch (e) {console.error("mixpanel integration get", e);@@ -97,13 +95,9 @@ export const mixpanelIntegrationRouter = createTRPCRouter({}}- // EVENTS is always accepted by this router, hence enrichedAvailable:- // true. An omitted source preserves the persisted row; on CREATE it- // falls back to a default that is validated like an explicit choice- // (LFE-9688 / LFE-10148). See export-source-policy.ts.- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );+ const writeMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const legacyWritesActive = areLegacyWritesActive(writeMode);+ const enrichedAvailable = areEnrichedWritesActive(writeMode);const existingIntegration =await ctx.prisma.mixpanelIntegration.findUnique({where: { projectId: input.projectId },@@ -146,7 +140,7 @@ export const mixpanelIntegrationRouter = createTRPCRouter({persistedExportSource: existingIntegration?.exportSource,ctx: {isCloud: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),- enrichedAvailable: true,+ enrichedAvailable,legacyWritesActive,projectCreatedAt,},@@ -198,7 +192,7 @@ export const mixpanelIntegrationRouter = createTRPCRouter({});const validation = validateExportSource(result.exportSource, {isCloud: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),- enrichedAvailable: true,+ enrichedAvailable,legacyWritesActive,projectCreatedAt: project.createdAt,});diff --git a/web/src/features/posthog-integration/posthog-integration-router.ts b/web/src/features/posthog-integration/posthog-integration-router.tsindex 2310f5b57e..50def81e07 100644--- a/web/src/features/posthog-integration/posthog-integration-router.ts+++ b/web/src/features/posthog-integration/posthog-integration-router.ts@@ -16,6 +16,7 @@ import { validateWebhookURL } from "@langfuse/shared/src/server";import { getDisplayCredential } from "@/src/features/analytics-integrations/server/displayCredential";import {AnalyticsIntegrationExportSource,+ areEnrichedWritesActive,areLegacyWritesActive,InvalidRequestError,LangfuseNotFoundError,@@ -31,10 +32,7 @@ export const posthogIntegrationRouter = createTRPCRouter({projectId: input.projectId,scope: "integrations:CRUD",});- // Data capability for legacy sources (see export-source-policy.ts).- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );+ const writeMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;try {const dbConfig = await ctx.prisma.posthogIntegration.findFirst({where: {@@ -43,7 +41,7 @@ export const posthogIntegrationRouter = createTRPCRouter({});if (!dbConfig) {- return { config: null, legacyWritesActive };+ return { config: null, writeMode };}const { encryptedPosthogApiKey, exportSource, ...config } = dbConfig;@@ -57,7 +55,7 @@ export const posthogIntegrationRouter = createTRPCRouter({decrypt(encryptedPosthogApiKey),),},- legacyWritesActive,+ writeMode,};} catch (e) {console.error("posthog integration get", e);@@ -110,13 +108,9 @@ export const posthogIntegrationRouter = createTRPCRouter({});}- // EVENTS is always accepted by this router, hence enrichedAvailable:- // true. An omitted source preserves the persisted row; on CREATE it- // falls back to a default that is validated like an explicit choice- // (LFE-9688 / LFE-10148). See export-source-policy.ts.- const legacyWritesActive = areLegacyWritesActive(- env.LANGFUSE_MIGRATION_V4_WRITE_MODE,- );+ const writeMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;+ const legacyWritesActive = areLegacyWritesActive(writeMode);+ const enrichedAvailable = areEnrichedWritesActive(writeMode);const existingIntegration =await ctx.prisma.posthogIntegration.findUnique({where: { projectId: input.projectId },@@ -159,7 +153,7 @@ export const posthogIntegrationRouter = createTRPCRouter({persistedExportSource: existingIntegration?.exportSource,ctx: {isCloud: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),- enrichedAvailable: true,+ enrichedAvailable,legacyWritesActive,projectCreatedAt,},@@ -213,7 +207,7 @@ export const posthogIntegrationRouter = createTRPCRouter({});const validation = validateExportSource(result.exportSource, {isCloud: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),- enrichedAvailable: true,+ enrichedAvailable,legacyWritesActive,projectCreatedAt: project.createdAt,});diff --git a/web/src/pages/api/public/integrations/blob-storage/index.ts b/web/src/pages/api/public/integrations/blob-storage/index.tsindex d369af2b85..7bbf8fc8d8 100644--- a/web/src/pages/api/public/integrations/blob-storage/index.ts+++ b/web/src/pages/api/public/integrations/blob-storage/index.ts@@ -19,8 +19,8 @@ import {import { upsertBlobStorageIntegration } from "@/src/features/blobstorage-integration/service";import { assertExportSourceAllowed } from "@/src/features/analytics-integrations/server/assertExportSourceAllowed";import {+ areEnrichedWritesActive,areLegacyWritesActive,- isEnrichedBlobExportAvailable,} from "@langfuse/shared";import { auditLog } from "@/src/features/audit-logs/auditLog";import { env } from "@/src/env.mjs";@@ -162,8 +162,6 @@ async function handleUpsertBlobStorageIntegration(const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);- const isV4PreviewEnabled =- env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN === "true";const internalExportSource =validatedData.exportSource != null? toInternalExportSource(validatedData.exportSource)@@ -185,9 +183,8 @@ async function handleUpsertBlobStorageIntegration(persistedExportSource: existingIntegration?.exportSource,ctx: {isCloud,- enrichedAvailable: isEnrichedBlobExportAvailable(- isCloud,- isV4PreviewEnabled,+ enrichedAvailable: areEnrichedWritesActive(+ env.LANGFUSE_MIGRATION_V4_WRITE_MODE,),legacyWritesActive: areLegacyWritesActive(env.LANGFUSE_MIGRATION_V4_WRITE_MODE,diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsxindex a891a3975b..7e1638194a 100644--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx@@ -3,6 +3,7 @@ import ContainerPage from "@/src/components/layouts/container-page";import { StatusBadge } from "@/src/components/ui/StatusBadge/StatusBadge";import { Button } from "@/src/components/ui/button";import { Card } from "@/src/components/ui/card";+import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";import Link from "next/link";import { useRouter } from "next/router";import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";@@ -106,15 +107,15 @@ export default function BlobStorageIntegrationSettings() {<><Header title="Configuration" className="mt-8" /><Card className="p-3">- <BlobStorageIntegrationContainer- config={state.data?.config ?? null}- projectId={projectId}- isLoading={state.isLoading}- isEnrichedExportAvailable={- state.data?.isEnrichedExportAvailable ?? false- }- legacyWritesActive={state.data?.legacyWritesActive ?? true}- />+ {!state.data ? (+ <IntegrationSettingsSkeleton />+ ) : (+ <BlobStorageIntegrationContainer+ config={state.data.config ?? null}+ projectId={projectId}+ writeMode={state.data.writeMode}+ />+ )}</Card></>)}diff --git a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsxindex 374e88ad2a..a77d485b84 100644--- a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx@@ -35,11 +35,13 @@ import {import {AnalyticsIntegrationExportSource,validateExportSource,+ type BlobExportWriteMode,type ExportSourceContext,} from "@langfuse/shared";import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";// Shared export-source UI adapters; policy in export-source-policy.ts.import {+ buildExportSourceContext,getExportSourceOptions,getExportSourceUnavailableMessage,isExportSourceSelectable,@@ -53,9 +55,10 @@ import { api } from "@/src/utils/api";import { type RouterOutput } from "@/src/utils/types";import { zodResolver } from "@hookform/resolvers/zod";import { Card } from "@/src/components/ui/card";+import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";import Link from "next/link";import { useRouter } from "next/router";-import { useEffect, useMemo } from "react";+import { useMemo } from "react";import { useForm } from "react-hook-form";import { type z } from "zod";import { Info, ExternalLink } from "lucide-react";@@ -75,6 +78,8 @@ export default function MixpanelIntegrationSettings() {},);+ const { project } = useQueryProject();+const status =state.isLoading || !hasAccess? undefined@@ -121,12 +126,19 @@ export default function MixpanelIntegrationSettings() {<Header title="Configuration" /><Card className="p-3"><MixpanelLogo className="text-foreground mb-4 w-20" />- <MixpanelIntegrationSettingsForm- state={state.data?.config ?? undefined}- projectId={projectId}- isLoading={state.isLoading}- legacyWritesActive={state.data?.legacyWritesActive ?? true}- />+ {!state.data || !project ? (+ <IntegrationSettingsSkeleton />+ ) : (+ <MixpanelIntegrationSettingsForm+ // Draft lifetime = entity identity, so background refetches+ // cannot reset a draft in progress.+ key={`${projectId}:${state.data.config ? "configured" : "new"}`}+ state={state.data.config ?? undefined}+ projectId={projectId}+ writeMode={state.data.writeMode}+ projectCreatedAt={project.createdAt}+ />+ )}</Card></>)}@@ -148,32 +160,27 @@ export default function MixpanelIntegrationSettings() {const MixpanelIntegrationSettingsForm = ({state,projectId,- isLoading,- legacyWritesActive,+ writeMode,+ projectCreatedAt,}: {state?: NonNullable<RouterOutput["mixpanelIntegration"]["get"]["config"]>;projectId: string;- isLoading: boolean;- legacyWritesActive: boolean;+ writeMode: BlobExportWriteMode;+ // Raw ISO string, not a Date: a Date built in the parent's JSX would be a new+ // reference on every render and would defeat the memo below.+ projectCreatedAt: string;}) => {const capture = usePostHogClientCapture();const { isBetaEnabled } = useV4Beta();const { isLangfuseCloud } = useLangfuseCloudRegion();- const { project } = useQueryProject();-- // Policy context; EVENTS is always accepted by this router, hence- // enrichedAvailable: true (see export-source-policy.ts).- const projectCreatedAt = project?.createdAt;const exportSourceCtx: ExportSourceContext = useMemo(- () => ({- isCloud: isLangfuseCloud,- enrichedAvailable: true,- legacyWritesActive,- projectCreatedAt: projectCreatedAt- ? new Date(projectCreatedAt)- : undefined,- }),- [isLangfuseCloud, legacyWritesActive, projectCreatedAt],+ () =>+ buildExportSourceContext({+ writeMode,+ isCloud: isLangfuseCloud,+ projectCreatedAt: new Date(projectCreatedAt),+ }),+ [writeMode, isLangfuseCloud, projectCreatedAt],);const legacyValidation = validateExportSource(AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,@@ -225,7 +232,7 @@ const MixpanelIntegrationSettingsForm = ({const defaultExportSource = isPostCutoffCloud? AnalyticsIntegrationExportSource.EVENTS: (state?.exportSource ??- (isBetaEnabled || !legacyWritesActive+ (isBetaEnabled || !exportSourceCtx.legacyWritesActive? AnalyticsIntegrationExportSource.EVENTS: AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS));@@ -239,21 +246,8 @@ const MixpanelIntegrationSettingsForm = ({enabled: state?.enabled ?? false,exportSource: defaultExportSource,},- disabled: isLoading,});- useEffect(() => {- mixpanelForm.reset({- mixpanelRegion:- (state?.mixpanelRegion as MixpanelRegion) ??- MIXPANEL_REGIONS[0].subdomain,- mixpanelProjectToken: "",- enabled: state?.enabled ?? false,- exportSource: defaultExportSource,- });- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [state]);-const watchedExportSource = mixpanelForm.watch("exportSource");const watchedValidation =watchedExportSource != null@@ -437,14 +431,13 @@ const MixpanelIntegrationSettingsForm = ({<Buttonloading={mut.isPending}onClick={mixpanelForm.handleSubmit(onSubmit)}- disabled={isLoading}>Save</Button><Buttonvariant="ghost"loading={mutDelete.isPending}- disabled={isLoading || !!!state}+ disabled={!state}onClick={() => {if (confirm(diff --git a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsxindex 5c670a61e3..aded193d25 100644--- a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx+++ b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx@@ -33,11 +33,13 @@ import { PostHogStatusSection } from "@/src/features/posthog-integration/componeimport {AnalyticsIntegrationExportSource,validateExportSource,+ type BlobExportWriteMode,type ExportSourceContext,} from "@langfuse/shared";import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";// Shared export-source UI adapters; policy in export-source-policy.ts.import {+ buildExportSourceContext,getExportSourceOptions,getExportSourceUnavailableMessage,isExportSourceSelectable,@@ -51,9 +53,10 @@ import { api } from "@/src/utils/api";import { type RouterOutput } from "@/src/utils/types";import { zodResolver } from "@hookform/resolvers/zod";import { Card } from "@/src/components/ui/card";+import { IntegrationSettingsSkeleton } from "@/src/features/analytics-integrations/components/IntegrationSettingsSkeleton";import Link from "next/link";import { useRouter } from "next/router";-import { useEffect, useMemo } from "react";+import { useMemo } from "react";import { useForm } from "react-hook-form";import { type z } from "zod";import { Info, ExternalLink } from "lucide-react";@@ -73,6 +76,8 @@ export default function PosthogIntegrationSettings() {},);+ const { project } = useQueryProject();+// A persisted fault outranks active/inactive: it is the state the admin has// to act on, and it is cleared by the next successful sync.const status =@@ -123,12 +128,19 @@ export default function PosthogIntegrationSettings() {<Header title="Configuration" /><Card className="p-3"><PostHogLogo className="text-foreground mb-4 w-36" />- <PostHogIntegrationSettings- state={state.data?.config ?? undefined}- projectId={projectId}- isLoading={state.isLoading}- legacyWritesActive={state.data?.legacyWritesActive ?? true}- />+ {!state.data || !project ? (+ <IntegrationSettingsSkeleton />+ ) : (+ <PostHogIntegrationSettings+ // Draft lifetime = entity identity, so background refetches+ // cannot reset a draft in progress.+ key={`${projectId}:${state.data.config ? "configured" : "new"}`}+ state={state.data.config ?? undefined}+ projectId={projectId}+ writeMode={state.data.writeMode}+ projectCreatedAt={project.createdAt}+ />+ )}</Card></>)}@@ -142,32 +154,27 @@ export default function PosthogIntegrationSettings() {const PostHogIntegrationSettings = ({state,projectId,- isLoading,- legacyWritesActive,+ writeMode,+ projectCreatedAt,}: {state?: NonNullable<RouterOutput["posthogIntegration"]["get"]["config"]>;projectId: string;- isLoading: boolean;- legacyWritesActive: boolean;+ writeMode: BlobExportWriteMode;+ // Raw ISO string, not a Date: a Date built in the parent's JSX would be a new+ // reference on every render and would defeat the memo below.+ projectCreatedAt: string;}) => {const capture = usePostHogClientCapture();const { isBetaEnabled } = useV4Beta();const { isLangfuseCloud } = useLangfuseCloudRegion();- const { project } = useQueryProject();-- // Policy context; EVENTS is always accepted by this router, hence- // enrichedAvailable: true (see export-source-policy.ts).- const projectCreatedAt = project?.createdAt;const exportSourceCtx: ExportSourceContext = useMemo(- () => ({- isCloud: isLangfuseCloud,- enrichedAvailable: true,- legacyWritesActive,- projectCreatedAt: projectCreatedAt- ? new Date(projectCreatedAt)- : undefined,- }),- [isLangfuseCloud, legacyWritesActive, projectCreatedAt],+ () =>+ buildExportSourceContext({+ writeMode,+ isCloud: isLangfuseCloud,+ projectCreatedAt: new Date(projectCreatedAt),+ }),+ [writeMode, isLangfuseCloud, projectCreatedAt],);const legacyValidation = validateExportSource(AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,@@ -219,7 +226,7 @@ const PostHogIntegrationSettings = ({const defaultExportSource = isPostCutoffCloud? AnalyticsIntegrationExportSource.EVENTS: (state?.exportSource ??- (isBetaEnabled || !legacyWritesActive+ (isBetaEnabled || !exportSourceCtx.legacyWritesActive? AnalyticsIntegrationExportSource.EVENTS: AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS));@@ -231,19 +238,8 @@ const PostHogIntegrationSettings = ({enabled: state?.enabled ?? false,exportSource: defaultExportSource,},- disabled: isLoading,});- useEffect(() => {- posthogForm.reset({- posthogHostname: state?.posthogHostName ?? "",- posthogProjectApiKey: "",- enabled: state?.enabled ?? false,- exportSource: defaultExportSource,- });- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [state]);-const watchedExportSource = posthogForm.watch("exportSource");const watchedValidation =watchedExportSource != null@@ -414,14 +410,13 @@ const PostHogIntegrationSettings = ({<Buttonloading={mut.isPending}onClick={posthogForm.handleSubmit(onSubmit)}- disabled={isLoading}>Save</Button><Buttonvariant="ghost"loading={mutDelete.isPending}- disabled={isLoading || !!!state}+ disabled={!state}onClick={() => {if (confirm(diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.tsindex 898f12c659..0decf0a41f 100644--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts@@ -132,19 +132,18 @@ describe("BlobStorageIntegrationProcessingJob", () => {s3Prefix = null;});- // LFE-10296: a persisted enriched export source on a deployment without the- // enriched export path (e.g. after a V4-preview rollback) must fail the job- // loudly instead of silently exporting from unpopulated tables.+ // A persisted enriched export source on a deployment that does not write the+ // v4 events table must fail the job loudly instead of silently exporting+ // from unpopulated tables.describe("enriched export source guard", () => {- const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;afterEach(() => {- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =- originalV4Preview;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;});- it("fails the job and persists lastError when the enriched export path is unavailable", async () => {- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ it("fails the job and persists lastError when an enriched source runs on legacy", async () => {+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { projectId } = await createOrgProjectAndApiKey();s3Prefix = projectId;@@ -242,11 +241,10 @@ describe("BlobStorageIntegrationProcessingJob", () => {// After BullMQ exhausts its retries, a customer-fault error disables the// integration; everything else keeps retrying as before.describe("customer-fault disable", () => {- const originalV4Preview = env.LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN;+ const originalWriteMode = env.LANGFUSE_MIGRATION_V4_WRITE_MODE;afterEach(() => {- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN =- originalV4Preview;+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = originalWriteMode;});// Minimal AWS SDK v3 S3 AccessDenied shape (high-confidence customer fault).@@ -337,9 +335,9 @@ describe("BlobStorageIntegrationProcessingJob", () => {});it("does not disable on the final attempt of a non-customer-fault ('other') error", async () => {- // Enriched source + V4 preview off => the guard throws a plain Error,- // which the classifier treats as "other".- (env as any).LANGFUSE_MIGRATION_V4_ALLOW_PREVIEW_OPT_IN = "false";+ // Enriched source on the legacy write mode => the guard throws a plain+ // Error, which the classifier treats as "other".+ (env as any).LANGFUSE_MIGRATION_V4_WRITE_MODE = "legacy";const { projectId } = await createOrgProjectAndApiKey();s3Prefix = projectId;diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.tsindex 8f563e1ce7..2596a44582 100644--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts@@ -60,8 +60,6 @@ import {BlobStorageExportMode,OBSERVATION_FIELD_GROUPS_FULL,type ObservationFieldGroupFull,- isEnrichedBlobExportAvailable,- isEnrichedBlobExportSource,isLegacyBlobExportSource,isLegacyBlobExporter,resolveBlobExportTuning,@@ -72,7 +70,7 @@ import { decrypt } from "@langfuse/shared/encryption";import { env as sharedEnv } from "@langfuse/shared/src/env";import { randomUUID } from "crypto";import { SpanKind } from "@opentelemetry/api";-import { env, v4AllowPreviewOptIn } from "../../env";+import { env } from "../../env";import { assertExportSourceWritable } from "../exportWriteModeGuard";import { recordExportVolume } from "../../services/exportVolumeMetric";import {@@ -1267,27 +1265,12 @@ export const handleBlobStorageIntegrationProjectJob = async (return;}- // Legacy-source deprecation is a Cloud policy (see blob-export-gate.ts:- // isLegacyBlobExportAllowed / isLegacyBlobExporter both exempt self-hosted),- // so the deprecation notice below is Cloud-only too.+ // Legacy-source deprecation is a Cloud policy (isLegacyBlobExporter exempts+ // self-hosted), so the deprecation notice below is Cloud-only too.const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);try {- // Fail loudly rather than export from unpopulated tables when an enriched- // source survives on a deployment without the enriched path, e.g. after a- // V4-preview rollback. The catch persists lastError and notifies admins- // (LFE-10296).- if (- isEnrichedBlobExportSource(blobStorageIntegration.exportSource) &&- !isEnrichedBlobExportAvailable(isCloud, v4AllowPreviewOptIn(env))- ) {- throw new Error(- "The configured export source includes enriched observations, but enriched export is not available on this deployment. Select a different export source in the blob storage integration settings, or re-enable enriched export (V4 preview opt-in) on this deployment.",- );- }-- // Write-mode guard, both directions (LFE-10148, LFE-11009); the catch- // persists lastError and notifies admins.+ // The catch persists lastError and notifies admins.assertExportSourceWritable(blobStorageIntegration.exportSource,"Select the enriched export source (OBSERVATIONS_V2) in the blob storage integration settings.",diff --git a/worker/src/features/exportWriteModeGuard.ts b/worker/src/features/exportWriteModeGuard.tsindex 0d15956cb1..4f293490e9 100644--- a/worker/src/features/exportWriteModeGuard.ts+++ b/worker/src/features/exportWriteModeGuard.ts@@ -1,9 +1,10 @@import {+ areEnrichedWritesActive,areLegacyWritesActive,validateExportSource,type AnalyticsIntegrationExportSource,} from "@langfuse/shared";-import { env, v4WritesToEventsTable } from "../env";+import { env } from "../env";/*** Write-mode guard for the export workers (blob storage, PostHog, Mixpanel);@@ -22,7 +23,9 @@ export function assertExportSourceWritable(const validation = validateExportSource(exportSource, {// No dates: the Cloud cutoffs gate writes, not running exports.isCloud: false,- enrichedAvailable: v4WritesToEventsTable(env),+ enrichedAvailable: areEnrichedWritesActive(+ env.LANGFUSE_MIGRATION_V4_WRITE_MODE,+ ),legacyWritesActive: areLegacyWritesActive(env.LANGFUSE_MIGRATION_V4_WRITE_MODE,),