mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 23:21:27 -07:00
do not persist the fallback model (#15483)
This commit is contained in:
@@ -69,6 +69,7 @@ describe('useQuotaAndFallback', () => {
|
||||
|
||||
setFallbackHandlerSpy = vi.spyOn(mockConfig, 'setFallbackModelHandler');
|
||||
vi.spyOn(mockConfig, 'setQuotaErrorOccurred');
|
||||
vi.spyOn(mockConfig, 'setModel');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -163,6 +164,9 @@ describe('useQuotaAndFallback', () => {
|
||||
const intent = await promise!;
|
||||
expect(intent).toBe('retry_always');
|
||||
|
||||
// Verify setModel was called with isFallbackModel=true
|
||||
expect(mockConfig.setModel).toHaveBeenCalledWith('gemini-flash', true);
|
||||
|
||||
// The pending request should be cleared from the state
|
||||
expect(result.current.proQuotaRequest).toBeNull();
|
||||
expect(mockHistoryManager.addItem).toHaveBeenCalledTimes(1);
|
||||
@@ -274,6 +278,9 @@ describe('useQuotaAndFallback', () => {
|
||||
const intent = await promise!;
|
||||
expect(intent).toBe('retry_always');
|
||||
|
||||
// Verify setModel was called with isFallbackModel=true
|
||||
expect(mockConfig.setModel).toHaveBeenCalledWith('model-B', true);
|
||||
|
||||
// The pending request should be cleared from the state
|
||||
expect(result.current.proQuotaRequest).toBeNull();
|
||||
expect(mockConfig.setQuotaErrorOccurred).toHaveBeenCalledWith(true);
|
||||
@@ -328,6 +335,13 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`,
|
||||
|
||||
const intent = await promise!;
|
||||
expect(intent).toBe('retry_always');
|
||||
|
||||
// Verify setModel was called with isFallbackModel=true
|
||||
expect(mockConfig.setModel).toHaveBeenCalledWith(
|
||||
'gemini-2.5-pro',
|
||||
true,
|
||||
);
|
||||
|
||||
expect(result.current.proQuotaRequest).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -411,6 +425,9 @@ To disable gemini-3-pro-preview, disable "Preview features" in /settings.`,
|
||||
expect(intent).toBe('retry_always');
|
||||
expect(result.current.proQuotaRequest).toBeNull();
|
||||
|
||||
// Verify setModel was called with isFallbackModel=true
|
||||
expect(mockConfig.setModel).toHaveBeenCalledWith('gemini-flash', true);
|
||||
|
||||
// Check for the "Switched to fallback model" message
|
||||
expect(mockHistoryManager.addItem).toHaveBeenCalledTimes(1);
|
||||
const lastCall = (mockHistoryManager.addItem as Mock).mock.calls[0][0];
|
||||
|
||||
@@ -130,9 +130,10 @@ export function useQuotaAndFallback({
|
||||
isDialogPending.current = false; // Reset the flag here
|
||||
|
||||
if (choice === 'retry_always') {
|
||||
// Explicitly set the model to the fallback model to persist the user's choice.
|
||||
// Set the model to the fallback model for the current session.
|
||||
// This ensures the Footer updates and future turns use this model.
|
||||
config.setModel(proQuotaRequest.fallbackModel);
|
||||
// The change is not persisted, so the original model is restored on restart.
|
||||
config.setModel(proQuotaRequest.fallbackModel, true);
|
||||
|
||||
historyManager.addItem(
|
||||
{
|
||||
|
||||
@@ -1641,6 +1641,18 @@ describe('Config getHooks', () => {
|
||||
|
||||
expect(onModelChange).toHaveBeenCalledWith(DEFAULT_GEMINI_MODEL);
|
||||
});
|
||||
|
||||
it('should NOT call onModelChange when a new model is set as a fallback', () => {
|
||||
const onModelChange = vi.fn();
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
onModelChange,
|
||||
});
|
||||
|
||||
config.setModel(DEFAULT_GEMINI_MODEL, true);
|
||||
|
||||
expect(onModelChange).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -877,13 +877,13 @@ export class Config {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
setModel(newModel: string): void {
|
||||
setModel(newModel: string, isFallbackModel: boolean = false): void {
|
||||
if (this.model !== newModel || this._activeModel !== newModel) {
|
||||
this.model = newModel;
|
||||
// When the user explicitly sets a model, that becomes the active model.
|
||||
this._activeModel = newModel;
|
||||
coreEvents.emitModelChanged(newModel);
|
||||
if (this.onModelChange) {
|
||||
if (this.onModelChange && !isFallbackModel) {
|
||||
this.onModelChange(newModel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user