@@ -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}
@@ -719,13 +743,16 @@ export async function loadConfig(
719743 dangerouslySkipPermissions =
720744 dangerouslySkipPermissions || settings ?. dangerouslySkipPermissions === true ;
721745 projectedOAuthProviders = applyPersistedOAuthDefaults ( settings , projectedOAuthProviders ) ;
746+ const liveSettings = useOAuthProfiles
747+ ? dropOrphanedOAuthEntries ( settings , projectedOAuthProviders )
748+ : settings ;
722749 const settingsForResolution : Settings | null =
723750 Object . keys ( projectedOAuthProviders ) . length > 0
724751 ? {
725- ...( settings ?? { providers : { } } ) ,
726- providers : { ...( settings ?. providers ?? { } ) , ...projectedOAuthProviders } ,
752+ ...( liveSettings ?? { providers : { } } ) ,
753+ providers : { ...( liveSettings ?. providers ?? { } ) , ...projectedOAuthProviders } ,
727754 }
728- : settings ;
755+ : liveSettings ;
729756
730757 // The per-repo selection file still applies on top of a --config source: that
731758 // file supplies provider definitions, while .corbits/settings.json supplies
0 commit comments