fix(subscription-state): remove dead code, change token route check#4062
fix(subscription-state): remove dead code, change token route check#4062icecrasher321 merged 4 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Adds client handling for 402 responses in Removes dead subscription-state/cost-limit helpers and the Reviewed by Cursor Bugbot for commit 5b9a5c5. Configure here. |
Greptile SummaryThis PR removes dead helper code from the subscription state layer and adjusts the billing check in the speech token route ( Confidence Score: 5/5Safe to merge — all findings are P2 style/type-cleanliness issues that don't affect runtime behaviour. The dead-code removal is clean, the token route auth flow is correct, and the updated imports in chat-payload are properly tested. Only P2 issues remain: redundant logger re-mock in the test, and No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/speech/token/route.ts | Token route now guards usage-limit check behind billingUserId; logic and auth flow look correct. |
| apps/sim/lib/billing/core/subscription.ts | Dead code removed; sendPlanWelcomeEmail still uses any for the subscription parameter, violating the project's no-any rule. |
| apps/sim/lib/billing/index.ts | Barrel updated to remove deleted re-exports; explicit named exports alongside export * from the same module is valid TS (explicit takes precedence). |
| apps/sim/lib/billing/types/index.ts | Types file cleaned up; still contains any in BillingEntity.metadata, SubscriptionAPIResponse.metadata, and BillingError.details. |
| apps/sim/lib/copilot/chat-payload.ts | Now imports getHighestPrioritySubscription directly from the core subscription module; subscription-error path correctly defaults shouldAppendEmailTagline to false. |
| apps/sim/lib/copilot/chat-payload.test.ts | New tests for subscription-path; unnecessarily re-mocks @sim/logger which is already globally mocked in vitest.setup.ts. |
| apps/sim/lib/table/billing.ts | No functional changes; continues to use getHighestPrioritySubscription correctly via the core module. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[POST /api/speech/token] --> B{chatId present?}
B -- Yes --> C[validateChatAuth]
C -- invalid --> D[401 Unauthorized]
C -- valid --> E[billingUserId = chat.ownerId]
B -- No --> F[getSession]
F -- no session --> D
F -- valid --> G[billingUserId = session.user.id]
E --> H{isBillingEnabled?}
G --> H
H -- Yes --> I[checkRateLimitDirect]
I -- exceeded --> J[429 Rate Limit]
I -- ok --> K{billingUserId set?}
H -- No --> K
K -- Yes --> L[checkServerSideUsageLimits]
L -- exceeded --> M[402 Limit Exceeded]
L -- ok --> N[Fetch ElevenLabs token]
K -- No --> N
N -- error --> O[502 Bad Gateway]
N -- ok --> P[recordUsage async]
P --> Q[200 token response]
Comments Outside Diff (2)
-
apps/sim/lib/billing/core/subscription.ts, line 486 (link)subscription: anyviolates the project's no-anyTypeScript rule. Use the schema type from@sim/db(e.g. the inferredSubscriptionrow type) or at minimumunknownwith a type guard. -
apps/sim/lib/billing/types/index.ts, line 88 (link)The open-ended index signature here and in
SubscriptionAPIResponse.metadata/BillingError.detailsviolates the project no-anyrule. Swap all three catch-all fields tounknownso callers must narrow the type before use.
Reviews (1): Last reviewed commit: "fix(subscription-state): remove dead cod..." | Re-trigger Greptile
|
bugbot run |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
1 issue from previous review remains unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5b9a5c5. Configure here.

Summary
Cleanup dead helpers for subscription state.
Type of Change
Testing
Tested manually
Checklist