mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-04 07:07:16 -07:00
testing
This commit is contained in:
@@ -882,6 +882,7 @@ export async function loadCliConfig(
|
||||
ideMode,
|
||||
disableLoopDetection: settings.model?.disableLoopDetection,
|
||||
compressionThreshold: settings.model?.compressionThreshold,
|
||||
forceCompressionRetries: settings.model?.forceCompressionRetries,
|
||||
folderTrust,
|
||||
interactive,
|
||||
trustedFolder,
|
||||
|
||||
@@ -970,6 +970,16 @@ const SETTINGS_SCHEMA = {
|
||||
showInDialog: true,
|
||||
unit: '%',
|
||||
},
|
||||
forceCompressionRetries: {
|
||||
type: 'boolean',
|
||||
label: 'Force Compression Retries',
|
||||
category: 'Model',
|
||||
requiresRestart: true,
|
||||
default: false as boolean,
|
||||
description:
|
||||
'If true, summarization will be retried even if a previous summarization attempt in the session failed. Useful for aggressive compression experiments.',
|
||||
showInDialog: false,
|
||||
},
|
||||
disableLoopDetection: {
|
||||
type: 'boolean',
|
||||
label: 'Disable Loop Detection',
|
||||
|
||||
@@ -598,6 +598,7 @@ export interface ConfigParameters {
|
||||
importFormat?: 'tree' | 'flat';
|
||||
discoveryMaxDirs?: number;
|
||||
compressionThreshold?: number;
|
||||
forceCompressionRetries?: boolean;
|
||||
interactive?: boolean;
|
||||
trustedFolder?: boolean;
|
||||
useBackgroundColor?: boolean;
|
||||
@@ -792,6 +793,7 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
private readonly importFormat: 'tree' | 'flat';
|
||||
private readonly discoveryMaxDirs: number;
|
||||
private readonly compressionThreshold: number | undefined;
|
||||
private readonly forceCompressionRetries: boolean;
|
||||
/** Public for testing only */
|
||||
readonly interactive: boolean;
|
||||
private readonly ptyInfo: string;
|
||||
@@ -1086,6 +1088,7 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
this.importFormat = params.importFormat ?? 'tree';
|
||||
this.discoveryMaxDirs = params.discoveryMaxDirs ?? 200;
|
||||
this.compressionThreshold = params.compressionThreshold;
|
||||
this.forceCompressionRetries = params.forceCompressionRetries ?? false;
|
||||
this.interactive = params.interactive ?? false;
|
||||
this.ptyInfo = params.ptyInfo ?? 'child_process';
|
||||
this.trustedFolder = params.trustedFolder;
|
||||
@@ -2749,6 +2752,10 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
return remoteThreshold;
|
||||
}
|
||||
|
||||
getForceCompressionRetries(): boolean {
|
||||
return this.forceCompressionRetries;
|
||||
}
|
||||
|
||||
async getUserCaching(): Promise<boolean | undefined> {
|
||||
await this.ensureExperimentsLoaded();
|
||||
|
||||
|
||||
@@ -266,7 +266,11 @@ export class ChatCompressionService {
|
||||
const threshold =
|
||||
(await config.getCompressionThreshold()) ??
|
||||
DEFAULT_COMPRESSION_TOKEN_THRESHOLD;
|
||||
if (originalTokenCount < threshold * tokenLimit(model)) {
|
||||
const calculatedLimit = threshold * tokenLimit(model);
|
||||
debugLogger.log(
|
||||
`Checking compression limit: ${originalTokenCount} / ${calculatedLimit} (Threshold: ${threshold})`,
|
||||
);
|
||||
if (originalTokenCount < calculatedLimit) {
|
||||
return {
|
||||
newHistory: null,
|
||||
info: {
|
||||
@@ -286,14 +290,22 @@ export class ChatCompressionService {
|
||||
);
|
||||
|
||||
// If summarization previously failed (and not forced), we only rely on truncation.
|
||||
// We do NOT attempt to invoke the LLM for summarization again to avoid repeated failures/costs.
|
||||
if (hasFailedCompressionAttempt && !force) {
|
||||
// We do NOT attempt to invoke the LLM for summarization again to avoid repeated failures/costs,
|
||||
// unless the 'forceCompressionRetries' config flag is set.
|
||||
if (
|
||||
hasFailedCompressionAttempt &&
|
||||
!force &&
|
||||
!config.getForceCompressionRetries()
|
||||
) {
|
||||
const truncatedTokenCount = estimateTokenCountSync(
|
||||
truncatedHistory.flatMap((c) => c.parts || []),
|
||||
);
|
||||
|
||||
// If truncation reduced the size, we consider it a successful "compression" (truncation only).
|
||||
if (truncatedTokenCount < originalTokenCount) {
|
||||
debugLogger.log(
|
||||
`Compression previously failed but truncation succeeded. Reduced ${originalTokenCount} to ${truncatedTokenCount} tokens.`,
|
||||
);
|
||||
return {
|
||||
newHistory: truncatedHistory,
|
||||
info: {
|
||||
@@ -302,16 +314,19 @@ export class ChatCompressionService {
|
||||
compressionStatus: CompressionStatus.CONTENT_TRUNCATED,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
debugLogger.log(
|
||||
'Compression previously failed and truncation did not reduce size. Bypassing summarization.',
|
||||
);
|
||||
return {
|
||||
newHistory: null,
|
||||
info: {
|
||||
originalTokenCount,
|
||||
newTokenCount: originalTokenCount,
|
||||
compressionStatus: CompressionStatus.NOOP,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
newHistory: null,
|
||||
info: {
|
||||
originalTokenCount,
|
||||
newTokenCount: originalTokenCount,
|
||||
compressionStatus: CompressionStatus.NOOP,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const splitPoint = findCompressSplitPoint(
|
||||
|
||||
Reference in New Issue
Block a user