mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-21 03:43:02 +00:00
fix(core): fall back to default model for invalid Gemini model IDs
This PR implements a validation check in `resolveModel` to ensure that Gemini model IDs are valid before use. ### Problem Outdated or non-existent Gemini model IDs (like `gemini-pro-latest`) can get persisted in a user's `settings.json` if they were ever used or resolved in previous CLI versions. On subsequent startups, the CLI picks this invalid model from settings, leading to "model not supported" API errors. ### Solution Modified `resolveModel` in `packages/core/src/config/models.ts` to verify if a Gemini model ID (starting with `gemini-`) is in the `VALID_GEMINI_MODELS` set. If it's not, the function now falls back to `DEFAULT_GEMINI_MODEL`. Custom (non-Gemini) model IDs are still allowed and returned as-is to maintain flexibility for proxies and other providers. Fixes: #26971 cc @kevinjwang1
This commit is contained in:
@@ -439,6 +439,15 @@ describe('resolveModel', () => {
|
||||
expect(model).toBe(customModel);
|
||||
});
|
||||
|
||||
it('should fallback for known legacy models like gemini-pro-latest', () => {
|
||||
expect(resolveModel('gemini-pro-latest')).toBe(DEFAULT_GEMINI_MODEL);
|
||||
});
|
||||
|
||||
it('should NOT fallback for unknown gemini models that might be future versions', () => {
|
||||
const futureModel = 'gemini-4-pro';
|
||||
expect(resolveModel(futureModel)).toBe(futureModel);
|
||||
});
|
||||
|
||||
it('should handle non-string inputs gracefully', () => {
|
||||
// @ts-expect-error - testing invalid runtime input
|
||||
expect(resolveModel(['a', 'b'])).toBe('b');
|
||||
|
||||
@@ -201,6 +201,12 @@ export function resolveModel(
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for known legacy Gemini model aliases that are no longer supported
|
||||
// by the API but may still be present in user settings.
|
||||
if (resolved === 'gemini-pro-latest') {
|
||||
return DEFAULT_GEMINI_MODEL;
|
||||
}
|
||||
|
||||
if (!hasAccessToPreview && isPreviewModel(resolved)) {
|
||||
// Downgrade to stable models if user lacks preview access.
|
||||
switch (resolved) {
|
||||
|
||||
Reference in New Issue
Block a user