fix(usage): deduplicate native subscription accounts #10700
main fromrefs/pull/10700/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- packages/shared/src/usageLimits.ts line 652OutdatedResolvedby stephenjason89(GitHub profile, opens in a new tab)@@ -644,6 +644,9 @@644644 ): UsageLimitsReport | null {645645 const selected = providers.find((provider) => provider.instanceId === instanceId);646646 if (!selected || !hasProviderUsageLimits(selected.driver, providers, sources)) return null;647- const native = providersWithLimits(providers).filter(648- (provider) => provider.driver === selected.driver,649- );647+ const seenNativeAccounts = new Set<string>();648+ const native = providersWithLimits(providers).filter((provider) => {649+ if (provider.driver !== selected.driver) return false;650+ const key = accountKey(provider.driver, provider.auth.email);651+ if (key === null) return true;652+ if (seenNativeAccounts.has(key)) return false;
- packages/shared/src/usageLimits.ts lines 652 to 654OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -644,6 +644,11 @@644644 ): UsageLimitsReport | null {645645 const selected = providers.find((provider) => provider.instanceId === instanceId);646646 if (!selected || !hasProviderUsageLimits(selected.driver, providers, sources)) return null;647- const native = providersWithLimits(providers).filter(648- (provider) => provider.driver === selected.driver,649- );647+ const seenNativeAccounts = new Set<string>();648+ const native = providersWithLimits(providers).filter((provider) => {649+ if (provider.driver !== selected.driver) return false;650+ const key = accountKey(provider.driver, provider.auth.email);651+ if (key === null) return true;652+ if (seenNativeAccounts.has(key)) return false;653+ seenNativeAccounts.add(key);654+ return true;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
stephenjason89(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/ClaudeProvider.ts line 602OutdatedResolvedby stephenjason89(GitHub profile, opens in a new tab)@@ -592,3 +599,4 @@592599 auth: {593600 status: "authenticated",594601 ...(capabilities.email ? { email: capabilities.email } : {}),602+ ...(capabilities.accountId ? { accountId: capabilities.accountId } : {}),
- apps/server/src/provider/Layers/CodexProvider.ts lines 181 to 183OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -152,0 +163,21 @@163+ }),164+ ),165+});166+const CodexIdentityClaims = Schema.Struct({167+ "https://api.openai.com/auth": Schema.optional(168+ Schema.Struct({169+ chatgpt_account_id: Schema.optional(Schema.String),170+ }),171+ ),172+});173+174+/** Reads only grouping identity from the same native home used by the app server. */175+export const readCodexAccountId = Effect.fn("readCodexAccountId")(function* (176+ homePath: string,177+ environment: NodeJS.ProcessEnv,178+) {179+ const fs = yield* FileSystem.FileSystem;180+ const path = yield* Path.Path;181+ const home = homePath.trim()182+ ? expandHomePath(homePath)183+ : environment.CODEX_HOME || path.join(environment.HOME || NodeOS.homedir(), ".codex");
stephenjason89(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- packages/shared/src/usageLimits.ts line 640OutdatedResolvedby stephenjason89(GitHub profile, opens in a new tab)@@ -630,8 +630,11 @@630630 ): UsageLimitsReport | null {631631 const selected = providers.find((provider) => provider.instanceId === instanceId);632632 if (!selected || !hasProviderUsageLimits(selected.driver, providers, sources)) return null;633- const native = providersWithLimits(providers).filter(634- (provider) => provider.driver === selected.driver,635- );636- const nativeAccounts = new Set(637- native.flatMap((provider) => {633+ const nativeByAccount = new Map<634+ string,635+ { provider: ServerProvider; creditProvider: ServerProvider | null }636+ >();637+ for (const provider of providersWithLimits(providers)) {638+ if (provider.driver !== selected.driver || !provider.usageLimits) continue;639+ const key =640+ accountKey(provider.driver, provider.auth.email, provider.usageLimits) ??
juliusmarminge assignedjuliusmarminge
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this780b62d
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed