Skip to content

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

fix: fix eval status on details page (#5944)

Max Deichmann0b485ad5d82d
diff --git a/web/src/components/level-counts-display.tsx b/web/src/components/level-counts-display.tsx
index 554f2ab325..8a89ee86b5 100644
--- a/web/src/components/level-counts-display.tsx
+++ b/web/src/components/level-counts-display.tsx
@@ -24,7 +24,7 @@ export function LevelCountsDisplay({
const nonZeroCounts = counts.filter((item) => item.count > 0);
return (
- <div className="flex min-h-6 flex-row gap-2 overflow-x-auto whitespace-nowrap">
+ <div className="flex min-h-6 flex-row items-center gap-2 overflow-x-auto whitespace-nowrap">
{nonZeroCounts.map(
({ level, count, symbol, customNumberFormatter }, index) => (
<React.Fragment key={level}>
diff --git a/web/src/ee/features/evals/components/evaluator-detail.tsx b/web/src/ee/features/evals/components/evaluator-detail.tsx
index 606939d162..922a4dcf64 100644
--- a/web/src/ee/features/evals/components/evaluator-detail.tsx
+++ b/web/src/ee/features/evals/components/evaluator-detail.tsx
@@ -27,6 +27,24 @@ import {
DialogTrigger,
} from "@/src/components/ui/dialog";
import Page from "@/src/components/layouts/page";
+import { LevelCountsDisplay } from "@/src/components/level-counts-display";
+import {
+ type JobExecutionState,
+ generateJobExecutionCounts,
+} from "@/src/ee/features/evals/utils/job-execution-utils";
+
+const JobExecutionCounts = ({
+ jobExecutionsByState,
+}: {
+ jobExecutionsByState?: JobExecutionState[];
+}) => {
+ if (!jobExecutionsByState || jobExecutionsByState.length === 0) {
+ return null;
+ }
+
+ const counts = generateJobExecutionCounts(jobExecutionsByState);
+ return <LevelCountsDisplay counts={counts} />;
+};
export const EvaluatorDetail = () => {
const router = useRouter();
@@ -67,7 +85,10 @@ export const EvaluatorDetail = () => {
const existingEvaluator =
evaluator.data && evaluator.data.evalTemplate
- ? { ...evaluator.data, evalTemplate: evaluator.data.evalTemplate }
+ ? {
+ ...evaluator.data,
+ evalTemplate: evaluator.data.evalTemplate,
+ }
: undefined;
return (
@@ -83,13 +104,22 @@ export const EvaluatorDetail = () => {
href: `/project/${router.query.projectId as string}/evals`,
},
],
+
actionButtonsRight: (
<>
+ {evaluator.data?.jobExecutionsByState && (
+ <div className="flex flex-col items-center justify-center rounded-md bg-muted-gray px-2">
+ <JobExecutionCounts
+ jobExecutionsByState={evaluator.data.jobExecutionsByState}
+ />
+ </div>
+ )}
<StatusBadge
- type={evaluator.data?.status.toLowerCase()}
+ type={evaluator.data?.finalStatus.toLowerCase()}
isLive
className="max-h-8"
/>
+
<DeactivateEvaluator
projectId={projectId}
evaluator={evaluator.data ?? undefined}
@@ -157,6 +187,7 @@ export const EvaluatorDetail = () => {
className="flex min-h-6 items-center"
/>
</CardDescription>
+
<div className="flex w-full flex-col items-start justify-between space-y-2 pb-4">
<EvaluatorForm
key={existingEvaluator.id}
diff --git a/web/src/ee/features/evals/components/evaluator-table.tsx b/web/src/ee/features/evals/components/evaluator-table.tsx
index 301c739947..011721e312 100644
--- a/web/src/ee/features/evals/components/evaluator-table.tsx
+++ b/web/src/ee/features/evals/components/evaluator-table.tsx
@@ -8,12 +8,12 @@ import useColumnVisibility from "@/src/features/column-visibility/hooks/useColum
import { InlineFilterState } from "@/src/features/filters/components/filter-builder";
import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";
import { type RouterOutputs, api } from "@/src/utils/api";
-import { compactNumberFormatter } from "@/src/utils/numbers";
import { type FilterState, singleFilter } from "@langfuse/shared";
import { createColumnHelper } from "@tanstack/react-table";
import { useEffect } from "react";
import { useQueryParams, withDefault, NumberParam } from "use-query-params";
import { z } from "zod";
+import { generateJobExecutionCounts } from "@/src/ee/features/evals/utils/job-execution-utils";
export type EvaluatorDataRow = {
id: string;
@@ -169,44 +169,11 @@ export default function EvaluatorTable({ projectId }: { projectId: string }) {
const convertToTableRow = (
jobConfig: RouterOutputs["evals"]["allConfigs"]["configs"][number],
): EvaluatorDataRow => {
- const result = [
- {
- level: "pending",
- count:
- jobConfig.jobExecutionsByState.find((je) => je.status === "PENDING")
- ?._count || 0,
- symbol: "🕒",
- customNumberFormatter: compactNumberFormatter,
- },
- {
- level: "error",
- count:
- jobConfig.jobExecutionsByState.find((je) => je.status === "ERROR")
- ?._count || 0,
- symbol: "❌",
- customNumberFormatter: compactNumberFormatter,
- },
- {
- level: "succeeded",
- count:
- jobConfig.jobExecutionsByState.find((je) => je.status === "COMPLETED")
- ?._count || 0,
- symbol: "✅",
- customNumberFormatter: compactNumberFormatter,
- },
- ];
-
- const finalStatus =
- jobConfig.timeScope.length === 1 &&
- jobConfig.timeScope[0] === "EXISTING" &&
- !jobConfig.jobExecutionsByState.some((je) => je.status === "PENDING") &&
- jobConfig.jobExecutionsByState.reduce((acc, je) => acc + je._count, 0) > 0
- ? "FINISHED"
- : jobConfig.status;
+ const result = generateJobExecutionCounts(jobConfig.jobExecutionsByState);
return {
id: jobConfig.id,
- status: finalStatus,
+ status: jobConfig.finalStatus,
createdAt: jobConfig.createdAt.toLocaleString(),
template: jobConfig.evalTemplate
? {
diff --git a/web/src/ee/features/evals/server/router.ts b/web/src/ee/features/evals/server/router.ts
index 8ab39dc2dd..93b7dd9591 100644
--- a/web/src/ee/features/evals/server/router.ts
+++ b/web/src/ee/features/evals/server/router.ts
@@ -37,6 +37,8 @@ import { traceException } from "@langfuse/shared/src/server";
import { isNotNullOrUndefined } from "@/src/utils/types";
import { v4 as uuidv4 } from "uuid";
import { env } from "@/src/env.mjs";
+import { type PrismaClient } from "@prisma/client";
+import { type JobExecutionState } from "@/src/ee/features/evals/utils/job-execution-utils";
const APIEvaluatorSchema = z.object({
id: z.string(),
@@ -117,6 +119,56 @@ const UpdateEvalJobSchema = z.object({
timeScope: TimeScopeSchema.optional(),
});
+const fetchJobExecutionsByState = async ({
+ prisma,
+ projectId,
+ configIds,
+}: {
+ prisma: PrismaClient;
+ projectId: string;
+ configIds: string[];
+}) => {
+ return prisma.jobExecution.groupBy({
+ where: {
+ jobConfiguration: {
+ projectId: projectId,
+ jobType: "EVAL",
+ id: { in: configIds },
+ },
+ projectId: projectId,
+ },
+ by: ["status", "jobConfigurationId"],
+ _count: true,
+ });
+};
+
+export const calculateEvaluatorFinalStatus = (
+ status: string,
+ timeScope: string[],
+ jobExecutionsByState: JobExecutionState[],
+): string => {
+ // If timeScope is only "EXISTING" and there are no pending jobs and there are some jobs,
+ // then the status is "FINISHED", otherwise it's the original status
+ const hasPendingJobs = jobExecutionsByState.some(
+ (je) => je.status === "PENDING",
+ );
+ const totalJobCount = jobExecutionsByState.reduce(
+ (acc, je) => acc + je._count,
+ 0,
+ );
+
+ if (
+ timeScope.length === 1 &&
+ timeScope[0] === "EXISTING" &&
+ !hasPendingJobs &&
+ totalJobCount > 0
+ ) {
+ return "FINISHED";
+ }
+
+ return status;
+};
+
export const evalRouter = createTRPCRouter({
globalJobConfigs: protectedProjectProcedure
.input(z.object({ projectId: z.string() }))
@@ -220,17 +272,10 @@ export const evalRouter = createTRPCRouter({
},
});
- const jobExecutionsByState = await ctx.prisma.jobExecution.groupBy({
- where: {
- jobConfiguration: {
- projectId: input.projectId,
- jobType: "EVAL",
- id: { in: configs.map((c) => c.id) },
- },
- projectId: input.projectId,
- },
- by: ["status", "jobConfigurationId"],
- _count: true,
+ const jobExecutionsByState = await fetchJobExecutionsByState({
+ prisma: ctx.prisma,
+ projectId: input.projectId,
+ configIds: configs.map((c) => c.id),
});
return {
@@ -239,6 +284,13 @@ export const evalRouter = createTRPCRouter({
jobExecutionsByState: jobExecutionsByState.filter(
(je) => je.jobConfigurationId === config.id,
),
+ finalStatus: calculateEvaluatorFinalStatus(
+ config.status,
+ Array.isArray(config.timeScope) ? config.timeScope : [],
+ jobExecutionsByState.filter(
+ (je) => je.jobConfigurationId === config.id,
+ ),
+ ),
})),
totalCount: count,
};
@@ -273,7 +325,25 @@ export const evalRouter = createTRPCRouter({
},
});
- return config;
+ if (!config) return null;
+
+ const jobExecutionsByState = await fetchJobExecutionsByState({
+ prisma: ctx.prisma,
+ projectId: input.projectId,
+ configIds: [config.id],
+ });
+
+ const finalStatus = calculateEvaluatorFinalStatus(
+ config.status,
+ Array.isArray(config.timeScope) ? config.timeScope : [],
+ jobExecutionsByState,
+ );
+
+ return {
+ ...config,
+ jobExecutionsByState: jobExecutionsByState,
+ finalStatus,
+ };
}),
allTemplatesForName: protectedProjectProcedure
diff --git a/web/src/ee/features/evals/utils/job-execution-utils.ts b/web/src/ee/features/evals/utils/job-execution-utils.ts
new file mode 100644
index 0000000000..2e84a2c588
--- /dev/null
+++ b/web/src/ee/features/evals/utils/job-execution-utils.ts
@@ -0,0 +1,40 @@
+import { compactNumberFormatter } from "@/src/utils/numbers";
+
+/**
+ * Type for job execution state data
+ */
+export type JobExecutionState = {
+ status: string;
+ jobConfigurationId: string;
+ _count: number;
+};
+
+export const generateJobExecutionCounts = (
+ jobExecutionsByState?: JobExecutionState[],
+) => {
+ return [
+ {
+ level: "pending",
+ count:
+ jobExecutionsByState?.find((je) => je.status === "PENDING")?._count ||
+ 0,
+ symbol: "🕒",
+ customNumberFormatter: compactNumberFormatter,
+ },
+ {
+ level: "error",
+ count:
+ jobExecutionsByState?.find((je) => je.status === "ERROR")?._count || 0,
+ symbol: "❌",
+ customNumberFormatter: compactNumberFormatter,
+ },
+ {
+ level: "succeeded",
+ count:
+ jobExecutionsByState?.find((je) => je.status === "COMPLETED")?._count ||
+ 0,
+ symbol: "✅",
+ customNumberFormatter: compactNumberFormatter,
+ },
+ ];
+};