fix: handle @docker-agent mentions in inline PR review comments (pull_request_review_comment)#181
Conversation
The reply-to-mention job was silently skipped whenever @docker-agent was mentioned in an inline PR review comment (pull_request_review_comment event) because: 1. The job's 'if:' condition only matched issue_comment events. 2. parseEventContext() read PR number from raw.issue.number, which doesn't exist in pull_request_review_comment payloads (it's at raw.pull_request.number). 3. addReaction() always called createForIssueComment, which 404s for review comments (need createForPullRequestReviewComment). Changes: .github/workflows/review-pr.yml - reply-to-mention job: add OR branch for pull_request_review_comment events (no issue.pull_request check needed — it's always a PR). - Add completion reaction step: route to the correct gh api endpoint (pulls/comments vs issues/comments) based on EVENT_NAME. src/add-reaction/index.ts - Export new CommentType = 'issue' | 'pull_request_review' type. - Add optional commentType parameter (default 'issue') to addReaction(). - When 'pull_request_review', call createForPullRequestReviewComment instead of createForIssueComment. src/mention-reply/index.ts - Add commentType field to EventContext interface. - parseEventContext(): check GITHUB_EVENT_NAME; for pull_request_review_comment read prNumber from raw.pull_request.number and set isPrComment=true and commentType='pull_request_review'. - Pass ctx.commentType to addReaction() so the correct API is used. Tests - src/add-reaction/__tests__: add beforeEach mock reset; cover new commentType parameter for both 'issue' and 'pull_request_review'. - src/mention-reply/__tests__: add makePrReviewCommentEvent fixture; test parseEventContext, runGuards, and run() for pull_request_review_comment events including guard paths, happy path, non-member path, and reaction call with correct commentType. Assisted-By: docker-agent
Users found the 😕 reaction confusing — it made them think they had done something wrong rather than signalling an internal action failure. In the 'Add completion reaction' step of the reply-to-mention job, only post the 👍 reaction when the reply step succeeds; do nothing on failure. Searched all workflow files for other confused-on-failure patterns; this was the only occurrence. Assisted-By: docker-agent
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
The core fix is correct — comment events are now properly routed, the right GitHub API endpoints are used for reactions, and PR numbers are read from the correct payload field. Two issues in the workflow if: conditions were found.
| github.event.comment.user.login != 'docker-agent' && | ||
| github.event.comment.user.type != 'Bot' | ||
| github.event.comment.user.type != 'Bot') || | ||
| (github.event_name == 'pull_request_review_comment' && |
There was a problem hiding this comment.
[MEDIUM] Double bot response when a user replies to a review comment and mentions @docker-agent
When a user replies to an existing inline review comment and includes @docker-agent in that reply, both reply-to-feedback and the newly-added reply-to-mention branch fire simultaneously on the same event:
reply-to-feedbacktriggers because:pull_request_review_comment+github.event.comment.in_reply_to_idis set (it's a reply) + user is notdocker-agentreply-to-mentiontriggers because:pull_request_review_comment+contains(@docker-agent)+ user is notdocker-agent
Neither condition checks for the other. The result is two concurrent agent runs posting separate responses to the same comment — a confusing double-response the user did not ask for.
This overlap was not possible before this PR because reply-to-mention only handled issue_comment events. The reply-to-feedback job (line 364) would need a !contains(github.event.comment.body, '@docker-agent') guard, or reply-to-mention would need !github.event.comment.in_reply_to_id to break the ambiguity.
There was a problem hiding this comment.
Fixed in the latest commit. Added !github.event.comment.in_reply_to_id as the first guard in the pull_request_review_comment branch, so reply-to-mention only fires on fresh top-level inline comments. Replies to existing threads — including those containing @docker-agent — fall through exclusively to reply-to-feedback, which has the full thread context. No more double-response.
| github.event.comment.user.type != 'Bot' | ||
| github.event.comment.user.type != 'Bot') || | ||
| (github.event_name == 'pull_request_review_comment' && | ||
| contains(github.event.comment.body, '@docker-agent') && |
There was a problem hiding this comment.
[LOW] Missing /review guard in the pull_request_review_comment branch of reply-to-mention
The issue_comment branch guards against /review-prefixed comments (line 705: !startsWith(github.event.comment.body, '/review')), but the new pull_request_review_comment branch does not:
(github.event_name == 'pull_request_review_comment' &&
contains(github.event.comment.body, '@docker-agent') &&
# ← !startsWith(..., '/review') is missing here
github.event.comment.user.login != 'docker-agent' &&
github.event.comment.user.type != 'Bot')If someone writes /review @docker-agent as an inline PR review comment, the reply-to-mention job will spin up unnecessarily. The TypeScript runGuards() does catch this and exits cleanly (so no incorrect output is produced), but runner minutes are wasted on every such event.
Suggested fix: add !startsWith(github.event.comment.body, '/review') && after the contains(...) check in this branch.
There was a problem hiding this comment.
Fixed in the same commit. Added !startsWith(github.event.comment.body, '/review') to the pull_request_review_comment branch, immediately after the @docker-agent mention check — matching the guard that already existed in the issue_comment branch.
…eview_comment Two review-comment fixes on the reply-to-mention job's if: condition for the pull_request_review_comment branch: 1. Add !github.event.comment.in_reply_to_id so reply-to-mention only fires on fresh top-level inline mentions, not on replies to existing threads. Replies that happen to contain @docker-agent are better handled by reply-to-feedback which has full thread context, avoiding a double-response when both jobs would otherwise fire simultaneously. 2. Add !startsWith(github.event.comment.body, '/review') to match the guard that already exists in the issue_comment branch, preventing the mention handler from running when the user is issuing a /review command. Assisted-By: docker-agent
|
/review |
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The three bug fixes are correctly implemented:
-
Workflow
if:condition —reply-to-mentionjob now correctly matches bothissue_commentandpull_request_review_commentevents, with the appropriate!github.event.comment.in_reply_to_idguard to avoid double-responding on thread replies. -
parseEventContext()payload mismatch —pull_request_review_commentevents now correctly readprNumberfromraw.pull_request.numberand setcommentType = 'pull_request_review'. -
Wrong reactions API —
addReaction()correctly routes tocreateForPullRequestReviewCommentvscreateForIssueCommentbased oncommentType. -
Completion reaction routing — The
Add completion reactionshell block correctly dispatches topulls/commentsvsissues/commentsendpoints based onEVENT_NAME, and theexit 0guard on non-success outcomes intentionally drops the oldconfusedreaction (per the earlierbebd4e8commit). -
Tests — New test fixtures and describe blocks cover the
pull_request_review_commenthappy path, guard paths (in-reply-to filter, bot/self-reply), non-member path, and correctcommentTypepropagation. Test count grows from 25 → 36.
No bugs found in the changed code.
Problem
When someone @docker-agent mentions in an inline PR review comment (a
pull_request_review_commentevent), thereply-to-mentionjob was always silently skipped and the 👀 reaction call would use the wrong GitHub API endpoint.Three bugs combined to produce this:
Workflow
if:condition — thereply-to-mentionjob only matchedissue_commentevents;pull_request_review_commentevents were never routed to it.parseEventContext()payload mismatch —src/mention-reply/index.tsalways read the PR number fromraw.issue.number, which does not exist inpull_request_review_commentpayloads (the PR lives atraw.pull_request.numberthere).Wrong reactions API —
src/add-reaction/index.tsalways calledcreateForIssueComment, which 404s on review comments;createForPullRequestReviewCommentis needed instead.Changes
.github/workflows/review-pr.ymlreply-to-mentionjobif:— adds an OR branch forpull_request_review_commentevents. Nogithub.event.issue.pull_requestguard is needed (review comments are always on PRs).Add completion reactionstep — routes to the correctgh apiendpoint (pulls/commentsvsissues/comments) depending onEVENT_NAME.src/add-reaction/index.tsCommentType = 'issue' | 'pull_request_review'type.commentTypeparameter (default'issue') toaddReaction().'pull_request_review', callsoctokit.rest.reactions.createForPullRequestReviewCommentinstead ofcreateForIssueComment.src/mention-reply/index.tscommentType: CommentTypefield toEventContext.parseEventContext()now checksGITHUB_EVENT_NAME; forpull_request_review_commentit readsprNumberfromraw.pull_request.numberand setsisPrComment = trueandcommentType = 'pull_request_review'.addReactioncall passesctx.commentTypeso the correct API endpoint is used.Tests
src/add-reaction/__tests__/add-reaction.test.ts— addsbeforeEachmock reset; covers the newcommentTypeparameter for both'issue'and'pull_request_review'.src/mention-reply/__tests__/mention-reply.test.ts— addsmakePrReviewCommentEventfixture and new describe blocks coveringparseEventContext,runGuards, andrun()forpull_request_review_commentevents (guard paths, happy path, non-member path, correct reactioncommentType). Test count goes from 25 to 36.Testing