Skip to content
TypeScript

fix(cursor): ignore a stale Keychain login when Cursor is not installed (#27143)

Riccardo Palleschi22ee8a43e57b
diff --git a/apps/server/src/usage/UsageService.test.ts b/apps/server/src/usage/UsageService.test.ts
index 9600f0a45ad..07a78dc6d50 100644
--- a/apps/server/src/usage/UsageService.test.ts
+++ b/apps/server/src/usage/UsageService.test.ts
@@ -1462,6 +1462,37 @@ describe("UsageService", () => {
}).pipe(Effect.scoped),
);
+ it.effect("ignores a stale macOS Keychain login when Cursor is not installed", () =>
+ Effect.gen(function* () {
+ const { settings, home } = yield* setup;
+ const cursor = makeFakeCursor();
+ cursor.state.error = "Sign in to Cursor again to read account usage.";
+ const readCursorSource = Effect.gen(function* () {
+ const service = yield* makeWithCursor(cursor.read);
+ const summary = yield* service.readSummary({ ...WINDOW, awaitRefresh: true });
+ return cursorSource(summary);
+ }).pipe(
+ Effect.provide(
+ layerService({
+ prefix: "usage-service-cursor-keychain-uninstalled",
+ home,
+ settings: { ...settings, cursorKeychainUsageEnabled: true },
+ platform: "darwin",
+ environment: {},
+ }),
+ ),
+ );
+
+ assert.isUndefined(yield* readCursorSource);
+ assert.lengthOf(cursor.state.calls, 0);
+
+ yield* Effect.promise(() => NodeFSP.mkdir(NodePath.join(home, ".cursor")));
+ const installed = yield* readCursorSource;
+ assert.strictEqual(installed?.message, "Sign in to Cursor again to read account usage.");
+ assert.lengthOf(cursor.state.calls, 1);
+ }).pipe(Effect.scoped),
+ );
+
it.live("ignores stale Cursor file logins when the active credential store differs", () =>
Effect.gen(function* () {
const { settings, home } = yield* setup;
diff --git a/packages/provider-cursor/src/server/CursorUsageAccounts.ts b/packages/provider-cursor/src/server/CursorUsageAccounts.ts
index 8f6b08670ea..07fa215f2ee 100644
--- a/packages/provider-cursor/src/server/CursorUsageAccounts.ts
+++ b/packages/provider-cursor/src/server/CursorUsageAccounts.ts
@@ -186,10 +186,9 @@ const make = Effect.gen(function* () {
retentionStartMs: number,
awaitRefresh: boolean,
) {
- if (
- typeof credential === "string" &&
- !(yield* fileSystem.exists(credential).pipe(Effect.orElseSucceed(() => true)))
- ) {
+ // A Keychain login outlives an uninstalled Cursor, so it also needs Cursor's local directory.
+ const localLogin = typeof credential === "string" ? credential : path.dirname(authPath);
+ if (!(yield* fileSystem.exists(localLogin).pipe(Effect.orElseSucceed(() => true)))) {
return null;
}
yield* ensureLoaded;