Skip to content

Commit 788bb04

Browse files
authored
log fallback mode (#15817)
1 parent 8a0190c commit 788bb04

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/cli/src/ui/hooks/useQuotaAndFallback.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ export function useQuotaAndFallback({
133133
// Set the model to the fallback model for the current session.
134134
// This ensures the Footer updates and future turns use this model.
135135
// The change is not persisted, so the original model is restored on restart.
136-
config.setModel(proQuotaRequest.fallbackModel, true);
137-
136+
config.activateFallbackMode(proQuotaRequest.fallbackModel);
138137
historyManager.addItem(
139138
{
140139
type: MessageType.INFO,

packages/core/src/config/config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ import { ideContextStore } from '../ide/ideContext.js';
6060
import { WriteTodosTool } from '../tools/write-todos.js';
6161
import type { FileSystemService } from '../services/fileSystemService.js';
6262
import { StandardFileSystemService } from '../services/fileSystemService.js';
63-
import { logRipgrepFallback } from '../telemetry/loggers.js';
64-
import { RipgrepFallbackEvent } from '../telemetry/types.js';
63+
import { logRipgrepFallback, logFlashFallback } from '../telemetry/loggers.js';
64+
import {
65+
RipgrepFallbackEvent,
66+
FlashFallbackEvent,
67+
} from '../telemetry/types.js';
6568
import type { FallbackModelHandler } from '../fallback/types.js';
6669
import { ModelAvailabilityService } from '../availability/modelAvailabilityService.js';
6770
import { ModelRouterService } from '../routing/modelRouterService.js';
@@ -911,6 +914,14 @@ export class Config {
911914
this.modelAvailabilityService.reset();
912915
}
913916

917+
activateFallbackMode(model: string): void {
918+
this.setModel(model, true);
919+
const authType = this.getContentGeneratorConfig()?.authType;
920+
if (authType) {
921+
logFlashFallback(this, new FlashFallbackEvent(authType));
922+
}
923+
}
924+
914925
getActiveModel(): string {
915926
return this._activeModel ?? this.model;
916927
}

packages/core/src/config/flashFallback.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
import { describe, it, expect, beforeEach, vi } from 'vitest';
88
import { Config } from './config.js';
99
import { DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_FLASH_MODEL } from './models.js';
10+
import { logFlashFallback } from '../telemetry/loggers.js';
11+
import { FlashFallbackEvent } from '../telemetry/types.js';
1012

1113
import fs from 'node:fs';
1214

1315
vi.mock('node:fs');
16+
vi.mock('../telemetry/loggers.js', () => ({
17+
logFlashFallback: vi.fn(),
18+
logRipgrepFallback: vi.fn(),
19+
}));
1420

1521
describe('Flash Model Fallback Configuration', () => {
1622
let config: Config;
@@ -57,4 +63,15 @@ describe('Flash Model Fallback Configuration', () => {
5763
expect(newConfig.getModel()).toBe('custom-model');
5864
});
5965
});
66+
67+
describe('activateFallbackMode', () => {
68+
it('should set model to fallback and log event', () => {
69+
config.activateFallbackMode(DEFAULT_GEMINI_FLASH_MODEL);
70+
expect(config.getModel()).toBe(DEFAULT_GEMINI_FLASH_MODEL);
71+
expect(logFlashFallback).toHaveBeenCalledWith(
72+
config,
73+
expect.any(FlashFallbackEvent),
74+
);
75+
});
76+
});
6077
});

0 commit comments

Comments
 (0)