From bb0db932fab80b2b258564d1d370e1d163633b95 Mon Sep 17 00:00:00 2001 From: Shaojin Wen Date: Sun, 14 Jun 2026 21:17:45 +0800 Subject: [PATCH] fix(core): default GLM-5.2+ and GLM-6.x onward to 1M context (#5103) GLM-5.2 ships a 1M context window, and 1M is becoming the norm for newer GLM releases. The previous `/^glm-5/` rule capped the whole GLM-5 line at 202752, so every new model would need a code change. Make 1M the forward default for GLM-5.2+, GLM-6.x..9.x and two-digit majors, while pinning the confirmed 200K families (GLM-5 / 5.0 / 5.1 and GLM-4.x or older) explicitly. Third-party deploy prefixes (e.g. `pai/glm-5.3`) are already stripped by normalize(), so they match the same rules. Non-numeric names (e.g. glm-z1) stay on the conservative fallback. --- packages/core/src/core/tokenLimits.test.ts | 23 +++++++++++++++++++++- packages/core/src/core/tokenLimits.ts | 8 ++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/core/src/core/tokenLimits.test.ts b/packages/core/src/core/tokenLimits.test.ts index 61b3455194..facfae57a2 100644 --- a/packages/core/src/core/tokenLimits.test.ts +++ b/packages/core/src/core/tokenLimits.test.ts @@ -185,11 +185,32 @@ describe('tokenLimit', () => { }); describe('Zhipu GLM', () => { - it('should return 200K for GLM-5 and GLM-4.7 (latest)', () => { + it('should default GLM-5.2+ and GLM-6.x onward to 1M (forward default)', () => { + expect(tokenLimit('glm-5.2')).toBe(1000000); + expect(tokenLimit('GLM-5.2')).toBe(1000000); + expect(tokenLimit('glm-5.3')).toBe(1000000); + expect(tokenLimit('glm-6')).toBe(1000000); + expect(tokenLimit('glm-6.5')).toBe(1000000); + expect(tokenLimit('glm-10')).toBe(1000000); // two-digit major + }); + + it('should strip third-party deploy prefixes before matching', () => { + expect(tokenLimit('zai/GLM-5.2')).toBe(1000000); + expect(tokenLimit('pai/glm-5.3')).toBe(1000000); + expect(tokenLimit('pai/glm-5.1')).toBe(202752); + }); + + it('should pin GLM-5 / 5.1 and GLM-4.x to 200K', () => { expect(tokenLimit('glm-5')).toBe(202752); + expect(tokenLimit('glm-5.0')).toBe(202752); + expect(tokenLimit('glm-5.1')).toBe(202752); expect(tokenLimit('glm-4.7')).toBe(202752); }); + it('should keep non-numeric GLM names on the conservative fallback', () => { + expect(tokenLimit('glm-z1')).toBe(202752); + }); + it('should return 200K for legacy GLM (fallback)', () => { expect(tokenLimit('glm-4.5')).toBe(202752); expect(tokenLimit('glm-4.5v')).toBe(202752); diff --git a/packages/core/src/core/tokenLimits.ts b/packages/core/src/core/tokenLimits.ts index c0a53c05dd..b42e7dcdc3 100644 --- a/packages/core/src/core/tokenLimits.ts +++ b/packages/core/src/core/tokenLimits.ts @@ -132,8 +132,12 @@ const PATTERNS: Array<[RegExp, TokenCount]> = [ // ------------------- // Zhipu GLM // ------------------- - [/^glm-5/, 202_752 as TokenCount], // GLM-5: exact vendor limit - [/^glm-/, 202_752 as TokenCount], // GLM fallback: 128K + // 1M context is the forward default for new GLM releases (GLM-5.2+, GLM-6.x, + // and beyond) so they need no future code change. Confirmed 200K families + // (GLM-5 / 5.0 / 5.1, GLM-4.x and older) are pinned explicitly first. + [/^glm-5(\.[01])?(-|$)/, 202_752 as TokenCount], // GLM-5 / 5.0 / 5.1: 200K + [/^glm-(?:[5-9]|\d{2,})/, LIMITS['1m']], // GLM-5.2+, 6.x..9.x, 10.x+: 1M + [/^glm-/, 202_752 as TokenCount], // GLM <=4.x / non-numeric fallback: 200K // ------------------- // MiniMax