Skip to content
Merged
Changes from all commits
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
12 changes: 5 additions & 7 deletions packages/core/src/services/chatCompressionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import { makeChatCompressionEvent } from '../telemetry/types.js';
import { getInitialChatHistory } from '../utils/environmentContext.js';

/**
* Threshold for compression token count as a fraction of the model's token limit.
* If the chat history exceeds this threshold, it will be compressed.
* Default threshold for compression token count as a fraction of the model's
* token limit. If the chat history exceeds this threshold, it will be compressed.
*/
export const COMPRESSION_TOKEN_THRESHOLD = 0.7;
export const DEFAULT_COMPRESSION_TOKEN_THRESHOLD = 0.2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

Changing the default compression threshold from 0.7 to 0.2 breaks an existing unit test. The test case 'should return NOOP if under token threshold and not forced' in packages/core/src/services/chatCompressionService.test.ts is hardcoded to expect the old threshold.

Specifically, the test mocks getLastPromptTokenCount to return 600 and tokenLimit to return 1000. The test comment even states: // Threshold is 0.7 * 1000 = 700. 600 < 700, so NOOP.

With the new default of 0.2, the threshold becomes 200, and 600 is no longer less than the threshold, causing the test to fail. The associated test file needs to be updated to reflect this new default value.


/**
* The fraction of the latest chat history to keep. A value of 0.3
Expand Down Expand Up @@ -104,13 +104,11 @@ export class ChatCompressionService {

const originalTokenCount = uiTelemetryService.getLastPromptTokenCount();

const contextPercentageThreshold =
config.getChatCompression()?.contextPercentageThreshold;

// Don't compress if not forced and we are under the limit.
if (!force) {
const threshold =
contextPercentageThreshold ?? COMPRESSION_TOKEN_THRESHOLD;
config.getChatCompression()?.contextPercentageThreshold ??
DEFAULT_COMPRESSION_TOKEN_THRESHOLD;
if (originalTokenCount < threshold * tokenLimit(model)) {
return {
newHistory: null,
Expand Down