fix(agents): Ollama provider always returns synthetic auth when no config exists

When a user sets models.primary = "ollama/..." without running the
provider setup wizard, the provider config entry does not exist in
models.providers. The previous resolveSyntheticLocalProviderAuth()
returned null early because providerConfig was undefined, causing the
auth resolver to throw "No API key found for provider ollama".

This regression (v2026.3.13) made it impossible to use Ollama local
models via direct config without interactive setup.

Fix: check for known local providers (ollama) at the top of the
function, before resolving providerConfig. For ollama, return synthetic
auth regardless of config state.

Fixes: #50759
This commit is contained in:
ziy 2026-03-20 20:52:04 +08:00
parent 4c60956d8e
commit 002011527c

View File

@ -167,6 +167,18 @@ function resolveSyntheticLocalProviderAuth(params: {
cfg: OpenClawConfig | undefined;
provider: string;
}): ResolvedProviderAuth | null {
// Check for known local providers first — these should always get synthetic auth,
// even when the user sets models.primary without running the provider setup wizard
// (i.e., no explicit models.providers.{name} config entry exists).
const normalizedProvider = normalizeProviderId(params.provider);
if (normalizedProvider === "ollama") {
return {
apiKey: OLLAMA_LOCAL_AUTH_MARKER,
source: "models.providers.ollama (synthetic local key)",
mode: "api-key",
};
}
const providerConfig = resolveProviderConfig(params.cfg, params.provider);
if (!providerConfig) {
return null;
@ -180,15 +192,6 @@ function resolveSyntheticLocalProviderAuth(params: {
return null;
}
const normalizedProvider = normalizeProviderId(params.provider);
if (normalizedProvider === "ollama") {
return {
apiKey: OLLAMA_LOCAL_AUTH_MARKER,
source: "models.providers.ollama (synthetic local key)",
mode: "api-key",
};
}
const authOverride = resolveProviderAuthOverride(params.cfg, params.provider);
if (authOverride && authOverride !== "api-key") {
return null;