{"slug": "beware-of-infinite-loops-when-using-ai", "title": "Beware of infinite loops when using AI", "summary": "A GitHub user reported that an AI coding agent entered an infinite loop after a workflow message containing the trigger command \"/pi\" caused the agent to repeatedly create new pull requests and messages. The incident, which cost approximately $2 in compute fees before being caught after one hour, occurred because the agent's trigger detection used a \"contains\" check instead of a \"startsWith\" check, allowing the command to be activated by its own output. The user has submitted a pull request to change the trigger detection to prevent similar costly infinite loops for other users.", "body_md": "# docs(README.md): improve 'if' clause to detect /pi#260\n\n[knocte](/knocte)wants to merge 1 commit into\n\n## Conversation\n\nEverywhere in this README.md file where the \"command\" /pi is explained, the verb \"prefix\" is used. So then it is making the user think that the \"bot\" will only be activated when /pi is used at the **beginning** of a github comment if one follows the samples (i.e. in the Quick Start section).\n\nTherefore, it is better to change these samples to use `startsWith`\n\ninstead of `contains`\n\n. On top of that, to prevent the potential (although rare) collision with other possible commands that the user might have set up, or may set up in the future (e.g. \"/pin yadda yadda\", or simply \"/ping\", etc), it's safer to add a space after \"/pi\" in the string: \"/pi \".\n\nBTW, if you're skeptical of merging this PR, then let me tell you a little funny story that wouldn't have happened if this change had been done before I tried your project. (Note: it's funny now, and fortunately I was using a cheap model and a pay-as-you-go provider, and I noticed only 1h after it started happening; but imagine if this happens to someone that is using a frontier model, a provider that takes your credit card, and she goes to bed after the problem starts happening; unlike me that I just went to walk the dog and that's why I caught it only 1h after.)\n\nThe story begins when I tried to instruct Pi via /pi to create a PR that changed my pi.yml workflow to secure it by adding an `if github.actor = ...`\n\nelement to it. That's when I filed [#255](https://github.com/shaftoe/pi-coding-agent-action/issues/255), remember? After that, I then created a PAT and used it in my workflow, and then I instructed Pi via `/pi`\n\nto try to fix the issue again.\n\nThen I decided to go walk my dog. And then when I came back, I found that, this time, it had been able to create PR, but the message to inform me about the work that had been done was written with my user account (because of the new PAT) and it contained the string /pi (because it was telling me that now only my github user can use the \"/pi\" command to trigger the workflow), so then that triggered another workflow, which itself created another PR and another message, which then spawned another workflow, and so on and so forth!\n\nI fortunately only caught the infinite loop after 1h, and only about 2USD were spent (thanks cheap Kimi 🙏). I stopped it right away and it stopped creating PRs for the same thing again and again. So with this PR in place, I HTH to avoid this happening to anyone in the future.\n\n|\n\n[Learn more about bidirectional Unicode characters](https://github.co/hiddenchars)", "url": "https://wpnews.pro/news/beware-of-infinite-loops-when-using-ai", "canonical_source": "https://github.com/shaftoe/pi-coding-agent-action/pull/260", "published_at": "2026-06-04 03:26:37+00:00", "updated_at": "2026-06-04 03:46:38.122677+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-safety", "ai-tools", "ai-products", "ai-agents"], "entities": ["knocte", "GitHub", "Pi", "README.md", "Quick Start"], "alternates": {"html": "https://wpnews.pro/news/beware-of-infinite-loops-when-using-ai", "markdown": "https://wpnews.pro/news/beware-of-infinite-loops-when-using-ai.md", "text": "https://wpnews.pro/news/beware-of-infinite-loops-when-using-ai.txt", "jsonld": "https://wpnews.pro/news/beware-of-infinite-loops-when-using-ai.jsonld"}}