fix: unbind disabled plugin handlers before reload#9284
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a force_unbind parameter to the plugin reload method, allowing plugins to be unbound during reload even if they are not currently activated. This parameter is utilized when turning on a plugin to ensure handlers are correctly rebound. Additionally, corresponding unit tests have been updated and a new test has been added to verify this behavior. The review feedback suggests adding **kwargs to the signature of a mocked load function in the new test to improve robustness and maintain consistency with other mocks in the test suite.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| async def mock_global_put(*_): | ||
| pass | ||
|
|
||
| async def mock_load(specified_module_path=None): |
There was a problem hiding this comment.
For robustness and consistency with other mock_load definitions in this test file, consider adding **kwargs to the signature of mock_load. This prevents the mock from breaking if the arguments passed to load are changed or expanded in the future.
| async def mock_load(specified_module_path=None): | |
| async def mock_load(specified_module_path=None, **kwargs): |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
force_unbindparameter onreloadchanges behavior but isn’t documented in the method’s docstring; consider updating the docstring (and any type hints/comments nearby) to explain when and whyforce_unbindshould be used and what it does. - The name
force_unbindis a bit vague at the call site (reload(plugin_name, force_unbind=True)); consider a more explicit name likeforce_unbind_handlersor adding a short inline comment at the call to clarify that it unbinds handlers even for previously deactivated plugins.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `force_unbind` parameter on `reload` changes behavior but isn’t documented in the method’s docstring; consider updating the docstring (and any type hints/comments nearby) to explain when and why `force_unbind` should be used and what it does.
- The name `force_unbind` is a bit vague at the call site (`reload(plugin_name, force_unbind=True)`); consider a more explicit name like `force_unbind_handlers` or adding a short inline comment at the call to clarify that it unbinds handlers even for previously deactivated plugins.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes #9280
Modifications / Changes
Force
turn_on_plugin()to unbind handlers before reloading a previously disabled plugin.Keep the normal reload behavior unchanged; the forced unbind is limited to the enable path.
Add a regression test covering a deactivated plugin whose handler would otherwise be wrapped twice.
This is complementary to fix: skip _unbind_plugin for inactivated plugins in reload() #9096: fix: skip _unbind_plugin for inactivated plugins in reload() #9096 preserves tools for disabled plugins during reload, while this change removes stale handlers when that plugin is enabled again.
This is NOT a breaking change.
Screenshots or Test Results / Verification
Reproduction path covered by the regression test:
turn_on_plugin().Automated verification:
uv run pytest -q—1797 passed, 6 warningsuv run ruff check astrbot/core/star/star_manager.py tests/test_plugin_manager.py— all checks passeduv run ruff format --check astrbot/core/star/star_manager.py tests/test_plugin_manager.py— both files already formattedgit diff --check— passedManual WebUI verification on AstrBot v4.26.6:
astrbot_plugin_livingmemory, disabled it, restarted AstrBot, and enabled it again.OK; no handler argument-countTypeErrorappeared.Checklist
Summary by Sourcery
Ensure plugin enablement reloads deactivated plugins with stale handlers correctly by unbinding handlers when turning a plugin back on.
Bug Fixes:
Tests: