Skip to content

[Bug] 核心依赖版本保护机制过于严格,导致插件依赖冲突 #6420

@EightEggs

Description

@EightEggs

What happened / 发生了什么

AstrBot 的插件依赖版本保护机制会将核心依赖的当前已安装版本作为精确版本约束(==),而不是使用 pyproject.toml 中的原始约束(>=)。这导致当插件要求更高版本的依赖时,即使满足向上兼容条件,也会被阻止安装。

DependencyConflictError: 检测到核心依赖版本保护冲突。
冲突详情: aiosqlite>=0.22.1 vs (constraint) aiosqlite==0.21.0

预期行为

插件依赖 aiosqlite>=0.22.1 应该能够正常安装,因为:

  • 0.22.1 >= 0.21.0,满足 AstrBot 核心的最低版本要求
  • 向上兼容不会破坏系统稳定性

实际行为

安装被阻止,错误提示插件依赖与 AstrBot 核心不兼容。

原因分析

问题出在 astrbot/core/utils/core_constraints.py 第 83 行:

constraints.append(f"{name}=={installed[name]}")

该代码将当前已安装的版本作为精确版本约束,而不是保留原始的 >= 约束。这导致:

  • 核心声明 >=0.21.0
  • 实际生成约束 ==0.21.0
  • 插件要求 >=0.22.1
  • pip 认为 0.22.1 不满足 ==0.21.0,冲突

相关代码

  • astrbot/core/utils/core_constraints.py - 约束生成逻辑
  • astrbot/core/utils/pip_installer.py - 依赖冲突检测

Reproduce / 如何复现?

  1. AstrBot 核心依赖声明:aiosqlite>=0.21.0
  2. 用户通过 uv sync 安装,得到 aiosqlite==0.21.0(uv 安装满足条件的最低版本)
  3. 开发插件,声明依赖:aiosqlite>=0.22.1
  4. 用户尝试安装插件,触发依赖冲突错误:

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

  • AstrBot 版本: v4.20.0
  • 部署方式: 源码部署 (uv)

OS

Linux

Logs / 报错日志

[2026-03-16 09:49:43.751] [Core] [ERRO] [v4.20.0] [star.star_manager:323]: 插件 astrbot_plugin_chatimitate 依赖冲突: 检测到核心依赖版本保护冲突。 冲突详情: aiosqlite>=0.22.1 vs (constraint) aiosqlite==0.21.0。插件要求的依赖版本与 AstrBot 核心不兼容,为了系统稳定,已阻止该降级行为。请联系插件作者或调整 requirements.txt。
[2026-03-16 09:49:43.752] [Core] [ERRO] [v4.20.0] [routes.plugin:646]: /api/plugin/update: Traceback (most recent call last):
File "/home/chihara/AstrBot/astrbot/dashboard/routes/plugin.py", line 640, in update_plugin
await self.plugin_manager.update_plugin(plugin_name, proxy)
File "/home/chihara/AstrBot/astrbot/core/star/star_manager.py", line 1453, in update_plugin
await self._ensure_plugin_requirements(
File "/home/chihara/AstrBot/astrbot/core/star/star_manager.py", line 316, in _ensure_plugin_requirements
await _install_requirements_with_precheck(
File "/home/chihara/AstrBot/astrbot/core/star/star_manager.py", line 150, in _install_requirements_with_precheck
await pip_installer.install(requirements_path=filtered_requirements_path)
File "/home/chihara/AstrBot/astrbot/core/utils/pip_installer.py", line 897, in install
await self._run_pip_with_classification(args)
File "/home/chihara/AstrBot/astrbot/core/utils/pip_installer.py", line 947, in _run_pip_with_classification
result_code = await self._run_pip_in_process(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/chihara/AstrBot/astrbot/core/utils/pip_installer.py", line 942, in _run_pip_in_process
raise conflict
astrbot.core.utils.pip_installer.DependencyConflictError: 检测到核心依赖版本保护冲突。 冲突详情: aiosqlite>=0.22.1 vs (constraint) aiosqlite==0.21.0。插件要求的依赖版本与 AstrBot 核心不兼容,为了系统稳定,已阻止该降级行为。请联系插件作者或调整 requirements.txt。

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

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't workingfeature:pluginThe bug / feature is about AstrBot plugin system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions