🪢 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
feat(evals): allow manual batch runs on inactive evaluators (#13824)
Tobias Wochinger291c351c8f32
diff --git a/packages/shared/src/features/evals/evalConfigBlocking.ts b/packages/shared/src/features/evals/evalConfigBlocking.tsindex ed84255ae2..224bc4bddc 100644--- a/packages/shared/src/features/evals/evalConfigBlocking.ts+++ b/packages/shared/src/features/evals/evalConfigBlocking.ts@@ -3,6 +3,7 @@ import {JobConfigState,JobExecutionStatus,} from "@prisma/client";+import { z } from "zod";export const PausedEvaluatorDisplayState = "PAUSED" as const;export type PausedEvaluatorDisplayState = typeof PausedEvaluatorDisplayState;@@ -27,6 +28,9 @@ type BlockStateLike = {blockedAt?: Date | null;};+export const JobConfigExecutionMode = z.enum(["LIVE", "MANUAL"]);+export type JobConfigExecutionMode = z.infer<typeof JobConfigExecutionMode>;+export function isJobConfigBlocked(config: Pick<BlockStateLike, "blockedAt">) {return config.blockedAt != null;}@@ -35,6 +39,18 @@ export function isJobConfigExecutable(config: BlockStateLike) {return config.status === JobConfigState.ACTIVE && !isJobConfigBlocked(config);}+export function isJobConfigExecutableForExecutionMode(+ config: BlockStateLike,+ executionMode?: JobConfigExecutionMode,+) {+ if (executionMode === "MANUAL") {+ // Manual batch runs bypass only the live-traffic toggle, not blocked configs.+ return !isJobConfigBlocked(config);+ }++ return isJobConfigExecutable(config);+}+type EvaluatorBlockMetadata = {message: string;shortLabel: string;diff --git a/packages/shared/src/server/queues.ts b/packages/shared/src/server/queues.tsindex 75c004bdce..19348ea4ab 100644--- a/packages/shared/src/server/queues.ts+++ b/packages/shared/src/server/queues.ts@@ -10,6 +10,7 @@ import { EventActionSchema } from "../domain";import { PromptDomainSchema } from "../domain/prompts";import { ObservationAddToDatasetConfigSchema } from "../features/batchAction/addToDatasetTypes";import { EvalTargetObjectSchema } from "../features/evals/types";+import { JobConfigExecutionMode } from "../features/evals/evalConfigBlocking";export const IngestionEvent = z.object({data: z.object({@@ -104,6 +105,7 @@ export const LLMAsJudgeExecutionEventSchema = z.object({projectId: z.string(),jobExecutionId: z.string(),observationS3Path: z.string(),+ executionMode: JobConfigExecutionMode.optional(),});export const PostHogIntegrationProcessingEventSchema = z.object({projectId: z.string(),diff --git a/worker/src/features/batchAction/processBatchedObservationEval.test.ts b/worker/src/features/batchAction/processBatchedObservationEval.test.tsindex d66824346d..dbb3aac6f8 100644--- a/worker/src/features/batchAction/processBatchedObservationEval.test.ts+++ b/worker/src/features/batchAction/processBatchedObservationEval.test.ts@@ -78,6 +78,7 @@ describe("processBatchedObservationEval", () => {expect(scheduleObservationEvals).toHaveBeenCalledWith(expect.objectContaining({configs: evaluators,+ executionMode: "MANUAL",}),);expect(diff --git a/worker/src/features/batchAction/processBatchedObservationEval.ts b/worker/src/features/batchAction/processBatchedObservationEval.tsindex 7c2165725e..998b497051 100644--- a/worker/src/features/batchAction/processBatchedObservationEval.ts+++ b/worker/src/features/batchAction/processBatchedObservationEval.ts@@ -55,6 +55,7 @@ export async function processBatchedObservationEval(params: {observation,configs: evaluators,schedulerDeps,+ executionMode: "MANUAL",});}),),diff --git a/worker/src/features/evaluation/observationEval/__tests__/observationEvalProcessor.test.ts b/worker/src/features/evaluation/observationEval/__tests__/observationEvalProcessor.test.tsindex d8994c793b..8bebfcf772 100644--- a/worker/src/features/evaluation/observationEval/__tests__/observationEvalProcessor.test.ts+++ b/worker/src/features/evaluation/observationEval/__tests__/observationEvalProcessor.test.ts@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach, type Mock } from "vitest";-import { JobExecutionStatus } from "@prisma/client";+import { JobConfigState, JobExecutionStatus } from "@prisma/client";import {processObservationEval,type ObservationEvalProcessorDeps,@@ -167,6 +167,77 @@ describe("processObservationEval", () => {expect(deps.downloadObservationFromS3).not.toHaveBeenCalled();expect(executeLLMAsJudgeEvaluation).not.toHaveBeenCalled();});++ it("should cancel inactive evaluators when execution mode is omitted", async () => {+ const job = createMockJobExecution({+ id: jobExecutionId,+ projectId,+ status: JobExecutionStatus.PENDING,+ jobConfigurationId: "config-123",+ });+ const config = createMockJobConfiguration({+ id: "config-123",+ projectId,+ status: JobConfigState.INACTIVE,+ });++ (prisma.jobExecution.findFirst as Mock).mockResolvedValue(job);+ (prisma.jobConfiguration.findFirst as Mock).mockResolvedValue(config);++ const deps = createMockProcessorDeps();++ await processObservationEval({ event: baseEvent, deps });++ expect(prisma.jobExecution.update).toHaveBeenCalledWith({+ where: {+ id: job.id,+ projectId,+ },+ data: {+ status: JobExecutionStatus.CANCELLED,+ endTime: expect.any(Date),+ },+ });+ expect(deps.downloadObservationFromS3).not.toHaveBeenCalled();+ expect(executeLLMAsJudgeEvaluation).not.toHaveBeenCalled();+ });++ it("should execute inactive evaluators for manual execution", async () => {+ const job = createMockJobExecution({+ id: jobExecutionId,+ projectId,+ status: JobExecutionStatus.PENDING,+ jobConfigurationId: "config-123",+ });+ const config = createMockJobConfiguration({+ id: "config-123",+ projectId,+ status: JobConfigState.INACTIVE,+ });++ (prisma.jobExecution.findFirst as Mock).mockResolvedValue(job);+ (prisma.jobConfiguration.findFirst as Mock).mockResolvedValue(config);++ const deps = createMockProcessorDeps();++ await processObservationEval({+ event: { ...baseEvent, executionMode: "MANUAL" },+ deps,+ });++ expect(prisma.jobExecution.update).not.toHaveBeenCalled();+ expect(deps.downloadObservationFromS3).toHaveBeenCalledWith(+ observationS3Path,+ );+ expect(executeLLMAsJudgeEvaluation).toHaveBeenCalledWith(+ expect.objectContaining({+ projectId,+ jobExecutionId,+ job: expect.objectContaining({ id: jobExecutionId }),+ config: expect.objectContaining({ id: "config-123" }),+ }),+ );+ });});describe("S3 download", () => {diff --git a/worker/src/features/evaluation/observationEval/__tests__/scheduleObservationEvals.test.ts b/worker/src/features/evaluation/observationEval/__tests__/scheduleObservationEvals.test.tsindex 07c1c1560b..a9a4beb67c 100644--- a/worker/src/features/evaluation/observationEval/__tests__/scheduleObservationEvals.test.ts+++ b/worker/src/features/evaluation/observationEval/__tests__/scheduleObservationEvals.test.ts@@ -147,6 +147,41 @@ describe("scheduleObservationEvals", () => {expect(schedulerDeps.upsertJobExecution).not.toHaveBeenCalled();expect(schedulerDeps.enqueueEvalJob).not.toHaveBeenCalled();});++ it("should schedule inactive configs for manual execution while skipping blocked configs", async () => {+ const schedulerDeps = createMockSchedulerDeps();+ const observation = createMockObservation();+ const inactiveConfig = createMockConfig({+ id: "inactive-config",+ status: JobConfigState.INACTIVE,+ });++ await scheduleObservationEvals({+ observation,+ configs: [+ createMockConfig({+ id: "blocked-config",+ blockedAt: new Date(),+ }),+ inactiveConfig,+ ],+ schedulerDeps,+ executionMode: "MANUAL",+ });++ expect(schedulerDeps.uploadObservationToS3).toHaveBeenCalledTimes(1);+ expect(schedulerDeps.upsertJobExecution).toHaveBeenCalledTimes(1);+ expect(schedulerDeps.upsertJobExecution).toHaveBeenCalledWith(+ expect.objectContaining({+ jobConfigurationId: inactiveConfig.id,+ }),+ );+ expect(schedulerDeps.enqueueEvalJob).toHaveBeenCalledWith(+ expect.objectContaining({+ executionMode: "MANUAL",+ }),+ );+ });});describe("S3 upload", () => {diff --git a/worker/src/features/evaluation/observationEval/createSchedulerDeps.ts b/worker/src/features/evaluation/observationEval/createSchedulerDeps.tsindex 5aca3176d6..9d45dfef2c 100644--- a/worker/src/features/evaluation/observationEval/createSchedulerDeps.ts+++ b/worker/src/features/evaluation/observationEval/createSchedulerDeps.ts@@ -74,6 +74,9 @@ export function createObservationEvalSchedulerDeps(): ObservationEvalSchedulerDeprojectId: params.projectId,jobExecutionId: params.jobExecutionId,observationS3Path: params.observationS3Path,+ ...(params.executionMode+ ? { executionMode: params.executionMode }+ : {}),},},{diff --git a/worker/src/features/evaluation/observationEval/observationEvalProcessor.ts b/worker/src/features/evaluation/observationEval/observationEvalProcessor.tsindex 005ccd6a01..b0de8f7555 100644--- a/worker/src/features/evaluation/observationEval/observationEvalProcessor.ts+++ b/worker/src/features/evaluation/observationEval/observationEvalProcessor.ts@@ -7,7 +7,7 @@ import {import {observationForEvalSchema,observationVariableMappingList,- isJobConfigExecutable,+ isJobConfigExecutableForExecutionMode,type ObservationVariableMapping,} from "@langfuse/shared";import { prisma, JobExecutionStatus } from "@langfuse/shared/src/db";@@ -102,7 +102,9 @@ export async function processObservationEval({);}- if (!isJobConfigExecutable(evalJobConfig)) {+ if (+ !isJobConfigExecutableForExecutionMode(evalJobConfig, event.executionMode)+ ) {logger.debug(`Job execution ${event.jobExecutionId} is not executable because the evaluator is blocked or inactive.`,);diff --git a/worker/src/features/evaluation/observationEval/scheduleObservationEvals.ts b/worker/src/features/evaluation/observationEval/scheduleObservationEvals.tsindex d82b16d229..95e5edd1c8 100644--- a/worker/src/features/evaluation/observationEval/scheduleObservationEvals.ts+++ b/worker/src/features/evaluation/observationEval/scheduleObservationEvals.ts@@ -9,7 +9,8 @@ import {EvalTargetObject,JobExecutionStatus,type FilterState,- isJobConfigExecutable,+ type JobConfigExecutionMode,+ isJobConfigExecutableForExecutionMode,mapEventEvalFilterColumnIdToField,} from "@langfuse/shared";import { createW3CTraceId } from "../../utils";@@ -18,6 +19,7 @@ interface ScheduleObservationEvalsParams {observation: ObservationForEval;configs: ObservationEvalConfig[];schedulerDeps: ObservationEvalSchedulerDeps;+ executionMode?: JobConfigExecutionMode;}/**@@ -36,7 +38,7 @@ interface ScheduleObservationEvalsParams {export async function scheduleObservationEvals(params: ScheduleObservationEvalsParams,): Promise<void> {- const { observation, configs, schedulerDeps } = params;+ const { observation, configs, schedulerDeps, executionMode } = params;// Early return if no configsif (configs.length === 0) {@@ -46,7 +48,7 @@ export async function scheduleObservationEvals(// Filter configs that match this observation (filter + sampling).// This is done before S3 upload to avoid unnecessary uploads.const matchingConfigs = configs.filter((config) => {- if (!isJobConfigExecutable(config)) {+ if (!isJobConfigExecutableForExecutionMode(config, executionMode)) {logger.debug("Skipping non-executable observation eval config", {configId: config.id,});@@ -98,6 +100,7 @@ export async function scheduleObservationEvals(matchingConfig,observationS3Path,schedulerDeps,+ executionMode,}).catch((error) => {logger.error("Failed to process observation eval config", {configId: matchingConfig.id,@@ -115,13 +118,19 @@ interface ProcessConfigParams {matchingConfig: ObservationEvalConfig;observationS3Path: string;schedulerDeps: ObservationEvalSchedulerDeps;+ executionMode?: JobConfigExecutionMode;}async function processMatchingConfig(params: ProcessConfigParams,): Promise<void> {- const { observation, matchingConfig, observationS3Path, schedulerDeps } =- params;+ const {+ observation,+ matchingConfig,+ observationS3Path,+ schedulerDeps,+ executionMode,+ } = params;const jobExecutionId = createW3CTraceId(`${matchingConfig.id}:${observation.span_id}`,@@ -144,6 +153,7 @@ async function processMatchingConfig(projectId: observation.project_id,observationS3Path,delay: 0,+ ...(executionMode ? { executionMode } : {}),});logger.debug("Scheduled observation eval job", {diff --git a/worker/src/features/evaluation/observationEval/types.ts b/worker/src/features/evaluation/observationEval/types.tsindex 90b9533fdb..859889bba6 100644--- a/worker/src/features/evaluation/observationEval/types.ts+++ b/worker/src/features/evaluation/observationEval/types.ts@@ -1,4 +1,5 @@import { JobConfiguration, JobExecutionStatus } from "@langfuse/shared/src/db";+import { type JobConfigExecutionMode } from "@langfuse/shared";/*** Re-export ObservationForEval as the canonical observation type for eval operations.@@ -61,5 +62,6 @@ export interface ObservationEvalSchedulerDeps {projectId: string;observationS3Path: string;delay: number;+ executionMode?: JobConfigExecutionMode;}) => Promise<void>;}