Skip to content

[Bug] reload() 跳过 disabled 插件解绑导致 handler 参数+1 / self=None #9280

Description

@6TBWhite

What happened / 发生了什么

正常启动AstrBot后,将插件 astrbot_plugin_livingmemory禁用状态下通过 WebUI 启用该插件后,其全部 3 个事件 handler 均收到比正确参数多 1 个的参数,导致 TypeError。重启 AstrBot 后问题消失,定位为 reload() 中 handler 解绑逻辑的 bug。

Reproduce / 如何复现?

  1. 安装 astrbot_plugin_livingmemory
  2. 在 WebUI 中禁用该插件
  3. 重启 AstrBot
  4. 在 WebUI 中重新启用该插件
  5. 发送一条消息触发 LLM → handler 报错

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

  • AstrBot v4.26.5 和 v4.26.6 均存在
  • Windows10 + uv tool 安装
  • glm5.2
  • aiocqhttp(Onebot v11)

OS

Windows

Logs / 报错日志

v4.26.5 — LivingMemory 全部 3 个 hook 均报参数+1:

[2026-07-14 18:19:07.906] [Core] [ERRO] [v4.26.5] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_memory_recall() takes 3 positional arguments but 4 were given

[2026-07-14 18:19:16.025] [Core] [ERRO] [v4.26.5] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_memory_reflection() takes 3 positional arguments but 4 were given

[2026-07-14 18:19:21.489] [Core] [ERRO] [v4.26.5] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_session_reset() takes 2 positional arguments but 3 were given

v4.26.6 — WebUI 启用后同样复现,日志一致:

[2026-07-14 20:06:37.439] [Core] [ERRO] [v4.26.6] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_memory_recall() takes 3 positional arguments but 4 were given

[2026-07-14 20:06:58.014] [Core] [ERRO] [v4.26.6] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_memory_reflection() takes 3 positional arguments but 4 were given

[2026-07-14 20:07:04.890] [Core] [ERRO] [v4.26.6] [pipeline.context_utils:100]:
Traceback (most recent call last):
  File "...\astrbot\core\pipeline\context_utils.py", line 98, in call_event_hook
    await handler.handler(event, *args, **kwargs)
TypeError: LivingMemoryPlugin.handle_session_reset() takes 2 positional arguments but 3 were given

Root Cause / 根因

定位到 star_manager.pyreload() 方法第 1016 行:

# 行 1005-1017
else:
    smd = star_map.get(specified_module_path)
    if smd:
        await self._terminate_plugin(smd)
        if smd.name and smd.activated:   # ← BUG: activated=False 时跳过解绑
            await self._unbind_plugin(smd.name, specified_module_path)

当插件被禁用(activated=False)时:

  • _terminate_plugin(行 1881)检测到 activated=False 直接 return,不清理实例
  • _unbind_pluginand smd.activated 跳过,旧 handler 残留在 star_handlers_registry

随后 load() 在第 1212 行对残留的旧 handler(已 functools.partial(func, None))再次 partial 套上新实例:

首次启动(禁用) → star_cls=None → partial(raw_func, None)
WebUI 启用      → reload() → 旧handler未解绑 → load()
               → partial(partial(raw_func, None), 新实例)
调用 handler     → raw_func(None, 新实例, event, req) → 多一个参数

修复建议: 将第 1016 行 if smd.name and smd.activated: 改为 if smd.name:,即无条件解绑。

对比全量重载(行 1002)star_handlers_registry.clear() 正是无条件的,所以重启 AstrBot 问题消失。

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