zai-org / zai-org/feedback

[Bug] 多个微信 Bot 连接同一项目时会话映射互相覆盖,导致多人协作需反复绑定

Open
#399 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2 status: 待评估 type: Bug
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category

对话 / Agent 交互 · Agent chat

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking (无法使用核心功能 / core function unusable)

复现频率 · Reproducibility

偶现 · Sometimes

问题描述 · Description

使用场景与影响

一名用户、几人团队或小公司,通常希望把 ZCode 连接到同一个公司知识库或业务项目:

  • 每位成员使用自己的微信和微信 Bot;
  • 所有 Bot 指向同一个 ZCode 工作区/知识库;
  • 成员通过微信上传客户资料、供应商资料、流程文档、报表等内容;
  • Agent 在共享项目中查询资料、整理信息,并把新的公司事项写入项目;
  • 每个成员仍保持自己独立、连续的会话上下文。

这样,微信 Bot 才能成为一个低门槛的在线协同入口:成员不必坐在安装 ZCode 的电脑前,也能围绕同一个公司项目持续工作。

当前问题

多个微信 Bot 连接同一个工作区、各自绑定不同 ZCode 会话后,不同成员交替或同时发送消息时,某个 Bot 的会话映射可能被另一个 Bot 的状态写入覆盖:

  1. 原有 activeTaskId 消失;
  2. 下一条普通消息被识别为“首次激活”并回复激活欢迎语;
  3. 再下一条消息创建新的 ZCode 会话;
  4. 原会话仍留在任务列表,但该成员的 Bot 不再继续原会话;
  5. 用户必须重新选择或绑定任务,历史上下文被拆散。

如果不同成员每次发送消息都有可能重新激活、误建会话或要求重新绑定,那么多人共享知识库/项目的核心协作场景就无法可靠使用。

根因

多个 Bot 共用 bot-state.v2.json;轮询游标和会话上下文仍采用“读取整份状态 → 修改一个 Bot → 覆盖整份状态”的方式更新。不同 Bot 的入站队列按 botId 隔离,不能互相串行,因此一个 Bot 的旧快照写回时,可以覆盖另一个 Bot 刚写入的 activeTaskId。

虽然不同工作区也可能触发同一状态竞争,但“多个成员通过不同微信 Bot 连接同一公司项目”是该缺陷影响最大的实际场景。

复现步骤 · Steps to reproduce
  1. 建立一个用于测试的共享工作区/知识库,并放入少量非敏感示例资料。
  2. 在 ZCode 中创建两个内置微信 Bot,分别供成员 A、成员 B 使用。
  3. 将两个 Bot 都绑定到同一个工作区。
  4. 分别让 Bot A、Bot B 连接两个不同的现有会话,并确认两边可以正常续聊。
  5. 保持两个 Bot 启用;从两个微信交替或同时发送查询、上传资料或录入事项的消息。为提高复现概率,可在一边创建/恢复会话时让另一边持续长轮询并发送消息。
  6. 重复一段时间后,观察其中一个 Bot 偶发发送“微信 Bot 已激活”,或下一条消息新建会话,而不是续接原会话。
  7. 查看任务列表:原会话仍存在,但该 Bot 已指向新会话;bot-state.v2.json 中相应 activeTaskId可能为空或改变。

确定性的竞争顺序如下:

  • Bot A读取整份旧状态,准备更新自己的微信轮询游标;
  • Bot B读取状态、写入自己的新activeTaskId并保存;
  • Bot A随后把旧快照连同新游标整体写回;
  • Bot B刚写入的activeTaskId被Bot A的旧快照覆盖。
期望表现 · Expected behavior
  • 一人、多人团队或小公司应能让多个微信 Bot 长期连接同一个工作区/知识库。
  • 每个 Bot 应保持自己独立、持久的会话映射;不同成员同时发送消息不能串会话或清空activeTaskId。
  • 成员上传资料或写入公司事项后,其他成员可以继续在共享项目中使用最新内容,但各自会话历史和身份归属保持稳定。
  • 长时间空闲、重新连接、同时收消息和多窗口/多进程运行后,两个Bot都应继续各自原会话,无需反复绑定。
  • 只有用户明确执行/new、/clear或手工选择任务时,才允许改变activeTaskId。
  • 状态读取或写入异常时应失败关闭并明确提示,不得回退为空状态后自动激活或创建新会话。
实际表现 · Actual behavior

3.9.2.6069

ZCode 版本 · ZCode version

3.9.2.6069

设备 / 系统 / 浏览器 · Device / OS / Browser

Windows x64 / ZCode Desktop / 内置微信 BotWindows x64 / ZCode Desktop / Built-in Weixin BotWindows x64 / ZCode Desktop / Built-in Weixin BotWWindows 11 x64W

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the built-in Weixin Bot polling and state-update path around bot-state.v2.json, activeTaskId, and per-bot session mappings. Reproduce the interleaved read/write sequence described in the issue, then verify that concurrent bots preserve each other's mappings and that reconnects or long idle periods do not require rebinding.

Written by the indexing model from the issue text.

Assessment

Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.