Skip to content

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

fix: search past observations with correct timestamp in evals (#5986)

Max Deichmann449c9360ac58
diff --git a/worker/src/__tests__/evalService.test.ts b/worker/src/__tests__/evalService.test.ts
index 4501d7e05e..376e6ff051 100644
--- a/worker/src/__tests__/evalService.test.ts
+++ b/worker/src/__tests__/evalService.test.ts
@@ -27,6 +27,8 @@ import { OpenAIServer } from "./network";
import { afterEach } from "node:test";
import {
convertDateToClickhouseDateTime,
+ createObservation,
+ createObservationsCh,
createTrace,
createTracesCh,
upsertObservation,
@@ -783,6 +785,63 @@ describe("eval service tests", () => {
expect(jobs.length).toBe(1);
}, 10_000);
+ test("does create eval for observation which is way in the past if timestamp is provided", async () => {
+ const traceId = randomUUID();
+
+ const timestamp = new Date(Date.now() - 1000 * 60 * 60 * 24 * 365 * 1);
+ const trace = createTrace({
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ id: traceId,
+ timestamp: timestamp.getTime(),
+ });
+
+ const observation = createObservation({
+ project_id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ id: randomUUID(),
+ start_time: timestamp.getTime(),
+ });
+
+ await createObservationsCh([observation]);
+ await createTracesCh([trace]);
+
+ const jobConfiguration = await prisma.jobConfiguration.create({
+ data: {
+ id: randomUUID(),
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ filter: JSON.parse("[]"),
+ jobType: "EVAL",
+ delay: 0,
+ sampling: new Decimal("1"),
+ targetObject: "observation",
+ scoreName: "score",
+ variableMapping: JSON.parse("[]"),
+ timeScope: ["EXISTING"],
+ },
+ });
+
+ const payload = {
+ projectId: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",
+ traceId: traceId,
+ configId: jobConfiguration.id,
+ timestamp: timestamp,
+ observationId: observation.id,
+ };
+
+ await createEvalJobs({
+ event: payload,
+ enforcedJobTimeScope: "EXISTING", // the config must contain NEW
+ });
+
+ const jobs = await kyselyPrisma.$kysely
+ .selectFrom("job_executions")
+ .selectAll()
+ .where("project_id", "=", "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a")
+ .where("job_configuration_id", "in", [jobConfiguration.id])
+ .execute();
+
+ expect(jobs.length).toBe(1);
+ }, 10_000);
+
test("creates eval for trace with timestamp in the future", async () => {
const traceId = randomUUID();
diff --git a/worker/src/ee/evaluation/evalService.ts b/worker/src/ee/evaluation/evalService.ts
index daa005cc71..12a841e741 100644
--- a/worker/src/ee/evaluation/evalService.ts
+++ b/worker/src/ee/evaluation/evalService.ts
@@ -176,9 +176,8 @@ export const createEvalJobs = async ({
const observationExists = await checkObservationExists(
event.projectId,
observationId,
- new Date(),
+ "timestamp" in event ? new Date(event.timestamp) : new Date(),
);
-
if (!observationExists) {
logger.warn(
`Observation ${observationId} not found, retrying dataset eval later`,