Skip to content

fix(cursor): distinguish usage failures from expired login - #24575

Merged
nwparker merged 1 commit into
mainfrom
nwparker/cursor-usage-auth-classification-1002
Oct 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/cursor-usage-auth-classification-1002

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2

ELI5

A refused Cursor usage request could tell users their login had expired even when Orca had no evidence of that. Orca now reports the HTTP failure instead.

What Changed

Before, HTTP 401, 403, and any redirect all became “Cursor sign-in expired.” After, only HTTP 401 or the existing local token-expiry check produces that message. Other responses retain their HTTP status and account fingerprint through the existing error result, on both usage endpoints. Requests still use manual redirects; transport failures stay generic and reveal no request credentials.

Why

A forbidden response does not establish token expiry. This independently reimplements the reviewed classification approach from #23626, with credit to @Li-Sanze, rather than adding another account subsystem. It addresses the misleading message; the account-specific failure behind #23612 remains unverified.

Linked Issue

Refs #23612

Visual Proof

N/A — no renderer layout change. Deterministic before/after: a synthetic HTTP 403 previously classified as stale-token and displayed login-expiry guidance; the same response now reports Cursor usage request failed (HTTP 403) with failure kind server. Regression cases cover both the summary and legacy usage routes, and 302/304 responses. No real account response or UI screenshot is claimed.

Testing

  • Automated tests added/updated: ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/rate-limits/cursor-fetcher.test.ts src/main/rate-limits/service-cursor-usage.test.ts — 25 passed.
  • Full ORCA_BACKGROUND_LAUNCH=1 pnpm tc and changed-lines quality gate passed.
  • Live dashboard failure reproduction: original account response not available; no accounts or credentials changed.

AI Disclosure

Implemented with Codex.

Review

Reviewed existing #23626 and tested the current source implementation. Existing 401, local expiry, rate-limit, and server-error behavior remain covered. No HTTP body, cookie, or account identity is exposed.

Agent skill upstream boundary

  • Not applicable; no skill-installer content copied.

Notes

Shared host-side fetcher serves existing desktop/mobile results. No platform-specific logic, wire changes, workspace assumptions, or SSH routing changes. Live usage and rendered notification proof remain outside this narrow classification fix.

Checklist

  • Small and focused
  • Before/after, mechanism, and approach explained
  • N/A visual reason and deterministic behavior proof supplied
  • Self-reviewed for correctness/security/performance
  • Cross-platform and host ownership considered
  • Typecheck, focused tests, changed-lines quality passed; live account reproduction remains a gap

@nwparker
nwparker marked this pull request as ready for review October 2, 2026 07:43
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e19c55c2-227b-4ff0-9bae-078c88b51dce

📥 Commits

Reviewing files that changed from the base of the PR and between 0e811fea1b1d91be1eb02fdd07213d58b5f3c019 and aa07e58.

📒 Files selected for processing (2)
  • src/main/rate-limits/cursor-fetcher.test.ts
  • src/main/rate-limits/cursor-fetcher.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 37a7a773-24f0-48ba-80d0-d64348a74bb0

📥 Commits

Reviewing files that changed from the base of the PR and between 3f37fcc and 0e811fea1b1d91be1eb02fdd07213d58b5f3c019.

📒 Files selected for processing (2)
  • src/main/rate-limits/cursor-fetcher.test.ts
  • src/main/rate-limits/cursor-fetcher.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

fetchDashboardJson now classifies only HTTP 401 responses as expired Cursor sessions. HTTP 403 and 3xx responses use the existing non-OK response handling. Tests cover these statuses and a 403 from the legacy usage endpoint.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0e811

The change preserves expired-session guidance for HTTP 401 while other tested HTTP failures retain server-error handling; the supplied evidence shows no remaining actionable merge risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: separating Cursor usage failures from expired-login errors.
Description check ✅ Passed The description is complete and focused. It covers the user impact, technical change, rationale, linked issue, visual-proof status, testing, AI disclosure, review notes, platform considerations, and c…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pullfrog pullfrog Bot left a comment

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.

ℹ️ No critical issues — one minor test-fidelity suggestion inline.

Reviewed changes

  • Cursor HTTP classification (src/main/rate-limits/cursor-fetcher.ts): the auth branch narrows to res.status === 401, so 403 and redirect-status responses now fall through to the generic Cursor usage request failed (HTTP <status>) result with failureKind: 'server' instead of stale-token. The redirect: 'manual' comment is reworded.
  • Regression coverage (src/main/rate-limits/cursor-fetcher.test.ts): the "redirect → expired sign-in" test is replaced by an it.each([403, 302, 304]) case asserting the HTTP status and server kind, plus a new legacy-endpoint 403 case.

The production change is small and correct: 401 and the local isCursorSessionTokenExpired check still produce the actionable login message, the service stale policy only special-cases rate-limited (so server vs stale-token changes no caching behavior), and the renderer's Cursor stale-token copy is unaffected. The only note below concerns which responses the new test can actually observe.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +122 to +129
it.each([403, 302, 304])('reports HTTP %i without claiming the login expired', async (status) => {
netFetchMock.mockResolvedValueOnce(jsonResponse({}, status, { location: '/login' }))
const limits = await fetchCursorRateLimits({ authReadResult: session() })
expect(limits.usageMetadata?.failureKind).toBe('stale-token')
expect(limits.error).toContain('cursor-agent login')
expect(limits.usageMetadata?.failureKind).toBe('server')
expect(limits.error).toBe(`Cursor usage request failed (HTTP ${status})`)
expect(limits.usageMetadata?.authProvenance).toBeTruthy()
expect(netFetchMock.mock.calls[0]?.[1]?.redirect).toBe('manual')
})

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.

The 302 case reportedly pins a branch production never reaches: real Electron net.fetch with redirect: 'manual' rejects 302/307 before returning a Response (the loopback behavior recorded in #23626, where it was found the login-path matcher could not work for this reason). A dashboard login redirect therefore surfaces as a thrown error → failureKind: 'network', not server/HTTP 302, so this case gives false confidence about redirect handling. The reworded comment at line 85 ("Keep dashboard redirects visible") reads the same way. Consider dropping 302 (or asserting the reject → network path) and narrowing the comment to 304, which does return a response.

@nwparker
nwparker force-pushed the nwparker/cursor-usage-auth-classification-1002 branch from 0e811fe to aa07e58 Compare October 2, 2026 09:13
@nwparker
nwparker merged commit d627b13 into main Oct 2, 2026
31 of 32 checks passed
nwparker added a commit that referenced this pull request Oct 4, 2026
Keep Cursor quota requests tied to the selected account by omitting ambient Electron session credentials. Preserve explicit account cookies and redirect handling.

Credit: Li-Sanze for the original credential-mode fix in #23626, carried through #24575; jjongsta and chengjiaxiao for the reports. Native HTTP/HTTPS cookie isolation, mutation controls and proxy behavior were verified before merging. This does not claim to resolve the separate initial-authentication failure in #23612.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant