fix: populate SenderId on inbound MsgContext for multi-user routing#88
Open
yarnovo wants to merge 1 commit intoTencent:mainfrom
Open
fix: populate SenderId on inbound MsgContext for multi-user routing#88yarnovo wants to merge 1 commit intoTencent:mainfrom
yarnovo wants to merge 1 commit intoTencent:mainfrom
Conversation
OpenClaw core's `buildInboundUserContextPrefix` reads `ctx.SenderId` to populate the `sender_id` field of the inbound `Conversation info (untrusted metadata)` block. Memory plugins like `openclaw-honcho` parse that block to route per-sender peer state. Currently `weixinMessageToMsgContext` only sets `From: from_user_id` and leaves `SenderId` undefined, so the metadata block omits `sender_id`. Downstream plugins that depend on it (honcho `extractSenderId`, etc.) collapse all senders into a single peer, breaking multi-user isolation. This change: - Adds optional `SenderId?: string` to `WeixinMsgContext` with a doc comment explaining the contract with OpenClaw core. - Sets `SenderId: from_user_id` alongside `From` in `weixinMessageToMsgContext`. - Adds two test cases: one that asserts `SenderId` matches `from_user_id` for a normal message, and one that verifies the empty-string fallback when `from_user_id` is missing. For comparison, both `@wecom/wecom-openclaw-plugin` and `@larksuite/openclaw-lark` already populate `SenderId` on inbound; this brings weixin in line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Set
SenderIdon theWeixinMsgContextreturned byweixinMessageToMsgContextso OpenClaw core can route per-sender peer state correctly when this plugin is used alongside multi-user-aware memory plugins (e.g.openclaw-honcho).Why
OpenClaw core's
buildInboundUserContextPrefixreadsctx.SenderIdto populate thesender_idfield of the inboundConversation info (untrusted metadata)block prepended to user messages. Memory plugins parse that block to attribute messages to a specific sender's peer.Currently
weixinMessageToMsgContextonly setsFrom: from_user_idand leavesSenderIdundefined. The resulting metadata block omitssender_id, so downstream plugins (e.g. honcho'sextractSenderId) cannot identify the sender and collapse all senders into a single peer. Multi-user isolation breaks for any deployment that exposes this plugin to more than one wxid.For comparison, the equivalent inbound builders in
@wecom/wecom-openclaw-plugin(monitor.jsline settingSenderId: body.from.userid) and@larksuite/openclaw-lark(dispatch-builders.jsline settingSenderId: opts.senderId) already populate this field. This change brings weixin in line.Changes
SenderId?: stringto theWeixinMsgContexttype with a doc comment explaining the contract with OpenClaw core. Optional rather than required to preserve backward compatibility for any external code that constructs this type directly.SenderId: from_user_idalongsideFrominweixinMessageToMsgContext.SenderIdis populated fromfrom_user_idfor a normal message.SenderIdfalls back to empty string whenfrom_user_idis missing (matches the existingFrom/Tobehavior).Test plan
npm run typecheckpasses.npm test— 337 of 338 tests pass; the single pre-existing failure insrc/auth/pairing.test.ts > registerUserInFrameworkStore > uses withFileLock for concurrency safetyreproduces on a clean checkout ofupstream/mainand is unrelated to this change.npx vitest run src/messaging/inbound.test.ts— all 26 inbound tests pass, including the two new SenderId cases.Diff