Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Sep 8, 2025

  • fix(notifications): increase precision on billing calculations

Summary

increase precision on billing calculations

Type of Change

  • Bug fix

Testing

Tested manually on upwards crossing over 80%, also ensured that we did not send duplicates on the following execution.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Building Building Preview Comment Sep 8, 2025 5:44pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 8, 2025 5:44pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR increases precision in billing calculations by removing rounding functions (Math.round(), Math.floor()) from percentage calculations across three core billing files. The changes affect usage percentage calculations in both development and production environments, allowing decimal precision instead of rounding to whole numbers.

The modifications span three key billing components:

  1. usage-monitor.ts - Removes Math.round() and Math.floor() from percentage calculations in both development (line 38) and production (line 72) code paths
  2. usage.ts - Removes Math.floor() from the getUserUsageData function's percentage calculation (line 89)
  3. billing.ts - Removes Math.round() from one percentage calculation (line 270) but leaves another similar calculation unchanged (line 195)

This change is particularly important for the usage monitoring system, which uses an 80% warning threshold (WARNING_THRESHOLD constant) to notify users when approaching their limits. Previously, rounding could cause inaccurate threshold detection - for example, 79.8% usage would be rounded down to 79%, potentially delaying important usage warnings. With decimal precision preserved, the system can now trigger notifications and enforce limits more accurately.

The changes integrate with the existing billing infrastructure that handles subscription limits for both individual Pro plans and Team plans, ensuring more precise usage tracking across different subscription tiers.

PR Description Notes:

  • The PR description is incomplete with placeholder text in several sections including Summary, Type of Change, Testing, and Checklist items are unchecked
  • The description mentions "update infra and remove railway" but no infrastructure changes are visible in the modified files

Confidence score: 2/5

  • This PR has inconsistent implementation that could cause billing discrepancies between individual and organization users
  • Score reflects the incomplete nature of the changes and potential for different precision behaviors across the billing system
  • Pay close attention to apps/sim/lib/billing/core/billing.ts which has inconsistent rounding behavior between lines 195 and 270

3 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 5218dd4 into staging Sep 8, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the sim-14-rev branch September 8, 2025 17:46
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…udioai#1283)

* update infra and remove railway

* fix(notifications): increase precision on billing calculations

* Revert "update infra and remove railway"

This reverts commit d17603e.

* cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant