Skip to content

Commit ccc56a8

Browse files
authored
fix(core): ensure loop detection respects session disable flag (#12347)
1 parent 0ea0591 commit ccc56a8

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/core/src/services/loopDetectionService.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ describe('LoopDetectionService', () => {
143143
}
144144
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
145145
});
146+
147+
it('should stop reporting a loop if disabled after detection', () => {
148+
const event = createToolCallRequestEvent('testTool', { param: 'value' });
149+
for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD; i++) {
150+
service.addAndCheck(event);
151+
}
152+
expect(service.addAndCheck(event)).toBe(true);
153+
154+
service.disableForSession();
155+
156+
// Should now return false even though a loop was previously detected
157+
expect(service.addAndCheck(event)).toBe(false);
158+
});
146159
});
147160

148161
describe('Content Loop Detection', () => {

packages/core/src/services/loopDetectionService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ export class LoopDetectionService {
123123
* @returns true if a loop is detected, false otherwise
124124
*/
125125
addAndCheck(event: ServerGeminiStreamEvent): boolean {
126-
if (this.loopDetected || this.disabledForSession) {
126+
if (this.disabledForSession) {
127+
return false;
128+
}
129+
130+
if (this.loopDetected) {
127131
return this.loopDetected;
128132
}
129133

0 commit comments

Comments
 (0)