Skip to content
Source
Sign inSign up
pingdotgg/t3code

refactor(usage): Cursor account usage comes from provider-cursor #17578

Mergedjuliusmarmingemerged 1 commit intot3/usage-opencode-reader fromrefs/pull/17578/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

UsageService owned Cursor's account usage: the dashboard reader, the in-memory and persisted account cache, TTL, failure memo, in-flight refresh dedupe, and the login/Keychain gating. Separately, keychainToken.ts in provider-cursor kept module-level memo state and threw a plain Error.

  • These move into a CursorUsageAccounts service in provider-cursor, behind a scan reader on CursorDriver.usage. It persists to the same usage-cursor-account-cache-v1.json under ProviderHost.paths.stateDir, so existing caches survive.
  • cursorKeychainUsageEnabled is read through ProviderHost.settings.
  • keychainToken.ts becomes a CursorKeychain service; its errors are Schema.TaggedErrors.

User-visible messages are unchanged.

Review note: CursorKeychain.layer is provided both in the adapter infrastructure and under layerUsage. Effect memoizes by layer reference, so this should build one instance (one Keychain prompt for usage limits and usage history), but that hasn't been verified at runtime on macOS.

🤖 Generated with Claude Code (Claude Opus 5.5, Claude Code harness)

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.9 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.2 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: aec4a9f · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This production refactor introduces substantial new Cursor usage and Keychain service wiring across the provider runtime, with cache, refresh, and credential behavior spanning multiple packages. It also adds a static-analysis suppression directive, so the change warrants direct human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 6a2aab68-d981-45f7-b46c-bf90a467c0c7

      📥 Commits

      Reviewing files that changed from the base of the PR and between 6c5f9b759c520c544b9a73234ff183025a2ee6b1 and aec4a9fc48c62e7007014d5224313eda4695f4ea.


      📒 Files selected for processing (4)
      • apps/server/src/usage/UsageService.ts
      • packages/provider-core/src/server/usage.ts
      • packages/provider-cursor/src/server/CursorUsageAccounts.ts
      • packages/provider-cursor/src/server/driver.ts

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



      📝 Walkthrough

      Walkthrough

      Cursor account-usage reading, Keychain access, and persisted scan caching now reside in the provider package. The server registers Cursor as a built-in usage driver. UsageService removes its dedicated Cursor account-refresh and cache path.

      Changes

      Cursor provider usage

      Layer / File(s)Summary
      Keychain access and account reading
      packages/provider-cursor/src/server/CursorKeychain.ts, packages/provider-cursor/src/server/CursorAccountReader.ts, packages/provider-cursor/src/server/accountUsage.ts, packages/provider-cursor/src/server/usageLimits.ts, packages/provider-cursor/package.json, packages/provider-cursor/src/server.ts, packages/provider-cursor/src/server/*test.ts
      Adds a Keychain service that shares in-flight reads, caches non-null tokens for five minutes, and reports timeout or read errors. Adds CursorAccountReader and uses the Keychain service for usage-limit reads. Account-usage tests cover pagination, response validation, and failure paths. The package exports the new server modules.
      Cached Cursor usage scans
      packages/provider-cursor/src/server/CursorUsageAccounts.ts, packages/provider-cursor/src/server/accountCache.ts, packages/provider-cursor/src/server/accountCache.test.ts
      Adds per-credential persisted usage caches, refresh coordination, failure handling, and filtered scan results.
      Provider and server wiring
      packages/provider-cursor/src/server/driver.ts, packages/provider-cursor/src/server/driver.test.ts, apps/server/src/provider/*, apps/server/src/provider/builtInDrivers.ts, apps/server/src/server.ts
      CursorDriver delegates usage scans to CursorUsageAccounts and includes CursorKeychain in its environment. The server registers Cursor in its built-in drivers and provides the provider usage layers.
      UsageService migration and tests
      packages/provider-core/src/server/usage.ts, apps/server/src/usage/UsageService.ts, apps/server/src/usage/UsageService.test.ts, apps/server/src/usage/*test.ts
      ProviderUsageScanInput now includes a settings snapshot. UsageService removes Cursor-specific account-cache persistence and refresh logic. Usage-service tests use the provider account layer; Cursor account-history tests are removed from the server usage tests.

      Priority: ⬇️ Low

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Refactor

      Sequence Diagram(s)

      sequenceDiagram
        participant CursorDriver
        participant CursorUsageAccounts
        participant CursorAccountReader
        participant CursorKeychain
        participant readCursorAccountUsage
        CursorDriver->>CursorUsageAccounts: scan window and refresh options
        CursorUsageAccounts->>CursorAccountReader: read account history
        CursorAccountReader->>CursorKeychain: retrieve token for Keychain credentials
        CursorAccountReader->>readCursorAccountUsage: read usage for the requested time range
        readCursorAccountUsage-->>CursorUsageAccounts: account usage result
        CursorUsageAccounts-->>CursorDriver: filtered usage scan

      Merge Risk: ⚪ Minimal · up to aec4a

      Cursor usage tracking moves into the Cursor provider package, and existing caches are preserved. No concrete defects were identified, so the change appears ready to merge. Someone with a Mac should confirm that the Keychain prompt appears only once.

      Pre-merge checks | Passed 3 | Failed 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Description checkWarningThe description explains the problem and the planned change, but it does not include the required Scope and approval or Verification sections. It also does not state focused test results or manual che…Add the required Problem, Change, Scope and approval, and Verification sections. Include the triaged issue or maintainer approval, focused test commands with observed results, and any checks not performed, including the unverified macOS lay…
      ✅ Passed checks (3 passed)
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly and concisely describes the main change: moving Cursor account usage handling into provider-cursor.

      Full details: Description check

      Explanation

      The description explains the problem and the planned change, but it does not include the required Scope and approval or Verification sections. It also does not state focused test results or manual checks.

      Resolution

      Add the required Problem, Change, Scope and approval, and Verification sections. Include the triaged issue or maintainer approval, focused test commands with observed results, and any checks not performed, including the unverified macOS layer-memoization behavior.



      • Fix all pre-merge checks with AI
      ✨ Finishing Touches 💡 1
      🛠️ Fix failing CI checks 💡
      • Commit to this branch
      • Create a new PR

      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR

      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR


      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    6. juliusmarminge merged this5a9c664

    7. juliusmarminge closed this

Sign in to join this conversation.