mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
feat(logging): Add clearcut logging for disabling loop detection (#8503)
This commit is contained in:
@@ -20,6 +20,7 @@ import { LoopDetectionService } from './loopDetectionService.js';
|
||||
|
||||
vi.mock('../telemetry/loggers.js', () => ({
|
||||
logLoopDetected: vi.fn(),
|
||||
logLoopDetectionDisabled: vi.fn(),
|
||||
}));
|
||||
|
||||
const TOOL_CALL_LOOP_THRESHOLD = 5;
|
||||
@@ -134,6 +135,7 @@ describe('LoopDetectionService', () => {
|
||||
|
||||
it('should not detect a loop when disabled for session', () => {
|
||||
service.disableForSession();
|
||||
expect(loggers.logLoopDetectionDisabled).toHaveBeenCalledTimes(1);
|
||||
const event = createToolCallRequestEvent('testTool', { param: 'value' });
|
||||
for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD; i++) {
|
||||
expect(service.addAndCheck(event)).toBe(false);
|
||||
@@ -746,6 +748,7 @@ describe('LoopDetectionService LLM Checks', () => {
|
||||
|
||||
it('should not trigger LLM check when disabled for session', async () => {
|
||||
service.disableForSession();
|
||||
expect(loggers.logLoopDetectionDisabled).toHaveBeenCalledTimes(1);
|
||||
await advanceTurns(30);
|
||||
const result = await service.turnStarted(abortController.signal);
|
||||
expect(result).toBe(false);
|
||||
|
||||
@@ -8,8 +8,15 @@ import type { Content } from '@google/genai';
|
||||
import { createHash } from 'node:crypto';
|
||||
import type { ServerGeminiStreamEvent } from '../core/turn.js';
|
||||
import { GeminiEventType } from '../core/turn.js';
|
||||
import { logLoopDetected } from '../telemetry/loggers.js';
|
||||
import { LoopDetectedEvent, LoopType } from '../telemetry/types.js';
|
||||
import {
|
||||
logLoopDetected,
|
||||
logLoopDetectionDisabled,
|
||||
} from '../telemetry/loggers.js';
|
||||
import {
|
||||
LoopDetectedEvent,
|
||||
LoopDetectionDisabledEvent,
|
||||
LoopType,
|
||||
} from '../telemetry/types.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
|
||||
import {
|
||||
@@ -97,6 +104,10 @@ export class LoopDetectionService {
|
||||
*/
|
||||
disableForSession(): void {
|
||||
this.disabledForSession = true;
|
||||
logLoopDetectionDisabled(
|
||||
this.config,
|
||||
new LoopDetectionDisabledEvent(this.promptId),
|
||||
);
|
||||
}
|
||||
|
||||
private getToolCallKey(toolCall: { name: string; args: object }): string {
|
||||
|
||||
@@ -49,6 +49,7 @@ export enum EventNames {
|
||||
FLASH_FALLBACK = 'flash_fallback',
|
||||
RIPGREP_FALLBACK = 'ripgrep_fallback',
|
||||
LOOP_DETECTED = 'loop_detected',
|
||||
LOOP_DETECTION_DISABLED = 'loop_detection_disabled',
|
||||
NEXT_SPEAKER_CHECK = 'next_speaker_check',
|
||||
SLASH_COMMAND = 'slash_command',
|
||||
MALFORMED_JSON_RESPONSE = 'malformed_json_response',
|
||||
@@ -657,6 +658,15 @@ export class ClearcutLogger {
|
||||
this.flushIfNeeded();
|
||||
}
|
||||
|
||||
logLoopDetectionDisabledEvent(): void {
|
||||
const data: EventValue[] = [];
|
||||
|
||||
this.enqueueLogEvent(
|
||||
this.createLogEvent(EventNames.LOOP_DETECTION_DISABLED, data),
|
||||
);
|
||||
this.flushIfNeeded();
|
||||
}
|
||||
|
||||
logNextSpeakerCheck(event: NextSpeakerCheckEvent): void {
|
||||
const data: EventValue[] = [
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ import type {
|
||||
FlashFallbackEvent,
|
||||
NextSpeakerCheckEvent,
|
||||
LoopDetectedEvent,
|
||||
LoopDetectionDisabledEvent,
|
||||
SlashCommandEvent,
|
||||
ConversationFinishedEvent,
|
||||
KittySequenceOverflowEvent,
|
||||
@@ -441,6 +442,13 @@ export function logLoopDetected(
|
||||
logger.emit(logRecord);
|
||||
}
|
||||
|
||||
export function logLoopDetectionDisabled(
|
||||
config: Config,
|
||||
_event: LoopDetectionDisabledEvent,
|
||||
): void {
|
||||
ClearcutLogger.getInstance(config)?.logLoopDetectionDisabledEvent();
|
||||
}
|
||||
|
||||
export function logNextSpeakerCheck(
|
||||
config: Config,
|
||||
event: NextSpeakerCheckEvent,
|
||||
|
||||
@@ -313,6 +313,18 @@ export class LoopDetectedEvent implements BaseTelemetryEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class LoopDetectionDisabledEvent implements BaseTelemetryEvent {
|
||||
'event.name': 'loop_detection_disabled';
|
||||
'event.timestamp': string;
|
||||
prompt_id: string;
|
||||
|
||||
constructor(prompt_id: string) {
|
||||
this['event.name'] = 'loop_detection_disabled';
|
||||
this['event.timestamp'] = new Date().toISOString();
|
||||
this.prompt_id = prompt_id;
|
||||
}
|
||||
}
|
||||
|
||||
export class NextSpeakerCheckEvent implements BaseTelemetryEvent {
|
||||
'event.name': 'next_speaker_check';
|
||||
'event.timestamp': string;
|
||||
@@ -524,6 +536,7 @@ export type TelemetryEvent =
|
||||
| ApiResponseEvent
|
||||
| FlashFallbackEvent
|
||||
| LoopDetectedEvent
|
||||
| LoopDetectionDisabledEvent
|
||||
| NextSpeakerCheckEvent
|
||||
| KittySequenceOverflowEvent
|
||||
| MalformedJsonResponseEvent
|
||||
|
||||
Reference in New Issue
Block a user