fix: make plugin imports rollback-safe - #9900
Open
JosephTian876 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. If the module-prefix ownership or retry cleanup is wrong, a failed plugin can leave stale provider or tool registrations behind, or cleanup can remove a legitimate registration from the running process. Those effects are bounded and can be repaired by restarting or reloading the process, although reverting would not undo registrations already made during a process run.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
5 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Plugin decorators mutate global Provider and tool registries while a module is imported. If that import raises, including during missing-dependency recovery, retrying in the same process can retain duplicate or partially registered objects. This also prevents startup from safely separating plugin discovery from plugin activation.
This PR makes plugin import side effects transactional without changing startup order or runtime Provider reload behavior.
Modifications / 改动点
Remove only Provider adapters and tools owned by the failed plugin module tree before retrying or reporting failure.
Resolve tool ownership from the raw handler module, including
functools.partialhandlers.Traverse Handoff wrappers and agent child tools so nested registrations are claimed and rolled back consistently.
Canonicalize successful submodule registrations to the plugin's main module.
Preserve Core tools, sibling plugins, and unrelated registrations that appear concurrently.
Clear a plugin's failed-import record after a later ordinary retry succeeds.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
The regressions cover partial Provider/tool registration, missing-dependency reimport, nested Handoff/agent tools, sibling and Core ownership, concurrent unrelated registrations, and successful retry cleanup.
No dependencies or API/OpenAPI schemas change. Startup phase ordering is intentionally left to the follow-up update of #9513; this PR is its rollback-safety prerequisite.
Checklist / 检查清单
requirements.txtandpyproject.toml.Summary by Sourcery
Make plugin registration side effects transactional so failed imports can be retried safely without disturbing unrelated runtime registrations.
Bug Fixes:
Enhancements:
Tests: