-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: skip _unbind_plugin for inactivated plugins in reload() #9096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -996,7 +996,7 @@ async def reload(self, specified_plugin_name=None): | |||||||||||||||||
| logger.warning( | ||||||||||||||||||
| f"插件 {smd.name} 未被正常终止: {e!s}, 可能会导致该插件运行不正常。", | ||||||||||||||||||
| ) | ||||||||||||||||||
| if smd.name and smd.module_path: | ||||||||||||||||||
| if smd.name and smd.module_path and smd.activated: | ||||||||||||||||||
| await self._unbind_plugin(smd.name, smd.module_path) | ||||||||||||||||||
|
|
||||||||||||||||||
| star_handlers_registry.clear() | ||||||||||||||||||
|
|
@@ -1013,7 +1013,7 @@ async def reload(self, specified_plugin_name=None): | |||||||||||||||||
| logger.warning( | ||||||||||||||||||
| f"插件 {smd.name} 未被正常终止: {e!s}, 可能会导致该插件运行不正常。", | ||||||||||||||||||
| ) | ||||||||||||||||||
| if smd.name: | ||||||||||||||||||
| if smd.name and smd.activated: | ||||||||||||||||||
| await self._unbind_plugin(smd.name, specified_module_path) | ||||||||||||||||||
|
Comment on lines
+1016
to
1017
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在单插件重载的情况下,如果该插件之前已被停用,跳过 然而,在 建议在跳过
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on the surface, but the underlying mechanism already handles this correctly. Let me explain:
At L1294: At L1299: The key insight: Scenario trace:
The old metadata's |
||||||||||||||||||
|
|
||||||||||||||||||
| result = await self.load(specified_module_path) | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在重载所有插件(
specified_plugin_name为None)的情况下,star_map和star_registry会被完全清空(star_map.clear()和star_registry.clear())。如果在此处对已停用的插件跳过
_unbind_plugin,其对应的模块将不会从sys.modules中被清除。当后续调用load()时,由于star_map已被清空,且模块由于缓存在sys.modules中而不会重新执行(导致类装饰器/子类钩子无法再次运行来注册插件),load()将无法在star_map中找到该插件。这会迫使load()回退到旧版的加载机制,如果插件类名不符合旧版命名规范(如以Plugin结尾或命名为Main),将会抛出异常导致加载失败。因此,在全量重载时,不应该跳过
_unbind_plugin。Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! However, this concern is not applicable here — I've verified it through source analysis.
_unbind_plugin(L1769-1820) never touchessys.modules. It only:star_map/star_registrystar_handlers_registryllm_tools.func_listThere is no
import importlib, nosys.modules, noreload()call anywhere in the function body.Additionally, in the full reload path,
star_map.clear()andstar_registry.clear()are called right after the unbind loop, so any skipped entries are still cleared.And regarding consistency:
_terminate_pluginalready has the same guard (if not star_metadata.activated: return) at L1882. Keeping_unbind_pluginaligned with that pattern is the safer design.