fix(core): ensure loop detection respects session disable flag (#12347)

This commit is contained in:
Sandy Tao
2025-10-31 09:06:10 -07:00
committed by GitHub
parent b31f6804fe
commit 11e1e98022
2 changed files with 18 additions and 1 deletions

View File

@@ -143,6 +143,19 @@ describe('LoopDetectionService', () => {
}
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
});
it('should stop reporting a loop if disabled after detection', () => {
const event = createToolCallRequestEvent('testTool', { param: 'value' });
for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD; i++) {
service.addAndCheck(event);
}
expect(service.addAndCheck(event)).toBe(true);
service.disableForSession();
// Should now return false even though a loop was previously detected
expect(service.addAndCheck(event)).toBe(false);
});
});
describe('Content Loop Detection', () => {

View File

@@ -123,7 +123,11 @@ export class LoopDetectionService {
* @returns true if a loop is detected, false otherwise
*/
addAndCheck(event: ServerGeminiStreamEvent): boolean {
if (this.loopDetected || this.disabledForSession) {
if (this.disabledForSession) {
return false;
}
if (this.loopDetected) {
return this.loopDetected;
}