Fix auto mode fallback for empty model providers (#316174)

Fix auto mode with empty model providers

Treat an empty current model provider as no provider affinity so Auto Mode still falls back to the first available model with a known endpoint.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Sean Goedecke
2026-06-04 17:13:43 +10:00
committed by GitHub
parent 3842af6c0f
commit 4e9a386ced
2 changed files with 19 additions and 1 deletions
@@ -403,7 +403,7 @@ export class AutomodeService extends Disposable implements IAutomodeService {
}
private _selectDefaultModel(currentModelProvider: string | undefined, availableModels: string[], knownEndpoints: IChatEndpoint[]): IChatEndpoint {
const selectedModel = (currentModelProvider && this._findSameProviderModel(currentModelProvider, availableModels, knownEndpoints))
const selectedModel = (currentModelProvider ? this._findSameProviderModel(currentModelProvider, availableModels, knownEndpoints) : undefined)
?? this._findFirstAvailableModel(availableModels, knownEndpoints);
if (selectedModel) {
return selectedModel;
@@ -433,6 +433,24 @@ describe('AutomodeService', () => {
expect(secondResult).toBe(firstResult);
});
it('should fall back to first available model when the current provider is empty', async () => {
const openaiEndpoint = createEndpoint('gpt-4o', 'OpenAI');
const chamomileEndpoint = createEndpoint('chamomile', '');
mockApiResponse(['chamomile'], 'token-empty-provider');
automodeService = createService();
const chatRequest: Partial<ChatRequest> = {
location: ChatLocation.Panel,
prompt: 'test',
sessionId: 'session-empty-provider'
};
const firstResult = await automodeService.resolveAutoModeEndpoint(chatRequest as ChatRequest, [openaiEndpoint, chamomileEndpoint]);
const secondResult = await automodeService.resolveAutoModeEndpoint(chatRequest as ChatRequest, [openaiEndpoint, chamomileEndpoint]);
expect([firstResult.model, secondResult.model]).toEqual(['chamomile', 'chamomile']);
});
it('should fall back to first known endpoint when no available models match', async () => {
mockApiResponse(['unknown-model-1', 'unknown-model-2']);