Skip to content

fix(discord): protect mention aliases in code fences - #90646

Closed
wyf027 wants to merge 3 commits into
openclaw:mainfrom
wyf027:fix/discord-mention-code-fence-90643
Closed

wyf027 wants to merge 3 commits into
openclaw:mainfrom
wyf027:fix/discord-mention-code-fence-90643

Conversation

@wyf027

@wyf027 wyf027 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the Discord mention code-region regex with a scanner that keeps fenced code blocks intact when the body contains shorter backtick runs
  • preserve multi-backtick inline code spans while still rewriting plain text aliases outside code
  • add regressions for triple-backtick literals, longer fenced blocks, and multi-backtick inline spans

Fixes #90643

Tests

  • node scripts/run-vitest.mjs extensions/discord/src/mentions.test.ts
  • node scripts/run-vitest.mjs extensions/discord/src/send.sends-basic-channel-messages.test.ts extensions/discord/src/send.webhook-activity.test.ts
  • git diff --check

Note

  • node_modules/.bin/tsc -p extensions/discord/tsconfig.json --noEmit --pretty false currently fails on pre-existing Discord/plugin-sdk type drift unrelated to this patch.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 5, 2026
@clawsweeper

clawsweeper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the central Discord code-fence fix is covered by the open replacement at #90648, while this branch still changes tilde-run mention behavior and lacks after-fix real behavior proof.

Canonical path: Use the proof-backed replacement PR at #90648 as the landing path for the Discord mention code-fence fix.

So I’m closing this here and keeping the remaining discussion on #90648.

Review details

Best possible solution:

Use the proof-backed replacement PR at #90648 as the landing path for the Discord mention code-fence fix.

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

Yes. Source inspection and the linked issue show the current regex can mis-handle a triple-backtick literal inside a fenced code block, and this branch's tilde handling creates a clear source-level regression path for ~~~\n@alice\n~~~.

Is this the best way to solve the issue?

No. The scanner approach is plausible for the backtick bug, but this branch is not the best landing path because it broadens the skipped syntax to tilde fences; the replacement PR keeps the fix scoped to Discord-rendered backtick code segments and has proof.

Security review:

Security review cleared: The diff changes Discord mention parsing and tests only; I found no new dependency, credential, workflow, package, or code-execution surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • Current mention contract: Current main rewrites mention aliases around backtick code segments only; rewriteDiscordKnownMentions uses MARKDOWN_CODE_SEGMENT_PATTERN for triple-backtick fences and single-backtick inline spans, and docs say mentions inside Markdown code spans are left unchanged. (extensions/discord/src/mentions.ts:11, b8adc11977ab)
  • Runtime call path: Normal sends, structured sends, webhooks, and final-preview create/edit gating all call rewriteDiscordKnownMentions, so scanner mistakes affect delivered Discord content and create/edit decisions. (extensions/discord/src/send.outbound.ts:180, b8adc11977ab)
  • Introduced branch regression: This PR's scanner accepts both backtick and tilde fence characters, so ~~~\n@alice\n~~~ becomes a skipped segment and no longer rewrites the alias, matching the review comment's reported behavior regression. (extensions/discord/src/mentions.ts:160, d1d942159999)
  • Canonical replacement PR: The replacement PR at fix(discord): protect mention aliases in code fences #90648 is open, mergeable, maintainer-editable, labeled proof supplied/sufficient, includes real helper-output proof, and adds a regression that tilde runs are not Discord code fences. (extensions/discord/src/mentions.test.ts:126, 891231290eed)
  • Related search: GitHub issue search for the title and rewriteDiscordKnownMentions code-fence terms returns this PR, the source issue, the older general mention-alias work, and the proof-backed replacement, making the replacement the canonical remaining fix path.
  • Feature history: Current-main blame ties the mention regex and rewrite loop to commit bab18d567b0cd9811012a50e032f71a9c9beb440; the local shallow history shows Peter Steinberger as the recent author for the implicated helper. (extensions/discord/src/mentions.ts:11, bab18d567b0c)

Likely related people:

  • Peter Steinberger: Current-main blame attributes the implicated mention regex and rewrite loop to bab18d567b0cd9811012a50e032f71a9c9beb440; history is shallow/grafted, so this is strongest recent routing evidence rather than full feature authorship. (role: recent area contributor; confidence: medium; commits: bab18d567b0c; files: extensions/discord/src/mentions.ts)
  • rohitjavvadi: Opened the source issue with source-level reproduction and the proof-backed replacement PR that preserves tilde-run alias rewriting. (role: likely follow-up owner; confidence: medium; commits: 891231290eed; files: extensions/discord/src/mentions.ts, extensions/discord/src/mentions.test.ts)

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

@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: 1c293d4e62

ℹ️ 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 on lines +194 to +196
let nextLineStart = findLineEnd(text, index);
if (nextLineStart < text.length) {
nextLineStart += 1;

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.

P2 Badge Preserve mentions after same-line code blocks

If a Discord message starts with a one-line triple-backtick block such as ```@alice``` outside @bob, the closing backticks are on the opener line. This starts the closer search on the next line, and the fallback below treats the opener as an unterminated fence through EOF, so mentionAliases after the closing backticks are left as plain text and the intended Discord ping is never sent. The previous regex only preserved the same-line code span and still rewrote the suffix; check same-line triple-backtick closers before falling back to an EOF segment.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 5, 2026
@rohitjavvadi

Copy link
Copy Markdown
Contributor

I think this still has a nearby behavior regression in the mention-alias path.

Current main only skips Discord backtick code blocks / inline backtick code before rewriting aliases. This PR's scanner treats ~~~ as a fenced code block too (currentFenceChar !== "\" && currentFenceChar !== "~"` plus the matching closer logic), so plain text like:

~~~
@alice
~~~

stops being rewritten to <@id>. That is a behavior change outside #90643: Discord mention aliases should still apply there because this is not the backtick code-fence case that caused the bug.

I pushed #90648 with the same #90643 fix but scoped to Discord-rendered backtick code segments, plus a regression for this case:

expect(rewriteDiscordKnownMentions("~~~\n@alice\n~~~", { accountId: "default" }))
  .toBe("~~~\n<@123456789>\n~~~");

That keeps the filed repro fixed while preserving the existing plain-text alias behavior for tilde runs.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 8, 2026
@wyf027

wyf027 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #90648, which keeps the Discord mention code-fence fix scoped to backtick code segments and carries the proof-backed regression coverage. This branch has no unique remaining landing path.

@wyf027 wyf027 closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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.

Discord mention aliases rewrite @handle inside fenced code when body contains triple-backtick literal

2 participants