Skip to content

fix(mentions): support single-char CJK names in mention pattern matching - #89864

Merged
steipete merged 6 commits into
openclaw:mainfrom
dwc1997:fix/87303-cjk-single-char-mention
Jul 18, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
dwc1997:fix/87303-cjk-single-char-mention

Conversation

@dwc1997

@dwc1997 dwc1997 commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

fix(mentions): support single-char CJK names in mention pattern matching

Summary

Problem: The \b word boundary assertion in JavaScript regex does not recognise CJK characters as word characters. When an agent identity name is a single CJK character (e.g. "包"), the derived mention pattern \b@?包\b fails to match @包 in group chat messages. This affected DingTalk/钉钉 and other Chinese group chat channels.

Fix: Added a wrapWithBoundaries helper in deriveMentionPatterns that detects CJK characters in the pattern and replaces \b with explicit Unicode-aware lookaround assertions. ASCII-only patterns continue to use \b unchanged.

Out of scope: No changes to extension-specific mention parsers. Only the core shared deriveMentionPatterns function is affected.

Linked context

Closes #87303

Real behavior proof

  • Behavior or issue addressed: Single-char CJK mention names (e.g. @包) were not detected as mentions in group chat messages because \b does not work with CJK characters in JavaScript regex
  • Real environment tested: Windows 10, Node.js v22.11.0, OpenClaw latest main (commit 70a989a, 2026-06-03)
  • Exact steps or command run after this patch: Ran OpenClaw's actual buildMentionRegexes helper via node --import tsx proof-87303.mjs with a real agents.list config containing a CJK identity name
  • Evidence after fix: Terminal output from running OpenClaw's production buildMentionRegexes and matchesMentionPatterns helpers:
$ node --import tsx proof-87303.mjs
regex count: 1
pattern: (?:(?<=^)|(?<![w一-鿿㐀-䶿]))@?包(?![w一-鿿㐀-䶿])

--- Single-char CJK mention tests ---
@包 你好 => true
包 你好 => true
面包好吃 => false

--- Two-char CJK mention tests ---
@苏苏 你好 => true
紫苏苏叶 => false
  • Observed result after fix: buildMentionRegexes with agents.list: [{ id: "cjk-agent", identity: { name: "包" } }] produces a regex that correctly matches @包 in Chinese text and correctly rejects 面包好吃 (no false positive inside longer CJK word). Two-char CJK names (苏苏) also work correctly.
  • What was not tested: Live DingTalk group chat end-to-end test (requires DingTalk bot credentials)

Tests and validation

  • src/auto-reply/reply/mentions.test.ts: New describe("CJK single-char mention matching (regression #87303)") — 5 tests using agents.list config shape with concrete agent id
  • No CHANGELOG.md edits

Risk checklist

  • userVisible: No
  • configEnvMigration: No
  • securityAuthNetwork: No
  • Mitigation: ASCII-only patterns unchanged; CJK path uses standard lookaround assertions

Current review state

  • Addressed ClawSweeper P1: Fixed tests to use agents.list with concrete agent id
  • Addressed ClawSweeper P1: Added real after-fix proof running OpenClaw's buildMentionRegexes helper
  • AI-assisted (built with Claude Code)

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 3, 2026
@clawsweeper

clawsweeper Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 1:50 AM ET / 05:50 UTC.

Summary
The PR replaces ASCII word-boundary matching for derived agent identity names with Unicode-aware boundaries and adds multilingual derived-mention regression tests.

PR surface: Source +18, Tests +73. Total +91 across 2 files.

Reproducibility: yes. —source-reproducible with high confidence: current main derives identity-name patterns with JavaScript word boundaries, while the supplied production-helper transcript demonstrates the failing CJK boundary case and the after-fix result. An independent live DingTalk run was not performed in this review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #87303
Summary: This PR is the active candidate fix for the canonical report of single-character CJK group-chat mentions failing to trigger.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh the branch against current main and establish whether the failed compact shard is attributable before merge.

Risk before merge

  • [P1] This changes the shared derived-name mention path used across channels, so a boundary mistake could cause false-positive replies or suppress legitimate mentions outside the reported DingTalk case.
  • [P1] The PR is behind current main and its current check set includes one failed compact shard plus still-running work; merge safety should be confirmed on the exact rebased head before landing.

Maintainer options:

  1. Refresh shared mention proof before merge (recommended)
    Rebase or refresh the exact head against current main, resolve or classify the failed compact shard, and retain focused Unicode matching and stripping coverage before landing.
  2. Pause for a narrower channel-specific alternative
    If maintainers do not want Unicode boundary semantics in the shared derived-name path, pause this PR and define the owner boundary for a channel-specific fix instead.

Next step before merge

  • [P2] The remaining action is assigned maintainer review of shared mention-routing semantics and a fresh exact-head merge/CI confirmation, not an autonomous repair.

Security
Cleared: The two-file diff changes regex derivation and tests only; it adds no dependency, workflow, permission, secret, network, or code-execution surface.

Review details

Best possible solution:

Keep Unicode-aware boundaries in the shared derived-identity path, preserve explicit user-configured patterns as-is, and land only after the rebased exact head demonstrates matching and stripping behavior without regressions.

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

Yes—source-reproducible with high confidence: current main derives identity-name patterns with JavaScript word boundaries, while the supplied production-helper transcript demonstrates the failing CJK boundary case and the after-fix result. An independent live DingTalk run was not performed in this review.

Is this the best way to solve the issue?

Yes, conditionally: changing the shared derived-name boundary logic is narrower and less duplicative than per-channel parser fixes, provided the refreshed head preserves explicit configured patterns and passes shared mention-routing validation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cafa7606b757.

Label changes

Label changes:

  • remove mantis: telegram-visible-proof: Current Telegram visible-proof status is not_needed.

Label justifications:

  • P2: The fix addresses a real group-chat mention-routing gap with limited but user-visible blast radius.
  • merge-risk: 🚨 message-delivery: Changing shared derived mention boundaries can alter which incoming group-chat messages trigger an agent or have their mention stripped.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR provides an after-fix terminal transcript using OpenClaw’s production mention helpers with a configured CJK identity name; it directly shows successful standalone matches and rejected embedded-word matches. Any future proof should redact private configuration details.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides an after-fix terminal transcript using OpenClaw’s production mention helpers with a configured CJK identity name; it directly shows successful standalone matches and rejected embedded-word matches. Any future proof should redact private configuration details.
Evidence reviewed

PR surface:

Source +18, Tests +73. Total +91 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 10 +18
Tests 1 75 2 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 103 12 +91

What I checked:

  • Current-main gap: Current main still derives identity-name mention patterns with JavaScript word boundaries, the behavior reported to fail for a single Han-character name; the proposed branch changes that shared derivation path rather than a channel-specific parser. (src/auto-reply/reply/mentions.ts, cafa7606b757)
  • Shared behavior coverage: The changed module owns both derived-pattern resolution and compilation used by mention matching and stripping, so the patch addresses the common core path while leaving explicit group-chat mentionPatterns untouched. (src/auto-reply/reply/mentions.ts, db8b6cad0fa1)
  • Regression coverage: The branch expands mention tests across Han, kana, Hangul, accented Latin, Cyrillic, Arabic, and Devanagari names, including rejection of embedded-word and combining-mark matches. (src/auto-reply/reply/mentions.test.ts, db8b6cad0fa1)
  • Feature-history signal: The latest PR-head commit is titled “fix(mentions): match derived names with Unicode boundaries” and was authored by steipete, who is also assigned to the PR; this is the strongest available routing signal for the current solution. (src/auto-reply/reply/mentions.ts, db8b6cad0fa1)
  • Related canonical bug: The PR explicitly closes the open canonical report for single-character Chinese group-chat mentions, so the issue remains open until this candidate fix is merged rather than being closed early.
  • Real behavior proof: The PR body includes an after-fix terminal run against production buildMentionRegexes and matchesMentionPatterns showing @包 and 包 match while 面包好吃 and other embedded forms do not. (src/auto-reply/reply/mentions.ts, db8b6cad0fa1)

Likely related people:

  • steipete: Authored the latest Unicode-boundary commit on this branch and is assigned to review the current candidate fix. (role: recent area contributor and assigned reviewer; confidence: high; commits: db8b6cad0fa1; files: src/auto-reply/reply/mentions.ts, src/auto-reply/reply/mentions.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-01T14:09:54.954Z sha 642aaea :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 3, 2026
@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. P2 Normal backlog priority with limited blast radius. labels Jun 3, 2026
@dwc1997

dwc1997 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 3, 2026
@dwc1997

dwc1997 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 4, 2026
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch from daaee81 to e50492d Compare June 4, 2026 14:14
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch from e50492d to 74095b5 Compare June 4, 2026 14:29
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch from 74095b5 to 3bebb72 Compare June 4, 2026 14:49
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch from 3bebb72 to 13bcec0 Compare June 4, 2026 15:07
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 6, 2026
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jun 20, 2026
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch 2 times, most recently from 187d24f to ccc0534 Compare July 1, 2026 07:55
dwc1997 and others added 3 commits July 1, 2026 20:08
The \b word boundary assertion does not recognise CJK characters as word
characters in JavaScript regex, so single-char CJK mention names (e.g.
@包) failed to match in group chat messages. Replace \b with explicit
lookaround assertions that treat CJK characters as boundary-worthy when
the mention pattern contains CJK characters.

Fixes openclaw#87303

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The test config uses agents.default.identity.name but was calling
buildMentionRegexes(cfg, undefined). Without an agentId, resolveAgentConfig
is never called and the identity is not resolved, producing empty regexes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Use the canonical agents.list array config shape instead of the
non-existent agents.default object. Pass the matching agent id to
buildMentionRegexes so resolveAgentConfig finds the identity.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dwc1997
dwc1997 force-pushed the fix/87303-cjk-single-char-mention branch from ccc0534 to 07288a6 Compare July 1, 2026 12:11
@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 Jul 16, 2026
@steipete steipete self-assigned this Jul 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 18, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 18, 2026
@clawsweeper clawsweeper Bot removed the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jul 18, 2026
@steipete
steipete merged commit 021d252 into openclaw:main Jul 18, 2026
179 of 181 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…ing (openclaw#89864)

* fix(mentions): support single-char CJK names in mention pattern matching

The \b word boundary assertion does not recognise CJK characters as word
characters in JavaScript regex, so single-char CJK mention names (e.g.
@包) failed to match in group chat messages. Replace \b with explicit
lookaround assertions that treat CJK characters as boundary-worthy when
the mention pattern contains CJK characters.

Fixes openclaw#87303

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(tests): pass agentId to buildMentionRegexes in CJK mention tests

The test config uses agents.default.identity.name but was calling
buildMentionRegexes(cfg, undefined). Without an agentId, resolveAgentConfig
is never called and the identity is not resolved, producing empty regexes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(tests): use agents.list config shape for CJK mention tests

Use the canonical agents.list array config shape instead of the
non-existent agents.default object. Pass the matching agent id to
buildMentionRegexes so resolveAgentConfig finds the identity.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(mentions): match derived names with Unicode boundaries

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…ing (openclaw#89864)

* fix(mentions): support single-char CJK names in mention pattern matching

The \b word boundary assertion does not recognise CJK characters as word
characters in JavaScript regex, so single-char CJK mention names (e.g.
@包) failed to match in group chat messages. Replace \b with explicit
lookaround assertions that treat CJK characters as boundary-worthy when
the mention pattern contains CJK characters.

Fixes openclaw#87303

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(tests): pass agentId to buildMentionRegexes in CJK mention tests

The test config uses agents.default.identity.name but was calling
buildMentionRegexes(cfg, undefined). Without an agentId, resolveAgentConfig
is never called and the identity is not resolved, producing empty regexes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(tests): use agents.list config shape for CJK mention tests

Use the canonical agents.list array config shape instead of the
non-existent agents.default object. Pass the matching agent id to
buildMentionRegexes so resolveAgentConfig finds the identity.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(mentions): match derived names with Unicode boundaries

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S stale Marked as stale due to inactivity status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 群聊 @ 提及:单字昵称无法解析为 mention

2 participants