GitHub adapter treats a bot mention inside code, quotes, or HTML as a new mention

Open
#1,177 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
github, typescript

Research direction

Start with parseIssueComment and parseReviewComment in packages/adapter-github/src/index.ts, then read the mention handling in packages/chat/src/chat.ts and the GitLab implementation referenced in the issue. Check the existing tests for both GitHub webhook event types and add cases for mentions inside code, quotes, and HTML. Done means normal text mentions still trigger onNewMention, while those examples do not.

Written by the indexing model from the issue text.

Description

Hope you're doing well! On the GitHub adapter, a comment that only shows the bot's name inside inline code, a code block, a > quote, or an HTML comment still fires onNewMention.

What the code is for

parseIssueComment and parseReviewComment turn issue_comment and pull_request_review_comment webhooks into a Message (adapter-github/src/index.ts#L856-L935). Chat reads message.isMention to decide whether onNewMention runs.

Current behaviour

  1. Someone comments try `@my-bot review` to rerun it on a PR, or quotes an earlier comment that mentioned the bot.
  2. The adapter builds the Message without setting isMention.
  3. setMentionFlags sees it unset and falls back to detectMention (chat.ts#L3526-L3545), which runs a regex over message.text (chat.ts#L3626-L3660).
  4. message.text comes from toPlainText, which keeps the text inside code, quotes, and HTML (markdown.ts#L539-L580).
  5. The regex finds @my-bot there and onNewMention runs, even though nobody mentioned the bot.

The comment in setMentionFlags already names this case: "code samples and quoted text can look like a mention".

Expected behaviour

Only a mention in the normal text of a comment counts. @my-bot inside inline code, a code block, a quote, or HTML shouldn't fire onNewMention.

Repro

On main (990411ea), I sent signed webhooks for both event types into a real Chat with userName: "test-bot" and the memory state. Same result for issue_comment and pull_request_review_comment:

"@test-bot please review"         onNewMention: yes (expected)
"run `@test-bot review`"          onNewMention: yes (should be no)
"```\n@test-bot review\n```"      onNewMention: yes (should be no)
"> @test-bot review"              onNewMention: yes (should be no)
"<!-- @test-bot -->"              onNewMention: yes (should be no)
"@test-botx hi"                   onNewMention: no (expected)
"mail [email protected]"          onNewMention: no (expected)

The lookalike and email cases are already handled nicely by the boundary checks in detectMention.

Prior work

The GitLab adapter already solves this: mentionsUser and mentionableText walk the parsed markdown and skip code, inlineCode, blockquote, and html before matching (adapter-gitlab/src/index.ts#L1502-L1539). #946 made isMention three state so adapters can report a definite false, and #947 and #1059 fixed the same kind of problem for Slack, where a bot name in code formatting was read as a mention.

mentionsUser callers on main

Only GitLabAdapter.buildMessage calls mentionsUser and mentionableText on main, Functions view in Architect

Question

Should quotes be left out too, like GitLab does, or only code, like the Slack fix? I have a small PR ready that sets isMention in both GitHub parse functions using GitLab's rule (code, inline code, quotes, and HTML), since that seemed the closest match. Happy to drop quotes or change anything else if you'd rather it work another way. Thanks for all the work on these adapters!

Dominant language
TypeScript
Stars
2.5k
Forks
355
Avg merge
2d 15h
Merged PRs (30d)
42

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/chat

All issues in vercel/chat

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.