hermes - ✅(Solved) Fix fix(weixin): _WEIXIN_TARGET_RE only matches @chatroom, rejects @im.wechat DM IDs causing ret=-2 [1 pull requests, 2 comments, 2 participants]

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…
GitHub stats
NousResearch/hermes-agent#17778Fetched 2026-05-01 05:55:53
View on GitHub
Comments
2
Participants
2
Timeline
9
Reactions
0
Timeline (top)
labeled ×3commented ×2renamed ×2closed ×1

Error Message

  1. Receive ret=-2 error

Root Cause

WeChat internally uses two session ID suffixes to distinguish session types:

SuffixSession TypeExample ID
@chatroomGroup chat12345678@chatroom
@im.wechatPersonal user (friend DM)[email protected]

Current regex:

_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")

@chatroom only matches group chats; DM IDs with @im.wechat are rejected at the format validation stage.

Fix Action

Fix

Change @chatroom to @(?:chatroom|im\.wechat) to allow both group chats and personal DMs:

-_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")
+_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$")

PR fix notes

PR #17784: fix(weixin): allow @im.wechat DM IDs in _WEIXIN_TARGET_RE

Description (problem / solution / changelog)

Summary

Fixes #17778 — the _WEIXIN_TARGET_RE regex in tools/send_message_tool.py only matched @chatroom suffix, rejecting personal user IDs ending in @im.wechat. This caused all Weixin direct messages to fail with ret=-2.

Root Cause

WeChat uses two types of session ID suffixes:

SuffixTypeExample
@chatroomGroup chat12345678@chatroom
@im.wechatPersonal user (DM)[email protected]

The regex only accepted @chatroom, causing personal DM IDs to be rejected at the format validation stage.

Fix

One-line change on line 30:

-_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")
+_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$")

Impact

  • Enables send_message to target personal WeChat users (DMs)
  • Fully backward compatible — existing @chatroom matching is preserved
  • No other platforms affected

Test Plan

  • send_message to @chatroom group IDs continues to work
  • send_message to @im.wechat personal IDs now passes format validation
  • filehelper, wxid_*, gh_* patterns still accepted

Closes #17778

Changed files

  • tools/send_message_tool.py (modified, +1/-1)

Code Example

_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")

---

-_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")
+_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$")
RAW_BUFFERClick to expand / collapse

Bug Description

The _WEIXIN_TARGET_RE regex on line 30 of tools/send_message_tool.py only matches session IDs with the @chatroom suffix, rejecting all personal user (DM) IDs ending in @im.wechat. When the send_message target is a personal user (e.g., weixin:[email protected]), _parse_target_ref() returns (None, None, False)is_explicit=False → falls through to channel name resolution → resolution fails → fallback to home channel → home channel lacks a valid context_token → iLink returns ret=-2.

Group chat messages (@chatroom) work fine because an inbound message in the same session carries a valid context_token.

Steps to Reproduce

  1. Configure the Weixin gateway (iLink clawbot mode)
  2. Use send_message(action='list') to obtain a personal user ID (ending in @im.wechat)
  3. Call send_message(action='send', target='weixin:[email protected]', message='test')
  4. Receive ret=-2 error

Root Cause

WeChat internally uses two session ID suffixes to distinguish session types:

SuffixSession TypeExample ID
@chatroomGroup chat12345678@chatroom
@im.wechatPersonal user (friend DM)[email protected]

Current regex:

_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")

@chatroom only matches group chats; DM IDs with @im.wechat are rejected at the format validation stage.

Fix

Change @chatroom to @(?:chatroom|im\.wechat) to allow both group chats and personal DMs:

-_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@chatroom|filehelper)\s*$")
+_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$")

Impact

  • The tool is named send_message but can only send to group chats — functionality doesn't match the API name
  • Affects all Weixin scenarios requiring direct messages (DM) to personal users
  • Fix is backward-compatible: existing @chatroom matching is unaffected

Environment

  • Hermes Agent main branch
  • Weixin platform (iLink clawbot)

extent analysis

TL;DR

Update the _WEIXIN_TARGET_RE regex to match both @chatroom and @im.wechat suffixes to fix the issue with sending messages to personal users.

Guidance

  • Verify the current regex pattern in tools/send_message_tool.py to confirm it only matches @chatroom suffixes.
  • Update the _WEIXIN_TARGET_RE regex to r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$" to allow matching of both @chatroom and @im.wechat suffixes.
  • Test the updated regex with personal user IDs ending in @im.wechat to ensure successful message sending.
  • Review the send_message function to ensure it correctly handles the updated regex and resolves the target reference for personal user IDs.

Example

_WEIXIN_TARGET_RE = re.compile(r"^\s*((?:wxid|gh|v\d+|wm|wb)_[A-Za-z0-9_-]+|[A-Za-z0-9._-]+@(?:chatroom|im\.wechat)|filehelper)\s*$")

Notes

The fix is backward-compatible and does not affect existing @chatroom matching. However, it's essential to test the updated regex thoroughly to ensure it works as expected for both group chats and personal user IDs.

Recommendation

Apply the workaround by updating the _WEIXIN_TARGET_RE regex to match both @chatroom and @im.wechat suffixes, as this fix is backward-compatible and resolves the issue with sending messages to personal users.

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

hermes - ✅(Solved) Fix fix(weixin): _WEIXIN_TARGET_RE only matches @chatroom, rejects @im.wechat DM IDs causing ret=-2 [1 pull requests, 2 comments, 2 participants]