AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] WebUI dist 缺失 index/assets 时启动阶段未校验,仍继续启动

Open Evernight275 opened this issue 5 months ago • 2 comments

What happened / 发生了什么

我注意到:当 WebUI dist 产物不完整时,AstrBot 仍可能继续启动,且没有明确日志提示当前 data/dist 已损坏,也没有显式 fallback / redownload / fail-fast 行为。 具体表现:

  • data/dist 是空目录时,AstrBot 仍会把它当作 WebUI 目录使用,访问面板返回 404。
  • data/dist/index.html 缺失时,AstrBot 仍会继续启动,访问面板返回 404。
  • data/dist/assets 缺失时,AstrBot 仍会继续启动,并可能输出 WebUI is ready / AstrBot started,但浏览器无法加载 index.html 引用的 JS/CSS 资源。 目前没有可观察的启动期诊断能说明 WebUI dist 已损坏。

Reproduce / 如何复现?

在干净文件夹clone完整项目,然后,同步依赖后。做以下动作: 1.在项目根目录新建data/dist文件夹,然后输入uv run main.py启动,输入127.0.0.1:6185会返回404 2.然后关掉该进程,删掉dist文件夹,仅留data文件夹,再次输入uv run main.py启动,之后就会正常下载dist.zip,然后正常解压,之后再次访问127.0.0.1:6185,即可正常进入。之后就会正常跳转登录页面。 3.再次关掉该进程,把index.html移动到项目外文件夹,再次输入相同命令启动,,输入127.0.0.1:6185会返回404 4.再次关掉该进程,把刚刚在项目外的index.html复原到原位置,删除assets文件夹,再次启动,输入127.0.0.1:6185,这次进去,你看到的是空白页面(也就是什么内容都没有)

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

v4.25.5 WebUI

OS

Windows

Logs / 报错日志

情况1. Image 执行结果: Image 情况2. Image 执行结果: Image 正常进入页面 情况3. Image 执行结果: Image 情况4. Image 执行结果:

Image

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

  • [ ] Yes!

Code of Conduct

Evernight275 avatar Jun 14 '26 16:06 Evernight275

Hi @Cyrene2026! I'm Dosu and I'm helping the AstrBotTeam team.

确认了这个问题。根本原因在于启动阶段的校验逻辑仅使用了 os.path.exists(data_dist_path) 来判断是否需要下载 WebUI 资源 [1],没有对目录内容做任何完整性校验。

具体流程:

  1. 启动时检查 data/dist 目录是否存在——空目录也会通过此检查
  2. 如存在,尝试读取 assets/version 文件 [2],若读取失败(返回 None),代码仍然直接返回该路径作为 WebUI 目录使用 [3]
  3. 实际的文件校验(如 index.html 是否存在)只在 请求时 才发生 [4],此时已经错过了自动下载的时机

修复方向建议:

在启动阶段的 os.path.exists() 之后增加内容校验,例如检查 index.html 是否存在:

data_dist_path = os.path.join(get_astrbot_data_path(), "dist")
index_html = os.path.join(data_dist_path, "index.html")
if os.path.exists(data_dist_path) and os.path.isfile(index_html):
    # 认为 dist 有效
    ...
else:
    # 触发重新下载
    ...

这样可以覆盖你提到的情况 1(空目录)和情况 3(缺 index.html)。对于情况 4(缺 assets),可以额外检查 assets 目录是否存在,或者校验 assets/version 文件不返回 None 时才跳过下载。

此前也有类似的 dist 下载失败仍显示启动成功的问题被报告过 [5],那次的原因是 fallback URL 命名错误,但启动期校验不足这个根本问题一直未被解决。

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about AstrBot Share Dosu with your team

dosubot[bot] avatar Jun 14 '26 16:06 dosubot[bot]

#8804 fixed

Soulter avatar Jun 16 '26 03:06 Soulter