diff --git a/src/plugin.ts b/src/plugin.ts index d70db85..3553a0a 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -313,14 +313,17 @@ async function persistAccountPool( } // Update existing account (this handles both email match and token match cases) - // When email matches but token differs, this effectively replaces the old token + // When email matches but token differs, this effectively replaces the old token. + // Existing (disk) projectId/managedProjectId take priority over incoming + // (OAuth-fetched) values to prevent auto-detected fallbacks from overwriting + // manually configured project IDs. const oldToken = existing.refreshToken; accounts[existingIndex] = { ...existing, email: result.email ?? existing.email, refreshToken: parts.refreshToken, - projectId: parts.projectId ?? existing.projectId, - managedProjectId: parts.managedProjectId ?? existing.managedProjectId, + projectId: existing.projectId ?? parts.projectId, + managedProjectId: existing.managedProjectId ?? parts.managedProjectId, lastUsed: now, }; diff --git a/src/plugin/accounts.ts b/src/plugin/accounts.ts index b4a00d7..b29b432 100644 --- a/src/plugin/accounts.ts +++ b/src/plugin/accounts.ts @@ -462,11 +462,14 @@ export class AccountManager { updateFromAuth(account: ManagedAccount, auth: OAuthAuthDetails): void { const parts = parseRefreshParts(auth.refresh); - // Preserve existing projectId/managedProjectId if not in the new parts + // Preserve existing (disk-loaded) projectId/managedProjectId over runtime values. + // The account's existing values may have been manually configured by the user; + // the auth refresh string may contain an auto-detected fallback that should not + // overwrite those manual edits. account.parts = { ...parts, - projectId: parts.projectId ?? account.parts.projectId, - managedProjectId: parts.managedProjectId ?? account.parts.managedProjectId, + projectId: account.parts.projectId ?? parts.projectId, + managedProjectId: account.parts.managedProjectId ?? parts.managedProjectId, }; account.access = auth.access; account.expires = auth.expires; diff --git a/src/plugin/storage.ts b/src/plugin/storage.ts index 2125830..db4623f 100644 --- a/src/plugin/storage.ts +++ b/src/plugin/storage.ts @@ -151,9 +151,11 @@ function mergeAccountStorage(existing: AccountStorageV3, incoming: AccountStorag accountMap.set(acc.refreshToken, { ...existingAcc, ...acc, - // Preserve manually configured projectId/managedProjectId if not in incoming - projectId: acc.projectId ?? existingAcc.projectId, - managedProjectId: acc.managedProjectId ?? existingAcc.managedProjectId, + // Preserve manually configured projectId/managedProjectId from disk. + // Existing (disk) values take priority over incoming (in-memory) values + // to prevent auto-detected fallback IDs from overwriting user edits. + projectId: existingAcc.projectId ?? acc.projectId, + managedProjectId: existingAcc.managedProjectId ?? acc.managedProjectId, rateLimitResetTimes: { ...existingAcc.rateLimitResetTimes, ...acc.rateLimitResetTimes,