Skip to content

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

feat(blobstorage): write run-completion manifest per export run (LFE-10843) (#14995)

Niklas Semmlerd8e063956d04
diff --git a/worker/src/__tests__/blobExportManifest.unit.test.ts b/worker/src/__tests__/blobExportManifest.unit.test.ts
new file mode 100644
index 0000000000..0e39018e0c
--- /dev/null
+++ b/worker/src/__tests__/blobExportManifest.unit.test.ts
@@ -0,0 +1,92 @@
+import { describe, expect, it } from "vitest";
+import {
+ BLOB_EXPORT_MANIFEST_VERSION,
+ buildBlobExportManifest,
+ buildBlobExportManifestKey,
+ formatBlobExportTimestamp,
+ type BlobExportManifestFile,
+} from "../features/blobstorage/manifest";
+
+const file = (
+ overrides: Partial<BlobExportManifestFile> = {},
+): BlobExportManifestFile => ({
+ key: "proj/traces/2026-07-10T10-00-00.jsonl",
+ table: "traces",
+ fileType: "JSONL",
+ format: "jsonl-raw",
+ compressed: false,
+ contentType: "application/x-ndjson; charset=utf-8",
+ sizeBytes: 42,
+ rowCount: 3,
+ ...overrides,
+});
+
+describe("blob export manifest builders (LFE-10843)", () => {
+ it("strips colons from the timestamp stem and truncates to seconds", () => {
+ expect(
+ formatBlobExportTimestamp(new Date("2026-07-10T10:20:30.123Z")),
+ ).toBe("2026-07-10T10-20-30");
+ });
+
+ it("builds the manifest key under the project's manifests/ prefix", () => {
+ expect(
+ buildBlobExportManifestKey({
+ prefix: "team/",
+ projectId: "proj",
+ maxTimestamp: new Date("2026-07-10T10:20:30Z"),
+ }),
+ ).toBe("team/proj/manifests/2026-07-10T10-20-30.json");
+ });
+
+ it("treats an absent prefix as empty", () => {
+ expect(
+ buildBlobExportManifestKey({
+ projectId: "proj",
+ maxTimestamp: new Date("2026-07-10T10:20:30Z"),
+ }),
+ ).toBe("proj/manifests/2026-07-10T10-20-30.json");
+ });
+
+ it("assembles the manifest payload with version, window, and distinct tables", () => {
+ const manifest = buildBlobExportManifest({
+ projectId: "proj",
+ exportSource: "TRACES_OBSERVATIONS",
+ minTimestamp: new Date("2026-07-10T09:00:00Z"),
+ maxTimestamp: new Date("2026-07-10T10:00:00Z"),
+ createdAt: new Date("2026-07-10T10:00:05Z"),
+ files: [
+ file({ table: "scores", key: "proj/scores/x.jsonl" }),
+ file({ table: "traces", key: "proj/traces/x.jsonl" }),
+ file({ table: "observations", key: "proj/observations/x.jsonl" }),
+ ],
+ });
+
+ expect(manifest.version).toBe(BLOB_EXPORT_MANIFEST_VERSION);
+ expect(manifest.projectId).toBe("proj");
+ expect(manifest.exportSource).toBe("TRACES_OBSERVATIONS");
+ expect(manifest.window).toEqual({
+ minTimestamp: "2026-07-10T09:00:00.000Z",
+ maxTimestamp: "2026-07-10T10:00:00.000Z",
+ });
+ expect(manifest.maxTimestamp).toBe(manifest.window.maxTimestamp);
+ expect(manifest.createdAt).toBe("2026-07-10T10:00:05.000Z");
+ expect(manifest.tables).toEqual(["scores", "traces", "observations"]);
+ expect(manifest.files).toHaveLength(3);
+ expect(JSON.parse(JSON.stringify(manifest))).toEqual(manifest);
+ });
+
+ it("deduplicates tables while preserving first-seen order", () => {
+ const manifest = buildBlobExportManifest({
+ projectId: "proj",
+ exportSource: "EVENTS",
+ minTimestamp: new Date("2026-07-10T09:00:00Z"),
+ maxTimestamp: new Date("2026-07-10T10:00:00Z"),
+ createdAt: new Date("2026-07-10T10:00:05Z"),
+ files: [
+ file({ table: "observations_v2" }),
+ file({ table: "observations_v2", key: "proj/observations_v2/y.jsonl" }),
+ ],
+ });
+ expect(manifest.tables).toEqual(["observations_v2"]);
+ });
+});
diff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
index b8f37ff9b8..bbc59e41ce 100644
--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts
@@ -636,11 +636,30 @@ describe("BlobStorageIntegrationProcessingJob", () => {
}
const files = await s3StorageService.listFiles(s3Prefix);
- const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const projectFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
// Should have 4 files (traces, observations, scores, events)
expect(projectFiles).toHaveLength(4);
+ const manifestFile = files.find((f) => f.file.includes("/manifests/"));
+ expect(manifestFile).toBeDefined();
+ const manifest = JSON.parse(
+ await s3StorageService.download(manifestFile!.file),
+ );
+ expect(manifest.version).toBe(1);
+ expect(manifest.projectId).toBe(projectId);
+ expect(manifest.exportSource).toBe("TRACES_OBSERVATIONS_EVENTS");
+ expect(new Set(manifest.tables)).toEqual(
+ new Set(["traces", "observations", "scores", "observations_v2"]),
+ );
+ expect(manifest.files).toHaveLength(4);
+ expect(
+ new Set(manifest.files.map((f: { key: string }) => f.key)),
+ ).toEqual(new Set(projectFiles.map((f) => f.file)));
+ expect(manifest.window.maxTimestamp).toBe(manifest.maxTimestamp);
+
// Check file paths follow the expected pattern
const traceFile = projectFiles.find((f) => f.file.includes("/traces/"));
const observationFile = projectFiles.find((f) =>
@@ -1046,7 +1065,10 @@ describe("BlobStorageIntegrationProcessingJob", () => {
// Get files for this file type
const files = await s3StorageService.listFiles(prefix);
const projectFiles = files.filter(
- (f) => f.file.includes(projectId) && f.file.includes(fileTypePrefix),
+ (f) =>
+ f.file.includes(projectId) &&
+ f.file.includes(fileTypePrefix) &&
+ !f.file.includes("/manifests/"),
);
// Should have 4 files (traces, observations, scores, events)
@@ -1643,7 +1665,9 @@ describe("BlobStorageIntegrationProcessingJob", () => {
} as Job);
const files = await s3StorageService.listFiles(s3Prefix);
- const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const projectFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
expect(projectFiles.length).toBeGreaterThan(0);
expect(projectFiles.every((f) => f.file.endsWith(".csv.gz"))).toBe(
@@ -1695,7 +1719,9 @@ describe("BlobStorageIntegrationProcessingJob", () => {
} as Job);
const files = await s3StorageService.listFiles(s3Prefix);
- const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const projectFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
expect(projectFiles.length).toBeGreaterThan(0);
expect(
@@ -1757,7 +1783,9 @@ describe("BlobStorageIntegrationProcessingJob", () => {
} as Job);
const files = await s3StorageService.listFiles(s3Prefix);
- const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const projectFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
expect(projectFiles.length).toBeGreaterThan(0);
expect(projectFiles.every((f) => f.file.endsWith(".jsonl.gz"))).toBe(
@@ -1767,6 +1795,118 @@ describe("BlobStorageIntegrationProcessingJob", () => {
);
});
+ // Uses the non-enriched TRACES_OBSERVATIONS source so it runs on every CI
+ // leg, independent of the V4-preview opt-in.
+ describe("run-completion manifest (LFE-10843)", () => {
+ maybeIt(
+ "writes a manifest listing every file, the window, and per-file format",
+ async () => {
+ const { projectId } = await createOrgProjectAndApiKey();
+ s3Prefix = `${projectId}/`;
+ const now = new Date();
+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);
+ const dataTime = now.getTime() - 40 * 60 * 1000;
+
+ await prisma.blobStorageIntegration.create({
+ data: {
+ projectId,
+ type: BlobStorageIntegrationType.S3,
+ bucketName,
+ prefix: s3Prefix,
+ accessKeyId: minioAccessKeyId,
+ secretAccessKey: encrypt(minioAccessKeySecret),
+ region: region ? region : "auto",
+ endpoint: minioEndpoint,
+ forcePathStyle:
+ env.LANGFUSE_S3_EVENT_UPLOAD_FORCE_PATH_STYLE === "true",
+ enabled: true,
+ exportFrequency: "hourly",
+ exportSource: "TRACES_OBSERVATIONS",
+ fileType: BlobStorageIntegrationFileType.JSONL,
+ compressed: false,
+ lastSyncAt: oneHourAgo,
+ },
+ });
+
+ const traceId = randomUUID();
+ await Promise.all([
+ createTracesCh([
+ createTrace({
+ id: traceId,
+ project_id: projectId,
+ timestamp: dataTime,
+ name: "Manifest Trace",
+ }),
+ ]),
+ createObservationsCh([
+ createObservation({
+ id: randomUUID(),
+ trace_id: traceId,
+ project_id: projectId,
+ start_time: dataTime,
+ end_time: dataTime + 5000,
+ name: "Manifest Observation",
+ }),
+ ]),
+ createScoresCh([
+ createTraceScore({
+ id: randomUUID(),
+ trace_id: traceId,
+ project_id: projectId,
+ timestamp: dataTime,
+ name: "Manifest Score",
+ value: 0.5,
+ }),
+ ]),
+ ]);
+
+ await handleBlobStorageIntegrationProjectJob({
+ data: { payload: { projectId } },
+ } as Job);
+
+ const files = await s3StorageService.listFiles(s3Prefix);
+ const tableFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
+ expect(tableFiles).toHaveLength(3); // scores, traces, observations
+
+ const manifestFile = files.find((f) => f.file.includes("/manifests/"));
+ expect(manifestFile).toBeDefined();
+ expect(manifestFile!.file).toContain(
+ `${s3Prefix}${projectId}/manifests/`,
+ );
+ expect(manifestFile!.file.endsWith(".json")).toBe(true);
+
+ const manifest = JSON.parse(
+ await s3StorageService.download(manifestFile!.file),
+ );
+ expect(manifest.version).toBe(1);
+ expect(manifest.projectId).toBe(projectId);
+ expect(manifest.exportSource).toBe("TRACES_OBSERVATIONS");
+ expect(new Set(manifest.tables)).toEqual(
+ new Set(["scores", "traces", "observations"]),
+ );
+
+ expect(
+ new Set(manifest.files.map((f: { key: string }) => f.key)),
+ ).toEqual(new Set(tableFiles.map((f) => f.file)));
+
+ const tracesEntry = manifest.files.find(
+ (f: { table: string }) => f.table === "traces",
+ );
+ expect(tracesEntry.fileType).toBe("JSONL");
+ expect(tracesEntry.format).toBe("jsonl-raw");
+ expect(tracesEntry.compressed).toBe(false);
+ expect(tracesEntry.rowCount).toBe(1);
+ expect(typeof tracesEntry.sizeBytes).toBe("number");
+
+ expect(typeof manifest.window.minTimestamp).toBe("string");
+ expect(manifest.maxTimestamp).toBe(manifest.window.maxTimestamp);
+ expect(typeof manifest.createdAt).toBe("string");
+ },
+ );
+ });
+
// LFE-10402: raw-passthrough streams ClickHouse JSONEachRow bytes straight to
// gzip → upload, skipping the per-row JS parse/enrich/serialize pipeline. The
// output must be parsed-equal to the standard path minus the dropped price
@@ -2111,7 +2251,9 @@ describe("BlobStorageIntegrationProcessingJob", () => {
} as Job);
const files = await s3StorageService.listFiles(s3Prefix);
- const projectFiles = files.filter((f) => f.file.includes(projectId));
+ const projectFiles = files.filter(
+ (f) => f.file.includes(projectId) && !f.file.includes("/manifests/"),
+ );
// traces, observations, scores, observations_v2 (events).
expect(projectFiles).toHaveLength(4);
@@ -2120,6 +2262,19 @@ describe("BlobStorageIntegrationProcessingJob", () => {
expect(f.file).not.toContain(".gz");
}
+ const manifestFile = files.find((f) => f.file.includes("/manifests/"));
+ expect(manifestFile).toBeDefined();
+ const manifest = JSON.parse(
+ await s3StorageService.download(manifestFile!.file),
+ );
+ expect(manifest.files).toHaveLength(4);
+ for (const f of manifest.files) {
+ expect(f.fileType).toBe("PARQUET");
+ expect(f.format).toBe("parquet");
+ expect(f.compressed).toBe(false);
+ expect(f.rowCount).toBeNull();
+ }
+
// Every object is a valid Parquet file (magic at both ends).
for (const f of projectFiles) {
const content = await s3StorageService.download(f.file);
diff --git a/worker/src/__tests__/blobStorageTuningWiring.unit.test.ts b/worker/src/__tests__/blobStorageTuningWiring.unit.test.ts
index b67b6fbb8b..5b76bacb08 100644
--- a/worker/src/__tests__/blobStorageTuningWiring.unit.test.ts
+++ b/worker/src/__tests__/blobStorageTuningWiring.unit.test.ts
@@ -34,6 +34,8 @@ vi.mock("@langfuse/shared/src/server", async (importOriginal) => {
}
return undefined;
}),
+ // Manifest write; string body, no stream to drain.
+ uploadFile: vi.fn(async () => undefined),
}),
},
getTracesForBlobStorageExport: () => empty(),
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 659baf8996..fc528b3b81 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -68,6 +68,12 @@ import { randomUUID } from "crypto";
import { SpanKind } from "@opentelemetry/api";
import { env, v4AllowPreviewOptIn } from "../../env";
import { recordExportVolume } from "../../services/exportVolumeMetric";
+import {
+ buildBlobExportManifest,
+ buildBlobExportManifestKey,
+ formatBlobExportTimestamp,
+ type BlobExportManifestFile,
+} from "./manifest";
export const BlobExportFormat = {
JSON_RAW: "json-raw",
@@ -312,18 +318,42 @@ const createRawJsonlNewlineTransform = (): Transform =>
},
});
-const processBlobStorageExport = async (config: {
- projectId: string;
- minTimestamp: Date;
- maxTimestamp: Date;
+// KMS SSE is not supported for this integration.
+type BlobStorageConnectionConfig = {
bucketName: string;
endpoint: string | null;
region: string;
accessKeyId: string | undefined;
secretAccessKey: string | undefined;
- prefix?: string;
forcePathStyle?: boolean;
type: BlobStorageIntegrationType;
+};
+
+const createBlobStorageService = (
+ config: BlobStorageConnectionConfig,
+): StorageService =>
+ StorageServiceFactory.getInstance({
+ accessKeyId: config.accessKeyId,
+ secretAccessKey: config.secretAccessKey,
+ bucketName: config.bucketName,
+ endpoint: config.endpoint ?? undefined,
+ region: config.region,
+ forcePathStyle: config.forcePathStyle ?? false,
+ awsSse: undefined,
+ awsSseKmsKeyId: undefined,
+ useAzureBlob: config.type === BlobStorageIntegrationType.AZURE_BLOB_STORAGE,
+ useGoogleCloudStorage: false, // Not supported in blob storage integration
+ useOCIObjectStorage: false, // Not supported in blob storage integration
+ connectionValidation: blobStorageEndpointConnectionValidationOptions(),
+ });
+
+const processBlobStorageExport = async (config: {
+ projectId: string;
+ minTimestamp: Date;
+ maxTimestamp: Date;
+ storageService: StorageService;
+ prefix?: string;
+ type: BlobStorageIntegrationType;
table: "traces" | "observations" | "scores" | "observations_v2"; // observations_v2 is the events table
fileType: BlobStorageIntegrationFileType;
compressed: boolean;
@@ -345,24 +375,9 @@ const processBlobStorageExport = async (config: {
`[BLOB INTEGRATION] Processing ${config.table} export for project ${config.projectId}`,
);
- // Initialize the storage service
- // KMS SSE is not supported for this integration.
- const storageService: StorageService = StorageServiceFactory.getInstance({
- accessKeyId: config.accessKeyId,
- secretAccessKey: config.secretAccessKey,
- bucketName: config.bucketName,
- endpoint: config.endpoint ?? undefined,
- region: config.region,
- forcePathStyle: config.forcePathStyle ?? false,
- awsSse: undefined,
- awsSseKmsKeyId: undefined,
- useAzureBlob: config.type === BlobStorageIntegrationType.AZURE_BLOB_STORAGE,
- useGoogleCloudStorage: false, // Not supported in blob storage integration
- useOCIObjectStorage: false, // Not supported in blob storage integration
- connectionValidation: blobStorageEndpointConnectionValidationOptions(),
- });
+ const storageService = config.storageService;
- await instrumentAsync(
+ return await instrumentAsync(
{
name: `blob-export-table`,
spanKind: SpanKind.INTERNAL,
@@ -460,10 +475,7 @@ const processBlobStorageExport = async (config: {
? "passthrough"
: "standard";
- const timestamp = config.maxTimestamp
- .toISOString()
- .replace(/:/g, "-")
- .substring(0, 19);
+ const timestamp = formatBlobExportTimestamp(config.maxTimestamp);
// Parquet: fixed `.parquet` extension (no `.gz`) and Parquet content type.
const extension = parquetEligible
? "parquet"
@@ -778,6 +790,23 @@ const processBlobStorageExport = async (config: {
const exportFormat = parquetEligible
? BlobExportFormat.PARQUET
: resolveBlobExportFormat(config.fileType, config.compressed);
+
+ // rowCount null on parquet: sourceStats.rows stays 0 for the binary
+ // stream and would misreport as an empty file.
+ const manifestFile: BlobExportManifestFile = {
+ key: filePath,
+ table: config.table,
+ fileType: parquetEligible
+ ? BlobStorageIntegrationFileType.PARQUET
+ : config.fileType,
+ format: exportFormat,
+ compressed: parquetEligible ? false : config.compressed,
+ contentType: uploadContentType,
+ sizeBytes: compressedCounter
+ ? compressedCounter.bytes
+ : serializedCounter.bytes,
+ rowCount: parquetEligible ? null : sourceStats.rows,
+ };
// Unified export-volume metric: the actual uploaded volume per
// source (post-gzip size for compressed formats, raw/parquet size
// otherwise). destination_type (S3 / S3_COMPATIBLE / AZURE_*) splits
@@ -842,6 +871,8 @@ const processBlobStorageExport = async (config: {
? ` gzipLevel=${gzipStats.level} compressedBytes=${compressedCounter.bytes}`
: ""),
);
+
+ return manifestFile;
} finally {
span.setAttribute("blob.rows", sourceStats.rows);
// Same chReadMs / uploadWaitMs derivation as the success path above.
@@ -1026,6 +1057,44 @@ const processBlobStorageExport = async (config: {
);
};
+// Small JSON body, so single-shot uploadFile instead of the buffered multipart
+// path the table streams use.
+const writeBlobExportManifest = async (params: {
+ storageService: StorageService;
+ prefix?: string;
+ projectId: string;
+ exportSource: string;
+ minTimestamp: Date;
+ maxTimestamp: Date;
+ files: BlobExportManifestFile[];
+}): Promise<void> => {
+ const manifest = buildBlobExportManifest({
+ projectId: params.projectId,
+ exportSource: params.exportSource,
+ minTimestamp: params.minTimestamp,
+ maxTimestamp: params.maxTimestamp,
+ createdAt: new Date(),
+ files: params.files,
+ });
+ const key = buildBlobExportManifestKey({
+ prefix: params.prefix,
+ projectId: params.projectId,
+ maxTimestamp: params.maxTimestamp,
+ });
+
+ await params.storageService.uploadFile({
+ fileName: key,
+ fileType: "application/json; charset=utf-8",
+ // Trailing newline for POSIX-friendly shell tooling.
+ data: JSON.stringify(manifest, null, 2) + "\n",
+ });
+
+ logger.info(
+ `[BLOB INTEGRATION] Wrote run manifest for project ${params.projectId}: ` +
+ `key=${key} files=${manifest.files.length} tables=${manifest.tables.join(",")}`,
+ );
+};
+
export const handleBlobStorageIntegrationProjectJob = async (
job: Job<TQueueJobTypes[QueueName.BlobStorageIntegrationProcessingQueue]>,
) => {
@@ -1172,10 +1241,8 @@ export const handleBlobStorageIntegrationProjectJob = async (
);
}
- const executionConfig = {
- projectId,
- minTimestamp,
- maxTimestamp,
+ // One client per run, shared by all table uploads and the manifest write.
+ const storageService = createBlobStorageService({
bucketName: blobStorageIntegration.bucketName,
endpoint: blobStorageIntegration.endpoint,
region: blobStorageIntegration.region || "auto",
@@ -1183,9 +1250,17 @@ export const handleBlobStorageIntegrationProjectJob = async (
secretAccessKey: blobStorageIntegration.secretAccessKey
? decrypt(blobStorageIntegration.secretAccessKey)
: undefined,
- prefix: blobStorageIntegration.prefix || undefined,
forcePathStyle: blobStorageIntegration.forcePathStyle || undefined,
type: blobStorageIntegration.type,
+ });
+
+ const executionConfig = {
+ projectId,
+ minTimestamp,
+ maxTimestamp,
+ storageService,
+ prefix: blobStorageIntegration.prefix || undefined,
+ type: blobStorageIntegration.type,
fileType: blobStorageIntegration.fileType,
compressed: blobStorageIntegration.compressed,
gzipLevel: exportTuning.gzipLevel,
@@ -1228,15 +1303,18 @@ export const handleBlobStorageIntegrationProjectJob = async (
);
}
+ let runFiles: BlobExportManifestFile[];
if (isTraceOnlyProject) {
// Only process traces table for projects in the trace-only list (legacy behavior)
logger.info(
`[BLOB INTEGRATION] Project ${projectId} is configured for trace-only export via env var, skipping observations, scores, and events`,
);
- await processBlobStorageExport({ ...executionConfig, table: "traces" });
+ runFiles = [
+ await processBlobStorageExport({ ...executionConfig, table: "traces" }),
+ ];
} else {
// Process tables based on exportSource setting
- const processPromises: Promise<void>[] = [];
+ const processPromises: Promise<BlobExportManifestFile>[] = [];
// Always include scores
processPromises.push(
@@ -1271,9 +1349,22 @@ export const handleBlobStorageIntegrationProjectJob = async (
);
}
- await Promise.all(processPromises);
+ runFiles = await Promise.all(processPromises);
}
+ // The manifest is the run's commit point: written strictly after every
+ // table upload succeeded. A failure here fails the run, so lastSyncAt does
+ // not advance and the retry idempotently overwrites the table files.
+ await writeBlobExportManifest({
+ storageService,
+ prefix: blobStorageIntegration.prefix || undefined,
+ projectId,
+ exportSource: blobStorageIntegration.exportSource,
+ minTimestamp,
+ maxTimestamp,
+ files: runFiles,
+ });
+
// Determine if we've caught up with present-day data
const caughtUp = maxTimestamp.getTime() >= uncappedMaxTimestamp.getTime();
diff --git a/worker/src/features/blobstorage/manifest.ts b/worker/src/features/blobstorage/manifest.ts
new file mode 100644
index 0000000000..e89e680034
--- /dev/null
+++ b/worker/src/features/blobstorage/manifest.ts
@@ -0,0 +1,71 @@
+// Run-completion manifest for blob storage exports (LFE-10843): written as the
+// last object of a successful run (the run's commit point), listing every file
+// written, the export window, and per-file format.
+
+/** Bump on breaking payload changes; additive fields do not require a bump. */
+export const BLOB_EXPORT_MANIFEST_VERSION = 1;
+
+export type BlobExportManifestFile = {
+ /** Full object key including the integration prefix. */
+ key: string;
+ table: string;
+ fileType: string;
+ format: string;
+ compressed: boolean;
+ contentType: string;
+ /** Post-gzip size for compressed formats. */
+ sizeBytes: number;
+ /** Null when not counted (parquet is a binary stream). */
+ rowCount: number | null;
+};
+
+export type BlobExportManifest = {
+ version: number;
+ projectId: string;
+ exportSource: string;
+ /**
+ * Export window, both bounds inclusive — a row at exactly maxTimestamp also
+ * falls into the next run's window.
+ */
+ window: { minTimestamp: string; maxTimestamp: string };
+ /** Equals window.maxTimestamp; also the manifest key stem. */
+ maxTimestamp: string;
+ createdAt: string;
+ tables: string[];
+ files: BlobExportManifestFile[];
+};
+
+/** Shared with table file names so a run's files and manifest sort together. */
+export const formatBlobExportTimestamp = (date: Date): string =>
+ date.toISOString().replace(/:/g, "-").substring(0, 19);
+
+/** `{prefix}{projectId}/manifests/{maxTimestamp}.json` — prefix-filterable per run. */
+export const buildBlobExportManifestKey = (params: {
+ prefix?: string;
+ projectId: string;
+ maxTimestamp: Date;
+}): string =>
+ `${params.prefix ?? ""}${params.projectId}/manifests/${formatBlobExportTimestamp(
+ params.maxTimestamp,
+ )}.json`;
+
+export const buildBlobExportManifest = (params: {
+ projectId: string;
+ exportSource: string;
+ minTimestamp: Date;
+ maxTimestamp: Date;
+ createdAt: Date;
+ files: BlobExportManifestFile[];
+}): BlobExportManifest => ({
+ version: BLOB_EXPORT_MANIFEST_VERSION,
+ projectId: params.projectId,
+ exportSource: params.exportSource,
+ window: {
+ minTimestamp: params.minTimestamp.toISOString(),
+ maxTimestamp: params.maxTimestamp.toISOString(),
+ },
+ maxTimestamp: params.maxTimestamp.toISOString(),
+ createdAt: params.createdAt.toISOString(),
+ tables: [...new Set(params.files.map((f) => f.table))],
+ files: params.files,
+});