feat(billing): bypass plan limits for platform admins#4463
feat(billing): bypass plan limits for platform admins#4463TheodoreSpeaks wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Adds Reviewed by Cursor Bugbot for commit d257bfb. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR introduces a platform-admin bypass across billing gates — usage caps, storage quotas, table limits, workspace creation, and workspace invites — by hoisting a shared
Confidence Score: 4/5Safe to merge with one ordering fix in usage-monitor.ts; all other bypass points are correctly guarded. The admin bypass in usage-monitor.ts is inserted after the org-owner billing-block loop, so a platform admin who is a member of any customer org with a frozen or disputed billing account will be incorrectly told their usage is exceeded and have workflow runs rejected. Every other bypass point is correctly placed and parallelized. apps/sim/lib/billing/calculations/usage-monitor.ts — the isPlatformAdmin check needs to move before the org-owner billing-block loop. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[checkServerSideUsageLimits] --> B{isBillingEnabled?}
B -- No --> Z[return not exceeded]
B -- Yes --> C[Fetch userStats]
C --> D{User billing-blocked?}
D -- Yes --> E[return isExceeded=true]
D -- No --> F[Fetch org memberships]
F --> G{Any org owner billing-blocked?}
G -- Yes --> H[return isExceeded=true admin bypass not yet reached]
G -- No --> I{isPlatformAdmin?}
I -- Yes --> J[return isExceeded=false limit=MAX_SAFE_INT]
I -- No --> K[checkUsageStatus]
K --> L[return usage result]
Reviews (2): Last reviewed commit: "feat(billing): bypass plan limits for pl..." | Re-trigger Greptile |
Extends the platform-admin bypass across usage caps, storage quota, table limits, log retention, and workspace invites. Hoists isPlatformAdmin into a shared helper for reuse.
|
@greptile review |
| if (await isPlatformAdmin(userId)) { | ||
| logger.info('Bypassing usage cap for platform admin', { userId, currentUsage }) | ||
| return { | ||
| isExceeded: false, | ||
| currentUsage, | ||
| limit: Number.MAX_SAFE_INTEGER, | ||
| } | ||
| } |
There was a problem hiding this comment.
Admin bypass after org-owner billing-block check
The isPlatformAdmin guard is placed after the org-owner billing-block loop (lines 304–338). That loop iterates every organization the calling user belongs to and returns isExceeded: true if any org owner is billing-blocked. A platform admin who has been added as a member to a customer org (e.g., for support or testing) whose owner has a billing dispute or frozen account will hit that early-return and never reach the admin bypass — causing their own workflow runs to be rejected as usage-exceeded. Moving the isPlatformAdmin check to before the org-owner loop (or parallelizing it with the initial stats fetch) would prevent the false block.
Summary
user.role === 'admin') bypass per-plan caps across usage, storage, tables, log retention, and workspace invites — in addition to the existing personal workspace bypassisPlatformAdminintolib/auth/platform-admin.ts(+getPlatformAdminUserIdsbulk variant for the list-workspaces endpoint) so the same check serves billing, storage, tables, logs, and invite policycleanup-dispatcherexcludes admin-owned workspaces at the SQL level (LEFT JOIN +ne(user.role, 'admin')) so admin data isn't auto-purged on free/pro/team retention defaultsstorage/limits.tsandtable/billing.ts— no added serial latency on the hot pathType of Change
Testing
bun run lint— cleanbun run check:api-validation:strict— passedbun run type-check— passedbunx vitest run lib/workspaces/policy.test.ts— 23 passed (2 new admin-invite tests)Checklist