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
7 changes: 4 additions & 3 deletions packages/core/src/core/geminiChat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ describe('GeminiChat', async () => {
// cheap-gate (real estimate via getHistory + userMessage) →
// splitter (real) → runSideQuery (mocked at baseLlmClient) →
// persistence.
const largeChars = 'x'.repeat(400_000); // ~100K estimated tokens
const largeChars = 'x'.repeat(520_000); // ~130K estimated tokens
const inheritedHistory: Content[] = [
{ role: 'user', parts: [{ text: largeChars }] },
{ role: 'model', parts: [{ text: 'ack' }] },
Expand All @@ -2198,8 +2198,9 @@ describe('GeminiChat', async () => {
chat.setHistory(inheritedHistory);
expect(chat.getLastPromptTokenCount()).toBe(0);

// Default DEFAULT_TOKEN_LIMIT = 128K → auto ≈ 95K. 100K estimate
// crosses, so cheap-gate must let compaction proceed.
// Default DEFAULT_TOKEN_LIMIT = 200K minus the 64K output reservation
// leaves a 136K effective window; 130K crosses the auto threshold, so
// cheap-gate must let compaction proceed.
const generateText = vi.fn().mockResolvedValue({
text: '<state_snapshot>compressed</state_snapshot>',
usage: {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/core/tokenLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ describe('normalize', () => {
});

describe('tokenLimit', () => {
it('uses 200K as the global default context window', () => {
expect(DEFAULT_TOKEN_LIMIT).toBe(200_000);
});

describe('Google Gemini', () => {
it('should return 1M for Gemini 3.x (latest)', () => {
expect(tokenLimit('gemini-3-pro-preview')).toBe(1000000);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/tokenLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type TokenCount = number;
*/
export type TokenLimitType = 'input' | 'output';

export const DEFAULT_TOKEN_LIMIT: TokenCount = 131_072; // 128K (power-of-two)
export const DEFAULT_TOKEN_LIMIT: TokenCount = 200_000; // 200K tokens
export const DEFAULT_OUTPUT_TOKEN_LIMIT: TokenCount = 32_000; // 32K tokens

export const ESCALATED_MAX_TOKENS: TokenCount = 64_000;
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/models/modelConfigResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,4 +959,23 @@ describe('modelConfigResolver', () => {
expect(result.sources['modalities'].kind).toBe('settings');
});
});

describe('[Regression] env-var-only path must apply model context defaults', () => {
it('env-var-only path: contextWindowSize auto-detected for claude-opus-4-6', () => {
const result = resolveModelConfig({
authType: AuthType.USE_OPENAI,
cli: {},
settings: {},
env: {
Comment thread
tanzhenxin marked this conversation as resolved.
Resolved
OPENAI_API_KEY: 'test-key',
OPENAI_BASE_URL: 'http://localhost:8000/v1',
OPENAI_MODEL: 'claude-opus-4-6',
},
});

expect(result.config.model).toBe('claude-opus-4-6');
expect(result.config.contextWindowSize).toBe(200_000);
expect(result.sources['contextWindowSize'].kind).toBe('computed');
});
});
});
6 changes: 6 additions & 0 deletions packages/core/src/models/modelConfigResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AuthType } from '../core/contentGenerator.js';
import type { ContentGeneratorConfig } from '../core/contentGenerator.js';
import { DEFAULT_QWEN_MODEL } from '../config/models.js';
import { defaultModalities } from '../core/modalityDefaults.js';
import { tokenLimit } from '../core/tokenLimits.js';
import {
resolveField,
resolveOptionalField,
Expand Down Expand Up @@ -400,6 +401,11 @@ function resolveGenerationConfig(
}
}

if (result.contextWindowSize === undefined && modelId) {
result.contextWindowSize = tokenLimit(modelId, 'input');
Comment thread
tanzhenxin marked this conversation as resolved.
Resolved
sources['contextWindowSize'] = computedSource('auto-detected from model');
}

// modalities fallback: auto-detect from model when neither modelProvider nor
// settings supplied it. Mirrors modelRegistry.resolveModelConfig and
// modelsConfig.applyResolvedModelDefaults so all paths agree on which models
Expand Down
Loading