feat(logging): Add clearcut logging for disabling loop detection (#8503)

This commit is contained in:
Sandy Tao
2025-09-15 14:12:39 -07:00
committed by GitHub
parent 2e12a67198
commit f7ff26ba65
5 changed files with 47 additions and 2 deletions
@@ -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 {