Skip to content

Discord: support Unicode handle mention rewrite - #43357

Closed
yunhaoli24 wants to merge 3 commits into
openclaw:mainfrom
yunhaoli24:fix/discord-unicode-mention-rewrite
Closed

yunhaoli24 wants to merge 3 commits into
openclaw:mainfrom
yunhaoli24:fix/discord-unicode-mention-rewrite

Conversation

@yunhaoli24

Copy link
Copy Markdown

Summary

  • expand Discord outbound mention candidate parsing from ASCII-only to Unicode letters/numbers
  • keep @everyone and @here passthrough behavior unchanged
  • avoid rewriting email local-parts while still allowing mentions in CJK text like 你好@张三
  • add regression tests for Unicode handles and email-address safety

Testing

  • pnpm vitest src/discord/mentions.test.ts src/discord/send.sends-basic-channel-messages.test.ts

@greptile-apps

greptile-apps Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR expands Discord mention candidate detection from ASCII-only ([a-z0-9_.-]) to full Unicode letters/numbers ([\p{L}\p{N}_.-]) and replaces the old consuming prefix-capture approach with a negative ASCII lookbehind ((?<![A-Za-z0-9._%+-])) to avoid rewriting ASCII email local-parts. The mechanical refactoring (dropping the captured prefix from the replacement return value) is correct because a lookbehind assertion is zero-width and the preceding character is never consumed from the matched text.

Key observations:

  • The CJK mention test (你好@张三) and email safety test ([email protected]) both validate the intended behaviour correctly.
  • The lookbehind is restricted to ASCII characters ([A-Za-z0-9._%+-]), so internationalized email addresses whose local-part ends in a Unicode letter (e.g. 用户@alice.com) will not be blocked — @alice.com becomes a mention candidate. A false positive only materialises if the domain portion happens to be a registered handle, which is unlikely, but the protection is asymmetric with the stated goal.
  • All existing tests (reserved mentions, code-span exclusion, account scoping) remain unaffected by the change.

Confidence Score: 3/5

  • Safe to merge with awareness of the Unicode email local-part edge case.
  • The core logic is sound and the refactoring is mechanically correct. The only concern is that the negative lookbehind is ASCII-only, leaving internationalized email addresses (Unicode local-parts) unguarded — a false positive can only occur if the email domain portion is also a registered handle, making it a low-probability practical risk. All existing and new tests pass.
  • src/discord/mentions.ts — specifically the lookbehind character class on line 5.

Last reviewed commit: c29e3ef

Comment thread src/discord/mentions.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c29e3ef73c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/discord/mentions.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: XS size: S and removed size: XS labels Mar 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c44e4d69b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/discord/mentions.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb54265c9f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/discord/mentions.ts Resolved
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The branch updates Discord mention parsing/tests for Unicode and CJK handles and also changes official Yuanbao external catalog metadata and matching tests.

Reproducibility: yes. at source level: current main's Discord mention regex only matches ASCII handles, so a cached Unicode handle such as @张三 will not be rewritten. I did not run a live Discord gateway proof in this read-only review.

Real behavior proof
Needs real behavior proof before merge: The PR body/comments provide only test commands; the contributor should add redacted live Discord output, screenshot, recording, linked artifact, or logs, then update the PR body to trigger re-review or ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Human/contributor handling is needed because the external PR lacks real behavior proof, is conflicting, and overlaps another open Discord CJK mention PR.

Security
Needs attention: The diff includes an unrelated official external plugin catalog downgrade with supply-chain and install-integrity impact.

Review findings

  • [P2] Drop the unrelated Yuanbao catalog downgrade — scripts/lib/official-external-channel-catalog.json:45-47
  • [P2] Preserve configured mention aliases — extensions/discord/src/mentions.ts:65-68
Review details

Best possible solution:

Consolidate a Discord-only Unicode/CJK mention rewrite that preserves alias, email, URL, code-span, reserved-mention, and account-scope safeguards while leaving official external catalog pins untouched.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main's Discord mention regex only matches ASCII handles, so a cached Unicode handle such as @张三 will not be rewritten. I did not run a live Discord gateway proof in this read-only review.

Is this the best way to solve the issue?

No. Unicode-aware parsing is the right direction, but this branch must first remove unrelated catalog changes, preserve current alias behavior during rebase, and provide real Discord proof.

Full review comments:

  • [P2] Drop the unrelated Yuanbao catalog downgrade — scripts/lib/official-external-channel-catalog.json:45-47
    This Discord mention PR changes the official Yuanbao install source to [email protected] with an older integrity value while current main has 2.13.1. That unrelated metadata change would regress official external plugin installation and should be removed from the branch.
    Confidence: 0.95
  • [P2] Preserve configured mention aliases — extensions/discord/src/mentions.ts:65-68
    Current main resolves mentionAliases before falling back to the directory cache, and send/webhook callers pass those aliases into rewriteDiscordKnownMentions. The PR head resolves only the directory cache with accountId, so alias-only mentions would stop rewriting after this change unless the conflict is resolved to keep aliases.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.92

Security concerns:

  • [medium] Unrelated external install metadata downgrade — scripts/lib/official-external-channel-catalog.json:45
    The PR changes official Yuanbao install metadata from current main's [email protected] pin to 2.11.0 with an older integrity value, which is unrelated to Discord mention parsing and can regress trusted plugin installation.
    Confidence: 0.93

Acceptance criteria:

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-discord.config.ts extensions/discord/src/mentions.test.ts extensions/discord/src/send.sends-basic-channel-messages.test.ts
  • Redacted live Discord proof showing a Unicode/CJK outbound mention rewriting to a real <@user_id> mention without corrupting email, URL, code-span, reserved, or alias behavior.

What I checked:

Likely related people:

  • thewilloftheshadow: The merged Discord mention-handling work added the outbound mention helper, directory cache, and original tests that this PR extends. (role: introduced behavior; confidence: high; commits: d493861c1692; files: src/discord/mentions.ts, src/discord/directory-cache.ts, src/discord/send.outbound.ts)
  • scoootscooob: The Discord implementation was moved from src/discord into extensions/discord, which is the current path touched by this PR. (role: major refactor carrier; confidence: medium; commits: 5682ec37fada; files: extensions/discord/src/mentions.ts, src/discord/mentions.ts)
  • steipete: Current-main blame and history tie the mention-alias implementation and current Discord mention helper shape to recent work by Peter Steinberger. (role: recent area contributor; confidence: medium; commits: f066dd2f31c2, 5d1f7bf05894; files: extensions/discord/src/mentions.ts, extensions/discord/src/send.outbound.ts, extensions/discord/src/send.webhook.ts)
  • loongfay: Recent Yuanbao catalog/version commits established the official external install pin that this PR would downgrade. (role: recent catalog source contributor; confidence: high; commits: c9f451996a90, 128b20431922; files: scripts/lib/official-external-channel-catalog.json, src/channels/plugins/contracts/channel-catalog.contract.test.ts, test/official-channel-catalog.test.ts)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 540a4a73d556.

@yunhaoli24
yunhaoli24 force-pushed the fix/discord-unicode-mention-rewrite branch from cb54265 to 42b1b11 Compare April 27, 2026 14:59
@yunhaoli24
yunhaoli24 force-pushed the fix/discord-unicode-mention-rewrite branch from 42b1b11 to 6a8da88 Compare April 27, 2026 15:14
@yunhaoli24

Copy link
Copy Markdown
Author

Updated this PR for the latest review feedback.

Changes:

Tested:

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-discord.config.ts extensions/discord/src/mentions.test.ts extensions/discord/src/send.sends-basic-channel-messages.test.ts

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Apr 27, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 28, 2026
@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label May 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 16, 2026
@clawsweeper clawsweeper Bot added impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. labels May 17, 2026
@thewilloftheshadow

Copy link
Copy Markdown
Member

Mentions on Discord are always ascii, the existing regex is correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord impact:message-loss Channel message delivery can be lost, duplicated, or misrouted. impact:security Security boundary, credential, authz, sandbox, or sensitive-data risk. P2 Normal backlog priority with limited blast radius. scripts Repository scripts size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants