fix(cursor): add REST fallback for Free accounts and fix team inference#497
fix(cursor): add REST fallback for Free accounts and fix team inference#497deep5deep wants to merge 2 commits into
Conversation
This addresses an issue where Cursor Free tier users fail the usage probe due to: 1) missing limit property in Connect RPC response, 2) false positive team-inferred account when pooledLimit is 0. Adds a robust REST/Stripe API fallback to retrieve Free tier usage details.
There was a problem hiding this comment.
1 issue found across 1 file
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
fab047d to
49f9f9c
Compare
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR updates the Cursor plugin usage probe to better support Free-tier accounts and to be more resilient when the Connect API can’t provide limits or can’t be reached.
Changes:
- Introduces a Stripe + REST fallback path when the Connect API call throws (e.g., transport/TLS/HTTP2 issues), returning a best-effort plan label and request usage.
- Refactors Stripe fetching into a shared helper and reuses it for both balance and membership info.
- Fixes team-account inference to require
pooledLimit > 0, preventing Free accounts from being misdetected as Team.
Comments suppressed due to low confidence (1)
plugins/cursor/plugin.js:424
didRefreshis assigned in therefreshcallback but never read anymore. Either remove it, or use it to decide whether to surface a post-refresh failure vs. falling back (to avoid dead code and keep error handling intentional).
let connectApiFailed = false
let didRefresh = false
try {
usageResp = ctx.util.retryOnceOnAuth({
request: (token) => {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -432,9 +438,64 @@ | |||
| }, | |||
| }) | |||
| } catch (e) { | |||
| const lines = [] | ||
| let plan = "Free" | ||
|
|
||
| if (stripeInfo) { | ||
| const membership = stripeInfo.membershipType || stripeInfo.individualMembershipType || "free" | ||
| plan = ctx.fmt.planLabel(membership) || "Free" | ||
|
|
| ctx.host.log.warn("Connect API failed, entering REST fallback: " + String(e)) | ||
| connectApiFailed = true | ||
| } | ||
|
|
||
| if (connectApiFailed) { | ||
| const stripeInfo = fetchStripeInfo(ctx, accessToken) | ||
| const requestUsage = fetchRequestBasedUsage(ctx, accessToken) | ||
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49f9f9cf91
ℹ️ 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".
| ctx.host.log.warn("Connect API failed, entering REST fallback: " + String(e)) | ||
| connectApiFailed = true |
There was a problem hiding this comment.
Re-throw auth/connect failures instead of forcing fallback
This catch block treats every exception from retryOnceOnAuth as a Connect API outage and unconditionally switches to the Free-tier fallback path. In cases like refresh throwing "Token expired"/"Session expired" or transient network failures, the probe no longer fails loud; it can return a synthetic success (Free tier active) when REST/Stripe calls also fail, which misreports logged-out/offline users as active Free accounts and suppresses re-login/error handling.
Useful? React with 👍 / 👎.
|
I took a local pass over the unresolved review feedback and reproduced the issue. Current PR head fails the Cursor plugin test file:
The smallest fix I found is to remove the synthetic fallback for exceptions from Patch that passes locally: diff --git a/plugins/cursor/plugin.js b/plugins/cursor/plugin.js
@@
- let connectApiFailed = false
let didRefresh = false
@@
} catch (e) {
ctx.host.log.warn("connectPost failed: " + String(e))
- throw e
+ if (didRefresh) {
+ throw "Usage request failed after refresh. Try again."
+ }
+ throw "Usage request failed. Check your connection."
}
@@
} catch (e) {
- ctx.host.log.warn("Connect API failed, entering REST fallback: " + String(e))
- connectApiFailed = true
- }
-
- if (connectApiFailed) {
- ...
- return { plan: plan, lines: lines }
+ if (typeof e === "string") throw e
+ ctx.host.log.error("usage request failed: " + String(e))
+ throw "Usage request failed. Check your connection."
}After applying that locally, This should close the Codex P1 and the related Copilot comments: auth/session string errors are re-thrown, non-string request wrapper errors stay user-facing failures, and the PR no longer defaults to |
This pull request addresses an issue where Cursor Free tier users fail the usage probe in OpenUsage.
Problems Addressed:
GetCurrentPeriodUsage) does not return alimitproperty inplanUsage.isTeamAccountcheck matched Free tier users becausespendLimitUsage.pooledLimitis0(which is a number). This caused the plugin to incorrectly attempt a Team/REST fallback.request-based: no usage data availableexception because Free tier users have no fast requests limits in the REST API.Changes:
probefunction so that if the main Connect API request fails (e.g., due to TLS/HTTP2 handshake issues on some systems), it gracefully resolves the Free plan name and total requests using the REST and Stripe APIs.pooledLimitmust be greater than0to prevent matching Free accounts:Summary by cubic
Adds REST + Stripe fallback in the Cursor usage probe to show plan and usage for Free accounts when the Connect API fails or returns no limits, and fixes team inference so Free users aren’t treated as Team. Also consolidates Stripe calls behind a shared helper.
New Features
Bug Fixes
Written for commit 49f9f9c. Summary will update on new commits. Review in cubic