Skip to content

Conversation

@ocetars
Copy link
Member

@ocetars ocetars commented Dec 29, 2025

Fixes #4188): 在从文件安装插件前先终止并解绑已存在的同名插件

Summary by Sourcery

Bug Fixes:

  • 在从文件安装插件之前,如果已存在同一目录名称的已安装插件,先终止并解绑该插件,以避免冲突。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Terminate and unbind an already-installed plugin with the same directory name before installing a plugin from a file to avoid conflicts.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 29, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • _terminate_plugin 周围使用宽泛的 except Exception 可能会导致系统处于部分拆卸的状态却仍然继续执行安装;建议要么收窄异常类型,要么在终止失败时中止安装,以避免插件状态不一致。
  • 通过 root_dir_name 查找已有插件的逻辑重复了遍历流程;如果已经存在用于按目录/名称解析插件的辅助方法或注册表,建议复用它,以保持这部分逻辑的一致性并提升可维护性。
  • 调用 _terminate_plugin 之后,你立刻调用 _unbind_plugin,但没有检查终止是否已经完全完成,或者插件是否已经解绑;建议把终止 + 解绑封装到一个单独的辅助方法中,在一个地方统一保证顺序正确并处理错误。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- The broad `except Exception` around `_terminate_plugin` can leave the system in a partially torn-down state while still proceeding with install; consider either narrowing the exception type or aborting the install when termination fails to avoid inconsistent plugin state.
- The lookup for an existing plugin by `root_dir_name` duplicates traversal logic; if there is already a helper or registry for resolving plugins by directory/name, reusing it would keep this logic consistent and easier to maintain.
- After calling `_terminate_plugin`, you immediately call `_unbind_plugin` without checking whether termination fully completed or the plugin was already unbound; consider encapsulating termination + unbind in a single helper to enforce the correct ordering and error handling in one place.

Sourcery 对开源项目免费——如果你喜欢我们的代码审查,请考虑分享 ✨
帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've left some high level feedback:

  • The broad except Exception around _terminate_plugin can leave the system in a partially torn-down state while still proceeding with install; consider either narrowing the exception type or aborting the install when termination fails to avoid inconsistent plugin state.
  • The lookup for an existing plugin by root_dir_name duplicates traversal logic; if there is already a helper or registry for resolving plugins by directory/name, reusing it would keep this logic consistent and easier to maintain.
  • After calling _terminate_plugin, you immediately call _unbind_plugin without checking whether termination fully completed or the plugin was already unbound; consider encapsulating termination + unbind in a single helper to enforce the correct ordering and error handling in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The broad `except Exception` around `_terminate_plugin` can leave the system in a partially torn-down state while still proceeding with install; consider either narrowing the exception type or aborting the install when termination fails to avoid inconsistent plugin state.
- The lookup for an existing plugin by `root_dir_name` duplicates traversal logic; if there is already a helper or registry for resolving plugins by directory/name, reusing it would keep this logic consistent and easier to maintain.
- After calling `_terminate_plugin`, you immediately call `_unbind_plugin` without checking whether termination fully completed or the plugin was already unbound; consider encapsulating termination + unbind in a single helper to enforce the correct ordering and error handling in one place.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Dec 29, 2025
@ocetars ocetars changed the title Fix/#4188 fix(#4188): 通过上传来安装插件前先终止并解绑已存在的同名插件 Dec 29, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 30, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 30, 2025
@Soulter Soulter changed the title fix(#4188): 通过上传来安装插件前先终止并解绑已存在的同名插件 fix(#4188): terminate the same plugin when install the plugin via file Dec 30, 2025
@Soulter Soulter merged commit 300a73a into AstrBotDevs:master Dec 30, 2025
6 checks passed
@ocetars ocetars deleted the fix/4188 branch December 30, 2025 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]当手动上传来更新插件时不会事先调用terminate

2 participants