Skip to content

fix(core): prevent infinite loops with hard cap on consecutive same-name tool calls#1

Closed
noxymon wants to merge 4 commits into
mainfrom
fix/issue-25671
Closed

fix(core): prevent infinite loops with hard cap on consecutive same-name tool calls#1
noxymon wants to merge 4 commits into
mainfrom
fix/issue-25671

Conversation

@noxymon
Copy link
Copy Markdown
Owner

@noxymon noxymon commented Apr 21, 2026

Summary

This PR implements a hard cap for consecutive calls to the same tool name to prevent infinite loops, especially in "thinking" tools where arguments (like thought numbers) change each time. It also enhances the loop detection event to carry more details to the UI.

Details

  • Added CONSECUTIVE_SAME_TOOL_NAME_THRESHOLD (50) and THINKING_TOOL_LOOP_THRESHOLD (15) to LoopDetectionService.
  • Enhanced loop detection to track consecutive calls to the same tool name even if arguments differ.
  • Updated LoopDetected event to carry specific loop details ( ype, count, detail).
  • Improved UI alerting in useGeminiStream to display detailed information about the detected loop.
  • Added comprehensive unit tests for the new loop detection logic.

Related Issues

Fixes google-gemini#25671

How to Validate

  1. Run
    pm test -w @google/gemini-cli-core -- loopDetectionService.test.ts to verify the logic.
  2. Trigger a loop in the CLI with a tool that changes arguments (e.g. sequentialthinking) and verify it stops after 15 calls with a detailed message.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

noxymon added 4 commits April 22, 2026 03:07
…oops (google-gemini#25671)

- Added CONSECUTIVE_SAME_TOOL_NAME_THRESHOLD (50) and THINKING_TOOL_LOOP_THRESHOLD (15) to LoopDetectionService.
- Enhanced loop detection to track consecutive calls to the same tool name even if arguments differ.
- Updated LoopDetected event to carry specific loop details.
- Improved UI alerting to display detailed information about the detected loop.
@noxymon noxymon closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite Loop in sequentialthinking Tool leading to Quota Exhaustion

1 participant