Repository navigation
feat(assistant): assistantGroupChat 控制助理模式 bot 是否在多人群工作(默认只服务单人群) - #3871
Conversation
…sistant-mode bots With assistantGroupChat off (the default), an assistant-mode bot only works in groups with a single human member (bots are not counted). In groups with two or more people it ignores every message; a human @-mention gets one notice per group per 10 minutes. Unknown member counts are treated as multi-user. Gates: inbound group messages (before group-context ingest, commands and claiming), the bot being added to a multi-user group (no claim, no auto-start), and scheduled runs targeting a multi-user group. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Re-read a cached single-human count before trusting it (the shared revalidateSolo only refreshed groups with at most one bot). - Serve only an exact count of one human: a missing user_count (0) or an unknown count is multi-user, for messages, bot-added and scheduled runs. - Apply the gate to polled message-listener matches and to edited-message group-context ingest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A voluntary leave arrives as a different event than a removal, so the cached multi-user count can outlive the second person by the full cache TTL, while the rate-limited notice keeps the bot silent. A human @ now always re-reads the count, so the bot recovers on the next mention. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the owner The voluntary-leave event is not delivered, so an owner who left a group stays recorded. Once the second person was alone, the group counted as a one-person group and their messages ran in the absent owner's workspace. When a human who is not the recorded owner speaks in a one-person group, the owner cannot be a member: treat it as the owner leaving (mark left, stop the chat's sessions, prompt for a new claim). A scheduled run into a one-person group is refused unless the owner is a member. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改: 另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe (本条为自动流程发出的提示消息) |
deepcoldy
left a comment
There was a problem hiding this comment.
复审结论:暂不建议合入
复核对象为作者 HEAD 4f0ae402 / 本地 rebase 后 5912e011f2;四个提交逐一 patch-id 相同。首审的「0 阻断」需要修正:以下 2 个 P1 + 3 个 P2 都有临时运行时探针复现,另有 1 个 P3。探针使用真实生产模块、mock Lark API,运行后均已还原。
1. [P1] DM 任务改投多人群会绕过群闸,并按原 DM owner 执行
位置:src/core/session-manager.ts:4913-4918。
creatorChatId === undefined 被当成「仍投回原始 DM」,但这不是稳定事实:
- 私聊
/schedule创建路径src/core/command-handler.ts:1137-1165不写creatorChatId; - Dashboard 改目标时
src/core/scheduler.ts:2117-2123只改chatId/chatIds,不同步chatType; - 因而一个
chatType='p2p'、creatorChatId=undefined的 DM 任务改投群后,在 4914 行直接跳过所有现查;后续src/core/session-manager.ts:5415-5421又仍按 p2p 使用原任务 owner。
探针序列:合法原 DM ownerOpenId + 上述任务形态,目标 mock 为 userCount=2 的群。真实 resolveAssistantSpawn 将原 owner 写入新会话,forkWorker 调用 1 次,而 getChatRoutingFacts/getChatInfo 均为 0 次。
建议:只有 creatorChatId === task.chatId 时才走私聊快捷路径;undefined 也必须现查。现查结果为群时,还要保证后续 spawn 使用目标的真实 chatType,而不是继续沿用 stale p2p。
2. [P1] bot 发言者绕过「唯一真人不是 owner」处理,可进入已离群 owner 的会话
位置:src/im/lark/assistant-command.ts:80-93,调用点 src/im/lark/event-dispatcher.ts:6085-6095。
87 行对 senderIsBot 直接返回 undefined。可达序列:
- 归属表仍记录旧 owner(主动退群没有 withdrawn 订阅,所以记录未标 left);
- 群内剩下另一名真人和一个已获 chat grant 的 bot,
userCount=1,人数闸放行; - 真人保持沉默,bot @ 本助理;由于没有人类 sender 可供比较,不触发 owner-left 清理;
- 群聊归属解析继续以归属表中的旧 owner 为准,消息进入其会话/工作目录。
探针结果:真实 dispatcher 在上述状态下 handleChatMemberUserDeleted 调用 0 次,handleThreadReply 调用 1 次。现有群归属规则会解析为该旧 owner,因此不是只发通知的表层问题。
建议:bot sender 无法用 sender≠owner 推断 owner 离群,但也不能据此默认 owner 仍在;在实际路由前现查成员列表并 fail-closed,或让所有 sender 共用一个「唯一真人且就是当前 owner」的异步准入门。
3. [P2] 多人群中轮询丢弃的消息没有结算,群恢复单人后会延迟补投
位置:src/im/lark/event-dispatcher.ts:4384-4389。
多人群 return 发生在 claimMessageOnce 之前,所以该 message_id 没有已处理记录。在 30 分钟 backfill 窗口内,第二人离群并触发缓存失效后,下轮轮询会重新处理同一条旧消息。实时入口与轮询入口的语义因此不同:前者已吞掉,后者只是延期。
探针序列:同一 listener 消息第一次以 userCount=2 轮询,handleNewTopic=0;模拟离群后的缓存失效,再以 userCount=1 轮询同一消息,handleNewTopic=1。
建议:对已经 match、且本次判定应丢弃的消息同步留下已处理记录(最简单是把 claim 放到群闸之前),不要让它在成员变化后重新获得执行资格。
4. [P2] 调度闸忽略成员列表中已经出现的第二位真人
位置:src/core/session-manager.ts:4917-4922。
人数和成员列表分两次 await,但第二次只检查 .includes(owner)。若 getChatInfo 返回 1 后第二人入群,成员列表返回 [owner, second_person],当前条件仍把 multiUser 置为 false。即使不考虑竞态,两个权威结果相互矛盾时也不应继续放行。
探针结果:userCount=1、成员列表同时含 owner 和第二人时,任务仍 forkWorker=1。
建议:用同一次成员列表结果要求「去重后恰好一人且就是 owner」,不要只检查包含 owner;这也能顺带合并首审指出的重复 chat.get。
5. [P2] 卡片点击仍未覆盖多人群与「唯一成员非 owner」两类新约束
位置:src/services/card-click-turn-runtime.ts:115-130,164-198;建会话时旧 owner 的目录来源见 src/services/card-click-turn-bind.ts:140-164。
这条链路不经过 processMessageEvent,也没有人数/owner 在场检查。持有未过期签名卡片且能通过现有 talk/canOperate 的点击者,在以下两种情况都可继续进入旧 owner 的会话:
- 群已从单人变成多人;
- owner 主动退群后只剩另一名真人,但归属表尚未标 left。
首审将其列为仅限全开放 bot 的 P3,范围需要扩大:最新 HEAD 已明确「单人群只在唯一成员是 owner 时服务」,而卡片链路连这一条也不检查;显式获授权的非 owner 同样可达,不只全开放 bot。
探针结果:把 binder 的 assistantMultiUserGroupsOff 置为 true 后,现有「非 owner 点击者在 owner workDir 建会话」用例仍通过,accept/run 和 forkWorker 均成功,说明新开关完全没有接入。
建议:在卡片 accept 后的实际 startTurn 投递边界复用同一个 fail-closed 群闸,并覆盖已有会话与新会话;仅限制创建分支会漏掉 live-session 注入。
6. [P3] 未认领单人群会先发布任务横幅,再拒绝执行
位置:src/core/session-manager.ts:4920-4922。
spawn.kind === 'unclaimed' 时 multiUser 保持 false,前置闸放行;非 silent 任务随后在 5008/5114/5184/5202 等分支发通知,直到 5417 才以 has no assistant owner 失败。这不符合本 PR 声明的「不发任何东西」,但目前探针只观察到横幅、没有 worker 执行,所以列 P3。
探针结果:userCount=1 + unclaimed 时,sendMessage 已调用,forkWorker=0,最终错误为 no assistant owner。建议群目标只有在 spawn.kind==='owner' 且成员核验通过时才继续。
验证记录
bun run build:通过。- 首审涉及的 7 个 vitest 文件:1278/1278 通过。
bun test test/assistant-command.test.ts:29/29 通过。- 所有探针还原后复跑
event-dispatcher/scheduler-silent-execute/card-click-turn-bind:868/868 通过;git diff --exit-code干净。 - 四个作者提交与本地 rebase 提交逐一 patch-id:全部 MATCH。
- 本轮未重复真机飞书验证;上述问题均由真实生产模块 + 可控 Lark mock 的运行时探针复现,不是仅凭源码猜测。
首审的 HTTP trigger / Dashboard 管理员入口仍按现有鉴权与 PR 非目标边界处理,不计为阻断;VC / relay / transfer / captureHumanInput / autoInviteOwner / withdrawn 订阅等声明的有意排除也未计入上述清单。
…es and card clicks A group is served only while its live member list (bots excluded), deduplicated, is exactly the recorded owner; a lookup failure refuses. - schedules: only a task delivered back to its own DM (creatorChatId === chatId) skips the lookup; a DM task retargeted to a group is checked and spawns as a group. Unclaimed one-person groups are refused before the banner. The member list replaces the second chat.get and a contains-owner check. - messages: a bot speaker cannot vouch for the owner, so the member list decides (owner gone => treated as left; otherwise unverifiable => dropped). - message-listener polling: claim the message before the group check so a message dropped in a multi-user group is not backfilled once it turns solo; polled senders go through the same member-list owner check. - card clicks: existing and new sessions both pass the same check before the nonce is consumed (reason assistant_group). Co-Authored-By: Claude Opus 5.5 <[email protected]>
3176350 to
bedb9f9
Compare
|
感谢复审,6 条全部接受,修复在 bedb9f9。核心改动是新增
验证:
|
- 轮询区分明确非法的终态丢弃与瞬时查询失败,恢复后可重试且避免重复成员查询\n- 定时任务绑定当前 owner 与执行者,补 union-only 身份换算及最终 authority 复核\n- 卡片处理等待期过期、最终投递、双点击接管和半建会话的 durable 清理 Co-Authored-By: Claude Code <[email protected]>
|
已在作者实现 这份增量不重复原六项修复,集中处理并发与持久状态交叠:
验证:
本轮未重复真机飞书验证;作者上一提交的真机结果保持不变。请按新 head |
合并 91d7bec。卡片 startTurnInner 保留群准入、nextStep 与 registry/status 投递前复查,复查后接 master 的 plannedOpeningBackendType input 构造;测试 mock 同时保留 assistant-spawn 与 created-groups-store 配置。 Co-Authored-By: Claude Code <[email protected]>
合码窗口 master 再进 4 提交。与本 PR 原创代码仅 daemon.ts、card-handler.ts 两文件重叠且改动区段不相邻(不同函数,相隔数十至数千行),git 自动合并零冲突。 合并 tree fd4c644 与 git merge-tree --write-tree 预测完全一致(三点一线)。 合并树验证:bun run build(tsc/typecheck/audit)通过;定向 458 用例全绿, 含本 PR 核心(streaming-card/capacity/session-contract-gateway)与新进提交 自带交集测试(ask-chat-scope/scheduler-silent/trigger-session); bun.lock/package.json 未变。 按复审意见不走 #109 豁免,本 merge commit 触发全新完整 CI 首跑后再合。 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@xu4wang @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 6a69b89…0331c8a78(5 个提交),同批合入的还有 #3892 #3888 #3884 #3889,失败不一定由本 PR 引起。
|
|
🚀 Released in v3.59.35 |
背景
个人助理模式(#3652)下,一个群归一个主人:群里每个人的发言都进主人的会话,也都能借助理看到主人让它记住的内容。主人把同事拉进群,就等于把自己的助理空间分享给了他们。对于全员可私聊、主要处理个人数据的 bot(财务对账、个人邮件、私聊汇总),这个默认值太宽了。
改动
新增 bot 配置
assistantGroupChat(布尔,默认关,/botconfig和 dashboard 都能即时改)。只在assistantMode开着时有意义。关着时,助理模式 bot 只在恰好有 1 个真人的群里工作(bot 不计入人数,用
chat.get的user_count判断):event-dispatcher,在群上下文采集、命令、认领、建会话之前拦截):user_count,都按多人群处理。im.chat.member.user.withdrawn_v1),我们没有订阅;不现查的话,人走后 bot 要等缓存过期才恢复。handleChatMemberUserDeleted→handleAssistantOwnerLeft处理:标记主人已离开、停掉群内会话、提示重新认领。这条消息不会进入原主人的目录。开关打开时,行为与现状完全一致。
不在本 PR 范围内(有意为之)
captureHumanInput,在 SDK ACK 之前同步执行),第二个人进群后,主人的回答仍会交给插件。要拦就得把异步查人数放进同步 ACK 路径。autoInviteOwnerOnGroupAdd不随开关联动:别人把 bot 拉进他的单人群时,默认会把 bot 管理员也拉进来,群就变成两人。需要的部署方自行关掉这个开关。handleAssistantOwnerLeft只订阅了user.deleted_v1。本 PR 在开关关着时用「单人群里说话的不是主人」兜底;开关打开时,主人主动退群的问题仍然存在,建议后续单独补订阅user.withdrawn_v1。测试
assistant-command、event-dispatcher(消息入口、单人群放行、开关打开、入群、主人不在)、scheduler-silent-execute(多人群、缺字段、查询失败、单人群放行、主人不在、私聊任务不查)、bot-config-store。另有 3 个测试文件的assistant-spawnmock 补了新导出。bun test test/assistant-command.test.ts通过。🤖 Generated with Claude Code