summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorSandy Tao <[email protected]>2025-07-16 22:32:48 -0700
committerGitHub <[email protected]>2025-07-17 05:32:48 +0000
commitac8e98511edc89533cf906f87835752c4531423a (patch)
tree4cd322fb96de035e16b7602133f7483f610ab5d7 /packages/core/src
parent9ab44ea9d675cd9d560e22fba50d057f1764f25c (diff)
Fix resetting loop counts on every other event (#4348)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/services/loopDetectionService.test.ts21
-rw-r--r--packages/core/src/services/loopDetectionService.ts1
2 files changed, 21 insertions, 1 deletions
diff --git a/packages/core/src/services/loopDetectionService.test.ts b/packages/core/src/services/loopDetectionService.test.ts
index f0d76166..2d410752 100644
--- a/packages/core/src/services/loopDetectionService.test.ts
+++ b/packages/core/src/services/loopDetectionService.test.ts
@@ -97,6 +97,27 @@ describe('LoopDetectionService', () => {
expect(service.addAndCheck(event3)).toBe(false);
}
});
+
+ it('should not reset tool call counter for other event types', () => {
+ const toolCallEvent = createToolCallRequestEvent('testTool', {
+ param: 'value',
+ });
+ const otherEvent = {
+ type: 'thought',
+ } as unknown as ServerGeminiStreamEvent;
+
+ // Send events just below the threshold
+ for (let i = 0; i < TOOL_CALL_LOOP_THRESHOLD - 1; i++) {
+ expect(service.addAndCheck(toolCallEvent)).toBe(false);
+ }
+
+ // Send a different event type
+ expect(service.addAndCheck(otherEvent)).toBe(false);
+
+ // Send the tool call event again, which should now trigger the loop
+ expect(service.addAndCheck(toolCallEvent)).toBe(true);
+ expect(loggers.logLoopDetected).toHaveBeenCalledTimes(1);
+ });
});
describe('Content Loop Detection', () => {
diff --git a/packages/core/src/services/loopDetectionService.ts b/packages/core/src/services/loopDetectionService.ts
index c1078f69..c4524b3e 100644
--- a/packages/core/src/services/loopDetectionService.ts
+++ b/packages/core/src/services/loopDetectionService.ts
@@ -54,7 +54,6 @@ export class LoopDetectionService {
case GeminiEventType.Content:
return this.checkContentLoop(event.value);
default:
- this.reset();
return false;
}
}