Repository navigation
Conversation
deepcoldy
force-pushed
the
fix/preserve-chat-scope-on-repo-switch
branch
from
July 20, 2026 19:18
29569df to
d73c280
Compare
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
deepcoldy
force-pushed
the
fix/preserve-chat-scope-on-repo-switch
branch
from
July 20, 2026 19:22
d73c280 to
f71d4c7
Compare
deepcoldy
approved these changes
Jul 21, 2026
deepcoldy
left a comment
Owner
There was a problem hiding this comment.
二审通过:rebase 到最新 master 后无冲突,repair 签名足够窄、load() catch 合理、createSession 可选 scope 兼容 master 其他调用点。tsc / pnpm build / 290 PR 相关测试 / 9777 完整 unit 全绿。不涉及隧道协议,platform/ 无需同步。
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.
问题现象
普通群使用 chat scope 时,先通过
/repo(或仓库选择卡片)切换工作目录,再由会话内的 Claude Code 调用botmux send,消息会发送失败。典型错误链路是:BotMux 把 Lark 群 ID(
oc_...)当作消息 ID,用 thread reply API 尝试回复,最终被 Lark 拒绝。daemon 重启后,受影响会话也会按错误的 thread scope 恢复。复现步骤
在 Lark 普通群中启动一个 chat-scope BotMux 会话。
确认初始持久化 session 形态正常:
{ "chatId": "oc_xxx", "rootMessageId": "om_xxx", "scope": "chat" }在群中执行
/repo 1;也可通过仓库选择卡片切换目录。查看对应
sessions-<appId>.json,切换后重建的记录会变成:{ "chatId": "oc_xxx", "rootMessageId": "oc_xxx" }即
scope丢失,且rootMessageId被写成 chat routing anchor。在该会话中执行
botmux send ...。CLI 读取 scope-less session 后按兼容逻辑将其视作 thread session,并尝试回复rootMessageId = oc_xxx,从而发送失败。根因
文本
/repo与仓库选择卡片的 mid-session 切换路径都会调用createSession()重建 session:rootId实际是路由用的chatId(oc_...),不是用于追踪的原始消息 ID(om_...);ds.scope;createSession()会立即保存,所以如果在调用后再补session.scope,磁盘上仍存在先写入坏记录的窗口。运行中的 daemon 仍持有
ds.scope = "chat",因此问题在当前内存路由中不明显;但botmux send和 daemon 重启恢复读取的是持久化 session,因而会触发错误。修复方案
扩展
createSession(),允许在首次落盘时原子写入 scope。文本
/repo与仓库选择卡片重建 session 时:ds.scope;om_...rootMessageId;rootId,保持原行为。加入窄范围历史数据修复,仅匹配以下已知坏记录:
scope === undefined;chatId以oc_开头;rootMessageId === chatId。对这些记录补上
scope: "chat"。普通 scope-less 旧版 thread session 不受影响。已经丢失的原始om_...trace root 无法恢复,但 chat scope 实际按chatId路由,不影响消息投递。修复数据写回失败时,保留已经成功加载并在内存中修复的 session,避免 ENOSPC/EACCES 等错误将有效会话清空。
测试
新增/更新回归覆盖:
/repo保留 scope 与原始 trace root;验证结果:
pnpm build:通过;git diff --check:通过;全量单测在清洁环境中仍有 1 个可独立复现、与本 PR 无关的既有失败:
test/v3-distillation-runner.test.ts的 PID namespace 用例中 helper PID 为 0;本 PR 涉及的测试均通过。🤖 Generated with Claude Code