@@ -160,7 +160,7 @@ import {
160160} from '../code_assist/experiments/experiments.js' ;
161161import { AgentRegistry } from '../agents/registry.js' ;
162162import { AcknowledgedAgentsService } from '../agents/acknowledgedAgents.js' ;
163- import { setGlobalProxy } from '../utils/fetch.js' ;
163+ import { setGlobalProxy , updateGlobalFetchTimeouts } from '../utils/fetch.js' ;
164164import { SubagentTool } from '../agents/subagent-tool.js' ;
165165import { ExperimentFlags } from '../code_assist/experiments/flagNames.js' ;
166166import { debugLogger } from '../utils/debugLogger.js' ;
@@ -1548,9 +1548,6 @@ export class Config implements McpContext, AgentLoopContext {
15481548 // Only assign to instance properties after successful initialization
15491549 this . contentGeneratorConfig = newContentGeneratorConfig ;
15501550
1551- // Initialize BaseLlmClient now that the ContentGenerator is available
1552- this . baseLlmClient = new BaseLlmClient ( this . contentGenerator , this ) ;
1553-
15541551 const codeAssistServer = getCodeAssistServer ( this ) ;
15551552 const quotaPromise = codeAssistServer ?. projectId
15561553 ? this . refreshUserQuota ( )
@@ -1566,6 +1563,17 @@ export class Config implements McpContext, AgentLoopContext {
15661563 return undefined ;
15671564 } ) ;
15681565
1566+ // Fetch experiments and update timeouts before continuing initialization
1567+ const experiments = await this . experimentsPromise ;
1568+
1569+ const requestTimeoutMs = this . getRequestTimeoutMs ( ) ;
1570+ if ( requestTimeoutMs !== undefined ) {
1571+ updateGlobalFetchTimeouts ( requestTimeoutMs ) ;
1572+ }
1573+
1574+ // Initialize BaseLlmClient now that the ContentGenerator and experiments are available
1575+ this . baseLlmClient = new BaseLlmClient ( this . contentGenerator , this ) ;
1576+
15691577 await quotaPromise ;
15701578
15711579 const authType = this . contentGeneratorConfig . authType ;
@@ -1585,9 +1593,6 @@ export class Config implements McpContext, AgentLoopContext {
15851593 this . setModel ( DEFAULT_GEMINI_MODEL_AUTO ) ;
15861594 }
15871595
1588- // Fetch admin controls
1589- const experiments = await this . experimentsPromise ;
1590-
15911596 const adminControlsEnabled =
15921597 experiments ?. flags [ ExperimentFlags . ENABLE_ADMIN_CONTROLS ] ?. boolValue ??
15931598 false ;
@@ -1633,6 +1638,11 @@ export class Config implements McpContext, AgentLoopContext {
16331638 getBaseLlmClient ( ) : BaseLlmClient {
16341639 if ( ! this . baseLlmClient ) {
16351640 // Handle cases where initialization might be deferred or authentication failed
1641+ if ( ! this . experiments ) {
1642+ throw new Error (
1643+ 'BaseLlmClient not initialized. Ensure experiments have been fetched and configuration is ready.' ,
1644+ ) ;
1645+ }
16361646 if ( this . contentGenerator ) {
16371647 this . baseLlmClient = new BaseLlmClient (
16381648 this . getContentGenerator ( ) ,
@@ -3153,6 +3163,21 @@ export class Config implements McpContext, AgentLoopContext {
31533163 ) ;
31543164 }
31553165
3166+ /**
3167+ * Returns the configured default request timeout in milliseconds.
3168+ */
3169+ getRequestTimeoutMs ( ) : number | undefined {
3170+ const flag =
3171+ this . experiments ?. flags ?. [ ExperimentFlags . DEFAULT_REQUEST_TIMEOUT ] ;
3172+ if ( flag ?. intValue !== undefined ) {
3173+ const seconds = parseInt ( flag . intValue , 10 ) ;
3174+ if ( Number . isInteger ( seconds ) && seconds >= 0 ) {
3175+ return seconds * 1000 ; // Convert seconds to milliseconds
3176+ }
3177+ }
3178+ return undefined ;
3179+ }
3180+
31563181 /**
31573182 * Returns whether Gemini 3.1 Flash Lite has been launched.
31583183 *
0 commit comments