mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 10:34:35 -07:00
fix(core): Improve loop detection for longer repeating patterns (#12505)
This commit is contained in:
@@ -28,7 +28,7 @@ import { debugLogger } from '../utils/debugLogger.js';
|
||||
const TOOL_CALL_LOOP_THRESHOLD = 5;
|
||||
const CONTENT_LOOP_THRESHOLD = 10;
|
||||
const CONTENT_CHUNK_SIZE = 50;
|
||||
const MAX_HISTORY_LENGTH = 1000;
|
||||
const MAX_HISTORY_LENGTH = 5000;
|
||||
|
||||
/**
|
||||
* The number of recent conversation turns to include in the history when asking the LLM to check for a loop.
|
||||
@@ -328,7 +328,7 @@ export class LoopDetectionService {
|
||||
* 2. Verify actual content matches to prevent hash collisions
|
||||
* 3. Track all positions where this chunk appears
|
||||
* 4. A loop is detected when the same chunk appears CONTENT_LOOP_THRESHOLD times
|
||||
* within a small average distance (≤ 1.5 * chunk size)
|
||||
* within a small average distance (≤ 5 * chunk size)
|
||||
*/
|
||||
private isLoopDetectedForChunk(chunk: string, hash: string): boolean {
|
||||
const existingIndices = this.contentStats.get(hash);
|
||||
@@ -353,7 +353,7 @@ export class LoopDetectionService {
|
||||
const totalDistance =
|
||||
recentIndices[recentIndices.length - 1] - recentIndices[0];
|
||||
const averageDistance = totalDistance / (CONTENT_LOOP_THRESHOLD - 1);
|
||||
const maxAllowedDistance = CONTENT_CHUNK_SIZE * 1.5;
|
||||
const maxAllowedDistance = CONTENT_CHUNK_SIZE * 5;
|
||||
|
||||
return averageDistance <= maxAllowedDistance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user