fix(agents): warn clearly on unresolved model ids (#39215, thanks @ademczuk)

Co-authored-by: ademczuk <andrew.demczuk@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 22:50:27 +00:00
parent 3a761fbcf8
commit e83094e63f
7 changed files with 105 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import type { OpenClawConfig } from "../config/config.js";
import { resolveAgentModelPrimaryValue, toAgentModelListLike } from "../config/model-input.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import { sanitizeForLog } from "../terminal/ansi.js";
import { resolveAgentConfig, resolveAgentEffectiveModelPrimary } from "./agent-scope.js";
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
import type { ModelCatalogEntry } from "./model-catalog.js";
@@ -302,8 +303,9 @@ export function resolveConfiguredModelRef(params: {
}
// Default to anthropic if no provider is specified, but warn as this is deprecated.
const safeTrimmed = sanitizeForLog(trimmed);
log.warn(
`Model "${trimmed}" specified without provider. Falling back to "anthropic/${trimmed}". Please use "anthropic/${trimmed}" in your config.`,
`Model "${safeTrimmed}" specified without provider. Falling back to "anthropic/${safeTrimmed}". Please use "anthropic/${safeTrimmed}" in your config.`,
);
return { provider: "anthropic", model: trimmed };
}
@@ -316,6 +318,11 @@ export function resolveConfiguredModelRef(params: {
if (resolved) {
return resolved.ref;
}
// User specified a model but it could not be resolved — warn before falling back.
const safe = sanitizeForLog(trimmed);
const safeFallback = sanitizeForLog(`${params.defaultProvider}/${params.defaultModel}`);
log.warn(`Model "${safe}" could not be resolved. Falling back to default "${safeFallback}".`);
}
// Before falling back to the hardcoded default, check if the default provider
// is actually available. If it isn't but other providers are configured, prefer