Skip to content

Commit d63640b

Browse files
authored
feat: reset availabilityService on /auth (#14911)
1 parent 2d35017 commit d63640b

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

packages/core/src/availability/modelAvailabilityService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ export class ModelAvailabilityService {
123123
}
124124
}
125125

126+
reset() {
127+
this.health.clear();
128+
}
129+
126130
private setState(model: ModelId, nextState: HealthState) {
127131
this.health.set(model, nextState);
128132
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ describe('Server Config (config.ts)', () => {
355355
expect(config.isInFallbackMode()).toBe(false);
356356
});
357357

358+
it('should reset model availability status', async () => {
359+
const config = new Config(baseParams);
360+
const service = config.getModelAvailabilityService();
361+
const spy = vi.spyOn(service, 'reset');
362+
363+
vi.mocked(createContentGeneratorConfig).mockImplementation(
364+
async (_: Config, authType: AuthType | undefined) =>
365+
({ authType }) as unknown as ContentGeneratorConfig,
366+
);
367+
368+
await config.refreshAuth(AuthType.USE_GEMINI);
369+
370+
expect(spy).toHaveBeenCalled();
371+
});
372+
358373
it('should strip thoughts when switching from GenAI to Vertex', async () => {
359374
const config = new Config(baseParams);
360375

@@ -1516,6 +1531,9 @@ describe('Config getHooks', () => {
15161531
describe('setModel', () => {
15171532
it('should allow setting a pro (any) model and disable fallback mode', () => {
15181533
const config = new Config(baseParams);
1534+
const service = config.getModelAvailabilityService();
1535+
const spy = vi.spyOn(service, 'reset');
1536+
15191537
config.setFallbackMode(true);
15201538
expect(config.isInFallbackMode()).toBe(true);
15211539

@@ -1525,10 +1543,14 @@ describe('Config getHooks', () => {
15251543
expect(config.getModel()).toBe(proModel);
15261544
expect(config.isInFallbackMode()).toBe(false);
15271545
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith(proModel);
1546+
expect(spy).toHaveBeenCalled();
15281547
});
15291548

15301549
it('should allow setting auto model from non-auto model and disable fallback mode', () => {
15311550
const config = new Config(baseParams);
1551+
const service = config.getModelAvailabilityService();
1552+
const spy = vi.spyOn(service, 'reset');
1553+
15321554
config.setFallbackMode(true);
15331555
expect(config.isInFallbackMode()).toBe(true);
15341556

@@ -1537,6 +1559,7 @@ describe('Config getHooks', () => {
15371559
expect(config.getModel()).toBe('auto');
15381560
expect(config.isInFallbackMode()).toBe(false);
15391561
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
1562+
expect(spy).toHaveBeenCalled();
15401563
});
15411564

15421565
it('should allow setting auto model from auto model if it is in the fallback mode', () => {
@@ -1548,6 +1571,9 @@ describe('Config getHooks', () => {
15481571
model: 'auto',
15491572
usageStatisticsEnabled: false,
15501573
});
1574+
const service = config.getModelAvailabilityService();
1575+
const spy = vi.spyOn(service, 'reset');
1576+
15511577
config.setFallbackMode(true);
15521578
expect(config.isInFallbackMode()).toBe(true);
15531579

@@ -1556,6 +1582,7 @@ describe('Config getHooks', () => {
15561582
expect(config.getModel()).toBe('auto');
15571583
expect(config.isInFallbackMode()).toBe(false);
15581584
expect(mockCoreEvents.emitModelChanged).toHaveBeenCalledWith('auto');
1585+
expect(spy).toHaveBeenCalled();
15591586
});
15601587
});
15611588
});

packages/core/src/config/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,9 @@ export class Config {
703703
}
704704

705705
async refreshAuth(authMethod: AuthType) {
706+
// Reset availability service when switching auth
707+
this.modelAvailabilityService.reset();
708+
706709
// Vertex and Genai have incompatible encryption and sending history with
707710
// thoughtSignature from Genai to Vertex will fail, we need to strip them
708711
if (
@@ -828,6 +831,7 @@ export class Config {
828831
coreEvents.emitModelChanged(newModel);
829832
}
830833
this.setFallbackMode(false);
834+
this.modelAvailabilityService.reset();
831835
}
832836

833837
getActiveModel(): string {

0 commit comments

Comments
 (0)