openclaw - 💡(How to fix) Fix [Feature]: Matrix — 允许通过配置开关控制 Agent emoji 是否触发 mention

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Matrix 渠道中,Agent 的 identity.emoji 会被自动加入 mention 匹配模式,导致任何包含该 emoji 的消息都会触发 Agent 回复,等同于被 @。建议增加配置开关让用户自主决定是否启用 emoji 作为 mention 触发条件。

Root Cause

Matrix 渠道中,Agent 的 identity.emoji 会被自动加入 mention 匹配模式,导致任何包含该 emoji 的消息都会触发 Agent 回复,等同于被 @。建议增加配置开关让用户自主决定是否启用 emoji 作为 mention 触发条件。

Fix Action

Fix / Workaround

影响:

  • 在多人 Agent 共享同一个 Matrix Room 时,某条消息里出现 📊 或 🌍 等 emoji,对应 Agent 就会误触发
  • 用户无法关闭这个行为,唯一的 workaround 是去掉 Agent 的 emoji 或通过 groupChat.mentionPatterns 完全覆盖(后者需要为每个 Agent 单独配置)

影响:

  • 在多人 Agent 共享同一个 Matrix Room 时,某条消息里出现 📊 或 🌍 等 Agent配置的 emoji,对应 Agent 就会误触发
  • 用户无法关闭这个行为,唯一的 workaround 是去掉 Agent 的 emoji 或通过 groupChat.mentionPatterns 完全覆盖(后者需要为每个 Agent 单独配置)

Code Example

function deriveMentionPatterns(identity) {
    const patterns = [];
    const name = normalizeOptionalString(identity?.name);
    if (name) {
        // name 有 \b 单词边界 + 可选的 @ 前缀,是安全的
        const parts = name.split(/\s+/).filter(Boolean).map(escapeRegExp);
        const re = parts.length ? parts.join(String.raw`\s+`) : escapeRegExp(name);
        patterns.push(String.raw`\b@?${re}\b`);
    }
    const emoji = normalizeOptionalString(identity?.emoji);
    if (emoji) patterns.push(escapeRegExp(emoji));  // ← 问题:无边界的纯文本匹配
    return patterns;
}

---

// 方案 A:channels.matrix 层级
{
  "channels": {
    "matrix": {
      "enableEmojiMention": false  // 默认 true 保持向后兼容
    }
  }
}

// 方案 B:messages 全局层级(影响所有渠道)
{
  "messages": {
    "groupChat": {
      "emojiMention": {
        "enabled": true  // 默认 true
      }
    }
  }
}

// 方案 C:agents.list.* 层级(per-agent 控制)
{
  "id": "a-stock-index",
  "groupChat": {
    "emojiMention": false
  }
}
RAW_BUFFERClick to expand / collapse

Summary

Matrix 渠道中,Agent 的 identity.emoji 会被自动加入 mention 匹配模式,导致任何包含该 emoji 的消息都会触发 Agent 回复,等同于被 @。建议增加配置开关让用户自主决定是否启用 emoji 作为 mention 触发条件。

Problem to solve

源码 dist/mentions-D6uUpOuN.jsderiveMentionPatterns 函数:

function deriveMentionPatterns(identity) {
    const patterns = [];
    const name = normalizeOptionalString(identity?.name);
    if (name) {
        // name 有 \b 单词边界 + 可选的 @ 前缀,是安全的
        const parts = name.split(/\s+/).filter(Boolean).map(escapeRegExp);
        const re = parts.length ? parts.join(String.raw`\s+`) : escapeRegExp(name);
        patterns.push(String.raw`\b@?${re}\b`);
    }
    const emoji = normalizeOptionalString(identity?.emoji);
    if (emoji) patterns.push(escapeRegExp(emoji));  // ← 问题:无边界的纯文本匹配
    return patterns;
}

问题:

  • Agent 名字有 \b 单词边界和 @ 前缀约束,是合理的 mention 匹配
  • Agent emoji 直接被 escapeRegExp 后作为无边界正则加入 patterns,任何位置出现该 emoji 字符都会 match

影响:

  • 在多人 Agent 共享同一个 Matrix Room 时,某条消息里出现 📊 或 🌍 等 emoji,对应 Agent 就会误触发
  • 用户无法关闭这个行为,唯一的 workaround 是去掉 Agent 的 emoji 或通过 groupChat.mentionPatterns 完全覆盖(后者需要为每个 Agent 单独配置)

Proposed solution

在 Matrix 渠道配置中增加一个开关,控制 deriveMentionPatterns 是否包含 emoji:

// 方案 A:channels.matrix 层级
{
  "channels": {
    "matrix": {
      "enableEmojiMention": false  // 默认 true 保持向后兼容
    }
  }
}

// 方案 B:messages 全局层级(影响所有渠道)
{
  "messages": {
    "groupChat": {
      "emojiMention": {
        "enabled": true  // 默认 true
      }
    }
  }
}

// 方案 C:agents.list.* 层级(per-agent 控制)
{
  "id": "a-stock-index",
  "groupChat": {
    "emojiMention": false
  }
}

推荐 方案 A + 方案 C 结合:

  • channels.matrix.enableEmojiMention 作为渠道级默认值
  • agents.list.*.groupChat.emojiMention 作为 per-agent 覆盖

Alternatives considered

No response

Impact

影响:

  • 在多人 Agent 共享同一个 Matrix Room 时,某条消息里出现 📊 或 🌍 等 Agent配置的 emoji,对应 Agent 就会误触发
  • 用户无法关闭这个行为,唯一的 workaround 是去掉 Agent 的 emoji 或通过 groupChat.mentionPatterns 完全覆盖(后者需要为每个 Agent 单独配置)

Evidence/examples

No response

Additional information

No response

extent analysis

TL;DR

To fix the issue, add a configuration switch to control whether deriveMentionPatterns includes emoji, allowing users to decide whether to enable emoji as a mention trigger.

Guidance

  • Identify the desired configuration level: channel, global, or per-agent, to determine where to add the enableEmojiMention switch.
  • Choose a configuration scheme, such as 方案 A + 方案 C, which combines channel-level defaults with per-agent overrides.
  • Update the deriveMentionPatterns function to respect the new configuration switch, conditionally including emoji in mention patterns based on the user's setting.
  • Test the new configuration to ensure it correctly controls emoji-based mentions and prevents unintended triggers.

Example

function deriveMentionPatterns(identity, config) {
    const patterns = [];
    // ...
    const emoji = normalizeOptionalString(identity?.emoji);
    if (emoji && config.enableEmojiMention) {
        patterns.push(escapeRegExp(emoji));
    }
    return patterns;
}

Notes

The proposed solution requires careful consideration of the configuration level and scheme to ensure flexibility and backward compatibility. The example code snippet assumes a config object with an enableEmojiMention property, which may need to be adapted to the actual configuration structure.

Recommendation

Apply workaround by adding a configuration switch to control emoji mentions, as this allows users to decide whether to enable emoji as a mention trigger and provides a flexible solution for different use cases.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: Matrix — 允许通过配置开关控制 Agent emoji 是否触发 mention