🪢 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
fix(billing): accept string event-bus timestamps on the CHB webhook (#17926)
Steffen Reuther8dfb8548dfd4
diff --git a/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts b/web/src/__tests__/server/unit/chbWebhookHandler.servertest.tsindex a5cca0dc6d..ed35fd15a3 100644--- a/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts+++ b/web/src/__tests__/server/unit/chbWebhookHandler.servertest.ts@@ -388,6 +388,20 @@ describe("chbWebhookHandler", () => {expect(mocks.findOrg).not.toHaveBeenCalled();});+ it.each([+ ["Unix milliseconds", 1_782_000_000_000],+ ["an ISO-8601 string", "2026-07-01T00:00:00.000Z"],+ ["a numeric string", "1782000000000"],+ ])("accepts the event bus timestamps as %s", async (_, value) => {+ const event = attachedPlanCreated({ createdAt: value });+ const response = await chbWebhookHandler(+ post({ ...event, data: { ...event.data, timestamp: value } }),+ );++ expect(response.status).toBe(200);+ expect(mocks.updateOrg).toHaveBeenCalledTimes(1);+ });+it("reads the attached plan back from CHB and persists it with the event's organization and occurredAt", async () => {await chbWebhookHandler(post(attachedPlanCreated()));diff --git a/web/src/ee/features/billing/server/chb/chbWebhookHandler.ts b/web/src/ee/features/billing/server/chb/chbWebhookHandler.tsindex 41f039641f..238afac006 100644--- a/web/src/ee/features/billing/server/chb/chbWebhookHandler.ts+++ b/web/src/ee/features/billing/server/chb/chbWebhookHandler.ts@@ -62,6 +62,12 @@ const ChbWebhookEventTypeSchema = z.enum(["BILLING_ATTACHEDPLAN_CANCELLED",]);+// Event-bus timestamps arrive as Unix milliseconds or as a string (ISO-8601 or+// numeric). Nothing reads them -- ordering runs on `occurredAt` -- so any of+// these shapes is accepted rather than failing a signed event over a field the+// handler ignores.+const ChbEventBusTimestampSchema = z.union([z.number(), z.string()]).nullish();+const ChbWebhookEventSchema = z.object({eventId: z.string().min(1),type: ChbWebhookEventTypeSchema,@@ -70,16 +76,14 @@ const ChbWebhookEventSchema = z.object({// Event-bus record id, not the attached plan idid: z.string().nullish(),source: z.string().nullish(),- // Unix milliseconds- timestamp: z.number().nullish(),+ timestamp: ChbEventBusTimestampSchema,version: z.number().nullish(),payload: z.object({eventType: ChbWebhookEventTypeSchema,// ClickHouse Organization ID owning the attached planorganizationId: z.uuid(),planCode: z.string().nullish(),- // Unix milliseconds- createdAt: z.number().nullish(),+ createdAt: ChbEventBusTimestampSchema,}),}),});