Skip to content

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

fix(scores): bump updated_at when editing annotation scores (#19202)

Niklas Semmler20f40bb79d4e
diff --git a/web/src/__tests__/server/scores-trpc.servertest.ts b/web/src/__tests__/server/scores-trpc.servertest.ts
index 78e50a2796..7c0b43801b 100644
--- a/web/src/__tests__/server/scores-trpc.servertest.ts
+++ b/web/src/__tests__/server/scores-trpc.servertest.ts
@@ -878,6 +878,55 @@ describe("scores trpc", () => {
});
});
+ describe("scores.updateAnnotationScore", () => {
+ it("bumps updated_at and keeps created_at when editing an existing score", async () => {
+ const originalTime = new Date(Date.now() - 60 * 60 * 1000);
+ const configId = randomUUID();
+ const scoreName = `numeric-annotation-score-${configId.slice(0, 8)}`;
+ await prisma.scoreConfig.create({
+ data: {
+ id: configId,
+ projectId,
+ name: scoreName,
+ dataType: ScoreConfigDataType.NUMERIC,
+ },
+ });
+ const existing = createTraceScore({
+ project_id: projectId,
+ source: "ANNOTATION",
+ name: scoreName,
+ config_id: configId,
+ value: 1,
+ timestamp: originalTime.getTime(),
+ created_at: originalTime.getTime(),
+ updated_at: originalTime.getTime(),
+ });
+ await createScoresCh([existing]);
+
+ await caller.scores.updateAnnotationScore({
+ id: existing.id,
+ projectId,
+ name: scoreName,
+ value: 2,
+ stringValue: null,
+ dataType: "NUMERIC",
+ scoreTarget: { type: "trace", traceId: existing.trace_id! },
+ configId,
+ environment: "default",
+ });
+
+ const updated = await getScoreById({
+ projectId,
+ scoreId: existing.id,
+ });
+ expect(updated?.value).toBe(2);
+ expect(updated?.createdAt.getTime()).toBe(originalTime.getTime());
+ expect(updated?.updatedAt.getTime()).toBeGreaterThan(
+ originalTime.getTime(),
+ );
+ });
+ });
+
describe("scores.deleteAnnotationScore", () => {
it("deletes a correction ingested via the API", async () => {
const correction = createTraceScore({
diff --git a/web/src/server/api/routers/scores.ts b/web/src/server/api/routers/scores.ts
index 589030785b..8b54ec89d3 100644
--- a/web/src/server/api/routers/scores.ts
+++ b/web/src/server/api/routers/scores.ts
@@ -651,6 +651,7 @@ export const scoresRouter = createTRPCRouter({
authorUserId: ctx.session.user.id,
queueId: input.queueId ?? null,
timestamp,
+ updatedAt: new Date(),
}
: {
id: input.id ?? v4(),
@@ -905,6 +906,8 @@ export const scoresRouter = createTRPCRouter({
}
}
+ const updatedAt = new Date();
+
await upsertScore({
id: input.id,
project_id: input.projectId,
@@ -923,12 +926,13 @@ export const scoresRouter = createTRPCRouter({
session_id: score.sessionId,
environment: score.environment,
created_at: convertDateToClickhouseDateTime(score.createdAt),
- updated_at: convertDateToClickhouseDateTime(score.updatedAt),
+ updated_at: convertDateToClickhouseDateTime(updatedAt),
metadata: score.metadata as Record<string, string>,
});
const baseScore = {
...score,
+ updatedAt,
value: input.value,
comment: input.comment ?? null,
authorUserId: ctx.session.user.id,
@@ -1069,6 +1073,7 @@ export const scoresRouter = createTRPCRouter({
authorUserId: ctx.session.user.id,
queueId: input.queueId ?? null,
longStringValue: input.value,
+ updatedAt: new Date(),
}
: {
id: input.id,