Skip to content

fix(usage): weight pooled limits by plan capacity - #13111

Open
omar7550 wants to merge 1 commit into
pingdotgg:mainfrom
omar7550:fix/weight-pooled-limits-by-plan
Open

omar7550 wants to merge 1 commit into
pingdotgg:mainfrom
omar7550:fix/weight-pooled-limits-by-plan

Conversation

@omar7550

@omar7550 omar7550 commented Sep 22, 2026 •

Copy link
Copy Markdown

What Changed

poolWindows in packages/shared/src/usageLimits.ts now weights each pooled account by its plan's capacity. The weight comes from the multiplier already in the plan label (ChatGPT Pro 20x Subscription → 20, Max 5x → 5). A label without one (Plus, Claude Pro, hub-reported Claude Subscription) counts as 1. The weights apply to:

  • the pooled used/remaining percent
  • pace (weighted used share vs. weighted elapsed share)
  • each reset's restoresPercent (the "+X% in …" hint and the "Restores" popover row)

The change adds planCapacityWeight and tests for both the helper and a Pro 20x + Plus pool.

Why

Fixes #13110. Pools averaged members evenly, so a Plus account counted as much as a Pro 20x account. Take a Pro 20x account that is fully used plus an untouched Plus account: the pool showed 50% left, but the real figure is about 5% (20 of 21 parts are spent). Web, mobile, and the mobile widget all use collectLimitPools, so fixing it here fixes all three. Pools whose accounts share a plan tier give the same numbers as before, so existing tests are unchanged.

UI Changes

Only the numbers change (pooled percent, pace arrow, "+X% in …" / "Restores +X% of pool"). Layout and segment widths are unchanged. Example: Pro 20x at 100% used + Plus at 0% went from "50% left" to "5% left".

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (numbers only; described above)
  • I included a video for animation/interaction changes (n/a)

Checks run locally: vp test run src/usageLimits.test.ts (shared, 32 passed; the new pool test fails on main with 50 ≠ 5), mobile subscriptionUsageSnapshot.test.ts (12 passed), tsc --noEmit for packages/shared, vp lint, vp fmt, knip --exports on packages/shared.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Pooled usage calculations now account for differences in plan capacity, providing more accurate combined quota and usage percentages.
    • Usage pacing and reset estimates now reflect each account’s plan capacity.
    • Plan capacity multipliers are recognized from plan labels, with standard handling for missing or invalid values.
  • Tests

    • Added coverage for capacity multiplier parsing and weighted pooled-quota calculations.

Pooled Limits averaged each account's window evenly, so a Plus account
counted as much as a Pro 20x one. Weight the pooled share, pace, and
per-reset restore figure by the multiplier in the plan label.

Fixes pingdotgg#13110

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 22, 2026
const first = members[0]!.window;
const usedPercent = members.reduce((sum, m) => sum + m.window.usedPercent, 0) / members.length;
// Each member counts by its plan's capacity, not one vote apiece.
const weightOf = (member: LimitPoolMember) => planCapacityWeight(member.account.plan);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Medium src/usageLimits.ts:366

Pooled usage, pace, and reset-restoration percentages use the wrong tier weight when collectLimitAccounts takes winner.limits from the fresher source but keeps previous.plan ?? next.plan. A Pro window can therefore be weighted as Plus (or vice versa) until the stale source disappears; the merged account's plan must be selected from the same source as limits (or otherwise reconciled with it).

🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/shared/src/usageLimits.ts around line 366:

Pooled usage, pace, and reset-restoration percentages use the wrong tier weight when `collectLimitAccounts` takes `winner.limits` from the fresher source but keeps `previous.plan ?? next.plan`. A Pro window can therefore be weighted as Plus (or vice versa) until the stale source disappears; the merged account's `plan` must be selected from the same source as `limits` (or otherwise reconciled with it).

@macroscopeapp

macroscopeapp Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Would Approve

Macroscope's review found this PR approvable — This is a focused, test-covered correction to pooled usage calculations, with understood impact limited to displayed quota, pace, and reset estimates across existing web and mobile consumers. An unresolved Medium finding separately flags a possible stale plan/limits mismatch during account merging, which remains a blocking correctness concern under repository policy.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2faeaf7d-310f-49ab-9515-f0f52e23276c

📥 Commits

Reviewing files that changed from the base of the PR and between 17e3477 and 0a55175.

📒 Files selected for processing (2)
  • packages/shared/src/usageLimits.test.ts
  • packages/shared/src/usageLimits.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds plan-capacity parsing and applies it to pooled usage, pace, and reset restoration calculations. Tests cover valid and fallback multipliers and verify a Pro 20x account contributes 20 times the capacity of a Plus account.

Changes

Weighted pooled limits

Layer / File(s) Summary
Plan capacity weighting
packages/shared/src/usageLimits.ts
Adds planCapacityWeight and documents reset restoration using capacity-weighted member usage.
Weighted pool calculations and validation
packages/shared/src/usageLimits.ts, packages/shared/src/usageLimits.test.ts
Updates pooled usage, timed averages, pace, and reset restoration calculations. Tests verify multiplier parsing and a pooled result with 5% remaining and 95% used.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to 0a551

No verified merge-blocking risk remains in the weighted pooled usage change.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #13110 requires plan-capacity weighting for pooled usage, pace, and reset restoration. planCapacityWeight parses labels such as 20x and defaults invalid or absent multipliers to 1. `poolWind…
Out of Scope Changes check ✅ Passed The changes are limited to packages/shared/src/usageLimits.ts and its tests. The helper, weighted pool calculations, comments, and tests directly support issue #13110. No unrelated change is shown.
Title check ✅ Passed The title clearly and concisely describes the main change: weighting pooled usage limits by plan capacity.
Description check ✅ Passed The description explains what changed, why it changed, affected calculations, test coverage, and validation results. It follows the required sections and remains focused. The UI section describes nume…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pooled Limits average accounts evenly, ignoring plan size (Pro 20x counts the same as Plus)

1 participant