Skip to content

Commit b1bbef4

Browse files
SandyTao520scidomino
authored andcommitted
fix(core): ensure loop detection respects session disable flag (#12347)
1 parent 8a72585 commit b1bbef4

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
@@ -142,6 +142,19 @@ describe('LoopDetectionService', () => {
142142
}
143143
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
144144
});
145+
146+
it('should stop reporting a loop if disabled after detection', () => {
147+
const event = createToolCallRequestEvent('testTool', { param: 'value' });
148+
for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD; i++) {
149+
service.addAndCheck(event);
150+
}
151+
expect(service.addAndCheck(event)).toBe(true);
152+
153+
service.disableForSession();
154+
155+
// Should now return false even though a loop was previously detected
156+
expect(service.addAndCheck(event)).toBe(false);
157+
});
145158
});
146159

147160
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)