🪢 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
chore: disentangle batch actions from batch exports (#7092)
Steffen Schmitz319b22ae782f
diff --git a/packages/shared/src/features/batchAction/types.ts b/packages/shared/src/features/batchAction/types.tsindex da71a41eaa..304069cff3 100644--- a/packages/shared/src/features/batchAction/types.ts+++ b/packages/shared/src/features/batchAction/types.ts@@ -1,7 +1,7 @@import z from "zod";import { singleFilter } from "../../interfaces/filters";import { orderBy } from "../../interfaces/orderBy";-import { BatchExportTableName } from "../batchExport/types";+import { BatchTableNames } from "../../interfaces/tableNames";/* eslint-disable no-unused-vars */export enum BatchActionType {@@ -29,11 +29,11 @@ export const CreateBatchActionSchema = z.object({actionId: ActionIdSchema,targetId: z.string().optional(),query: BatchActionQuerySchema,- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),});export const GetIsBatchActionInProgressSchema = z.object({projectId: z.string(),actionId: ActionIdSchema,- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),});diff --git a/packages/shared/src/features/batchExport/types.ts b/packages/shared/src/features/batchExport/types.tsindex f21766c367..2dddaf4662 100644--- a/packages/shared/src/features/batchExport/types.ts+++ b/packages/shared/src/features/batchExport/types.ts@@ -4,6 +4,7 @@ import { BatchExport } from "@prisma/client";import { singleFilter } from "../../interfaces/filters";import { orderBy } from "../../interfaces/orderBy";+import { BatchTableNames } from "../../interfaces/tableNames";export enum BatchExportStatus {QUEUED = "QUEUED",@@ -18,13 +19,9 @@ export enum BatchExportFileFormat {JSONL = "JSONL",}-export enum BatchExportTableName {- Scores = "scores",- Sessions = "sessions",- Traces = "traces",- Observations = "observations",- DatasetRunItems = "dataset_run_items",-}+// Use shared BatchTableNames enum for consistency across batch operations+// Keep BatchExportTableName as alias for backward compatibility+export { BatchTableNames as BatchExportTableName };export const exportOptions: Record<BatchExportFileFormat,@@ -44,7 +41,7 @@ export const exportOptions: Record<} as const;export const BatchExportQuerySchema = z.object({- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),filter: z.array(singleFilter).nullable(),orderBy,limit: z.number().optional(),diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex a7ceb1397f..c3f0565d29 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -26,6 +26,7 @@ export * from "./features/evals/utilities";// table actionsexport * from "./features/batchExport/types";export * from "./features/batchAction/types";+export { BatchTableNames } from "./interfaces/tableNames";// annotationexport * from "./features/annotation/types";diff --git a/packages/shared/src/interfaces/tableNames.ts b/packages/shared/src/interfaces/tableNames.tsnew file mode 100644index 0000000000..62076fc1e8--- /dev/null+++ b/packages/shared/src/interfaces/tableNames.ts@@ -0,0 +1,12 @@+/**+ * Shared table names used across batch operations (exports, actions, etc.)+ * This enum provides a centralized definition of database table names+ * to avoid coupling between different batch operation types.+ */+export enum BatchTableNames {+ Scores = "scores",+ Sessions = "sessions",+ Traces = "traces",+ Observations = "observations",+ DatasetRunItems = "dataset_run_items",+}diff --git a/packages/shared/src/server/queues.ts b/packages/shared/src/server/queues.tsindex 8711e65fc2..1218c50eb0 100644--- a/packages/shared/src/server/queues.ts+++ b/packages/shared/src/server/queues.ts@@ -5,7 +5,7 @@ import {BatchActionQuerySchema,BatchActionType,} from "../features/batchAction/types";-import { BatchExportTableName } from "../features/batchExport/types";+import { BatchTableNames } from "../interfaces/tableNames";export const IngestionEvent = z.object({data: z.object({@@ -76,7 +76,7 @@ export const BatchActionProcessingEventSchema = z.discriminatedUnion(actionId: z.literal("score-delete"),projectId: z.string(),query: BatchActionQuerySchema,- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),cutoffCreatedAt: z.date(),targetId: z.string().optional(),type: z.nativeEnum(BatchActionType),@@ -85,7 +85,7 @@ export const BatchActionProcessingEventSchema = z.discriminatedUnion(actionId: z.literal("trace-delete"),projectId: z.string(),query: BatchActionQuerySchema,- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),cutoffCreatedAt: z.date(),targetId: z.string().optional(),type: z.nativeEnum(BatchActionType),@@ -94,7 +94,7 @@ export const BatchActionProcessingEventSchema = z.discriminatedUnion(actionId: z.literal("trace-add-to-annotation-queue"),projectId: z.string(),query: BatchActionQuerySchema,- tableName: z.nativeEnum(BatchExportTableName),+ tableName: z.nativeEnum(BatchTableNames),cutoffCreatedAt: z.date(),targetId: z.string().optional(),type: z.nativeEnum(BatchActionType),diff --git a/worker/src/features/batchAction/handleBatchActionJob.ts b/worker/src/features/batchAction/handleBatchActionJob.tsindex 6e4d07f08c..1d465a4c3a 100644--- a/worker/src/features/batchAction/handleBatchActionJob.ts+++ b/worker/src/features/batchAction/handleBatchActionJob.ts@@ -9,7 +9,7 @@ import {} from "@langfuse/shared/src/server";import {BatchActionType,- BatchExportTableName,+ BatchTableNames,FilterCondition,} from "@langfuse/shared";import {@@ -149,15 +149,15 @@ export const handleBatchActionJob = async (cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,- exportLimit: env.BATCH_ACTION_EXPORT_ROW_LIMIT,+ rowLimit: env.BATCH_ACTION_EXPORT_ROW_LIMIT,}): await getDatabaseReadStream({projectId: projectId,cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,- tableName: tableName as unknown as BatchExportTableName,- exportLimit: env.BATCH_ACTION_EXPORT_ROW_LIMIT,+ tableName: tableName,+ rowLimit: env.BATCH_ACTION_EXPORT_ROW_LIMIT,});// Process stream in database-sized batches@@ -207,15 +207,15 @@ export const handleBatchActionJob = async (cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,- exportLimit: env.LANGFUSE_MAX_HISTORIC_EVAL_CREATION_LIMIT,+ rowLimit: env.LANGFUSE_MAX_HISTORIC_EVAL_CREATION_LIMIT,}) // when reading from clickhouse, we only want to read the necessary identifiers.: await getDatabaseReadStream({projectId: projectId,cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,- tableName: BatchExportTableName.DatasetRunItems,- exportLimit: env.LANGFUSE_MAX_HISTORIC_EVAL_CREATION_LIMIT,+ tableName: BatchTableNames.DatasetRunItems,+ rowLimit: env.LANGFUSE_MAX_HISTORIC_EVAL_CREATION_LIMIT,});const evalCreatorQueue = CreateEvalQueue.getInstance();diff --git a/worker/src/features/database-read-stream/getDatabaseReadStream.ts b/worker/src/features/database-read-stream/getDatabaseReadStream.tsindex 6afa35d8c1..c820a73824 100644--- a/worker/src/features/database-read-stream/getDatabaseReadStream.ts+++ b/worker/src/features/database-read-stream/getDatabaseReadStream.ts@@ -1,5 +1,5 @@import {- BatchExportTableName,+ BatchTableNames,FilterCondition,TimeFilter,BatchExportQueryType,@@ -28,14 +28,14 @@ import Decimal from "decimal.js";import { env } from "../../env";import { BatchExportTracesRow, BatchExportSessionsRow } from "./types";-const tableNameToTimeFilterColumn: Record<BatchExportTableName, string> = {+const tableNameToTimeFilterColumn: Record<BatchTableNames, string> = {scores: "timestamp",sessions: "createdAt",traces: "timestamp",observations: "startTime",dataset_run_items: "createdAt",};-const tableNameToTimeFilterColumnCh: Record<BatchExportTableName, string> = {+const tableNameToTimeFilterColumnCh: Record<BatchTableNames, string> = {scores: "timestamp",sessions: "createdAt",traces: "timestamp",@@ -86,11 +86,11 @@ export const getDatabaseReadStream = async ({filter,orderBy,cutoffCreatedAt,- exportLimit = env.BATCH_EXPORT_ROW_LIMIT,+ rowLimit = env.BATCH_EXPORT_ROW_LIMIT,}: {projectId: string;cutoffCreatedAt: Date;- exportLimit?: number;+ rowLimit?: number;} & BatchExportQueryType): Promise<DatabaseReadStream<unknown>> => {// Set createdAt cutoff to prevent exporting data that was created after the job was queuedconst createdAtCutoffFilter: FilterCondition = {@@ -147,7 +147,7 @@ export const getDatabaseReadStream = async ({}));},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);}@@ -208,7 +208,7 @@ export const getDatabaseReadStream = async ({});},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);case "observations": {let emptyScoreColumns: Record<string, null>;@@ -264,7 +264,7 @@ export const getDatabaseReadStream = async ({return getChunkWithFlattenedScores(chunk, emptyScoreColumns);},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);}case "traces": {@@ -372,7 +372,7 @@ export const getDatabaseReadStream = async ({return getChunkWithFlattenedScores(chunk, emptyScoreColumns);},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);}@@ -422,7 +422,7 @@ export const getDatabaseReadStream = async ({}));},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);}default:@@ -473,9 +473,9 @@ export const getTraceIdentifierStream = async (props: {cutoffCreatedAt: Date;filter: FilterCondition[];orderBy: OrderByState;- exportLimit?: number;+ rowLimit?: number;}): Promise<DatabaseReadStream<Array<TraceIdentifiers>>> => {- const { projectId, cutoffCreatedAt, filter, orderBy, exportLimit } = props;+ const { projectId, cutoffCreatedAt, filter, orderBy, rowLimit } = props;const createdAtCutoffFilter: FilterCondition = {column: "timestamp",@@ -504,6 +504,6 @@ export const getTraceIdentifierStream = async (props: {return identifiers;},env.BATCH_EXPORT_PAGE_SIZE,- exportLimit,+ rowLimit,);};