fix: multi-bot accountId isolation in shared gateway#143
Merged
yujiawei merged 3 commits intodmwork-org:mainfrom Apr 1, 2026
Merged
fix: multi-bot accountId isolation in shared gateway#143yujiawei merged 3 commits intodmwork-org:mainfrom
yujiawei merged 3 commits intodmwork-org:mainfrom
Conversation
When multiple bots share the same OpenClaw Gateway process and are members of the same group, _groupToAccount (Map<string, string>) used a last-write-wins strategy — whichever bot last processed a group message overwrote the mapping. The handleAction correction logic then replaced the caller's correct accountId with the wrong one, causing messages/files to be sent from the wrong bot's identity. Changes: - Change _groupToAccount from Map<string, string> to Map<string, Set<string>> to support 1:N group-to-account mapping - registerGroupToAccount now adds to a Set instead of overwriting - resolveAccountForGroup returns undefined when multiple bots share a group (ambiguous), only resolves for single-bot groups - handleAction correction logic uses resolveAccountForGroup and only corrects when a definitive answer exists (single bot owns the group) - Add 8 test cases covering single-bot, multi-bot, and handleAction correction scenarios Fixes: dmwork-org/dmwork-PM#183
yujiawei
reviewed
Apr 1, 2026
Collaborator
yujiawei
left a comment
There was a problem hiding this comment.
CI Fix — Type Check Errors
核心逻辑没问题 👍,就是测试文件有两个类型问题导致 CI 挂了:
1. ctx 缺少 channel 属性
ChannelMessageActionContext 要求 channel 字段,三个 handleAction 测试的 ctx 都要补上:
const ctx = {
accountId: "wrongBot",
action: "send",
channel: "dmwork", // ← 补这个
// ... 其余不变
};2. dmworkPlugin.actions 可能为 undefined
三处 dmworkPlugin.actions!.handleAction(ctx) 需要加非空断言 !(或者统一在 describe 外面断言一次):
// 方式 A:每次调用加 !
await dmworkPlugin.actions!.handleAction(ctx);
// 方式 B:describe 开头断言一次(推荐)
const handleAction = dmworkPlugin.actions?.handleAction;
assert(handleAction, "actions should be defined");两处改完就能过 CI。
- Add missing 'channel: "dmwork"' to all handleAction test ctx objects - Add non-null assertion (!) on handleAction calls for type safety
yujiawei
approved these changes
Apr 1, 2026
Collaborator
yujiawei
left a comment
There was a problem hiding this comment.
CI green ✅ 310/310 tests pass. 逻辑正确,类型问题已修。
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.
Problem
When multiple bots share the same OpenClaw Gateway process and are members of the same group, messages/files sent by Bot A could be sent from Bot B's identity (accountId isolation failure).
Root Cause
_groupToAccount(Map<string, string>) used a last-write-wins strategy — whichever bot last processed a group message overwrote the mapping. ThehandleActioncorrection logic then replaced the caller's correct accountId with the wrong one.Trigger Path
registerGroupToAccount(groupNo, 'bot-b')overwrites Bot A's entryhandleActioncallsresolveAccountForGroup(groupNo)→ returns'bot-b'Changes
_groupToAccountfromMap<string, string>toMap<string, Set<string>>(1:N mapping)registerGroupToAccountnow adds to a Set instead of overwritingresolveAccountForGroupreturnsundefinedwhen multiple bots share a group (ambiguous)handleActioncorrection only applies when a single bot definitively owns the groupTesting
Fixes: dmwork-org/dmwork-PM#183