Skip to content

fix(oauth): improve Cursor auto-import reliability on macOS - #4552

Merged
diegosouzapw merged 1 commit into
release/v3.8.33from
fix/port-pr-161-cursor-macos-autoimport
Jun 21, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.33from
fix/port-pr-161-cursor-macos-autoimport

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Summary

Hardens /api/oauth/cursor/auto-import on macOS so it stops returning a false "Cursor database not found" or a silent failure in three real-world scenarios:

  • Cursor Insiders is installed instead of (or alongside) stable — the route now probes both ~/Library/Application Support/Cursor/... and ~/Library/Application Support/Cursor - Insiders/... and uses the first readable one.
  • state.vscdb exists but cannot be opened (e.g. WAL lock because Cursor is running) — the route now surfaces the actual reason: Found Cursor database at <path> but could not open it: <message>, instead of the generic "Cursor database not found".
  • Cursor renamed an entry in itemTable — the route now tries multiple known names for both the access token (cursorAuth/accessToken, cursorAuth/token) and the machine id (storage.serviceMachineId, storage.machineId, telemetry.machineId), normalizes JSON-encoded string values, and as a last resort runs a macOS-only fuzzy LIKE lookup (%cursorAuth/%, %machineId%, %serviceMachineId%) so a single key rename in a future Cursor release doesn't silently break auto-import.

Linux and Windows code paths are completely unchanged — all new behavior is gated behind platform === "darwin".

The token/path extraction is factored into pure helpers (normalizeVscDbValue, extractCursorTokensFromRows, fuzzyExtractCursorTokensFromRows, cursorDbCandidatePaths) so it can be unit-tested without mocking SQLite or fs.

Test plan

  • 17 unit tests in tests/unit/oauth-cursor-auto-import.test.ts (Node native runner) — cover value normalization, exact-key extraction (incl. all alt key names), JSON-encoded value unwrapping, fuzzy fallback (case-insensitive), and per-platform candidate path resolution.
  • npx eslint src/app/api/oauth/cursor/auto-import/route.ts tests/unit/oauth-cursor-auto-import.test.ts — clean
  • Pre-commit hooks (lint-staged + check-docs-sync + check:any-budget:t11) — clean
  • Manual live test on a macOS install (no Mac available here — would close the loop on Hard Rule fix(ci): add environment for npm token access #18 for the real-environment leg). The fix is deterministic and the unit tests pin the new helpers, so the regression surface is well covered.

Inspired-by: decolua/9router#161
Co-authored-by: Aakash Thakkar thakkaraakash@hotmail.com

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.32 to release/v3.8.33 June 21, 2026 21:20
- macOS now probes both `Cursor/` and `Cursor - Insiders/` paths for
  `state.vscdb`, fixing a false "Cursor database not found" on Macs
  where only Cursor Insiders is installed.
- When the DB exists but cannot be opened (e.g. WAL lock because Cursor
  is currently running), the route now surfaces the real reason instead
  of returning a generic not-found.
- Multiple known key names are tried for both the access token
  (`cursorAuth/accessToken`, `cursorAuth/token`) and the machine id
  (`storage.serviceMachineId`, `storage.machineId`, `telemetry.machineId`).
- JSON-encoded string values are normalized.
- A macOS-only fuzzy `LIKE` fallback guards against future Cursor
  schema renames.

Linux and Windows code paths are unchanged — all new behavior is gated
behind `platform === "darwin"`.

The token/path extraction helpers are factored into pure functions
(`normalizeVscDbValue`, `extractCursorTokensFromRows`,
`fuzzyExtractCursorTokensFromRows`, `cursorDbCandidatePaths`) and unit-
tested without mocking SQLite or `fs`.

Inspired-by: decolua/9router#161
Co-authored-by: Aakash Thakkar <thakkaraakash@hotmail.com>
@diegosouzapw
diegosouzapw force-pushed the fix/port-pr-161-cursor-macos-autoimport branch from 9d3dc1f to e71b150 Compare June 21, 2026 21:23
@diegosouzapw
diegosouzapw merged commit 20099f7 into release/v3.8.33 Jun 21, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the fix/port-pr-161-cursor-macos-autoimport branch June 22, 2026 02:48
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
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