perf(core): fix slow boot by fetching experiments and quota asynchronously (#25758)

Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: David Pierce <davidapierce@google.com>
Co-authored-by: Keith Schaab <keithsc@google.com>
Co-authored-by: Keith Schaab <keith.schaab@gmail.com>
Co-authored-by: Emily Hedlund <ehedlund@google.com>
This commit is contained in:
Spencer
2026-04-23 17:52:58 -04:00
committed by GitHub
parent 69150e87b2
commit 1f73ec70c5
7 changed files with 428 additions and 26 deletions
+4 -1
View File
@@ -960,8 +960,11 @@ describe('Server Config (config.ts)', () => {
});
await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
await config.getExperimentsAsync();
expect(config.getModel()).toBe(PREVIEW_GEMINI_FLASH_MODEL);
await vi.waitFor(() => {
expect(config.getModel()).toBe(PREVIEW_GEMINI_FLASH_MODEL);
});
});
it('should NOT switch to flash model if user has Pro access and model is auto', async () => {
+21 -14
View File
@@ -1590,8 +1590,12 @@ export class Config implements McpContext, AgentLoopContext {
return undefined;
});
// Fetch experiments and update timeouts before continuing initialization
const experiments = await this.experimentsPromise;
const [experiments] = await Promise.all([
this.experimentsPromise,
quotaPromise.catch((e) => {
debugLogger.error('Failed to fetch user quota', e);
}),
]);
const requestTimeoutMs = this.getRequestTimeoutMs();
if (requestTimeoutMs !== undefined) {
@@ -1601,8 +1605,6 @@ export class Config implements McpContext, AgentLoopContext {
// Initialize BaseLlmClient now that the ContentGenerator and experiments are available
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
await quotaPromise;
const authType = this.contentGeneratorConfig.authType;
if (
authType === AuthType.USE_GEMINI ||
@@ -1623,16 +1625,21 @@ export class Config implements McpContext, AgentLoopContext {
const adminControlsEnabled =
experiments?.flags[ExperimentFlags.ENABLE_ADMIN_CONTROLS]?.boolValue ??
false;
const adminControls = await fetchAdminControls(
codeAssistServer,
this.getRemoteAdminSettings(),
adminControlsEnabled,
(newSettings: AdminControlsSettings) => {
this.setRemoteAdminSettings(newSettings);
coreEvents.emitAdminSettingsChanged();
},
);
this.setRemoteAdminSettings(adminControls);
try {
const adminControls = await fetchAdminControls(
codeAssistServer,
this.getRemoteAdminSettings(),
adminControlsEnabled,
(newSettings: AdminControlsSettings) => {
this.setRemoteAdminSettings(newSettings);
coreEvents.emitAdminSettingsChanged();
},
);
this.setRemoteAdminSettings(adminControls);
} catch (e) {
debugLogger.error('Failed to fetch admin controls', e);
}
if ((await this.getProModelNoAccess()) && isAutoModel(this.model)) {
this.setModel(PREVIEW_GEMINI_FLASH_MODEL);
+9 -2
View File
@@ -37,6 +37,7 @@ describe('Tracker Tools Integration', () => {
model: 'gemini-3-flash',
debugMode: false,
});
await config.initialize();
messageBus = new MessageBus(null as unknown as PolicyEngine, false);
});
@@ -120,8 +121,14 @@ describe('Tracker Tools Integration', () => {
);
const tasks = await config.getTrackerService().listTasks();
const parentId = tasks.find((t) => t.title === 'Parent Task')!.id;
const childId = tasks.find((t) => t.title === 'Child Task')!.id;
const parentTask = tasks.find((t) => t.title === 'Parent Task');
const childTask = tasks.find((t) => t.title === 'Child Task');
expect(parentTask).toBeDefined();
expect(childTask).toBeDefined();
const parentId = parentTask!.id;
const childId = childTask!.id;
// Add Dependency
const addDepTool = new TrackerAddDependencyTool(config, messageBus);
+1
View File
@@ -680,6 +680,7 @@ export class TestRig {
key !== 'GEMINI_DEBUG' &&
key !== 'GEMINI_CLI_TEST_VAR' &&
key !== 'GEMINI_CLI_INTEGRATION_TEST' &&
key !== 'GOOGLE_GEMINI_BASE_URL' &&
!key.startsWith('GEMINI_CLI_ACTIVITY_LOG')
) {
delete cleanEnv[key];