Skip to content

Fix NaN handling in formatFreebuffRowQuota - #1247

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/format-row-quota-nan-handling
Open

Fix NaN handling in formatFreebuffRowQuota#1247
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/format-row-quota-nan-handling

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix NaN handling in the formatFreebuffRowQuota function in common/src/util/freebuff-session-pools.ts.

Bug Description

The function didn't validate that recentCount and limit are finite numbers. If either was NaN or Infinity, Math.min(NaN, NaN) would return NaN, causing the function to return 'NaN of NaN' as a string.

Fix

Added Number.isFinite() checks 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/freebuff-session-pools.ts - Added NaN validation

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The function didn't validate that recentCount and limit are finite numbers. If
either was NaN or Infinity, Math.min(NaN, NaN) would return NaN, causing the
function to return 'NaN of NaN' as a string.

Added Number.isFinite() checks to default to 0 for invalid numbers.
@codebuff-team

Copy link
Copy Markdown
Contributor

Thanks for taking a look at common/src/util/freebuff-session-pools.ts — this file is in scope and the diff itself is clean and minimal.

That said, the PR doesn't show where quota.recentCount or quota.limit actually become NaN/Infinity in practice. FreebuffSessionRateLimit is presumably constructed internally from counts and configured limits, so if NaN is showing up, the real bug is almost certainly upstream where the quota object is built (e.g. a division by zero or an unset limit), and this patch only masks the symptom at the display layer. Silently coercing to 0 could also produce a misleading 0 of 0 label instead of surfacing the actual data problem, which isn't obviously better than 'NaN of NaN'.

To make this a solid port candidate:

  1. Trace where recentCount/limit originate and fix (or at least identify) the root cause, not just the formatter.
  2. Add a unit test for formatFreebuffRowQuota exercising the NaN/Infinity case you describe, since the repo has no coverage for this function yet — that's exactly the kind of change that should ship with a test.
  3. If you can't find a real code path that produces NaN today, it's worth saying so explicitly and treating this as defensive-only, which lowers its priority.

Right instinct, but as-is this reads like a speculative fix rather than one grounded in an observed failure.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written labels Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:needs-work Right idea, not mergeable as written

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants