From 93694c6a65dab0ac431b77bf6caadfea4c0e3c78 Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Sat, 27 Sep 2025 05:15:53 -0700 Subject: [PATCH] Make compression algo slightly more aggressive (#10024) --- packages/core/src/core/client.test.ts | 4 ++-- packages/core/src/core/client.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index db897a6f2b..6ab25ce658 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -131,7 +131,7 @@ async function fromAsync(promise: AsyncGenerator): Promise { return results; } -describe('findIndexAfterFraction', () => { +describe('findCompressSplitPoint', () => { it('should throw an error for non-positive numbers', () => { expect(() => findCompressSplitPoint([], 0)).toThrow( 'Fraction must be between 0 and 1', @@ -156,7 +156,7 @@ describe('findIndexAfterFraction', () => { { role: 'model', parts: [{ text: 'This is the fourth message.' }] }, // JSON length: 68 (80%) { role: 'user', parts: [{ text: 'This is the fifth message.' }] }, // JSON length: 65 (100%) ]; - expect(findCompressSplitPoint(history, 0.5)).toBe(2); + expect(findCompressSplitPoint(history, 0.5)).toBe(4); }); it('should handle a fraction of last index', () => { diff --git a/packages/core/src/core/client.ts b/packages/core/src/core/client.ts index 5d3015195e..07e645ba9e 100644 --- a/packages/core/src/core/client.ts +++ b/packages/core/src/core/client.ts @@ -83,7 +83,6 @@ export function findCompressSplitPoint( let lastSplitPoint = 0; // 0 is always valid (compress nothing) let cumulativeCharCount = 0; for (let i = 0; i < contents.length; i++) { - cumulativeCharCount += charCounts[i]; const content = contents[i]; if ( content.role === 'user' && @@ -94,6 +93,7 @@ export function findCompressSplitPoint( } lastSplitPoint = i; } + cumulativeCharCount += charCounts[i]; } // We found no split points after targetCharCount.