Repository navigation
fix(fork): new-topic 模式下 /fork --create 新群的消息命中分身会话 - #3042
Merged
Merged
Conversation
现象:Bot 普通群默认回复模式为 new-topic 时,/fork --create 建出的新群里,顶层直接发言或 @ 机器人都不会继续分身会话,而是新开空白会话并弹出选仓卡;在新群执行 /reply-mode chat-topic 后恢复正常。 根因:/fork --create 把分身登记为 chat 作用域、锚点为新群 chatId(command-handler 中 forkSession(..., 'group', 'chat')),而新群顶层消息按 resolveRegularGroupMode 路由, new-topic 下落到 thread 作用域、锚点为消息 id(event-dispatcher 的 regularGroupRouting), 两者永远对不上。 修法:建群成功后、登记分身之前,若新群解析出的普通群模式为 new-topic,就用 setChatReplyMode 给这个新群写群级 chat-topic 覆盖(不改 Bot 默认):顶层消息平铺 命中 chatId 上的分身,群内原生话题仍各自独立。写入失败只记 warn、不阻断分身; 分身失败时用 clearChatReplyMode 撤掉刚写的覆盖。chat / chat-topic / shared 三种 模式下顶层本来就落在 chatId,不写覆盖。 验证: - bunx vitest run --project unit test/command-handler.test.ts:563 通过;新增的两条 new-topic 用例在修复前失败(expected 'new-topic' to be 'chat-topic') - bunx vitest run --project unit test/event-dispatcher.test.ts test/chat-reply-mode-store.test.ts test/reply-mode-command.test.ts test/group-creator.test.ts:688 通过 - bunx vitest run --project unit test/test-hygiene.test.ts:28 通过 - bunx tsc --noEmit -p tsconfig.json:通过 - bun run build:通过
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 11:32
|
🚀 Released in v3.59.0 |
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.
现象
Bot 的普通群默认回复模式为
new-topic时,/fork --create <新群名>建出的新群里,顶层直接发言或 @ 机器人都不会继续分身会话,而是新开空白会话并弹出选仓卡。在新群执行/reply-mode chat-topic后恢复正常。根因
/fork --create把分身登记为 chat 作用域、锚点为新群 chatId(forkSession(..., 'group', 'chat'))。而新群顶层消息按resolveRegularGroupMode路由,new-topic 下落到 thread 作用域、锚点为消息 id(event-dispatcher 的regularGroupRouting)。每条消息都是新锚点,永远命不中分身。修法
src/core/command-handler.ts:建群成功后、登记分身之前,如果新群解析出的普通群模式是new-topic,就用现有的setChatReplyMode给这个新群写群级chat-topic覆盖。这与 issue 里验证有效的/reply-mode chat-topic走同一个入口:顶层消息平铺命中 chatId 上的分身,群内原生话题仍各自独立。/reply-mode chat-topic)。clearChatReplyMode撤掉刚写的覆盖。chat/chat-topic/shared三种模式下顶层本来就落在 chatId,不写覆盖。关于 PR #1403
按要求先审了 #1403。它的核心同样是「给新群写群级 chat-topic 覆盖」,但没有基于它推进:
bot.added让位、setChatReplyMode的force/source参数和重启后重建登记,超出了根因修复的最小范围。本 PR 只取了其中的核心修法,在当前 master 上重写。
影响面
/fork --create新群会在 bots.json 的chatReplyModes里多一条群级覆盖,与用户手动/reply-mode chat-topic的效果完全一致,之后可用/reply-mode随时改或inherit恢复继承。/fork <task>子话题不经过这条路径。已知限制(本次不改)
autoStartOnGroupJoin(默认关闭)的 bot,入群自动开工与分身可能争抢同一个新群。这与回复模式无关,是既有行为。验证
bunx vitest run --project unit test/command-handler.test.ts test/event-dispatcher.test.ts test/chat-reply-mode-store.test.ts --maxWorkers=2:3 个文件 1178 个用例通过。command-handler:走真实的/fork --create。Bot 默认 new-topic 时断言分身登记前新群已是 chat-topic、Bot 默认不变;分身失败时断言覆盖被撤掉;写覆盖抛错时断言分身照常完成;chat / chat-topic / shared 三种模式不写覆盖。event-dispatcher:Bot 默认 new-topic、新群有 chat-topic 覆盖时,顶层 @ 和 1v1 群里不 @ 的直接发言都路由到 chatId 上的 chat 作用域会话。bunx tsc --noEmit -p tsconfig.json、bun run build通过。Fixes #1400