Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions packages/core/src/models/modelConfigResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,186 @@ describe('modelConfigResolver', () => {
expect(result.config.timeout).toBe(60000);
expect(result.sources['timeout'].kind).toBe('modelProviders');
});

@wenshao wenshao Apr 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] Add a test case to verify that QWEN_CODE_API_TIMEOUT_MS correctly overrides settings when authType is AuthType.QWEN_OAUTH. This would have helped catch the missing support in the implementation.\n\n_— Gemini CLI /review_

it('QWEN_CODE_API_TIMEOUT_MS env var overrides settings timeout', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {
apiKey: 'key',
generationConfig: {
timeout: 30000,
},
},
env: {
OPENAI_API_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: '900000',
},
});

expect(result.config.timeout).toBe(900000);
expect(result.sources['timeout'].kind).toBe('env');
expect(result.sources['timeout'].envKey).toBe(
'QWEN_CODE_API_TIMEOUT_MS',
);
});

it('modelProvider timeout wins over QWEN_CODE_API_TIMEOUT_MS', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {},
env: {
MY_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: '900000',
},
modelProvider: {
id: 'model',
name: 'Model',
envKey: 'MY_KEY',
baseUrl: 'https://api.example.com',
generationConfig: {
timeout: 60000,
},
},
});

// modelProvider > env: modelProvider timeout should win
expect(result.config.timeout).toBe(60000);
expect(result.sources['timeout'].kind).toBe('modelProviders');
});

it('QWEN_CODE_API_TIMEOUT_MS applies when modelProvider has no timeout', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {},
env: {
MY_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: '900000',
},
modelProvider: {
id: 'model',
name: 'Model',
envKey: 'MY_KEY',
baseUrl: 'https://api.example.com',
generationConfig: {},
},
});

expect(result.config.timeout).toBe(900000);
expect(result.sources['timeout'].kind).toBe('env');
expect(result.sources['timeout'].envKey).toBe(
'QWEN_CODE_API_TIMEOUT_MS',
);
});

it('ignores invalid QWEN_CODE_API_TIMEOUT_MS values', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {
apiKey: 'key',
generationConfig: {
timeout: 30000,
},
},
env: {
OPENAI_API_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: 'invalid',
},
});

// Should fall back to settings value
expect(result.config.timeout).toBe(30000);
expect(result.sources['timeout'].kind).toBe('settings');
});

it('ignores negative or zero QWEN_CODE_API_TIMEOUT_MS values', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {
apiKey: 'key',
generationConfig: {
timeout: 30000,
},
},
env: {
OPENAI_API_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: '0',
},
});

// Should fall back to settings value
expect(result.config.timeout).toBe(30000);
expect(result.sources['timeout'].kind).toBe('settings');
});

it('timeout is undefined when not configured, default applied in buildClient', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {
apiKey: 'key',
},
env: {
OPENAI_API_KEY: 'key',
},
});

// timeout is undefined here; DEFAULT_TIMEOUT (120000) is applied in
// the provider's buildClient() when timeout is not set.
expect(result.config.timeout).toBeUndefined();
});

it('QWEN_CODE_API_TIMEOUT_MS works for Anthropic auth type', () => {
const result = resolveModelConfig({
authType: AuthType.USE_ANTHROPIC,
cli: {},
settings: {},
env: {
ANTHROPIC_API_KEY: 'key',
ANTHROPIC_BASE_URL: 'https://api.anthropic.com',
QWEN_CODE_API_TIMEOUT_MS: '600000',
},
});

expect(result.config.timeout).toBe(600000);
expect(result.sources['timeout'].kind).toBe('env');
expect(result.sources['timeout'].envKey).toBe(
'QWEN_CODE_API_TIMEOUT_MS',
);
});

it('env var actually changes resolved timeout value', () => {
// Integration-style test: proves the env var flows through to the resolved config
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {
apiKey: 'key',
generationConfig: {
timeout: 30000,
},
},
env: {
OPENAI_API_KEY: 'key',
QWEN_CODE_API_TIMEOUT_MS: '900000',
},
});

// Timeout should be the env var value, not the settings value
expect(result.config.timeout).toBe(900000);
expect(result.sources['timeout'].kind).toBe('env');
expect(result.sources['timeout'].envKey).toBe(
'QWEN_CODE_API_TIMEOUT_MS',
);

// Prove it would be used by the client (default.ts:48 reads config.timeout)
const clientTimeout = result.config.timeout;
expect(clientTimeout).toBe(900000);
});
});

describe('proxy handling', () => {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/models/modelConfigResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ export function resolveModelConfig(
sources,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Critical] The timeout env override is only applied in the non-OAuth path because resolveModelConfig() returns early for AuthType.QWEN_OAUTH before reaching this new block. resolveQwenOAuthConfig() never reads input.env, so Qwen OAuth users still cannot override API timeouts with QWEN_CODE_API_TIMEOUT_MS.

Please move this override into shared generation-config resolution used by both paths, preserving modelProvider > env > settings, and add a Qwen OAuth test for the env timeout override.

— gpt-5.5 via Qwen Code /review

);

// ---- Env override: QWEN_CODE_API_TIMEOUT_MS ----

@wenshao wenshao Apr 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The QWEN_CODE_API_TIMEOUT_MS override logic here is skipped for QWEN_OAUTH due to the early return at the start of resolveModelConfig. Consider moving this logic or applying it within resolveQwenOAuthConfig for consistency across all auth types.\n\n_— Gemini CLI /review_

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Critical] This override is applied only after the AuthType.QWEN_OAUTH early return above, so QWEN_CODE_API_TIMEOUT_MS is ignored for Qwen OAuth sessions. That means the new env override does not work on the default Qwen auth path, even though the downstream provider can consume config.timeout.

Please apply the same env-timeout merge in resolveQwenOAuthConfig() as well, or factor this logic into a shared helper used by both resolver paths after resolveGenerationConfig(), while preserving modelProvider > env > settings precedence.

— gpt-5.5 via Qwen Code /review

// Precedence: modelProvider > env > settings > default (CLI doesn't set timeout)
const modelProviderSetTimeout =
modelProvider?.generationConfig?.timeout !== undefined;
if (!modelProviderSetTimeout) {
const envTimeout = env['QWEN_CODE_API_TIMEOUT_MS'];
if (envTimeout !== undefined) {
const parsed = Number(envTimeout);
if (Number.isFinite(parsed) && parsed > 0) {

@wenshao wenshao Apr 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nice to have] Use Math.floor(Number(envTimeout)) or parseInt(envTimeout, 10) to ensure the timeout value is an integer, which is the standard format for millisecond durations.\n\n_— Gemini CLI /review_

generationConfig.timeout = parsed;
sources['timeout'] = {
kind: 'env',
envKey: 'QWEN_CODE_API_TIMEOUT_MS',
};
}
}
}

// Build final config
const config: ContentGeneratorConfig = {
authType,
Expand Down
Loading