From 8afad737ba1a4d4443f6946611bd2ebf6aeb7fa6 Mon Sep 17 00:00:00 2001 From: latte Date: Mon, 29 Dec 2025 13:12:19 +0000 Subject: [PATCH] fix: Prevent bot self-trigger infinite loops in all workflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL FIX: Bot was triggering itself causing 10+ duplicate runs Problem: - When bot posts comments containing @codebot (e.g., help responses, PR reviews) - Workflows trigger on those bot comments - Bot responds again with @codebot mention - Infinite loop → 10+ duplicate workflow runs → excessive API costs Solution: - Added github.event.comment.user.login != 'Bartender' to all workflow conditions - Prevents bot from reacting to its own comments - Bot username 'Bartender' is now hardcoded in workflows Changes: - .gitea/workflows/ai-comment-reply.yml: Added bot username check - .gitea/workflows/ai-chat.yml: Added bot username check - .gitea/workflows/ai-issue-triage.yml: Added bot username check - CLAUDE.md: Documented bot self-trigger prevention and username update instructions - README.md: Added Step 3 to bot customization with critical warning Impact: - Eliminates infinite loop scenarios - Prevents excessive API costs from duplicate runs - Workflows only trigger on human user comments Note: If bot username changes from 'Bartender', all three workflow files must be updated. --- .gitea/workflows/ai-chat.yml | 2 ++ .gitea/workflows/ai-comment-reply.yml | 2 ++ .gitea/workflows/ai-issue-triage.yml | 5 ++++- CLAUDE.md | 16 +++++++++++++++- README.md | 9 +++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ai-chat.yml b/.gitea/workflows/ai-chat.yml index ea2ad47..19b7918 100644 --- a/.gitea/workflows/ai-chat.yml +++ b/.gitea/workflows/ai-chat.yml @@ -17,7 +17,9 @@ jobs: ai-chat: # Only run if comment mentions the bot but NOT a specific command # This prevents duplicate runs with ai-comment-reply.yml and ai-issue-triage.yml + # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: Bartender) if: | + github.event.comment.user.login != 'Bartender' && contains(github.event.comment.body, '@codebot') && !contains(github.event.comment.body, '@codebot triage') && !contains(github.event.comment.body, '@codebot help') && diff --git a/.gitea/workflows/ai-comment-reply.yml b/.gitea/workflows/ai-comment-reply.yml index 25707b7..dc469fe 100644 --- a/.gitea/workflows/ai-comment-reply.yml +++ b/.gitea/workflows/ai-comment-reply.yml @@ -17,7 +17,9 @@ jobs: runs-on: ubuntu-latest # Only run for specific commands (not free-form chat or triage) # This prevents duplicate runs with ai-chat.yml and ai-issue-triage.yml + # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: Bartender) if: | + github.event.comment.user.login != 'Bartender' && (contains(github.event.comment.body, '@codebot help') || contains(github.event.comment.body, '@codebot explain') || contains(github.event.comment.body, '@codebot suggest') || diff --git a/.gitea/workflows/ai-issue-triage.yml b/.gitea/workflows/ai-issue-triage.yml index 48a10ed..bb9ad80 100644 --- a/.gitea/workflows/ai-issue-triage.yml +++ b/.gitea/workflows/ai-issue-triage.yml @@ -12,7 +12,10 @@ jobs: ai-triage: runs-on: ubuntu-latest # Only run if comment contains @codebot triage - if: contains(github.event.comment.body, '@codebot triage') + # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: Bartender) + if: | + github.event.comment.user.login != 'Bartender' && + contains(github.event.comment.body, '@codebot triage') steps: - uses: actions/checkout@v4 diff --git a/CLAUDE.md b/CLAUDE.md index 7f63769..a3275a4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -190,7 +190,7 @@ Workflows are located in `.gitea/workflows/` and are **mutually exclusive** to p - **enterprise-ai-review.yml** - Triggered on PR open/sync - **ai-issue-triage.yml** - Triggered ONLY on `@codebot triage` in comments -- **ai-comment-reply.yml** - Triggered on specific commands: `help`, `explain`, `suggest`, `security`, `summarize`, `review-again`, `setup-labels` +- **ai-comment-reply.yml** - Triggered on specific commands: `help`, `explain`, `suggest`, `security`, `summarize`, `changelog`, `explain-diff`, `review-again`, `setup-labels` - **ai-chat.yml** - Triggered on `@codebot` mentions that are NOT specific commands (free-form questions) - **ai-codebase-review.yml** - Scheduled weekly analysis @@ -201,6 +201,20 @@ Workflows are located in `.gitea/workflows/` and are **mutually exclusive** to p This prevents the issue where all three workflows would trigger on every `@codebot` mention, causing massive duplication. +**CRITICAL: Bot Self-Trigger Prevention** + +All workflows include `github.event.comment.user.login != 'Bartender'` to prevent infinite loops. Without this check: +- Bot posts comment mentioning `@codebot` +- Workflow triggers, bot posts another comment with `@codebot` +- Triggers again infinitely → 10+ duplicate runs + +**If you change the bot username**, update all three workflow files: +- `.gitea/workflows/ai-comment-reply.yml` +- `.gitea/workflows/ai-chat.yml` +- `.gitea/workflows/ai-issue-triage.yml` + +Look for: `github.event.comment.user.login != 'Bartender'` and replace `'Bartender'` with your bot's username. + **Note**: Issue triage is now **opt-in** via `@codebot triage` command, not automatic on issue creation. Key workflow pattern: diff --git a/README.md b/README.md index b81bb5a..2707c29 100644 --- a/README.md +++ b/README.md @@ -479,6 +479,15 @@ if: contains(github.event.comment.body, '@codebot') Change `@codebot` to your new bot name. +**Step 3 (CRITICAL):** Update bot username to prevent infinite loops: + +In all three workflow files, find: +```yaml +github.event.comment.user.login != 'Bartender' +``` + +Replace `'Bartender'` with your bot's Gitea username. This prevents the bot from triggering itself when it posts comments containing `@codebot`, which would cause infinite loops and 10+ duplicate workflow runs. + --- ## Security Scanning