You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(shared): usage limits no longer read 0% left while room remains - #44289
The usage limits panel says "0% left" while a limit still has room, and "100% left" after some of it is used. With 99.6% of a Claude session used, the label, bar and tone all read as exhausted although the account can still send. With 0.4% used it reads as untouched. Web (Settings usage, thread details, pooled view) and mobile (usage section, pooled view, widget) all show this.
The cause is remainingPercent in packages/shared/src/usageLimits.ts (line 767), which returns Math.round(100 - usedPercent). Usage percents are often fractional: the Claude adapter turns stream utilization into utilization * 100 and monthly spend into used / limit * 100, so anything under 0.5% on either side rounds to the edge. The pooled remainingPercent in collectLimitPools (line 748) rounds a weighted mean the same way.
The fix keeps the rounding but clamps a window that is neither empty nor exhausted to 1..99, the same edge guard #44246 added to formatPercent. Both the per-window helper and the pooled field now go through it. Exact 0 and 100 used, integer inputs, NaN and out-of-range values behave as before. Exhaustion checks use the raw usedPercent, so nothing that blocks or switches accounts changes. paceRemainingPercent is left alone: it tracks elapsed time, not quota.
New cases in usageLimits.test.ts cover the helper (0, 0.4, 40, 99.6, 100 used) and a two-account pool (0.2/0.4 and 99.5/99.8 used). On origin/main the four fractional cases fail (100 instead of 99, 0 instead of 1); with the fix all 140 tests in the shared usage test files pass, as do the web ThreadDetailsUsage and mobile widget snapshot tests that consume the helper.
Remaining percentages for individual and pooled usage windows now use a shared calculation. Tests cover exact endpoints and fractional values near rounding boundaries.
remainingPercent and pooled windows use a shared calculation. It clamps used percentages to 0–100 and rounds partial remaining values to 1–99. Tests cover individual and pooled usage values, including rounding boundaries.
Usage limits no longer show 0% left while quota remains or 100% left after usage has started. Pooled windows above 100% used now show 0% remaining instead of a negative number, which differs slightly from the PR description. The impact is minor and display-only, so the change is low risk to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the change: usage limits no longer show 0% left while quota remains. It matches the main fix in usageLimits.ts (clamping rounded remaining percentages to 1..99 for partially used windo…
Description check
The description follows the template. It explains the problem with the 0%/100% labels and the rounding cause, and it describes the change, including the clamp, the unchanged exhaustion checks, and the…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the change: usage limits no longer show 0% left while quota remains. It matches the main fix in usageLimits.ts (clamping rounded remaining percentages to 1..99 for partially used windows). It is specific, follows the conventional commit style, and is one sentence.
Full details: Description check
Explanation
The description follows the template. It explains the problem with the 0%/100% labels and the rounding cause, and it describes the change, including the clamp, the unchanged exhaustion checks, and the excluded paceRemainingPercent. It names the scope as a bug fix that builds on #44246. Verification lists the new tests, the failing cases on origin/main, and the passing suites. It does not include a screenshot, but the change is a label fix, so the template does not require one. The template asks for the agent model at the end, and the author gives 'Claude Opus 5.5 via T3 Code'. The Scope section does not link a specific issue for the bug, and it gives no reason for skipping one, so this is a minor gap.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Additional comments: 1
packages/shared/src/usageLimits.ts-748-748: 1
748-748: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Preserve pooled out-of-range results.
For a weekly window at 120% used, the previous calculation returned -20% remaining. remainingOf now clamps it to 0%, hiding the overage. Preserve the previous pooled result for out-of-range inputs and add a regression case. The PR objective says those inputs retain their prior behavior.
Reviewing files that changed from the base of the PR and between 0a47638 and 02c1f83.
Files selected for processing: 2
packages/shared/src/usageLimits.test.ts
packages/shared/src/usageLimits.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Independently checked the proposed calculation change at 02c1f83b276f925d844abea98fe57b8c83270e4e against main 8335c0951b using additional boundary assertions in packages/shared/src/usageLimits.test.ts.
Before the fix: 6 failures, 100 passes. Individual cases at 0.01%, 0.4%, 99.6%, and 99.99% used round to misleading endpoints; pooled cases [0.2, 0.4] and [99.5, 99.8] also fail.
With the proposed implementation and the same assertions: all 106 tests pass.
Exact 0%/100%, out-of-range clamping, and the raw usedPercent >= 100 exhaustion threshold also pass.
Command: vp test run packages/shared/src/usageLimits.test.ts.
This verifies the calculations only. Rendered clients were not verified. Verification was performed with Codex assistance.
Applied from upstream pingdotgg#44289 (not yet merged upstream).
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).takeover:needs-juliusTakeover done; route gate says Julius decidesvouch:unvouchedAuthor is not yet trusted in the VOUCHED list.
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The usage limits panel says "0% left" while a limit still has room, and "100% left" after some of it is used. With 99.6% of a Claude session used, the label, bar and tone all read as exhausted although the account can still send. With 0.4% used it reads as untouched. Web (Settings usage, thread details, pooled view) and mobile (usage section, pooled view, widget) all show this.
The cause is
remainingPercentinpackages/shared/src/usageLimits.ts(line 767), which returnsMath.round(100 - usedPercent). Usage percents are often fractional: the Claude adapter turns stream utilization intoutilization * 100and monthly spend intoused / limit * 100, so anything under 0.5% on either side rounds to the edge. The pooledremainingPercentincollectLimitPools(line 748) rounds a weighted mean the same way.The fix keeps the rounding but clamps a window that is neither empty nor exhausted to 1..99, the same edge guard #44246 added to
formatPercent. Both the per-window helper and the pooled field now go through it. Exact 0 and 100 used, integer inputs, NaN and out-of-range values behave as before. Exhaustion checks use the rawusedPercent, so nothing that blocks or switches accounts changes.paceRemainingPercentis left alone: it tracks elapsed time, not quota.Found while reading
usageLimits.tsafter #44246.New cases in
usageLimits.test.tscover the helper (0, 0.4, 40, 99.6, 100 used) and a two-account pool (0.2/0.4 and 99.5/99.8 used). On origin/main the four fractional cases fail (100 instead of 99, 0 instead of 1); with the fix all 140 tests in the shared usage test files pass, as do the web ThreadDetailsUsage and mobile widget snapshot tests that consume the helper.Claude Opus 5.5 via T3 Code