Skip to content

Comments

feat: add hot reload when failed to load plugins#5334

Merged
Soulter merged 2 commits intoAstrBotDevs:masterfrom
Waterwzy:issue/5333
Feb 23, 2026
Merged

feat: add hot reload when failed to load plugins#5334
Soulter merged 2 commits intoAstrBotDevs:masterfrom
Waterwzy:issue/5333

Conversation

@Waterwzy
Copy link
Contributor

@Waterwzy Waterwzy commented Feb 22, 2026

Modifications / 改动点

Close: #5333
当重载插件发生import失败时,这里的处理不够完善,导致因上述原因加载失败的插件无法热重载。

具体修复如下:

astrbot/core/star/star_manager.py

  • 完善导入模块时的错误处理逻辑,使得 self.failed_plugin_dictself.failed_plugin_info 可以正确记录失败消息,保证前端拿到正确的数据。

dashboard/src/views/ExtensionPage.vue

  • 完善 reloadPlugin 重载插件时的渲染逻辑,无论重载是否成功,都调用 getExtensions 以正确刷新插件页面和响应卡片。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

e277fa69771cb394345eb5a2e76e019e f65684781cbfedc822ab5f6341254cef

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

改进插件在导入失败时的重新加载处理方式,以便正确追踪失败的插件,并让 UI 反映最新状态。

Bug 修复:

  • 在插件加载过程中导入失败时,记录详细的错误和回溯信息,并将失败的插件排除在活动插件映射之外。
  • 确保扩展页面在每次插件重新加载尝试后(无论成功或失败)都会刷新其数据。
Original summary in English

Summary by Sourcery

Improve plugin reload handling when plugin imports fail so that failed plugins are correctly tracked and the UI reflects the latest state.

Bug Fixes:

  • Record detailed error and traceback information for plugins that fail to import during loading, and keep failed plugins out of the active plugin map.
  • Ensure the extensions page always refreshes its data after a plugin reload attempt, regardless of success or failure.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 22, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Waterwzy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where plugins that failed to load due to import errors could not be properly hot reloaded. It improves the robustness of the plugin management system by enhancing error handling on the backend to accurately track and report failed plugins, and by ensuring the frontend consistently updates its display after any reload operation. This provides a more reliable and informative experience for users managing extensions.

Highlights

  • Improved Plugin Error Handling: Enhanced the backend's plugin loading mechanism to correctly capture and record detailed error information (traceback and error messages) for plugins that fail to import.
  • Accurate Failed Plugin Tracking: Ensured that plugins failing to load are properly removed from the active plugin map (star_map) and their failure details are stored in self.failed_plugin_dict, providing accurate status for the frontend.
  • Consistent Frontend Refresh: Modified the frontend's plugin reload function to always refresh the list of extensions after a reload attempt, guaranteeing the UI reflects the most current plugin status, regardless of success or failure.
Changelog
  • astrbot/core/star/star_manager.py
    • Enhanced error handling within the plugin loading process to store full traceback and error messages for failed imports.
    • Ensured that plugins which fail to import are explicitly removed from the star_map and their failure details are recorded in failed_plugin_dict.
  • dashboard/src/views/ExtensionPage.vue
    • Modified the reloadPlugin function to unconditionally call getExtensions after a plugin reload attempt, ensuring the UI is always synchronized with the backend's plugin status.
Activity
  • The pull request addresses and closes issue [Feature]关于重载插件失败的热重载问题 #5333.
  • The author has provided screenshots demonstrating the effective resolution of the problem.
  • The author has confirmed that this change is not a breaking change.
  • The author has verified that the changes are well-tested and that no new dependencies have been introduced.
  • The author has confirmed that no malicious code has been introduced.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些整体性的反馈:

  • reloadPlugin 中,可以考虑把 getExtensions() 移动到 finally 代码块中(或者在成功路径和捕获异常路径中都调用),这样即使重载请求本身失败(例如网络错误或抛出异常),扩展列表也仍然会被刷新。
  • star_manager.load 中,记录失败时你更新了 failed_plugin_dict,但没有更新 failed_plugin_info;如果后续代码依赖这两个结构保持同步,那么把它们一起更新,或者将失败插件的元数据整合到单一的“可信源”中,可能会更安全。
供 AI 代理使用的提示词
Please address the comments from this code review:

## Overall Comments
- In `reloadPlugin`, consider moving `getExtensions()` into a `finally` block (or calling it both in success and catch paths) so the extension list is refreshed even when the reload request itself fails (e.g., network error or thrown exception).
- In `star_manager.load`, when recording failures you update `failed_plugin_dict` but not `failed_plugin_info`; if the rest of the code relies on both structures being in sync, it may be safer to update them together or consolidate to a single source of truth for failed plugin metadata.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • In reloadPlugin, consider moving getExtensions() into a finally block (or calling it both in success and catch paths) so the extension list is refreshed even when the reload request itself fails (e.g., network error or thrown exception).
  • In star_manager.load, when recording failures you update failed_plugin_dict but not failed_plugin_info; if the rest of the code relies on both structures being in sync, it may be safer to update them together or consolidate to a single source of truth for failed plugin metadata.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `reloadPlugin`, consider moving `getExtensions()` into a `finally` block (or calling it both in success and catch paths) so the extension list is refreshed even when the reload request itself fails (e.g., network error or thrown exception).
- In `star_manager.load`, when recording failures you update `failed_plugin_dict` but not `failed_plugin_info`; if the rest of the code relies on both structures being in sync, it may be safer to update them together or consolidate to a single source of truth for failed plugin metadata.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the feature:plugin The bug / feature is about AstrBot plugin system. label Feb 22, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to improve the hot reload mechanism for failed plugins, ensuring import failures are logged and failed plugins are cleaned from the active plugin map, with the frontend extension list refreshing after reload attempts. However, a potential information disclosure vulnerability is introduced by storing and exposing full Python stack traces to the frontend dashboard. Furthermore, the backend cleanup logic should also remove failed plugins from star_registry for consistency, and this robust cleanup approach should be extended to other error handling blocks.

Comment on lines 540 to 542
if path in star_map:
logger.info("失败插件依旧在插件列表中")
star_map.pop(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

当插件加载失败时,代码正确地将其从 star_map 中移除。但是,它仍然保留在 star_registry 中。这可能会导致数据不一致,因为 get_all_stars()(返回 star_registry)可能仍会将失败的插件报告为已加载。为确保彻底清理,插件的元数据也应从 star_registry 中移除。

此外,建议在第 784 行附近的 except BaseException 块中也应用类似的清理逻辑,以一致地处理所有插件加载失败的情况。

                    if path in star_map:
                        logger.info("失败插件依旧在插件列表中,正在清理...")
                        metadata = star_map.pop(path)
                        if metadata in star_registry:
                            star_registry.remove(metadata)

Comment on lines +536 to +539
self.failed_plugin_dict[root_dir_name] = {
"error": str(e),
"traceback": error_trace,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The application captures and stores full Python stack traces in self.failed_plugin_dict when a plugin fails to load. This data is intended to be sent to the frontend dashboard. Stack traces can reveal sensitive information about the server's internal file structure, installed libraries, and code logic, which can be leveraged by an attacker to plan further attacks.

Recommendation: Avoid sending full stack traces to the frontend. Log the full traceback on the server for debugging purposes and return only a generic error message or a sanitized version of the error to the client.

                    self.failed_plugin_dict[root_dir_name] = {
                        "error": str(e),
                    }

@Soulter Soulter changed the title feat:add hot reload when failed to load plugins feat: add hot reload when failed to load plugins Feb 23, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 23, 2026
@Soulter Soulter merged commit ecaec41 into AstrBotDevs:master Feb 23, 2026
6 checks passed
astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 23, 2026
@astrbot-doc-agent
Copy link

Generated docs update PR (pending manual review):
AstrBotDevs/AstrBot-docs#139
Trigger: PR merged


AI change summary:

  • 更新 zh/use/webui.mden/use/webui.md,同步中英文文档。
  • 在“插件加载失败处理”章节补充常见失败原因(如依赖缺失、导入错误等)。
  • 新增热重载行为说明:重载插件后管理面板将自动刷新列表并反馈结果。

Experimental bot notice:

  • This output is generated by AstrBot-Doc-Agent for review only.
  • It does not represent the final documentation form.

@Waterwzy Waterwzy deleted the issue/5333 branch February 24, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:plugin The bug / feature is about AstrBot plugin system. lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]关于重载插件失败的热重载问题

2 participants