Agent enters infinite loop re-reading the exact same file range with Auto mode)

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Summary

In Agent mode (using Auto / Claude 3.7 Sonnet), the agent fell into a completely unconstrained infinite tool-calling loop. It repeatedly called read_file on the exact same file range dozens/hundreds of times.

While infinite loops are a bug in themselves, the most critical issue is that there was no circuit breaker or loop-detection safeguard in place. Because each turn sends the entire accumulated context back and forth, this runaway loop resulted in a massive, unexpected bill / token consumption in a matter of minutes until I manually aborted it.

Screenshot

(Please attach the screenshot here)

Environment

  • OS: Windows 10/11
  • Cursor Version: [Your Cursor version, e.g. 0.45.x]
  • Mode: Agent Mode
  • Model Setting: Auto (Auto Cost) / Claude 3.7 Sonnet

What Happened

  1. The session underwent automatic context summarization (“Chat context summarized”).
  2. Immediately afterwards, the agent attempted to inspect a file and entered a tight degenerative loop, invoking read_file with identical arguments (service.go L970-1029) over and over again without stopping or replying.
  3. Because the client did not detect that the exact same tool call with identical arguments was running consecutively, it kept executing the calls automatically.
  4. Each repetitive iteration consumed thousands of tokens across the large context window, leading to an alarming surge in API usage/cost within a few minutes.

Critical Concerns & Missing Safeguards

  1. Absence of Client-Side Circuit Breaker:
    A modern AI agent orchestration framework should immediately trip a circuit breaker when it detects repeated identical tool calls (e.g., calling the same tool with the exact same arguments 3–5 times in a row). Cursor currently lacks any hard stop for this behavior.

  2. Severe Financial Risk for Users:
    If a user steps away from their desk or runs tasks in the background, a bug like this could easily drain hundreds of dollars or deplete monthly usage limits in an hour. Even though models can occasionally hallucinate or loop, the hosting platform must protect users from infinite billing loops.

Proposed Solutions / Feature Requests

  • Identical Tool Call Threshold: Automatically interrupt the agent and alert the user if the exact same tool call (same name, same arguments) is repeated more than 3 consecutive times.
  • Cost / Iteration Throttling per Turn: Implement a configurable limit on the maximum number of tool calls allowed within a single user turn without intermediate user approval.
  • Fail-Safe Abort: Post-context compaction, if the model appears to be repeating previous actions, force a fallback prompt to ask the user for guidance rather than continuing autonomously.

Steps to Reproduce

Steps to Reproduce (Non-deterministic)

Due to the non-deterministic nature of LLMs, this issue cannot be 100% deterministically reproduced with a simple prompt. However, it occurred under the following conditions:

  1. Engage in an extensive coding session in Agent mode with heavy tool usage (file reads/writes, bash commands).
  2. Continue until the conversation hits the context window limit and triggers automatic context summarization (Chat context summarized).
  3. Immediately after compaction, the agent attempts to inspect a file (in my case, calling read_file on service.go L970-1029).
  4. Instead of reading once and reasoning over the content, the agent repeatedly re-issues the identical tool call in an unbroken loop.

Note on Reproducibility:
While reproducing the exact model hallucination may be difficult, the bug report does not rely on reproducing the model’s behavior.
The core issue is architectural: Cursor currently lacks a client-side circuit breaker or loop-detection safeguard. Anyone can verify that if a model outputs identical consecutive tool calls, Cursor’s orchestrator will blindly execute them forever without any threshold-based cutoff, exposing users to catastrophic billing spikes.

Screenshots / Screen Recordings

Operating System

Windows 10/11

Version Information

Version: 3.17.19 (user setup)
VS Code Extension API: 1.128.0
Commit: ae3a2b7231dd56194447fe4570dfdc61640b1e90
Date: 2026-08-24T06:42:14.583Z
Layout: IDE
Build Type: Stable
Release Track: Default
Electron: 40.10.3
Chromium: 144.0.7559.236
Node.js: 24.15.0
V8: 14.4.258.32-electron.0
xterm.js: 6.1.0-beta.291
OS: Windows_NT x64 10.0.26200

For AI issues: which model did you use?

Claude 3.7 Sonnet

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @YamazakiYasuhiro thanks for the detailed report, and sorry about the runaway usage.

You’re reading it right: after the context was summarized, the agent kept re-issuing the same file read and nothing stopped it until you did. That’s not intended behavior, and it isn’t anything in your setup. We’ve let the team know and it’s an issue we’re tracking.

For now, picking a specific model in the model picker instead of Auto (Composer works well here) should keep you clear of it.

If you’d like us to look at the usage from that session, email [email protected] referencing this thread.