Skip to content

Title: pr-review-mention: kill the self-trigger — bot's own mention-ack re-fires the listener #538

Closed

Description

@don-petry

The pr-review cascade's acknowledgement comment @-mentions the bot itself (@donpetry-bot I'm on it…). That self-mention is an issue_comment: created event, which pr-review-mention-reusable.yml interprets as a review request and re-triggers the cascade → another identical ack. On combsmith/.github-private#860 this produced 1,481 byte-identical comments at a ~9s cadence for ~4.5h (93.6% of the PR's 1,582 comments). This is the org-repo half of the #860 runaway; the .github-private half (per-PR churn breaker + human-gated cap reset) landed in .github-private#928, but it only bounds the storm — the self-trigger still fires at the source.
Root cause
pr-review-mention-reusable.yml does not exclude the bot's own comments, so the agent triggers itself. The #467 3-cycle cap couldn't stop it because the cap's documented re-engage path is "mention the bot," which the ack performs.
Fix (P0)
In pr-review-mention-reusable.yml, ignore mention events authored by the bot itself (github.event.comment.user.login == ) and any comment carrying a marker — a comment the agent posts about its own work must never trigger the agent.
And/or change the ack text so it does not literally @-mention donpetry-bot (plain text fires no mention webhook). Do both for defense-in-depth.
Acceptance
[ ] A comment authored by the bot, or carrying a pr-review-agent marker, never re-triggers the mention listener.
[ ] The ack comment fires no mention webhook.
[ ] Land org-first (before/with the .github-private stub guard) so the stub never assumes undeployed reusable behavior.
References: .github-private#860 (incident), .github-private#926 (tracker), .github-private#928 (merged .github-private half), .github-private#855 / #916 (same class).

Activity

  1. don-petry commented on Jun 26, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead Implementation Plan

    Issue: #538 — pr-review-mention: kill the self-trigger — bot's own mention-ack re-fires the listener

    Scope

    Stop pr-review-mention-reusable.yml from re-triggering itself: ignore mention events authored by the bot or carrying a <!-- pr-review-agent marker, and make the acknowledgement comment fire no mention webhook — defense-in-depth, org-first.

    Root cause

    The bot's ack comment historically rendered @donpetry-bot … (when the triggering comment was itself bot-authored), which is an issue_comment: created event that the listener interprets as a fresh review request → identical ack → loop. The listener never excludes the bot's own / agent-marked comments.

    Implementation Checklist

    • /.github/scripts/pr-review-mention/lib/mention-guard.sh (new) — pure, bats-testable functions: mention_is_self_trigger BOT AUTHOR BODY (bot-authored OR carries <!-- pr-review-agent marker) and mention_ack_message KIND ACTOR (marker + acknowledgement with no @-mention).
    • /.github/scripts/pr-review-mention/README.md (new) — contract doc, mirroring the auto-rebase scripts README.
    • /.github/workflows/pr-review-mention-reusable.yml — add the self-trigger exclusions (comment.user.login != 'donpetry-bot', !contains(body,'<!-- pr-review-agent')) to the job-level if: (coarse pre-filter); check out tooling at github.job_workflow_sha; add a lib-backed "Detect self-trigger" guard step gating dispatch/ack; replace the inline ack text with mention_ack_message (no @-mention).
    • /.github/workflows/pr-review-mention-tests.yml (new) — shellcheck + bats gate, mirroring auto-rebase-tests.yml.

    Tests to Write

    • test/workflows/pr-review-mention/mention-guard.bats + helpers/setup.bash
      • mention_is_self_trigger: bot-authored comment → self-trigger; comment carrying the <!-- pr-review-agent marker → self-trigger; ordinary human @donpetry-bot mention → not; empty author/body (reviewer-assignment event) → not.
      • mention_ack_message: comment & reviewer kinds both carry the <!-- pr-review-agent mention-ack --> marker, name the actor, and contain no @ character (fires no mention webhook); unknown kind errors (exit 2).
      • The bot's own ack body is itself classified as a self-trigger by mention_is_self_trigger (marker round-trip).

    Test Command

    bats test/workflows/pr-review-mention/ (full suite: bats test/) plus shellcheck -x .github/scripts/pr-review-mention/lib/mention-guard.sh and bash .dev-lead/scripts/dev-lead-lint.sh

  2. don-petry commented on Jun 26, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead: issue #538 implementation failed — will retry

    The engine failed (engine-error — e.g. a timeout or transient engine error). This was attempt 1 of 3; dev-lead will retry automatically. You can also re-apply the dev-lead label to retry now.

  3. don-petry commented on Jun 26, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead Implementation Plan

    Issue: #538 — pr-review-mention: kill the self-trigger — bot's own mention-ack re-fires the listener

    Scope

    Stop the pr-review mention listener from triggering on its own acknowledgement comment by excluding bot-authored / marker-bearing comments at the job gate, and remove the literal @-mention from the ack so it fires no mention webhook (defense-in-depth).

    Implementation Checklist

    • .github/workflows/pr-review-mention-reusable.yml — add to the comment branch of the job if: guard: github.event.comment.user.login != 'donpetry-bot' and !contains(github.event.comment.body, '<!-- pr-review-agent')
    • .github/workflows/pr-review-mention-reusable.yml — drop the @ prefix from the ack message so it never @-mentions any user (plain text fires no mention webhook)
    • .github/workflows/pr-review-mention-tests.yml — new per-workflow CI suite mirroring auto-rebase-tests.yml

    Tests to Write

    • test/workflows/pr-review-mention/helpers/setup.bash — repo-root helper
    • test/workflows/pr-review-mention/self-trigger.bats — contract tests:
      • if-guard excludes comments authored by donpetry-bot
      • if-guard excludes comments carrying a <!-- pr-review-agent marker
      • ack message contains no @-mention (no mention webhook), and never @donpetry-bot
      • existing trust gate / @donpetry-bot trigger preserved

    Test Command

    bats test/workflows/pr-review-mention/

    Org-first: this lands in the central reusable before the .github-private stub guard, per acceptance criterion 3.

  4. don-petry commented on Jun 26, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead: Implementation Complete

    Plan Execution

    • Added bot-author + marker exclusions to the comment branch of the job if: guard in pr-review-mention-reusable.yml
    • Removed the literal @-mention from the ack message (plain-text actor name) so it fires no mention webhook
    • Added a test/workflows/pr-review-mention/ bats contract suite (red → green)
    • Added pr-review-mention-tests.yml CI gate (mirrors auto-rebase-tests.yml)
    • Verified: full bats suite, dev-lead lint, yamllint, actionlint all pass

    Test Results

    1..9
    ok 1 reusable workflow file exists
    ok 2 if-guard excludes comments authored by the bot itself
    ok 3 if-guard excludes comments carrying a pr-review-agent marker
    ok 4 if-guard still requires an @donpetry-bot mention to fire (trigger preserved)
    ok 5 if-guard still gates on trusted author_association (trust gate preserved)
    ok 6 ack step never @-mentions any user (no mention webhook)
    ok 7 ack step never literally @-mentions donpetry-bot
    ok 8 ack step still tags its comment with the pr-review-agent marker
    ok 9 ack step still names the actor in the acknowledgement (plain text)
    
    Full repo suite: 325 tests, all passing (bats --recursive test/)
    dev-lead-lint.sh: all checks passed
    yamllint (CI config): OK   |   actionlint 1.7.7: OK
    

    Files Changed

    • .github/workflows/pr-review-mention-reusable.yml:
      • Comment branch of the job if: now also requires github.event.comment.user.login != 'donpetry-bot' and !contains(github.event.comment.body, '<!-- pr-review-agent') — the secrets-bearing job never starts for the agent's own comments.
      • Ack message references the actor in plain text (dropped the @), so the ack fires no mention webhook (defense-in-depth alongside the gate).
    • .github/workflows/pr-review-mention-tests.yml (new): per-workflow bats CI gate.
    • test/workflows/pr-review-mention/self-trigger.bats (new): contract tests for the guard + ack.
    • test/workflows/pr-review-mention/helpers/setup.bash (new): repo-root + YAML-extraction helpers.

    Acceptance

    • A comment authored by the bot, or carrying a pr-review-agent marker, never re-triggers the mention listener (gated at the job if:, before secrets load).
    • The ack comment fires no mention webhook (plain-text actor, no @).
    • Landed org-first — only the central reusable changed; no .github-private stub assumptions. The thin caller stubs (pr-review-mention.yml, standards/workflows/pr-review-mention.yml) were intentionally left untouched since all logic lives in the reusable.

    Notes

    Triple defense at the source: (a) bot-author exclusion, (b) marker exclusion, (c) no @-mention in the ack. The marker check intentionally also suppresses any human comment that quotes a <!-- pr-review-agent marker, per the issue's "a comment the agent posts about its own work must never trigger the agent." No changes were needed to the caller stubs. Did not commit/push — CI handles git operations.

  5. added
    dev-leadFor dev-lead agent pickup
    and removed
    dev-leadFor dev-lead agent pickup
    on Jul 15, 2026
  6. don-petry commented on Jul 15, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead Implementation Plan

    Issue: #538 — pr-review-mention: kill the self-trigger (bot's own mention-ack re-fires the listener)

    Scope

    Stop the pr-review-mention reusable from re-triggering itself by (a) excluding bot-authored and agent-marker-carrying comments in the job-level if: guard, and (b) ensuring the acknowledgement comment never literally @-mentions donpetry-bot.

    Root cause (org-repo half of .github-private#860)

    pr-review-mention-reusable.yml only excludes the exact marker string pr-review-agent mention-ack. Any agent-posted comment that @donpetry-bots but carries a different <!-- pr-review-agent … --> marker (or none) still satisfies the guard and re-dispatches the cascade → identical-ack storm.

    Implementation Checklist

    • .github/workflows/pr-review-mention-reusable.yml — job if: guard: add github.event.comment.user.login != 'donpetry-bot' (bot-author exclusion) and broaden the marker exclusion from 'pr-review-agent mention-ack' to '<!-- pr-review-agent' (any agent marker). Update the recursion-guard comment to reflect the new rationale.
    • .github/workflows/pr-review-mention-reusable.yml — "Post acknowledgement comment" step: make it env-driven (pass actor/event via env:, not inline ${{ }} in the shell body — avoids script-injection) and build the addressee so a bot actor is addressed by plain login (no leading @, fires no mention webhook). Marker stays on the ack for defense-in-depth.
    • .github/workflows/pr-review-mention-tests.yml — new per-feature CI test workflow (shellcheck-free; runs the bats suite) mirroring pr-auto-review-tests.yml.

    Tests to Write

    • test/workflows/pr-review-mention/guard.bats — parse the reusable's job if: and assert it excludes bot-authored comments and any <!-- pr-review-agent marker while still firing on a trusted human @donpetry-bot.
    • test/workflows/pr-review-mention/ack.bats — extract and execute the ack step's run: block with a stubbed gh; assert the emitted body carries the marker, @-mentions a human requester, and NEVER contains @donpetry-bot when the actor is the bot.
    • test/workflows/pr-review-mention/helpers/setup.bash — test helpers (repo root, yq extraction).

    Test Command

    ./node_modules/.bin/bats --print-output-on-failure test/workflows/pr-review-mention/
    (CI: bats test/workflows/pr-review-mention/ via the new tests workflow; plus bash .dev-lead/scripts/dev-lead-lint.sh)

  7. don-petry commented on Jul 15, 2026

    @don-petry
    ContributorAuthor

    Dev-Lead: Implementation Complete

    Plan Execution

    • Job if: guard now excludes bot-authored comments (github.event.comment.user.login != 'donpetry-bot') and any comment carrying an <!-- pr-review-agent marker (broadened from the narrow pr-review-agent mention-ack string so every agent-posted comment is caught, not just the ack).
    • Ack step made env-driven (event fields passed via env:, not inline ${{ }} — closes a script-injection vector) and now never emits a literal @donpetry-bot: when the actor is the bot it is addressed by plain login (no leading @ → fires no mention webhook); a human requester still gets a real @-mention.
    • Added test/workflows/pr-review-mention/ bats suite (guard + ack) and pr-review-mention-tests.yml CI gate (shellcheck + bats).
    • TDD: tests written first, confirmed red against the old workflow, then green after the fix.

    Acceptance criteria

    • A comment authored by the bot, or carrying a pr-review-agent marker, never re-triggers the mention listener (job if: guard, two independent exclusion axes).
    • The ack comment fires no mention webhook (never contains @donpetry-bot).
    • Landed org-first: this is the petry-projects/.github reusable; no dependency on undeployed .github-private behavior.

    Test Results

    1..11
    ok 1 ack: a human commenter is @-mentioned in the acknowledgement
    ok 2 ack: the acknowledgement always carries the pr-review-agent marker
    ok 3 ack: never emits a literal @donpetry-bot when the bot is the actor (comment path)
    ok 4 ack: never emits a literal @donpetry-bot when the bot self-assigns as reviewer (pull_request path)
    ok 5 ack: a human reviewer-assigner is still @-mentioned (pull_request path)
    ok 6 guard: excludes comments authored by donpetry-bot itself
    ok 7 guard: excludes any comment carrying an <!-- pr-review-agent marker
    ok 8 guard: no longer keys the exclusion on the narrow mention-ack string alone
    ok 9 guard: still fires on an @donpetry-bot mention
    ok 10 guard: still gates comment events on trusted author_association
    ok 11 guard: still fires when donpetry-bot is assigned as reviewer
    

    Full repo suite: 810 tests, 0 failures. bash .dev-lead/scripts/dev-lead-lint.sh → all checks passed. shellcheck -x on the new gh stub → clean.

    Files Changed

    • .github/workflows/pr-review-mention-reusable.yml: bot-author + broadened-marker exclusions in the job if:; env-driven, self-mention-safe ack step.
    • .github/workflows/pr-review-mention-tests.yml: new per-feature CI gate (shellcheck + bats), mirroring pr-auto-review-tests.yml.
    • test/workflows/pr-review-mention/guard.bats: pins the guard's self-trigger exclusions while preserving the human/@-mention and reviewer-assign trigger paths.
    • test/workflows/pr-review-mention/ack.bats: executes the real ack run: block against a fake gh; asserts no @donpetry-bot self-mention and a real ping for humans.
    • test/workflows/pr-review-mention/helpers/setup.bash, test/workflows/pr-review-mention/stubs/gh: test harness.

    Notes

    • The guard stays a job-level if: (not a runtime step) by design — it gates whether the job and its secrets start at all, so a bot/agent comment is rejected before the job spins up.
    • Trade-off (intentional, per issue): donpetry-bot can no longer request a review by commenting @donpetry-bot; the self-trigger risk (.github-private#860) outweighs that. The bot can still request a review via the review_requested / assign-reviewer path, which is unchanged.
  8. added a commit that references this issue on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev-leadFor dev-lead agent pickup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions