AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] 同时进行多个对话,回答会串

Open pyao12 opened this issue 7 months ago • 2 comments

What happened / 发生了什么

我同时在网页端进行两个对话(先记作A、B),打开B对话的回答进度,然后A的回答串到了B里,返回A对话时提醒“正在进行中”,无法流式回复,过一会只有返回完整结果了才能输出。

Reproduce / 如何复现?

  1. 同时开启两个会话
  2. 切换到一个对话

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

4.22.3 1Panel OpenAI(Compatible) ChatUI

OS

Linux

Logs / 报错日志

Image
Image

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [x] Yes!

Code of Conduct

pyao12 avatar Apr 12 '26 11:04 pyao12

这个问题之前在 #5762 中也有人报告过,是同样的现象——对话未完成时切换会话,流式输出会串到另一个会话中。

根据代码分析,问题很可能出在前端 useMessages.ts 中的 currentRunningSessionId、currentReader、currentRequestController 等状态是全局共享的,而不是按会话隔离的 [1]。当你切换到会话 B 时,会话 A 的流式 reader 仍在写入,但前端已经把当前视图切换到了 B,导致 A 的响应数据被渲染到 B 的界面上。

后端方面,PR #6698 引入了 stream_request_ids 和 subscription_request_ids 的区分,send_by_session() 会优先向 stream consumer 发送消息。如果多个会话的 WebSocket 连接/请求 ID 没有正确隔离,也可能导致消息路由到错误的会话。

如果你打算提交 PR 修复,建议重点关注:

  1. 前端:astrbot/dashboard/src/composables/useMessages.ts — 将流式状态(reader、controller、running session)改为按 session 隔离,而非全局单例
  2. 后端:astrbot/core/platform/webchat/ 的 send_by_session() 及 open_api.py 的 _handle_chat_ws_send() — 确认 WebSocket 消息路由是否严格按 session ID 分发

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Apr 12 '26 11:04 dosubot[bot]

v4.23.0 修复了这个问题。

Soulter avatar Apr 13 '26 15:04 Soulter