Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions webview-ui/src/components/settings/ModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ export const ModelPicker = ({
}, [])

useEffect(() => {
if (!selectedModelId && !isInitialized.current) {
const initialValue = modelIds.includes(selectedModelId) ? selectedModelId : defaultModelId
// Only initialize if the field has never been set (undefined), not when it's an empty string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment could be more specific about why this distinction matters. Consider adding context about the IO Intelligence provider issue:

Suggested change
// Only initialize if the field has never been set (undefined), not when it's an empty string
// Only initialize if the field has never been set (undefined), not when it's an empty string
// IO Intelligence can have empty string as a valid state, and we shouldn't reinitialize in that case

if (apiConfiguration[modelIdKey] === undefined && !isInitialized.current) {
const initialValue = defaultModelId
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we're removing the model validation logic here. The original code checked modelIds.includes(selectedModelId) to ensure only valid models were set. Without this check, we might initialize with an invalid model ID. Was this intentional, or should we preserve the validation while fixing the empty string issue?

Suggested change
const initialValue = defaultModelId
// Only initialize if the field has never been set (undefined), not when it's an empty string
if (apiConfiguration[modelIdKey] === undefined && !isInitialized.current) {
const initialValue = modelIds.includes(defaultModelId) ? defaultModelId : modelIds[0] || defaultModelId
setApiConfigurationField(modelIdKey, initialValue, false) // false = automatic initialization

setApiConfigurationField(modelIdKey, initialValue, false) // false = automatic initialization
}

isInitialized.current = true
}, [modelIds, setApiConfigurationField, modelIdKey, selectedModelId, defaultModelId])
}, [modelIds, setApiConfigurationField, modelIdKey, apiConfiguration, defaultModelId])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing the dependency from selectedModelId to apiConfiguration, this effect now runs whenever ANY field in apiConfiguration changes, not just the model ID. This could trigger unnecessary re-initializations. Should we be more specific and use apiConfiguration[modelIdKey] instead?

Suggested change
}, [modelIds, setApiConfigurationField, modelIdKey, apiConfiguration, defaultModelId])
}, [modelIds, setApiConfigurationField, modelIdKey, apiConfiguration[modelIdKey], defaultModelId])


// Cleanup timeouts on unmount to prevent test flakiness
useEffect(() => {
Expand Down
Loading