Fix NaN handling in ttftBucketIndex - #1238
Conversation
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.
|
Good catch — One suggestion: since the module has no existing tests, it'd strengthen this PR to add a couple of unit tests in Overall this is exactly the kind of small, scoped, well-reasoned fix that's easy to review and port. |
Overview
Fix NaN handling in the
ttftBucketIndexfunction incommon/src/util/ttft-histogram.ts.Bug Description
The function didn't validate that ttftMs is a finite number. If ttftMs was NaN or Infinity,
Math.max(NaN, 1)would return NaN, causingMath.log(NaN)to return NaN, and the entire calculation would produce NaN.Fix
Added
Number.isFinite()check to default to 0 for invalid numbers.Testing
No existing tests for this function, but the fix prevents incorrect behavior with invalid inputs.
Files Changed
common/src/util/ttft-histogram.ts- Added NaN validationScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.