fix: canonicalize subscription entitlements - #134
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5e28136c1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function subscriptionTimestamp(subscription: SubscriptionPlanState): number { | ||
| return subscription.updatedAt ?? subscription.createdAt ?? 0; | ||
| } |
There was a problem hiding this comment.
Avoid using maintenance timestamps to order entitlements
When a user has multiple subscription rows and an older row is repaired, migration/repair_subscriptions.ts sets that row's updatedAt to Date.now() even when merely correcting its customer ID; updateFromWebhook similarly timestamps updates by processing time. This selector therefore makes that historical row canonical over a genuinely newer subscription, so an old canceled row can revoke an active payer's Pro access or an old active row can restore access after cancellation. Use a billing-lifecycle/event ordering field, or keep non-lifecycle maintenance from changing the field used here.
Useful? React with 👍 / 👎.
| .withIndex("by_user", (q) => q.eq("userId", userId)) | ||
| .first(); | ||
| .order("desc") | ||
| .take(20); |
There was a problem hiding this comment.
Include lifetime grants outside the recent-row window
When an account has more than 20 subscription rows, this newest-by-creation window can exclude its durable manual lifetime grant. In particular, grantLifetimeProByEmail patches the oldest by_user row, while all new entitlement readers take only the 20 newest rows before canonicalization; such a user is then treated as free for checkout, quotas, API access, and export despite the helper's lifetime-wins invariant. Query lifetime status separately or use an indexed selection that cannot truncate the winning row.
Useful? React with 👍 / 👎.
Summary
Test Plan
ulimit -v unlimited; pnpm --filter @workspace/backend exec vitest run convex/billing/plans.test.ts --reporter=verbose- passed, 13 testsgit diff --cached --check- passed before commitRisk/Rollback
Known baseline failures
tsc --noEmitattempts produced existing workspace/module-resolution noise across extensions/mobile/UI packages, not tied to this Convex hotfix.pnpm --filter @workspace/backend test -- convex/billing/plans.test.tsalso collected unrelated backend suites and hit existingconvex/valuesmodule-resolution failures; the targetedvitest run convex/billing/plans.test.tscommand passed.