From e84a0c742d9d6d66ba4e67860a5f3e7fe0c391d9 Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 12:11:52 +0530 Subject: [PATCH] Fix NaN handling in ttftBucketIndex The function didn't validate that ttftMs is a finite number. If ttftMs was NaN or Infinity, Math.max(NaN, 1) would return NaN, causing Math.log(NaN) to return NaN, and the entire calculation would produce NaN. Added Number.isFinite() check to default to 0 for invalid numbers. --- common/src/util/ttft-histogram.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/util/ttft-histogram.ts b/common/src/util/ttft-histogram.ts index f6c1820010..8c2f582f22 100644 --- a/common/src/util/ttft-histogram.ts +++ b/common/src/util/ttft-histogram.ts @@ -37,7 +37,8 @@ const LN_BASE = Math.log(TTFT_HISTOGRAM_BASE) * Sub-millisecond and zero samples land in bucket 0 rather than at -Infinity. */ export function ttftBucketIndex(ttftMs: number): number { - const index = Math.floor(Math.log(Math.max(ttftMs, 1)) / LN_BASE) + const safeTtftMs = Number.isFinite(ttftMs) ? ttftMs : 0 + const index = Math.floor(Math.log(Math.max(safeTtftMs, 1)) / LN_BASE) return Math.min(TTFT_HISTOGRAM_BUCKET_COUNT - 1, Math.max(0, index)) }