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)) }