# Can an LLM find infinite loops in agent code just by reading it?

Not reliably. In the study that built the infinite-loop scanner IAL-Scan (arXiv:2607.01641), a Codex coding agent pointed at the same repositories found 50 of the 68 confirmed loops, and prompting a model file by file found 23. The 68 are the failures confirmed from the scanner's own 74 alerts, so it is the reference, not an independent score. Both baselines used gpt-5.5, and the prompt read at most 80 files per project, 3,000 characters each.

Reading also raised false alarms. The coding agent produced 140 alerts and the file-by-file prompt 183, against 74 for the scanner, six of them false. The coding agent hit its timeout or error limit on 75 of 264 projects and used about 142K tokens per project, against 4.2K. Most extra baseline alerts were tutorials, examples, or human-driven loops.

The scanner isn't complete either. Reviewing the baselines' extra alerts confirmed 7 loops it missed, and repeat scanner runs covered 68, 64, and 60. It flags unbounded repeated paths, and can't say whether a run takes one. The baselines ran under a time and size budget, so their counts are minimums. [A looping agent in production](/answers/failure-modes/why-does-an-agent-get-stuck-in-a-loop) shows up in traces, not in code.

---

Sources:
- Hou, Wang, Zhao, and Wang, "When Agents Do Not Stop" (arXiv:2607.01641), Table IV and Section V.C: https://arxiv.org/abs/2607.01641 (fetched 2026-10-27)

Source: https://tessary.ai/answers/agent-loops-research/can-an-llm-find-infinite-loops-in-agent-code-by-reading-it
More on Agent loops research: https://tessary.ai/answers/agent-loops-research
From Tessary, agent reliability for AI agents in production: https://tessary.ai
