🪢 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(annotation-scores): revert to synchronous delete; upsert on create route (#6282)
marliessophie4b733c4da8a7
diff --git a/web/src/features/scores/components/AnnotateDrawerContent.tsx b/web/src/features/scores/components/AnnotateDrawerContent.tsxindex d9d6de57d9..4b8bde6e52 100644--- a/web/src/features/scores/components/AnnotateDrawerContent.tsx+++ b/web/src/features/scores/components/AnnotateDrawerContent.tsx@@ -359,7 +359,13 @@ export function AnnotateDrawerContent({await Promise.all([utils.scores.invalidate(),- utils.traces.invalidate(),+ utils.traces.byIdWithObservationsAndScores.invalidate(+ { projectId, traceId },+ {+ type: "all",+ refetchType: "all",+ },+ ),utils.sessions.invalidate(),]);diff --git a/web/src/server/api/routers/scores.ts b/web/src/server/api/routers/scores.tsindex 7cfd9cf5f4..34872bc419 100644--- a/web/src/server/api/routers/scores.ts+++ b/web/src/server/api/routers/scores.ts@@ -22,7 +22,6 @@ import {ScoreSource,type Score,LangfuseNotFoundError,- InvalidRequestError,InternalServerError,BatchActionQuerySchema,BatchActionType,@@ -43,6 +42,7 @@ import {hasAnyScore,ScoreDeleteQueue,QueueJobs,+ deleteScores,} from "@langfuse/shared/src/server";import { v4 } from "uuid";import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEntitlement";@@ -268,34 +268,35 @@ export const scoresRouter = createTRPCRouter({input.configId,);- if (clickhouseScore) {- logger.error(- `Score for name ${input.name} already exists for trace ${input.traceId} in project ${input.projectId}`,- );- throw new InvalidRequestError(- `Score for name ${input.name} already exists for trace ${input.traceId} in project ${input.projectId}`,- );- }-- const score = {- id: v4(),- projectId: input.projectId,- environment: input.environment ?? "default",- traceId: input.traceId,- observationId: input.observationId ?? null,- value: input.value ?? null,- stringValue: input.stringValue ?? null,- dataType: input.dataType ?? null,- configId: input.configId ?? null,- name: input.name,- comment: input.comment ?? null,- authorUserId: ctx.session.user.id,- source: ScoreSource.ANNOTATION,- queueId: input.queueId ?? null,- createdAt: new Date(),- updatedAt: new Date(),- timestamp: new Date(),- };+ const score = !!clickhouseScore+ ? {+ ...clickhouseScore,+ value: input.value ?? null,+ stringValue: input.stringValue ?? null,+ comment: input.comment ?? null,+ authorUserId: ctx.session.user.id,+ queueId: input.queueId ?? null,+ timestamp: new Date(),+ }+ : {+ id: v4(),+ projectId: input.projectId,+ environment: input.environment ?? "default",+ traceId: input.traceId,+ observationId: input.observationId ?? null,+ value: input.value ?? null,+ stringValue: input.stringValue ?? null,+ dataType: input.dataType ?? null,+ configId: input.configId ?? null,+ name: input.name,+ comment: input.comment ?? null,+ authorUserId: ctx.session.user.id,+ source: ScoreSource.ANNOTATION,+ queueId: input.queueId ?? null,+ createdAt: new Date(),+ updatedAt: new Date(),+ timestamp: new Date(),+ };await upsertScore({id: score.id, // Reuse ID that was generated by Prisma@@ -374,6 +375,7 @@ export const scoresRouter = createTRPCRouter({comment: input.comment ?? null,authorUserId: ctx.session.user.id,queueId: input.queueId ?? null,+ timestamp: new Date(),};await auditLog({@@ -418,14 +420,6 @@ export const scoresRouter = createTRPCRouter({);}- const scoreDeleteQueue = ScoreDeleteQueue.getInstance();- if (!scoreDeleteQueue) {- throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",- message: "ScoreDeleteQueue not initialized",- });- }-await auditLog({session: ctx.session,resourceType: "score",@@ -434,16 +428,9 @@ export const scoresRouter = createTRPCRouter({before: clickhouseScore,});- // Delete the score from Clickhouse- await scoreDeleteQueue.add(QueueJobs.ScoreDelete, {- timestamp: new Date(),- id: randomUUID(),- payload: {- projectId: input.projectId,- scoreIds: [input.id],- },- name: QueueJobs.ScoreDelete,- });+ await deleteScores(input.projectId, [clickhouseScore.id]);++ return validateDbScore(clickhouseScore);}),getScoreKeysAndProps: protectedProjectProcedure.input(