Skip to content

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

feat(blob-storage): block legacy export source for new Cloud exporters (#14044)

Niklas Semmlere59b04efb90a
diff --git a/.env.dev.example b/.env.dev.example
index eab622d100..da622a98c8 100644
--- a/.env.dev.example
+++ b/.env.dev.example
@@ -67,6 +67,9 @@ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION="DEV"
# post-cutoff, or a future date (e.g. 2099-01-01T00:00:00.000Z) to grandfather
# all projects. Must be a valid ISO 8601 datetime string. Leave unset in prod.
# NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF=
+# Same, for the integration-level cutoff applied to the blob storage
+# integration row's creation date instead of the project's.
+# NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF=
# Langfuse experimental features
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES="false"
diff --git a/fern/apis/server/definition/blob-storage-integrations.yml b/fern/apis/server/definition/blob-storage-integrations.yml
index 2fd9ac968f..69b96fcf5b 100644
--- a/fern/apis/server/definition/blob-storage-integrations.yml
+++ b/fern/apis/server/definition/blob-storage-integrations.yml
@@ -131,9 +131,11 @@ types:
exportSource:
type: optional<BlobStorageExportSource>
docs: |
- Data to export. When omitted on update, the existing value is preserved. When omitted on create: pre-cutoff Cloud projects and self-hosted deployments fall back to `LEGACY_TRACES_OBSERVATIONS`; post-cutoff Cloud projects (created on or after 2026-05-20) auto-default to `OBSERVATIONS_V2`. Required when `exportFieldGroups` is provided.
+ 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.
- **Cloud-only 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. Omitting `exportSource` on these projects silently defaults to `OBSERVATIONS_V2` rather than the schema column default. Use `OBSERVATIONS_V2` for all new integrations. Projects created before 2026-05-20 and self-hosted deployments are unaffected.
+ **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.
+
+ **Cloud-only integration deprecation gate (effective 2026-06-22):** On Langfuse Cloud, legacy export sources are only accepted for blob storage integrations created before 2026-06-22, regardless of project age. Requests that would create a new integration with `LEGACY_TRACES_OBSERVATIONS` or `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` are rejected with HTTP 400. Use `OBSERVATIONS_V2` instead. Self-hosted deployments are unaffected.
exportFieldGroups:
type: optional<list<BlobStorageExportFieldGroup>>
diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.ts
index 2fe208b038..ee195d5525 100644
--- a/packages/shared/src/env.ts
+++ b/packages/shared/src/env.ts
@@ -7,6 +7,8 @@ const EnvSchema = z.object({
// export cutoff for local testing (e.g. "2020-01-01T00:00:00.000Z" makes
// every project post-cutoff; "2099-01-01T00:00:00.000Z" grandfathers all).
NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF: z.iso.datetime().optional(),
+ // Same, for the integration-level cutoff (BlobStorageIntegration.createdAt).
+ NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF: z.iso.datetime().optional(),
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
diff --git a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts b/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
index 2eaf732474..136f028acb 100644
--- a/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
+++ b/packages/shared/src/features/analytics-integrations/blob-export-gate.ts
@@ -4,6 +4,10 @@
import { AnalyticsIntegrationExportSource } from "@prisma/client";
// Cloud projects created on or after this instant cannot use legacy export sources.
+// Both cutoffs in this file are Cloud-only by design (the `!isCloud` short-circuits
+// below): self-hosted instances can enable the enriched export via the V4 preview
+// opt-in, but that must not activate these cutoffs β€” deprecating legacy sources
+// on self-hosted is a separate, still-open decision.
// NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF overrides the default for local dev testing.
const _override = process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF
? new Date(process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF)
@@ -13,6 +17,19 @@ export const LEGACY_BLOB_EXPORT_CUTOFF =
? _override
: new Date("2026-05-20T00:00:00.000Z");
+// Cloud blob storage integrations created on or after this instant cannot use legacy
+// export sources. Symmetric with `LEGACY_BLOB_EXPORT_CUTOFF` (project-level) but applied
+// to `BlobStorageIntegration.createdAt` instead of `Project.createdAt`. Cloud-only β€”
+// see the note above.
+// NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF overrides the default for local dev testing.
+const _exporterOverride = process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF
+ ? new Date(process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF)
+ : null;
+export const LEGACY_BLOB_EXPORTER_CUTOFF =
+ _exporterOverride && !isNaN(_exporterOverride.getTime())
+ ? _exporterOverride
+ : new Date("2026-06-22T00:00:00.000Z");
+
// Internal enum values that are considered "legacy". satisfies ensures each
// element remains a valid AnalyticsIntegrationExportSource β€” catches renames or
// removals at compile time. Adding a new enum variant does NOT automatically
@@ -37,6 +54,24 @@ export function isLegacyBlobExportAllowed(
return projectCreatedAt < LEGACY_BLOB_EXPORT_CUTOFF;
}
+/**
+ * Whether a blob storage integration row counts as legacy β€” i.e. may still use
+ * legacy export sources. Applied to `BlobStorageIntegration.createdAt`.
+ *
+ * - `!isCloud` β†’ `true`: self-hosted is exempt (cutoff does not apply).
+ * - `null` createdAt β†’ `false`: no existing row means a brand-new integration,
+ * which follows new-customer rules.
+ * - otherwise legacy iff the row was created strictly before the cutoff.
+ */
+export function isLegacyBlobExporter(
+ integrationCreatedAt: Date | null,
+ isCloud: boolean,
+): boolean {
+ if (!isCloud) return true;
+ if (integrationCreatedAt == null) return false;
+ return integrationCreatedAt < LEGACY_BLOB_EXPORTER_CUTOFF;
+}
+
/**
* Whether this deployment has the enriched events export path.
* True for Cloud, or for self-hosted instances that have opted into the V4 preview
diff --git a/turbo.json b/turbo.json
index 72a5a30d45..76a221c1e9 100644
--- a/turbo.json
+++ b/turbo.json
@@ -2,7 +2,10 @@
"$schema": "https://turbo.build/schema.json",
"noUpdateNotifier": true,
"globalDependencies": [".env"],
- "globalEnv": ["NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF"],
+ "globalEnv": [
+ "NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF",
+ "NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF"
+ ],
"envMode": "loose",
"tasks": {
"build": {
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index 3e0ade99c1..1a69277474 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -7847,21 +7847,28 @@ components:
nullable: true
description: >-
Data to export. When omitted on update, the existing value is
- preserved. When omitted on create: pre-cutoff Cloud projects and
- self-hosted deployments fall back to `LEGACY_TRACES_OBSERVATIONS`;
- post-cutoff Cloud projects (created on or after 2026-05-20)
- auto-default to `OBSERVATIONS_V2`. Required when `exportFieldGroups`
- is provided.
+ 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.
- **Cloud-only deprecation gate (effective 2026-05-20):** For projects
- created on or after 2026-05-20 on Langfuse Cloud,
+ **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. Omitting `exportSource` on these projects silently defaults to
- `OBSERVATIONS_V2` rather than the schema column default. Use
- `OBSERVATIONS_V2` for all new integrations. Projects created before
- 2026-05-20 and self-hosted deployments are unaffected.
+ 400. Use `OBSERVATIONS_V2` for all new integrations. Self-hosted
+ deployments are unaffected.
+
+
+ **Cloud-only integration deprecation gate (effective 2026-06-22):**
+ On Langfuse Cloud, legacy export sources are only accepted for blob
+ storage integrations created before 2026-06-22, regardless of
+ project age. Requests that would create a new integration with
+ `LEGACY_TRACES_OBSERVATIONS` or
+ `LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS` are rejected with HTTP
+ 400. Use `OBSERVATIONS_V2` instead. Self-hosted deployments are
+ unaffected.
exportFieldGroups:
type: array
items:
diff --git a/web/src/__tests__/server/blob-storage-integration-api.servertest.ts b/web/src/__tests__/server/blob-storage-integration-api.servertest.ts
index 05860ad331..6c8b009575 100644
--- a/web/src/__tests__/server/blob-storage-integration-api.servertest.ts
+++ b/web/src/__tests__/server/blob-storage-integration-api.servertest.ts
@@ -12,12 +12,19 @@ import {
import {
OBSERVATION_FIELD_GROUPS_FULL,
LEGACY_BLOB_EXPORT_CUTOFF,
+ LEGACY_BLOB_EXPORTER_CUTOFF,
} from "@langfuse/shared";
import { decrypt } from "@langfuse/shared/encryption";
const MS_PER_DAY = 24 * 60 * 60 * 1000;
const PRE_CUTOFF = new Date(LEGACY_BLOB_EXPORT_CUTOFF.getTime() - MS_PER_DAY);
const POST_CUTOFF = new Date(LEGACY_BLOB_EXPORT_CUTOFF.getTime() + MS_PER_DAY);
+const INTEGRATION_PRE_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() - MS_PER_DAY,
+);
+const INTEGRATION_POST_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() + MS_PER_DAY,
+);
// Schemas based on Fern schema definition
const BlobStorageIntegrationResponseSchema = z.object({
@@ -294,7 +301,8 @@ describe("Blob Storage Integrations API", () => {
});
it("should update an existing blob storage integration", async () => {
- // Create initial integration
+ // Backdated: the row keeps the legacy exportSource column default,
+ // which only grandfathered (pre-integration-cutoff) rows may carry.
await prisma.blobStorageIntegration.create({
data: {
projectId: testProject1Id,
@@ -309,6 +317,7 @@ describe("Blob Storage Integrations API", () => {
forcePathStyle: true,
fileType: "JSON",
exportMode: "FROM_TODAY",
+ createdAt: INTEGRATION_PRE_CUTOFF,
},
});
@@ -593,7 +602,8 @@ describe("Blob Storage Integrations API", () => {
});
it("should preserve exportFieldGroups in DB when updating via REST", async () => {
- // Seed a row with a custom subset
+ // Seed a custom subset. Backdated: the row keeps the legacy exportSource
+ // column default, which only grandfathered rows may carry.
await prisma.blobStorageIntegration.create({
data: {
projectId: testProject1Id,
@@ -609,6 +619,7 @@ describe("Blob Storage Integrations API", () => {
fileType: "JSONL",
exportMode: "FULL_HISTORY",
exportFieldGroups: ["core", "io"],
+ createdAt: INTEGRATION_PRE_CUTOFF,
},
});
@@ -659,6 +670,32 @@ describe("Blob Storage Integrations API", () => {
});
});
+ // Pre-integration-cutoff legacy row: lets a legacy-source PUT pass the
+ // integration-level gate (new Cloud rows can no longer be legacy, so these
+ // tests exercise the UPDATE path).
+ const seedGrandfatheredLegacyRow = (
+ data: { exportFieldGroups?: string[] } = {},
+ ) =>
+ prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProject1Id,
+ type: "S3",
+ bucketName: "seed-bucket",
+ region: "us-east-1",
+ accessKeyId: "key",
+ secretAccessKey: "secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ exportSource: "TRACES_OBSERVATIONS",
+ createdAt: INTEGRATION_PRE_CUTOFF,
+ ...data,
+ },
+ });
+
// ---- OBSERVATIONS_V2 / LEGACY_TRACES_AND_ENRICHED_OBSERVATIONS path ----
it("OBSERVATIONS_V2 + exportFieldGroups=[core,io] -> 200 and GET returns same value", async () => {
@@ -792,6 +829,7 @@ describe("Blob Storage Integrations API", () => {
// ---- LEGACY_TRACES_OBSERVATIONS path ----
it("LEGACY_TRACES_OBSERVATIONS + exportFieldGroups omitted -> 200; GET returns all 11 groups", async () => {
+ await seedGrandfatheredLegacyRow();
const requestBody = {
...validBlobStorageConfig,
projectId: testProject1Id,
@@ -826,6 +864,7 @@ describe("Blob Storage Integrations API", () => {
});
it("LEGACY_TRACES_OBSERVATIONS + exportFieldGroups=null -> 200; GET returns all 11 groups", async () => {
+ await seedGrandfatheredLegacyRow();
const requestBody = {
...validBlobStorageConfig,
projectId: testProject1Id,
@@ -879,6 +918,7 @@ describe("Blob Storage Integrations API", () => {
});
it("LEGACY_TRACES_OBSERVATIONS + exportFieldGroups=[core,io] -> 200 and GET returns same value", async () => {
+ await seedGrandfatheredLegacyRow();
const requestBody = {
...validBlobStorageConfig,
projectId: testProject1Id,
@@ -944,25 +984,8 @@ describe("Blob Storage Integrations API", () => {
});
it("PUT LEGACY_TRACES_OBSERVATIONS preserves existing export_field_groups column in DB", async () => {
- // Seed with a custom subset
- await prisma.blobStorageIntegration.create({
- data: {
- projectId: testProject1Id,
- type: "S3",
- bucketName: "initial-bucket",
- region: "us-east-1",
- accessKeyId: "key",
- secretAccessKey: "secret",
- prefix: "",
- exportFrequency: "daily",
- enabled: true,
- forcePathStyle: false,
- fileType: "JSONL",
- exportMode: "FULL_HISTORY",
- exportSource: "TRACES_OBSERVATIONS",
- exportFieldGroups: ["core", "io"],
- },
- });
+ // Seed a grandfathered row with a custom subset
+ await seedGrandfatheredLegacyRow({ exportFieldGroups: ["core", "io"] });
await makeZodVerifiedAPICall(
BlobStorageIntegrationResponseSchema,
@@ -988,6 +1011,7 @@ describe("Blob Storage Integrations API", () => {
// ---- Response shape ----
it("PUT response includes exportSource and exportFieldGroups for LEGACY_TRACES_OBSERVATIONS", async () => {
+ await seedGrandfatheredLegacyRow();
const requestBody = {
...validBlobStorageConfig,
projectId: testProject1Id,
@@ -1501,6 +1525,26 @@ describe("Blob Storage Integrations API", () => {
where: { id: testProject1Id },
data: { createdAt: PRE_CUTOFF },
});
+ // Grandfathered row: legacy sources are only allowed on existing
+ // pre-integration-cutoff rows.
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProject1Id,
+ type: "S3",
+ bucketName: "seed-bucket",
+ region: "us-east-1",
+ accessKeyId: "key",
+ secretAccessKey: "secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ exportSource: "TRACES_OBSERVATIONS",
+ createdAt: INTEGRATION_PRE_CUTOFF,
+ },
+ });
const result = await makeAPICall(
"PUT",
"/api/public/integrations/blob-storage",
@@ -1666,4 +1710,164 @@ describe("Blob Storage Integrations API", () => {
}
});
});
+
+ describe("integration-level legacy exporter cutoff gate", () => {
+ // Cloud mode comes from the server process env (see note in the
+ // project-level gate suite). The project is pinned pre-cutoff, so every
+ // 400 here is the integration-level cutoff. The self-hosted bypass cannot
+ // be tested over HTTP (frozen server env); the tRPC suite covers it
+ // through the same shared gate.
+ const basePayload = {
+ ...validBlobStorageConfig,
+ projectId: "", // set per test
+ };
+
+ const seedIntegration = (createdAt: Date) =>
+ prisma.blobStorageIntegration.create({
+ data: {
+ projectId: testProject1Id,
+ type: "S3",
+ bucketName: "existing-bucket",
+ region: "us-east-1",
+ accessKeyId: "key",
+ secretAccessKey: "secret",
+ prefix: "",
+ exportFrequency: "daily",
+ enabled: true,
+ forcePathStyle: false,
+ fileType: "JSONL",
+ exportMode: "FULL_HISTORY",
+ exportSource: "TRACES_OBSERVATIONS",
+ createdAt,
+ },
+ });
+
+ beforeAll(async () => {
+ await prisma.project.update({
+ where: { id: testProject1Id },
+ data: { createdAt: PRE_CUTOFF },
+ });
+ });
+
+ afterAll(async () => {
+ await prisma.project.update({
+ where: { id: testProject1Id },
+ data: { createdAt: new Date() },
+ });
+ });
+
+ afterEach(async () => {
+ await prisma.blobStorageIntegration.deleteMany({
+ where: { projectId: testProject1Id },
+ });
+ });
+
+ it("no existing row + legacy source β†’ 400 mentioning the integration cutoff", async () => {
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ {
+ ...basePayload,
+ projectId: testProject1Id,
+ exportSource: "LEGACY_TRACES_OBSERVATIONS",
+ },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(400);
+ expect(result.body.message).toContain(
+ "blob storage integrations created on or after",
+ );
+ expect(result.body.message).toContain(
+ LEGACY_BLOB_EXPORTER_CUTOFF.toISOString(),
+ );
+ expect(result.body.message).toContain("OBSERVATIONS_V2");
+ });
+
+ it("pre-cutoff existing row + legacy source β†’ 200 (grandfathered)", async () => {
+ await seedIntegration(INTEGRATION_PRE_CUTOFF);
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ {
+ ...basePayload,
+ projectId: testProject1Id,
+ exportSource: "LEGACY_TRACES_OBSERVATIONS",
+ },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(200);
+ expect(result.body.exportSource).toBe("LEGACY_TRACES_OBSERVATIONS");
+ });
+
+ it("existing row created exactly at the cutoff + legacy source β†’ 400", async () => {
+ // Boundary: only rows created strictly before the cutoff are
+ // grandfathered.
+ await seedIntegration(LEGACY_BLOB_EXPORTER_CUTOFF);
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ {
+ ...basePayload,
+ projectId: testProject1Id,
+ exportSource: "LEGACY_TRACES_OBSERVATIONS",
+ },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(400);
+ expect(result.body.message).toContain(
+ "blob storage integrations created on or after",
+ );
+ });
+
+ it("post-cutoff existing row + legacy source β†’ 400", async () => {
+ await seedIntegration(INTEGRATION_POST_CUTOFF);
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ {
+ ...basePayload,
+ projectId: testProject1Id,
+ exportSource: "LEGACY_TRACES_OBSERVATIONS",
+ },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(400);
+ expect(result.body.message).toContain(
+ "blob storage integrations created on or after",
+ );
+ });
+
+ it("no existing row + OBSERVATIONS_V2 β†’ 200", async () => {
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ {
+ ...basePayload,
+ projectId: testProject1Id,
+ exportSource: "OBSERVATIONS_V2",
+ },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(200);
+ expect(result.body.exportSource).toBe("OBSERVATIONS_V2");
+ });
+
+ it("no existing row + omitted exportSource β†’ 200 and persists EVENTS", async () => {
+ // New Cloud rows must never get the legacy column default, even on a
+ // pre-cutoff project.
+ const result = await makeAPICall(
+ "PUT",
+ "/api/public/integrations/blob-storage",
+ { ...basePayload, projectId: testProject1Id },
+ createBasicAuthHeader(testApiKey, testApiSecretKey),
+ );
+ expect(result.status).toBe(200);
+ expect(result.body.exportSource).toBe("OBSERVATIONS_V2");
+
+ const saved = await prisma.blobStorageIntegration.findUnique({
+ where: { projectId: testProject1Id },
+ });
+ expect(saved?.exportSource).toBe("EVENTS");
+ });
+ });
});
diff --git a/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
index 8e71c54632..d68f55adf8 100644
--- a/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
+++ b/web/src/__tests__/server/blob-storage-integration-trpc.servertest.ts
@@ -14,6 +14,7 @@ import {
import {
OBSERVATION_FIELD_GROUPS_FULL,
LEGACY_BLOB_EXPORT_CUTOFF,
+ LEGACY_BLOB_EXPORTER_CUTOFF,
} from "@langfuse/shared";
import { env } from "@/src/env.mjs";
import { env as sharedEnv } from "@langfuse/shared/src/env";
@@ -21,6 +22,13 @@ import { env as sharedEnv } from "@langfuse/shared/src/env";
const MS_PER_DAY = 24 * 60 * 60 * 1000;
const PRE_CUTOFF = new Date(LEGACY_BLOB_EXPORT_CUTOFF.getTime() - MS_PER_DAY);
const POST_CUTOFF = new Date(LEGACY_BLOB_EXPORT_CUTOFF.getTime() + MS_PER_DAY);
+// Integration-level cutoff applied to BlobStorageIntegration.createdAt.
+const INTEGRATION_PRE_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() - MS_PER_DAY,
+);
+const INTEGRATION_POST_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() + MS_PER_DAY,
+);
vi.mock("@langfuse/shared/src/server", async () => {
const actual = await vi.importActual("@langfuse/shared/src/server");
@@ -474,6 +482,14 @@ describe("Blob Storage Integration tRPC Router", () => {
where: { id: project.id },
data: { createdAt: PRE_CUTOFF },
});
+ // Pre-cutoff integration row (legacy exporter) so the integration-cutoff
+ // gate allows the legacy source; this test only exercises field-group
+ // handling, not the cutoff.
+ await createIntegration({ projectId: project.id });
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: project.id },
+ data: { createdAt: INTEGRATION_PRE_CUTOFF },
+ });
await expect(
caller.blobStorageIntegration.update({
@@ -491,6 +507,14 @@ describe("Blob Storage Integration tRPC Router", () => {
where: { id: project.id },
data: { createdAt: PRE_CUTOFF },
});
+ // Pre-cutoff integration row (legacy exporter) so the integration-cutoff
+ // gate allows the legacy source; this test only exercises field-group
+ // handling, not the cutoff.
+ await createIntegration({ projectId: project.id });
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: project.id },
+ data: { createdAt: INTEGRATION_PRE_CUTOFF },
+ });
await caller.blobStorageIntegration.update({
projectId: project.id,
@@ -536,7 +560,7 @@ describe("Blob Storage Integration tRPC Router", () => {
vi.restoreAllMocks();
});
- it("Cloud + pre-cutoff project + legacy source β†’ allow", async () => {
+ it("Cloud + pre-cutoff project + pre-cutoff legacy row + legacy source β†’ allow", async () => {
const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
try {
@@ -545,6 +569,14 @@ describe("Blob Storage Integration tRPC Router", () => {
where: { id: project.id },
data: { createdAt: PRE_CUTOFF },
});
+ // The project-level gate allows pre-cutoff projects, but the
+ // integration-cutoff gate also applies: a legacy source is only allowed
+ // when an existing pre-cutoff row classifies the exporter as legacy.
+ await createIntegration({ projectId: project.id });
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: project.id },
+ data: { createdAt: INTEGRATION_PRE_CUTOFF },
+ });
await expect(
caller.blobStorageIntegration.update({
projectId: project.id,
@@ -728,4 +760,112 @@ describe("Blob Storage Integration tRPC Router", () => {
).resolves.not.toThrow();
});
});
+
+ describe("legacy blob exporter (integration createdAt) cutoff gate", () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ // All cases use a pre-cutoff project so the project-level delegate gate
+ // allows and the integration-level cutoff is isolated.
+
+ it("(a) Cloud + pre-cutoff project + no row + legacy β†’ BAD_REQUEST", async () => {
+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
+ try {
+ 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" as const,
+ exportFieldGroups: ["core"],
+ }),
+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });
+ } finally {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ }
+ });
+
+ it("(b) Cloud + pre-cutoff project + row (createdAt < CUTOFF) + legacy β†’ succeeds", async () => {
+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
+ try {
+ const { caller, project } = await prepare();
+ await prisma.project.update({
+ where: { id: project.id },
+ data: { createdAt: PRE_CUTOFF },
+ });
+ await createIntegration({ projectId: project.id });
+ // Backdate the row to before the integration cutoff (legacy exporter).
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: project.id },
+ data: { createdAt: INTEGRATION_PRE_CUTOFF },
+ });
+ await expect(
+ caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...baseConfig,
+ exportSource: "TRACES_OBSERVATIONS" as const,
+ exportFieldGroups: ["core"],
+ }),
+ ).resolves.not.toThrow();
+ } finally {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ }
+ });
+
+ it("(c) Cloud + pre-cutoff project + no row + EVENTS β†’ succeeds", async () => {
+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
+ try {
+ 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,
+ }),
+ ).resolves.not.toThrow();
+ } finally {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ }
+ });
+
+ it("(d) Cloud + pre-cutoff project + row (createdAt >= CUTOFF, reset-recreated) + legacy β†’ BAD_REQUEST", async () => {
+ const originalRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "us";
+ try {
+ const { caller, project } = await prepare();
+ await prisma.project.update({
+ where: { id: project.id },
+ data: { createdAt: PRE_CUTOFF },
+ });
+ await createIntegration({ projectId: project.id });
+ // Post-date the row to on/after the integration cutoff (not legacy).
+ await prisma.blobStorageIntegration.update({
+ where: { projectId: project.id },
+ data: { createdAt: INTEGRATION_POST_CUTOFF },
+ });
+ await expect(
+ caller.blobStorageIntegration.update({
+ projectId: project.id,
+ ...baseConfig,
+ exportSource: "TRACES_OBSERVATIONS" as const,
+ exportFieldGroups: ["core"],
+ }),
+ ).rejects.toMatchObject({ code: "BAD_REQUEST" });
+ } finally {
+ (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalRegion;
+ }
+ });
+ });
});
diff --git a/web/src/__tests__/server/unit/assertLegacyBlobExportSourceAllowedForUpsert.servertest.ts b/web/src/__tests__/server/unit/assertLegacyBlobExportSourceAllowedForUpsert.servertest.ts
new file mode 100644
index 0000000000..916af64b36
--- /dev/null
+++ b/web/src/__tests__/server/unit/assertLegacyBlobExportSourceAllowedForUpsert.servertest.ts
@@ -0,0 +1,112 @@
+import { describe, it, expect } from "vitest";
+import { assertLegacyBlobExportSourceAllowedForUpsert } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert";
+import {
+ LEGACY_BLOB_EXPORT_CUTOFF,
+ LEGACY_BLOB_EXPORTER_CUTOFF,
+} from "@langfuse/shared";
+
+const MS_PER_DAY = 24 * 60 * 60 * 1000;
+
+// Project-level cutoff (post-cutoff Cloud projects are forced to EVENTS).
+const PROJECT_PRE_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORT_CUTOFF.getTime() - MS_PER_DAY,
+);
+const PROJECT_POST_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORT_CUTOFF.getTime() + MS_PER_DAY,
+);
+
+// Integration-level cutoff (rows created on/after this cannot keep legacy sources).
+const INTEGRATION_PRE_CUTOFF = new Date(
+ LEGACY_BLOB_EXPORTER_CUTOFF.getTime() - MS_PER_DAY,
+);
+const INTEGRATION_AT_CUTOFF = LEGACY_BLOB_EXPORTER_CUTOFF;
+
+describe("assertLegacyBlobExportSourceAllowedForUpsert", () => {
+ it("Cloud + pre-cutoff project + no row + legacy β†’ throws", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_PRE_CUTOFF },
+ existingIntegration: null,
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: true,
+ }),
+ ).toThrow();
+ });
+
+ it("Cloud + pre-cutoff project + row (createdAt < CUTOFF) + legacy β†’ allows", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_PRE_CUTOFF },
+ existingIntegration: { createdAt: INTEGRATION_PRE_CUTOFF },
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: true,
+ }),
+ ).not.toThrow();
+ });
+
+ it("Cloud + post-cutoff project + no row + legacy β†’ throws (delegate)", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_POST_CUTOFF },
+ existingIntegration: null,
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: true,
+ }),
+ ).toThrow();
+ });
+
+ it("Cloud + post-cutoff project + row (createdAt < CUTOFF) + legacy β†’ throws (delegate wins)", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_POST_CUTOFF },
+ existingIntegration: { createdAt: INTEGRATION_PRE_CUTOFF },
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: true,
+ }),
+ ).toThrow();
+ });
+
+ it("Cloud + any + EVENTS β†’ allows", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_POST_CUTOFF },
+ existingIntegration: null,
+ nextInternalExportSource: "EVENTS",
+ isCloud: true,
+ }),
+ ).not.toThrow();
+ });
+
+ it("self-hosted + post-cutoff project + no row + legacy β†’ allows (short-circuit)", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_POST_CUTOFF },
+ existingIntegration: null,
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: false,
+ }),
+ ).not.toThrow();
+ });
+
+ it("Cloud + pre-cutoff project + no row + TRACES_OBSERVATIONS_EVENTS β†’ throws", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_PRE_CUTOFF },
+ existingIntegration: null,
+ nextInternalExportSource: "TRACES_OBSERVATIONS_EVENTS",
+ isCloud: true,
+ }),
+ ).toThrow();
+ });
+
+ it("Cloud + pre-cutoff project + row (createdAt >= CUTOFF, reset-recreated) + legacy β†’ throws", () => {
+ expect(() =>
+ assertLegacyBlobExportSourceAllowedForUpsert({
+ project: { createdAt: PROJECT_PRE_CUTOFF },
+ existingIntegration: { createdAt: INTEGRATION_AT_CUTOFF },
+ nextInternalExportSource: "TRACES_OBSERVATIONS",
+ isCloud: true,
+ }),
+ ).toThrow();
+ });
+});
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 390de1fb8c..fc32df8712 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -466,6 +466,7 @@ export const env = createEnv({
.enum(["US", "EU", "STAGING", "DEV", "HIPAA", "JP"])
.optional(),
NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF: z.iso.datetime().optional(),
+ NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF: z.iso.datetime().optional(),
NEXT_PUBLIC_DEMO_PROJECT_ID: z.string().optional(),
NEXT_PUBLIC_DEMO_ORG_ID: z.string().optional(),
NEXT_PUBLIC_SIGN_UP_DISABLED: z.enum(["true", "false"]).default("false"),
@@ -499,6 +500,8 @@ export const env = createEnv({
process.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,
NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF:
process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORT_CUTOFF,
+ NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF:
+ process.env.NEXT_PUBLIC_LANGFUSE_BLOB_EXPORTER_CUTOFF,
NEXT_PUBLIC_SIGN_UP_DISABLED: process.env.NEXT_PUBLIC_SIGN_UP_DISABLED,
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:
process.env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES,
diff --git a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
index 4594e35665..88a50325f5 100644
--- a/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
+++ b/web/src/features/blobstorage-integration/blobstorage-integration-router.ts
@@ -12,7 +12,7 @@ import {
validateExportFieldGroups,
} from "@/src/features/blobstorage-integration/validation";
import { upsertBlobStorageIntegration } from "@/src/features/blobstorage-integration/service";
-import { assertLegacyBlobExportSourceAllowed } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowed";
+import { assertLegacyBlobExportSourceAllowedForUpsert } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert";
import { assertEnrichedBlobExportSourceAllowed } from "@/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed";
import { TRPCError } from "@trpc/server";
import { env } from "@/src/env.mjs";
@@ -94,12 +94,19 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
if (input.exportSource) {
const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);
- const project = await ctx.prisma.project.findUniqueOrThrow({
- where: { id: input.projectId },
- select: { createdAt: true },
- });
- assertLegacyBlobExportSourceAllowed({
+ const [project, existingIntegration] = await Promise.all([
+ ctx.prisma.project.findUniqueOrThrow({
+ where: { id: input.projectId },
+ select: { createdAt: true },
+ }),
+ ctx.prisma.blobStorageIntegration.findUnique({
+ where: { projectId: input.projectId },
+ select: { createdAt: true },
+ }),
+ ]);
+ assertLegacyBlobExportSourceAllowedForUpsert({
project,
+ existingIntegration,
nextInternalExportSource: input.exportSource,
isCloud,
});
@@ -123,6 +130,10 @@ export const blobStorageIntegrationRouter = createTRPCRouter({
return await upsertBlobStorageIntegration({
prisma: ctx.prisma,
projectId,
+ // In-transaction backstop closing the TOCTOU window: if a concurrent
+ // DELETE flips this upsert to the CREATE branch, refuse a legacy
+ // source so a new (post-cutoff) Cloud row can never be born legacy.
+ refuseLegacyOnCreate: Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION),
data: {
type: rest.type,
bucketName: rest.bucketName,
diff --git a/web/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert.ts b/web/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert.ts
new file mode 100644
index 0000000000..9cb72de63c
--- /dev/null
+++ b/web/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert.ts
@@ -0,0 +1,59 @@
+import {
+ InvalidRequestError,
+ isLegacyBlobExporter,
+ LEGACY_BLOB_EXPORT_SOURCES,
+ LEGACY_BLOB_EXPORTER_CUTOFF,
+} from "@langfuse/shared";
+import { type AnalyticsIntegrationExportSource } from "@langfuse/shared/src/db";
+import { assertLegacyBlobExportSourceAllowed } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowed";
+
+/**
+ * Write-time gate for blob storage upserts, shared by the tRPC and REST paths.
+ * Composes the project-level post-cutoff gate
+ * (`assertLegacyBlobExportSourceAllowed`) with the integration-level cutoff: a
+ * row may only keep using a legacy export source if its own `createdAt`
+ * predates `LEGACY_BLOB_EXPORTER_CUTOFF`.
+ *
+ * `existingIntegration` is `null` for a brand-new integration, which is treated
+ * as non-legacy (new-customer rules) by `isLegacyBlobExporter`.
+ *
+ * Keyed on `isCloud` directly, not on enriched-export availability: self-hosted
+ * stays exempt even with the V4 preview enabled (see blob-export-gate.ts).
+ */
+export function assertLegacyBlobExportSourceAllowedForUpsert({
+ project,
+ existingIntegration,
+ nextInternalExportSource,
+ isCloud,
+}: {
+ project: { createdAt: Date };
+ existingIntegration: { createdAt: Date } | null;
+ nextInternalExportSource: AnalyticsIntegrationExportSource;
+ isCloud: boolean;
+}): void {
+ // Project-level post-cutoff gate first (shared with REST). Throws on a
+ // post-cutoff Cloud project + legacy source regardless of the row's age.
+ assertLegacyBlobExportSourceAllowed({
+ project,
+ nextInternalExportSource,
+ isCloud,
+ });
+
+ if (
+ !(LEGACY_BLOB_EXPORT_SOURCES as ReadonlyArray<string>).includes(
+ nextInternalExportSource,
+ )
+ )
+ return; // OBSERVATIONS_V2 (internal: EVENTS) is always allowed.
+
+ if (isLegacyBlobExporter(existingIntegration?.createdAt ?? null, isCloud))
+ return;
+
+ // Distinct message from the project-level gate so the two rejection paths can
+ // be counted separately in logs. Customer-facing via the public REST PUT
+ // (the UI prevents this state in the form flow). The date is read from the
+ // constant so a cutoff override stays accurate.
+ throw new InvalidRequestError(
+ `Legacy export sources are not available for blob storage integrations created on or after ${LEGACY_BLOB_EXPORTER_CUTOFF.toISOString()} on Cloud. Use 'OBSERVATIONS_V2' instead.`,
+ );
+}
diff --git a/web/src/features/blobstorage-integration/service.ts b/web/src/features/blobstorage-integration/service.ts
index 412d846de9..6d98f6ae4f 100644
--- a/web/src/features/blobstorage-integration/service.ts
+++ b/web/src/features/blobstorage-integration/service.ts
@@ -4,6 +4,9 @@ import {
BlobStorageIntegrationType,
InvalidRequestError,
AnalyticsIntegrationExportSource,
+ LEGACY_BLOB_EXPORT_SOURCES,
+ LEGACY_BLOB_EXPORTER_CUTOFF,
+ isLegacyBlobExporter,
type BlobStorageIntegrationFileType,
type ObservationFieldGroupFull,
} from "@langfuse/shared";
@@ -58,6 +61,12 @@ export async function upsertBlobStorageIntegration(params: {
// Evaluated inside the transaction so the row-state check and the INSERT are
// atomic β€” no TOCTOU window.
forceEventsOnCreate?: boolean;
+ // When true and no existing row is found inside the transaction, the CREATE
+ // branch refuses a legacy export source (throws). Evaluated in-transaction so
+ // a concurrent DELETE between the router's pre-flight read and this upsert
+ // cannot slip a new post-cutoff row in with a legacy source. Symmetric with
+ // forceEventsOnCreate; set by both the tRPC and REST paths on Cloud.
+ refuseLegacyOnCreate?: boolean;
}) {
const { prisma, projectId, data } = params;
@@ -141,7 +150,7 @@ export async function upsertBlobStorageIntegration(params: {
? AnalyticsIntegrationExportSource.EVENTS
: undefined);
- return tx.blobStorageIntegration.upsert({
+ const result = await tx.blobStorageIntegration.upsert({
where: { projectId },
create: {
...writeData,
@@ -160,5 +169,27 @@ export async function upsertBlobStorageIntegration(params: {
...(modeChanged ? { lastSyncAt: null, nextSyncAt: null } : {}),
},
});
+
+ // Race-free integration-cutoff backstop. The pre-flight `existing` snapshot
+ // (and the router's pre-flight gate) are racy under READ COMMITTED: a
+ // concurrent DELETE can flip this upsert to a CREATE after those reads.
+ // Validate the *persisted* row instead β€” its `createdAt` reflects the actual
+ // CREATE/UPDATE outcome (CREATE β†’ now(); UPDATE β†’ preserved). If the row
+ // that now exists is a brand-new post-cutoff Cloud exporter carrying a legacy
+ // source, throw to roll back. UPDATEs of pre-cutoff rows keep their
+ // original createdAt and are unaffected.
+ if (
+ params.refuseLegacyOnCreate &&
+ !isLegacyBlobExporter(result.createdAt, !isSelfHosted) &&
+ (LEGACY_BLOB_EXPORT_SOURCES as ReadonlyArray<string>).includes(
+ result.exportSource,
+ )
+ ) {
+ throw new InvalidRequestError(
+ `Legacy export sources are not available for blob storage integrations created on or after ${LEGACY_BLOB_EXPORTER_CUTOFF.toISOString()} on Cloud. Use 'OBSERVATIONS_V2' instead.`,
+ );
+ }
+
+ return result;
});
}
diff --git a/web/src/pages/api/public/integrations/blob-storage/index.ts b/web/src/pages/api/public/integrations/blob-storage/index.ts
index b4a7ba4e43..0ef0c0e35c 100644
--- a/web/src/pages/api/public/integrations/blob-storage/index.ts
+++ b/web/src/pages/api/public/integrations/blob-storage/index.ts
@@ -15,11 +15,10 @@ import {
LangfuseNotFoundError,
UnauthorizedError,
ForbiddenError,
- isLegacyBlobExportAllowed,
isEnrichedBlobExportAvailable,
} from "@langfuse/shared";
import { upsertBlobStorageIntegration } from "@/src/features/blobstorage-integration/service";
-import { assertLegacyBlobExportSourceAllowed } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowed";
+import { assertLegacyBlobExportSourceAllowedForUpsert } from "@/src/features/blobstorage-integration/server/assertLegacyBlobExportSourceAllowedForUpsert";
import { assertEnrichedBlobExportSourceAllowed } from "@/src/features/blobstorage-integration/server/assertEnrichedBlobExportSourceAllowed";
import { auditLog } from "@/src/features/audit-logs/auditLog";
import { env } from "@/src/env.mjs";
@@ -168,27 +167,28 @@ async function handleUpsertBlobStorageIntegration(
? toInternalExportSource(validatedData.exportSource)
: undefined;
+ // Single conditional read serving both write-time gates: the legacy upsert
+ // gate needs the row's createdAt when exportSource is provided; the enriched
+ // gate needs the persisted exportSource when it is omitted (partial PUT) and
+ // enriched export is unavailable, so a stale enriched value is rejected.
+ const existingIntegration =
+ internalExportSource !== undefined ||
+ !isEnrichedBlobExportAvailable(isCloud, isV4PreviewEnabled)
+ ? await prisma.blobStorageIntegration.findUnique({
+ where: { projectId: validatedData.projectId },
+ select: { createdAt: true, exportSource: true },
+ })
+ : null;
+
if (internalExportSource) {
- assertLegacyBlobExportSourceAllowed({
+ assertLegacyBlobExportSourceAllowedForUpsert({
project,
+ existingIntegration,
nextInternalExportSource: internalExportSource,
isCloud,
});
}
- // Partial PUTs that omit exportSource preserve the persisted value, so the
- // enriched gate must consider the existing row too β€” otherwise a stale
- // enriched source left behind by a V4-preview flag rollback keeps driving
- // the worker against unpopulated tables. The extra read only happens when
- // the gate could actually reject (enriched export unavailable).
- const existingIntegration =
- internalExportSource === undefined &&
- !isEnrichedBlobExportAvailable(isCloud, isV4PreviewEnabled)
- ? await prisma.blobStorageIntegration.findUnique({
- where: { projectId: validatedData.projectId },
- select: { exportSource: true },
- })
- : null;
assertEnrichedBlobExportSourceAllowed({
nextInternalExportSource: internalExportSource,
existingExportSource: existingIntegration?.exportSource,
@@ -207,12 +207,14 @@ async function handleUpsertBlobStorageIntegration(
const integration = await upsertBlobStorageIntegration({
prisma,
projectId: validatedData.projectId,
- // When exportSource is absent and the project is post-cutoff Cloud, have
- // the service substitute EVENTS on CREATE inside its own transaction β€”
- // eliminating the TOCTOU window that a pre-flight findUnique would create.
- forceEventsOnCreate:
- validatedData.exportSource == null &&
- !isLegacyBlobExportAllowed(project.createdAt, isCloud),
+ // New Cloud rows default to EVENTS when exportSource is omitted: a
+ // brand-new row is post-cutoff, so the legacy column default would trip
+ // refuseLegacyOnCreate and fail a partial PUT that never mentioned
+ // exportSource. Substituted in-transaction to avoid a TOCTOU window.
+ forceEventsOnCreate: validatedData.exportSource == null && isCloud,
+ // In-transaction backstop: a concurrent DELETE can flip this upsert to
+ // CREATE; never let a new Cloud row be born with a legacy source.
+ refuseLegacyOnCreate: isCloud,
data: {
type: validatedData.type,
bucketName: validatedData.bucketName,
diff --git a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
index 978510f6cc..019e9fb8bb 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/blobstorage.tsx
@@ -56,6 +56,7 @@ import {
OBSERVATION_FIELD_GROUPS_FULL,
type ObservationFieldGroupFull,
isLegacyBlobExportAllowed,
+ isLegacyBlobExporter,
} from "@langfuse/shared";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useQueryProject } from "@/src/features/projects/hooks";
@@ -255,7 +256,21 @@ const BlobStorageIntegrationSettingsForm = ({
project?.createdAt != null &&
!isLegacyBlobExportAllowed(new Date(project.createdAt), isLangfuseCloud);
const eventsExportAvailable = isEnrichedExportAvailable;
- const showExportSourceField = eventsExportAvailable && !isPostCutoffCloud;
+ // Integration-level cutoff (Cloud only): an existing row created before
+ // LEGACY_BLOB_EXPORTER_CUTOFF stays legacy (picker visible); a new row (no
+ // state yet) or a post-cutoff row is not legacy (picker hidden, pinned to
+ // EVENTS). Stable across revisits because the row's createdAt is immutable.
+ const isLegacyExporter = isLegacyBlobExporter(
+ state?.createdAt ? new Date(state.createdAt) : null,
+ isLangfuseCloud,
+ );
+ const forceEventsExport =
+ isPostCutoffCloud || (eventsExportAvailable && !isLegacyExporter);
+ // The picker only exists where the enriched events export is available
+ // (Cloud, or self-hosted with the V4 preview opt-in β€” server-computed flag).
+ // Where it isn't, the picker stays hidden and the form defaults to
+ // TRACES_OBSERVATIONS, since EVENTS is not provisioned there.
+ const showExportSourceField = eventsExportAvailable && !forceEventsExport;
const blobStorageForm = useForm({
resolver: zodResolver(blobStorageIntegrationFormSchema),
@@ -277,7 +292,7 @@ const BlobStorageIntegrationSettingsForm = ({
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
exportStartDate: state?.exportStartDate || null,
- exportSource: isPostCutoffCloud
+ exportSource: forceEventsExport
? AnalyticsIntegrationExportSource.EVENTS
: (() => {
const persisted = state?.exportSource;
@@ -321,7 +336,7 @@ const BlobStorageIntegrationSettingsForm = ({
fileType: state?.fileType || BlobStorageIntegrationFileType.JSONL,
exportMode: state?.exportMode || BlobStorageExportMode.FULL_HISTORY,
exportStartDate: state?.exportStartDate || null,
- exportSource: isPostCutoffCloud
+ exportSource: forceEventsExport
? AnalyticsIntegrationExportSource.EVENTS
: (() => {
const persisted = state?.exportSource;