Fix pull_request_reviewer double-trigger on comment events#33702
Fix pull_request_reviewer double-trigger on comment events#33702Copilot wants to merge 4 commits into
Conversation
…ve comment CommandEvents Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes unintended double-triggering of on.pull_request_reviewer workflows by tightening the compiled job if: guard logic and adjusting how reviewer workflows participate in centralized routing.
Changes:
- Replace the reviewer job
if:guard from a logically-inverted denylist to an allowlist. - Stop enrolling
pull_request_reviewerworkflows in comment-based centralized routing by alteringCommandEventshandling. - Update/add tests to validate the new guard and updated reviewer routing expectations.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/tools.go | Updates the compiled reviewer if: guard to an allowlist including workflow_dispatch and open-PR PR/review events. |
| pkg/workflow/compiler_safe_outputs.go | Changes reviewer workflow parsing to clear CommandEvents to avoid comment routing registration. |
| pkg/workflow/compiler_safe_outputs_test.go | Updates reviewer trigger tests to assert CommandEvents is now nil. |
| pkg/workflow/pull_request_reviewer_if_guard_test.go | Adds a regression test asserting the new allowlist guard is emitted and the old denylist form is absent. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
pkg/workflow/compiler_safe_outputs_test.go:529
- Same issue as the earlier reviewer CommandEvents assertion: nil is interpreted elsewhere as “all/default events”, so this test can mask unintended enrollment of reviewer workflows into centralized comment routing. Consider asserting the explicit opt-out representation used to ensure reviewer workflows are not added to GH_AW_SLASH_ROUTING.
}
err := c.parseOnSection(frontmatter, workflowData, "/path/to/reviewer.md")
require.NoError(t, err)
assert.Equal(t, []string{"review", "reviewer-workflow-id"}, workflowData.Command)
// pull_request_reviewer takes ownership and clears comment events to prevent
// the central router from dispatching the workflow on comment triggers.
assert.Nil(t, workflowData.CommandEvents)
assert.True(t, workflowData.CommandCentralized)
}
- Files reviewed: 4/4 changed files
- Comments generated: 3
| // commands in comments. Leave CommandEvents nil so the central router | ||
| // does not register this workflow for comment-based routing (which was | ||
| // the source of accidental double-triggers when comments were posted). | ||
| workflowData.CommandEvents = nil |
| err := c.parseOnSection(frontmatter, workflowData, "/path/to/reviewer.md") | ||
| require.NoError(t, err) | ||
| assert.Equal(t, []string{"review", "reviewer-workflow-id"}, workflowData.Command) | ||
| assert.Equal(t, []string{"pull_request_comment", "pull_request_review_comment"}, workflowData.CommandEvents) | ||
| // Reviewer workflows must not register for comment events in the central router | ||
| // to prevent accidental double-triggers when PR comments are posted. | ||
| assert.Nil(t, workflowData.CommandEvents) | ||
| assert.True(t, workflowData.CommandCentralized) | ||
| } |
| // accidentally trigger the reviewer job – either directly or via workflow_dispatch | ||
| // from the central router. |
|
@copilot review all comments |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…CommandRoutes - Add explicit PullRequestReviewer skip in collectCentralSlashCommandRoutes so reviewer workflows are never enrolled in comment-based slash-command routing, even when CommandEvents is nil (FilterCommentEvents treats nil as "all events") - Update comment in compiler_safe_outputs.go to accurately describe the mechanism - Fix misleading test comment in pull_request_reviewer_if_guard_test.go - Update compiler_safe_outputs_test.go assertions to reflect the PullRequestReviewer flag - Add TestCollectCentralSlashCommandRoutes_ExcludesPullRequestReviewerWorkflows Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed all three review comments in commit
|
Workflows using
on.pull_request_reviewerwere running twice — triggered correctly by PR lifecycle events and again unexpectedly when comments were posted.Root causes
Inverted
if:guard (tools.go): The compiled job guard used a denylist that short-circuited totruefor every event outsidepull_request/pull_request_review(includingworkflow_dispatch,pull_request_review_comment):Reviewer workflows registered in comment routing (
compiler_safe_outputs.go):CommandEventswas set to["pull_request_comment", "pull_request_review_comment"], which enrolled reviewer workflows in the central router's slash-command table. Any comment starting with/reviewdispatched the workflow a second time viaworkflow_dispatch. Fixed by settingCommandEvents = nilfor reviewer workflows.Changes
tools.go— Replace denylist reviewer guard with allowlistcompiler_safe_outputs.go— SetCommandEvents = nilforpull_request_reviewerworkflowscompiler_safe_outputs_test.go— Update assertions for the now-nilCommandEventspull_request_reviewer_if_guard_test.go— New test asserting the allowlist guard is emitted and the old denylist form is absent