-
-
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
Merged
Soulter
merged 3 commits into
AstrBotDevs:master
from
irmia2026:fix/8582-inactivated-plugin-reload-unbind
Jul 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
在单插件重载的情况下,如果该插件之前已被停用,跳过
_unbind_plugin会导致现有的StarMetadata对象被保留并复用。然而,在
load()方法中,只有当插件在inactivated_plugins中时才会将其metadata.activated设为False,但从未在启用时将其设为True。这意味着,当用户重新启用该插件(turn_on_plugin)并触发重载时,虽然插件类会被实例化,但其activated状态仍将保持为False。这会导致该插件的所有事件处理器在get_handlers_by_event_type中被过滤掉,从而使插件完全无法工作。建议在跳过
_unbind_plugin的同时,检查该插件是否已被移出inactivated_plugins,如果是,则将其activated状态恢复为True。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.
Good catch on the surface, but the underlying mechanism already handles this correctly. Let me explain:
load()always creates a freshStarMetadataand overwritesstar_map.At L1294:
star_map[path] = metadata— this unconditionally overwrites whatever was instar_mapwith the newly created metadata object.At L1299:
if metadata.module_path in inactivated_plugins: metadata.activated = False— it only flips to False for inactivated plugins.The key insight:
StarMetadata.activateddefaults toTrue(defined atstar.py:51:activated: bool = True). So whenload()creates a fresh metadata and the plugin is NOT ininactivated_plugins(i.e., afterturn_on_plugin),activatedstaysTrueautomatically.Scenario trace:
reload()with our fix skips_unbind_plugin→load()creates fresh metadata →activated = False✅turn_on_plugin→ plugin removed frominactivated_plugins→reload()skips_unbind_plugin→load()creates fresh new metadata →activated = True✅ (not in inactivated_plugins)The old metadata's
activated=Falsestate is irrelevant becausestar_map[path] = metadataoverwrites it every time.