fix(model-resolver): use connected providers cache when model cache is empty (#1227)

- Remove resolved.model from userModel in tools.ts (was bypassing fallback chain)
- Use connected providers cache in model-resolver when availableModels is empty
- Allows proper provider selection (e.g., github-copilot instead of google)
This commit is contained in:
Peïo Thibault
2026-01-29 01:30:19 +01:00
committed by GitHub
parent cfe037782c
commit 2246f13d5a
3 changed files with 51 additions and 19 deletions
+21 -4
View File
@@ -55,10 +55,27 @@ export function resolveModelWithFallback(
// Step 2: Provider fallback chain (with availability check)
if (fallbackChain && fallbackChain.length > 0) {
if (availableModels.size === 0) {
// When model cache is empty, we cannot verify if a provider actually has the model.
// Skip fallback chain entirely and fall through to system default.
// This prevents selecting provider/model combinations that may not exist.
log("No model cache available, skipping fallback chain to use system default")
const connectedProviders = readConnectedProvidersCache()
const connectedSet = connectedProviders ? new Set(connectedProviders) : null
if (connectedSet === null) {
log("Model fallback chain skipped (no connected providers cache) - falling through to system default")
} else {
for (const entry of fallbackChain) {
for (const provider of entry.providers) {
if (connectedSet.has(provider)) {
const model = `${provider}/${entry.model}`
log("Model resolved via fallback chain (no model cache, using connected provider)", {
provider,
model: entry.model,
variant: entry.variant,
})
return { model, source: "provider-fallback", variant: entry.variant }
}
}
}
log("No connected provider found in fallback chain, falling through to system default")
}
}
for (const entry of fallbackChain) {