Merge pull request 'fix: Prevent bot self-trigger infinite loops in all workflows' (#28) from hotfix/prevent-bot-self-trigger into dev
All checks were successful
Enterprise AI Code Review / ai-review (pull_request) Successful in 36s

Reviewed-on: #28
This commit was merged in pull request #28.
This commit is contained in:
2025-12-29 13:13:25 +00:00
5 changed files with 32 additions and 2 deletions

View File

@@ -17,7 +17,9 @@ jobs:
ai-chat: ai-chat:
# Only run if comment mentions the bot but NOT a specific command # 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 # 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: | if: |
github.event.comment.user.login != 'Bartender' &&
contains(github.event.comment.body, '@codebot') && contains(github.event.comment.body, '@codebot') &&
!contains(github.event.comment.body, '@codebot triage') && !contains(github.event.comment.body, '@codebot triage') &&
!contains(github.event.comment.body, '@codebot help') && !contains(github.event.comment.body, '@codebot help') &&

View File

@@ -17,7 +17,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Only run for specific commands (not free-form chat or triage) # Only run for specific commands (not free-form chat or triage)
# This prevents duplicate runs with ai-chat.yml and ai-issue-triage.yml # 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: | if: |
github.event.comment.user.login != 'Bartender' &&
(contains(github.event.comment.body, '@codebot help') || (contains(github.event.comment.body, '@codebot help') ||
contains(github.event.comment.body, '@codebot explain') || contains(github.event.comment.body, '@codebot explain') ||
contains(github.event.comment.body, '@codebot suggest') || contains(github.event.comment.body, '@codebot suggest') ||

View File

@@ -12,7 +12,10 @@ jobs:
ai-triage: ai-triage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Only run if comment contains @codebot triage # 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: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View File

@@ -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 - **enterprise-ai-review.yml** - Triggered on PR open/sync
- **ai-issue-triage.yml** - Triggered ONLY on `@codebot triage` in comments - **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-chat.yml** - Triggered on `@codebot` mentions that are NOT specific commands (free-form questions)
- **ai-codebase-review.yml** - Scheduled weekly analysis - **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. 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. **Note**: Issue triage is now **opt-in** via `@codebot triage` command, not automatic on issue creation.
Key workflow pattern: Key workflow pattern:

View File

@@ -479,6 +479,15 @@ if: contains(github.event.comment.body, '@codebot')
Change `@codebot` to your new bot name. 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 ## Security Scanning