@@ -101,6 +101,30 @@ function applyPersistedOAuthDefaults(
101101 return merged ;
102102}
103103
104+ // OAuth entries in settings.json carry no credentials; they are only usable
105+ // while a matching auth-store profile exists. Drop orphans in memory so a
106+ // removed profile does not pin resolution to an unauthenticatable provider.
107+ function dropOrphanedOAuthEntries (
108+ settings : Settings | null ,
109+ projected : Record < string , ProviderSettings > ,
110+ ) : Settings | null {
111+ if ( settings === null ) return null ;
112+ const providers = Object . fromEntries (
113+ Object . entries ( settings . providers ) . filter (
114+ ( [ name ] ) =>
115+ ( ! isCodexProviderName ( name ) && ! isXaiProviderName ( name ) ) || projected [ name ] !== undefined ,
116+ ) ,
117+ ) ;
118+ const { defaultProvider, ...rest } = settings ;
119+ return {
120+ ...rest ,
121+ providers,
122+ ...( defaultProvider !== undefined && providers [ defaultProvider ] !== undefined
123+ ? { defaultProvider }
124+ : { } ) ,
125+ } ;
126+ }
127+
104128function hasExaEntry ( servers : MCPServerSettingsEntry [ ] | undefined ) : boolean {
105129 return servers ?. some ( ( server ) => server . name === EXA_MCP_SERVER_NAME ) === true ;
106130}
@@ -715,13 +739,16 @@ export async function loadConfig(
715739 dangerouslySkipPermissions =
716740 dangerouslySkipPermissions || settings ?. dangerouslySkipPermissions === true ;
717741 projectedOAuthProviders = applyPersistedOAuthDefaults ( settings , projectedOAuthProviders ) ;
742+ const liveSettings = useOAuthProfiles
743+ ? dropOrphanedOAuthEntries ( settings , projectedOAuthProviders )
744+ : settings ;
718745 const settingsForResolution : Settings | null =
719746 Object . keys ( projectedOAuthProviders ) . length > 0
720747 ? {
721- ...( settings ?? { providers : { } } ) ,
722- providers : { ...( settings ?. providers ?? { } ) , ...projectedOAuthProviders } ,
748+ ...( liveSettings ?? { providers : { } } ) ,
749+ providers : { ...( liveSettings ?. providers ?? { } ) , ...projectedOAuthProviders } ,
723750 }
724- : settings ;
751+ : liveSettings ;
725752
726753 // The per-repo selection file still applies on top of a --config source: that
727754 // file supplies provider definitions, while .corbits/settings.json supplies
0 commit comments