Skip to content

Commit e26ee80

Browse files
committed
refactor(core): restructure refreshAuth to await experiments before client init
1 parent 9f8e3f3 commit e26ee80

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/core/src/config/config.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,9 +1544,6 @@ export class Config implements McpContext, AgentLoopContext {
15441544
// Only assign to instance properties after successful initialization
15451545
this.contentGeneratorConfig = newContentGeneratorConfig;
15461546

1547-
// Initialize BaseLlmClient now that the ContentGenerator is available
1548-
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
1549-
15501547
const codeAssistServer = getCodeAssistServer(this);
15511548
const quotaPromise = codeAssistServer?.projectId
15521549
? this.refreshUserQuota()
@@ -1562,6 +1559,17 @@ export class Config implements McpContext, AgentLoopContext {
15621559
return undefined;
15631560
});
15641561

1562+
// Fetch experiments and update timeouts before continuing initialization
1563+
const experiments = await this.experimentsPromise;
1564+
1565+
const requestTimeoutMs = this.getRequestTimeoutMs();
1566+
if (requestTimeoutMs !== undefined) {
1567+
updateGlobalFetchTimeouts(requestTimeoutMs);
1568+
}
1569+
1570+
// Initialize BaseLlmClient now that the ContentGenerator and experiments are available
1571+
this.baseLlmClient = new BaseLlmClient(this.contentGenerator, this);
1572+
15651573
await quotaPromise;
15661574

15671575
const authType = this.contentGeneratorConfig.authType;
@@ -1581,14 +1589,6 @@ export class Config implements McpContext, AgentLoopContext {
15811589
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
15821590
}
15831591

1584-
// Fetch admin controls
1585-
const experiments = await this.experimentsPromise;
1586-
1587-
const requestTimeoutMs = this.getRequestTimeoutMs();
1588-
if (requestTimeoutMs !== undefined) {
1589-
updateGlobalFetchTimeouts(requestTimeoutMs);
1590-
}
1591-
15921592
const adminControlsEnabled =
15931593
experiments?.flags[ExperimentFlags.ENABLE_ADMIN_CONTROLS]?.boolValue ??
15941594
false;

packages/core/src/utils/fetch.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ setGlobalDispatcher(
4040
);
4141

4242
export function updateGlobalFetchTimeouts(timeoutMs: number) {
43+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
44+
throw new RangeError(
45+
`Invalid timeout value: ${timeoutMs}. Must be a positive finite number.`,
46+
);
47+
}
4348
defaultTimeout = timeoutMs;
4449
if (currentProxy) {
4550
setGlobalProxy(currentProxy);

0 commit comments

Comments
 (0)