mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-04 10:21:02 -07:00
Fix message too large issue. (#19499)
This commit is contained in:
committed by
GitHub
parent
a00eb3b8e6
commit
c276d0c7b6
@@ -240,10 +240,7 @@ export class ChatCompressionService {
|
||||
const curatedHistory = chat.getHistory(true);
|
||||
|
||||
// Regardless of `force`, don't do anything if the history is empty.
|
||||
if (
|
||||
curatedHistory.length === 0 ||
|
||||
(hasFailedCompressionAttempt && !force)
|
||||
) {
|
||||
if (curatedHistory.length === 0) {
|
||||
return {
|
||||
newHistory: null,
|
||||
info: {
|
||||
@@ -285,6 +282,35 @@ export class ChatCompressionService {
|
||||
config,
|
||||
);
|
||||
|
||||
// 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) {
|
||||
const truncatedTokenCount = estimateTokenCountSync(
|
||||
truncatedHistory.flatMap((c) => c.parts || []),
|
||||
);
|
||||
|
||||
// If truncation reduced the size, we consider it a successful "compression" (truncation only).
|
||||
if (truncatedTokenCount < originalTokenCount) {
|
||||
return {
|
||||
newHistory: truncatedHistory,
|
||||
info: {
|
||||
originalTokenCount,
|
||||
newTokenCount: truncatedTokenCount,
|
||||
compressionStatus: CompressionStatus.CONTENT_TRUNCATED,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
newHistory: null,
|
||||
info: {
|
||||
originalTokenCount,
|
||||
newTokenCount: originalTokenCount,
|
||||
compressionStatus: CompressionStatus.NOOP,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const splitPoint = findCompressSplitPoint(
|
||||
truncatedHistory,
|
||||
1 - COMPRESSION_PRESERVE_THRESHOLD,
|
||||
|
||||
Reference in New Issue
Block a user