Skip to content

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

chore: tighten project_failure.active_projects (#14845)

Valery Meleshkinc825d6125f77
diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.ts
index d71c33f3d3..c5a7fcc31c 100644
--- a/packages/shared/src/env.ts
+++ b/packages/shared/src/env.ts
@@ -302,7 +302,7 @@ const EnvSchema = z.object({
.number()
.int()
.gt(60)
- .default(3600), // 1 hour
+ .default(600), // 10 minutes
LANGFUSE_S3_CORE_DATA_EXPORT_IS_ENABLED: z
.enum(["true", "false"])
.default("false"),
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index 163675f51c..64332fab9f 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -2,6 +2,8 @@ import { Cluster, Redis } from "ioredis";
import { v4 } from "uuid";
import { Decimal } from "decimal.js";
import {
+ InvalidRequestError,
+ LangfuseNotFoundError,
Model,
ObservationLevel,
PrismaClient,
@@ -534,6 +536,7 @@ export class IngestionService {
minTimestamp === Infinity
? undefined
: convertDateToClickhouseDateTime(new Date(minTimestamp));
+ const unexpectedScoreValidationErrors: unknown[] = [];
const [clickhouseScoreRecord, scoreRecords] = await Promise.all([
this.getClickhouseRecord({
projectId,
@@ -587,6 +590,13 @@ export class IngestionService {
};
// Gracefully handle any score schema validation errors, skip the score insert and reject silently.
} catch (error) {
+ if (
+ !(error instanceof InvalidRequestError) &&
+ !(error instanceof LangfuseNotFoundError)
+ ) {
+ unexpectedScoreValidationErrors.push(error);
+ }
+
logger.info(
`Failed to validate and enrich score body for project: ${projectId} and score: ${entityId}`,
error,
@@ -608,6 +618,20 @@ export class IngestionService {
});
}
+ if (unexpectedScoreValidationErrors.length > 0) {
+ throw new AggregateError(
+ unexpectedScoreValidationErrors,
+ `Unexpected error(s) validating score batch for project: ${projectId} and score: ${entityId}`,
+ );
+ }
+
+ if (scoreRecords.length === 0 && !clickhouseScoreRecord) {
+ logger.warn(
+ `No valid score records found for project: ${projectId} and score: ${entityId}`,
+ );
+ return;
+ }
+
const finalScoreRecord: ScoreRecordInsertType =
await this.mergeScoreRecords({
clickhouseScoreRecord,
diff --git a/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts b/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
index 93aa753538..b04c893e8c 100644
--- a/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
+++ b/worker/src/services/IngestionService/tests/IngestionService.unit.test.ts
@@ -2,7 +2,9 @@ import { expect, describe, it, vi } from "vitest";
import { IngestionService } from "../../IngestionService";
import {
convertDateToClickhouseDateTime,
+ createTraceScore,
type ObservationEvent,
+ type ScoreEventType,
} from "@langfuse/shared/src/server";
import { TableName } from "../../ClickhouseWriter";
@@ -89,4 +91,162 @@ describe("IngestionService unit tests", () => {
attributes: JSON.stringify({ "custom.attribute": "keep-me" }),
});
});
+
+ it("silently rejects score batches with no valid records", async () => {
+ const addToQueue = vi.fn();
+ const ingestionService = new IngestionService(
+ {} as any,
+ {} as any,
+ { addToQueue } as any,
+ {} as any,
+ );
+ const timestamp = "2024-10-12T12:13:14.123Z";
+ const scoreEventList: ScoreEventType[] = [
+ {
+ id: "event-id",
+ timestamp,
+ type: "score-create",
+ body: {
+ id: "score-id",
+ dataType: "NUMERIC",
+ name: "invalid-score",
+ value: "not-a-number",
+ source: "API",
+ traceId: "trace-id",
+ environment: "default",
+ },
+ },
+ ];
+
+ vi.spyOn(ingestionService as any, "getClickhouseRecord").mockResolvedValue(
+ null,
+ );
+
+ await expect(
+ (ingestionService as any).processScoreEventList({
+ projectId: "project-id",
+ entityId: "score-id",
+ createdAtTimestamp: new Date(timestamp),
+ scoreEventList,
+ attribution: {
+ ingestionApiKey: "pk-lf-unit-test",
+ ingestionSdkName: "langfuse-test",
+ ingestionSdkVersion: "0.0.0",
+ },
+ }),
+ ).resolves.toBeUndefined();
+
+ expect(addToQueue).not.toHaveBeenCalled();
+ });
+
+ it("does not silently reject score batches with unexpected record errors", async () => {
+ const addToQueue = vi.fn();
+ const ingestionService = new IngestionService(
+ {} as any,
+ {} as any,
+ { addToQueue } as any,
+ {} as any,
+ );
+ const timestamp = "2024-10-12T12:13:14.123Z";
+ const scoreEventList: ScoreEventType[] = [
+ {
+ id: "event-id",
+ timestamp,
+ type: "score-create",
+ body: {
+ id: "score-id",
+ dataType: "NUMERIC",
+ name: "valid-score",
+ value: 1,
+ source: "API",
+ traceId: "trace-id",
+ environment: "default",
+ },
+ },
+ ];
+
+ vi.spyOn(ingestionService as any, "getClickhouseRecord").mockResolvedValue(
+ null,
+ );
+ vi.spyOn(
+ ingestionService as any,
+ "getMillisecondTimestamp",
+ ).mockImplementation(() => {
+ throw new Error("unexpected timestamp failure");
+ });
+
+ await expect(
+ (ingestionService as any).processScoreEventList({
+ projectId: "project-id",
+ entityId: "score-id",
+ createdAtTimestamp: new Date(timestamp),
+ scoreEventList,
+ attribution: {
+ ingestionApiKey: "pk-lf-unit-test",
+ ingestionSdkName: "langfuse-test",
+ ingestionSdkVersion: "0.0.0",
+ },
+ }),
+ ).rejects.toThrow("Unexpected error(s) validating score batch");
+
+ expect(addToQueue).not.toHaveBeenCalled();
+ });
+
+ it("propagates unexpected score errors even when a ClickHouse score exists", async () => {
+ const addToQueue = vi.fn();
+ const ingestionService = new IngestionService(
+ {} as any,
+ {} as any,
+ { addToQueue } as any,
+ {} as any,
+ );
+ const timestamp = "2024-10-12T12:13:14.123Z";
+ const scoreEventList: ScoreEventType[] = [
+ {
+ id: "event-id",
+ timestamp,
+ type: "score-update",
+ body: {
+ id: "score-id",
+ dataType: "NUMERIC",
+ name: "valid-score",
+ value: 1,
+ source: "API",
+ traceId: "trace-id",
+ environment: "default",
+ },
+ },
+ ];
+
+ vi.spyOn(ingestionService as any, "getClickhouseRecord").mockResolvedValue(
+ createTraceScore({
+ id: "score-id",
+ project_id: "project-id",
+ trace_id: "trace-id",
+ timestamp: new Date(timestamp).getTime(),
+ }),
+ );
+ vi.spyOn(
+ ingestionService as any,
+ "getMillisecondTimestamp",
+ ).mockImplementation(() => {
+ throw new Error("unexpected timestamp failure");
+ });
+
+ await expect(
+ (ingestionService as any).processScoreEventList({
+ projectId: "project-id",
+ entityId: "score-id",
+ createdAtTimestamp: new Date(timestamp),
+ scoreEventList,
+ attribution: {
+ ingestionApiKey: "pk-lf-unit-test",
+ ingestionSdkName: "langfuse-test",
+ ingestionSdkVersion: "0.0.0",
+ },
+ }),
+ ).rejects.toThrow("Unexpected error(s) validating score batch");
+
+ expect(addToQueue).not.toHaveBeenCalled();
+ });
});