@@ -299,7 +299,12 @@ function applyLiveOllamaProviderEnvCompat(params: {
299299 const liveBaseUrl = params . env ?. OPENCLAW_LIVE_OLLAMA_BASE_URL ?. trim ( ) ;
300300 const baseUrl = liveBaseUrl || configuredBaseUrl || OLLAMA_DEFAULT_BASE_URL ;
301301 const shouldPreserveConfiguredApiKey =
302- ! liveBaseUrl || Boolean ( configuredBaseUrl && configuredBaseUrl === baseUrl ) ;
302+ ! liveBaseUrl ||
303+ Boolean (
304+ configuredBaseUrl &&
305+ canonicalOllamaCredentialBaseUrl ( configuredBaseUrl ) ===
306+ canonicalOllamaCredentialBaseUrl ( baseUrl ) ,
307+ ) ;
303308 const apiKey = resolveLiveOllamaProviderApiKey ( {
304309 baseUrl,
305310 existingApiKey : existingProvider ?. apiKey ,
@@ -1069,6 +1074,39 @@ describe("explicit live model discovery scope", () => {
10691074 } ) ;
10701075 } ) ;
10711076
1077+ it ( "preserves configured Ollama auth for equivalent live env base URLs" , ( ) => {
1078+ const cfg = {
1079+ plugins : {
1080+ bundledDiscovery : "compat" ,
1081+ } ,
1082+ models : {
1083+ providers : {
1084+ ollama : {
1085+ api : "ollama" ,
1086+ baseUrl : "http://127.0.0.1:11434/v1" ,
1087+ apiKey : { source : "env" , provider : "default" , id : "LOCAL_OLLAMA_API_KEY" } ,
1088+ models : [ ] ,
1089+ } ,
1090+ } ,
1091+ } ,
1092+ } satisfies OpenClawConfig ;
1093+
1094+ const result = applyLiveProviderDiscoveryPluginCompat ( {
1095+ config : cfg ,
1096+ providers : [ "ollama" ] ,
1097+ env : {
1098+ OPENCLAW_LIVE_OLLAMA_BASE_URL : "http://127.0.0.1:11434" ,
1099+ } ,
1100+ } ) ;
1101+
1102+ expect ( result . models ?. providers ?. ollama ) . toEqual ( {
1103+ api : "ollama" ,
1104+ baseUrl : "http://127.0.0.1:11434" ,
1105+ apiKey : { source : "env" , provider : "default" , id : "LOCAL_OLLAMA_API_KEY" } ,
1106+ models : [ ] ,
1107+ } ) ;
1108+ } ) ;
1109+
10721110 it ( "keeps local Ollama live auth on the non-secret marker" , async ( ) => {
10731111 const cfg = applyLiveProviderDiscoveryPluginCompat ( {
10741112 config : {
0 commit comments