Skip to content

Commit 1f01a42

Browse files
committed
fix: prevent model selection failures when API requests fail (fixes RooCodeInc#3813, RooCodeInc#3874)
- Use Promise.allSettled instead of Promise.all to handle provider API failures gracefully - Fix model initialization logic in ModelPicker component - Ensures models can be selected even when some provider APIs fail
1 parent b8aa4b4 commit 1f01a42

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/core/webview/webviewMessageHandler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,20 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
288288
case "requestRouterModels":
289289
const { apiConfiguration } = await provider.getState()
290290

291-
const [openRouterModels, requestyModels, glamaModels, unboundModels, litellmModels] = await Promise.all([
291+
// Use Promise.allSettled instead of Promise.all to handle API failures gracefully
292+
const results = await Promise.allSettled([
292293
getModels("openrouter", apiConfiguration.openRouterApiKey),
293294
getModels("requesty", apiConfiguration.requestyApiKey),
294295
getModels("glama", apiConfiguration.glamaApiKey),
295296
getModels("unbound", apiConfiguration.unboundApiKey),
296297
getModels("litellm", apiConfiguration.litellmApiKey, apiConfiguration.litellmBaseUrl),
297298
])
298299

300+
// Extract results, using empty objects for any failed requests
301+
const [openRouterModels, requestyModels, glamaModels, unboundModels, litellmModels] = results.map(
302+
(result) => (result.status === "fulfilled" ? result.value : {}),
303+
)
304+
299305
provider.postMessageToWebview({
300306
type: "routerModels",
301307
routerModels: {

webview-ui/src/components/settings/ModelPicker.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ export const ModelPicker = ({
9494
}, [])
9595

9696
useEffect(() => {
97-
if (!selectedModelId && !isInitialized.current) {
98-
const initialValue = modelIds.includes(selectedModelId) ? selectedModelId : defaultModelId
99-
setApiConfigurationField(modelIdKey, initialValue)
97+
if (!isInitialized.current) {
98+
// If no model is selected or the selected model is not in the available models list,
99+
// initialize with the default model
100+
if (!selectedModelId || !modelIds.includes(selectedModelId)) {
101+
setApiConfigurationField(modelIdKey, defaultModelId)
102+
}
103+
isInitialized.current = true
100104
}
101-
102-
isInitialized.current = true
103105
}, [modelIds, setApiConfigurationField, modelIdKey, selectedModelId, defaultModelId])
104106

105107
return (

0 commit comments

Comments
 (0)