Repository navigation
fix: initialize providers across plugin startup phases - #10845
JosephTian876 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/star/star_manager.py" line_range="823-840" />
<code_context>
)
+ @staticmethod
+ def _plugin_root_module_path(plugin_module_path: str) -> str:
+ """Return the import prefix shared by every module in one plugin.
+
+ Args:
+ plugin_module_path: Plugin main or child module path.
</code_context>
<issue_to_address>
**Unneeded helper adds indirection**
The plugin-root calculation is extracted into a helper used at only one call site; inlining it in the short caller would stay below the documented length threshold, so this adds indirection contrary to the repository guidance.
Inline the plugin-root calculation in `_claim_llm_tools_for_plugin` unless it gains repeated use or makes that function too long.
</issue_to_address>Sourcery assessment
Approved.
|
Startup now loads configured Providers before plugin activation and runs a second Provider pass after it, so a plugin Star can query its Provider during
Tests: 10 new tests in Known limitation: the pending pass runs once per startup, so an adapter registered by a plugin loaded later at runtime is not picked up by it. Note on the base: the first commit on this branch, |
473fb89 to
49f1b7a
Compare
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
49f1b7a to
91781d5
Compare
|
Rebased onto the updated Local Verification
建议合并顺序
|
91781d5 to
0d56858
Compare
|
Rebased onto the updated Local Verification
|
0d56858 to
8a9aacd
Compare
Modifications / 改动点
AstrBotCoreLifecycle.initialize()activates every plugin before any Provider exists, so a plugin that resolves its configured Provider during startup sees an emptyinst_map:Plugins register Provider adapters in two different places — at module import, and inside
Star.initialize()— so simply movingprovider_manager.initialize()earlier is not compatible with both. This PR introduces explicit startup phases instead:PluginManager.initialize_plugins) before the first Provider pass, so import-time adapters are registered;ProviderManager.initialize_pending_registered_providers), without reinitialising anything that already exists;Rebased onto
abf683071. One conflict instar_manager.pywas resolved in favour of this PR's extracted_apply_plugin_metadata_yaml/_ensure_supported_plugin_versionhelpers (master still has that body inline, and three other call sites in this commit use the helpers); the helper's field list now copiesviews, which upstream renamed frompagesafter this branch was first written.ProviderType.DECISION, added upstream since, is handled in the pending pass and in the rolled-back-adapter cleanup.Screenshots or Test Results / 运行截图或测试结果
Diff scope: 5 files (
+622/-91):astrbot/core/core_lifecycle.py,astrbot/core/provider/manager.py,astrbot/core/provider/register.py,astrbot/core/star/star_manager.py, plus the required mock updates in existingtests/unit/test_core_lifecycle.py(+24/-5forinitialize_plugins/initialize_pending_registered_providers).Existing
tests/test_plugin_manager.py,tests/unit/test_core_lifecycle.py, andtests/unit/test_command_plugin_activation.pypass in CI (ruff format --checkandruff checkclean). In addition, 8 local behavioral regression scenarios (covering import-time and activation-time plugin provider loading, incompatible-plugin isolation, disabled-plugin adapter retention, failed-activation reconciliation, inactive tools before activation, and partial-import rollback) were verified locally before/after the fix and omitted fromtests/test_plugin_manager.pyin this PR diff to keep test changes minimal (happy to restore compact tests if preferred).This branch includes the rollback-safety prerequisite from #9900 until #9900 merges, as originally described.
Checklist / 检查清单
docs/zh/docs/enneed no update.Supersedes #9513
#9513 was closed on 2026-10-12 by the staleness sweep with an invitation to rebase and reopen, not on its merits. GitHub refuses to reopen it:
gh pr reopen 9513returnsGraphQL: Could not open the pull request (reopenPullRequest), andPATCH /pulls/9513 {"state": "open"}returns HTTP 422state cannot be changed. This PR is the same change rebased onto currentmaster, so it supersedes #9513; the original description and discussion stay there.Suggested merge order
Independent from
#10895and#10846, though all three touchastrbot/core/provider/manager.py. Suggested order: #10845 → #10895 → #10846 (any order works with a minor rebase if needed).Summary by Sourcery
Initialize plugin-provided Providers across discovery and activation phases while safely reconciling failures and preserving configured selections.
Bug Fixes:
Enhancements:
Tests: