From ee72fa7f5fc0ed5c187758e4b3311ddcacd5f24f Mon Sep 17 00:00:00 2001 From: liuhao1024 Date: Mon, 29 Jun 2026 02:46:20 +0800 Subject: [PATCH] fix(auth): skip legacy OAuth repair when destination profile already exists (#97541) When doctor --fix runs legacy OAuth profile id repair, it picks the single non-legacy OAuth profile as the migration target. If that target profile already exists as a separate user-configured account, the repair unconditionally overwrites it, destroying the account's config (displayName, email) and collapsing two distinct accounts into one. Add a guard: if the destination profile id already exists in cfg.auth.profiles, skip the repair entirely to preserve both accounts. Also pass cfg to resolveAuthProfileMetadata so config-set displayName is preserved when the repair does proceed. Fixes #97522 --- src/agents/auth-profiles/repair.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/agents/auth-profiles/repair.ts b/src/agents/auth-profiles/repair.ts index 0c655a41b742..5a76e2c2b40b 100644 --- a/src/agents/auth-profiles/repair.ts +++ b/src/agents/auth-profiles/repair.ts @@ -123,7 +123,16 @@ export function repairOAuthProfileIdMismatch(params: { return { config: params.cfg, changes: [], migrated: false }; } + // Skip repair if destination profile already exists as a separate + // user-configured account. Overwriting it would destroy the existing + // account's config (displayName, email, etc.) and collapse two distinct + // accounts into one. See #97522. + if (params.cfg.auth?.profiles?.[toProfileId]) { + return { config: params.cfg, changes: [], migrated: false }; + } + const { email: toEmail, displayName: toDisplayName } = resolveAuthProfileMetadata({ + cfg: params.cfg, store: params.store, profileId: toProfileId, });