Repository navigation
Conversation
There was a problem hiding this comment.
Hey - I've found 4 issues
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="1967" />
<code_context>
- if plugin.reserved:
- raise Exception("该插件是 AstrBot 保留插件,无法更新。")
-
- await self._updater.update(
- plugin,
- proxy=proxy,
</code_context>
<issue_to_address>
**Uninstall can be undone by update**
When an uninstall removes a plugin while its update is downloading, `uninstall_plugin` does not acquire this per-directory update lock. If it removes the plugin while `_updater.update` is downloading, the updater can then recreate the directory; the subsequent reload can load that plugin again, so the uninstall caller sees success but the plugin is installed again.
Coordinate uninstall with the same installation-directory lock, and recheck that the plugin is still installed before committing or reloading an update.
</issue_to_address>
### Comment 2
<location path="astrbot/dashboard/services/plugin_service.py" line_range="113" />
<code_context>
EventType.OnPluginErrorEvent: "插件报错时",
}
self._logo_cache: dict[str, str] = {}
+ self._install_source_lock = asyncio.Lock()
@staticmethod
</code_context>
<issue_to_address>
**Plugin sources revert after concurrent writes**
When an install, source binding, or removal overlaps an update’s source refresh, `refresh_plugin_install_source_after_update`, `persist_plugin_install_source`, `bind_plugin_market_source`, and `remove_plugin_install_source` read and write the same records mapping without all using the shared lock, so a stale save overwrites another plugin’s record or a newer binding or removal.
Use `_install_source_lock` for every read-modify-write operation on the install-source records.
Also at `astrbot/dashboard/services/plugin_service.py:1557-1583`.
</issue_to_address>
### Comment 3
<location path="astrbot/core/star/star_manager.py" line_range="1962-1963" />
<code_context>
+ update_lock = self._update_locks.setdefault(plugin_path, asyncio.Lock())
+ async with update_lock:
+ plugin = self.context.get_registered_star(plugin_name)
+ if not plugin or plugin.root_dir_name != root_dir_name:
+ raise Exception("插件不存在。")
+ if plugin.reserved:
+ raise Exception("该插件是 AstrBot 保留插件,无法更新。")
</code_context>
<issue_to_address>
**Queued update cannot recover failed reload**
When two updates for the same plugin overlap and the first replacement fails to reload, the first update can replace the files and then fail to reload, causing `load` to remove the plugin from the runtime registry. A second request already waiting on the same directory lock then fails this registry check and never applies its update, leaving the installed files unrepaired even when its source contains a fix.
Allow the queued update to proceed using the captured installation directory and a safe reload path even if the preceding reload removed the plugin from the runtime registry.
</issue_to_address>
### Comment 4
<location path="tests/test_plugin_manager.py" line_range="2212" />
<code_context>
EventType.OnPluginErrorEvent: "插件报错时",
}
self._logo_cache: dict[str, str] = {}
+ self._install_source_lock = asyncio.Lock()
</code_context>
<issue_to_address>
**Stale source timestamp passes**
When the source refresh writes a stale or malformed `updated_at` value, `test_update_plugin_persists_source_only_after_replacing_files` copies `record["updated_at"]` into its own expected value on line 2211, so a stale or malformed timestamp still passes the equality assertion.
Assert that `updated_at` parses as a timestamp and is newer than a fixed old timestamp in the source record.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and after the updater replaces plugin files, the callback can persist new repository and download-source details before dependency installation or reload succeeds. If those steps fail, the changed source record remains and may influence a later update; reverting this code does not restore it, though the record is bounded and can be corrected.
Blocking findings: astrbot/core/star/star_manager.py:1967, astrbot/dashboard/services/plugin_service.py:113, astrbot/core/star/star_manager.py:1963, tests/test_plugin_manager.py:2212
| if not plugin or plugin.root_dir_name != root_dir_name: | ||
| raise Exception("插件不存在。") |
There was a problem hiding this comment.
🟡 Medium · Queued update cannot recover failed reload
When two updates for the same plugin overlap and the first replacement fails to reload, the first update can replace the files and then fail to reload, causing load to remove the plugin from the runtime registry. A second request already waiting on the same directory lock then fails this registry check and never applies its update, leaving the installed files unrepaired even when its source contains a fix.
Allow the queued update to proceed using the captured installation directory and a safe reload path even if the preceding reload removed the plugin from the runtime registry.
Prompt for AI agents
In `astrbot/core/star/star_manager.py` at lines 1962-1963:
**Queued update cannot recover failed reload**
When two updates for the same plugin overlap and the first replacement fails to reload, the first update can replace the files and then fail to reload, causing `load` to remove the plugin from the runtime registry. A second request already waiting on the same directory lock then fails this registry check and never applies its update, leaving the installed files unrepaired even when its source contains a fix.
Allow the queued update to proceed using the captured installation directory and a safe reload path even if the preceding reload removed the plugin from the runtime registry.
Overlapping plugin updates can replace the same installation directory before either reload finishes. A reload failure can also remove the plugin from the runtime registry, leaving the old installation source attached to the new files. Updates can additionally recreate a directory after a concurrent uninstall has reported success.
Modifications / 改动点
Queued updates revalidate the plugin registration after acquiring the directory lock and fail if it disappeared. Automatic repair of failed plugins and rollback of updated files are outside this change. Because a failed reload leaves the replacement files installed, their source record remains current.
Related: #11072 covers missing entry modules and entry-name changes. This PR addresses the separate update concurrency and source persistence findings.
Test Results / 测试结果
Windows / Python 3.12:
The warning is the existing
audioopdeprecation warning. The symlink case is skipped on Windows without symlink privileges. Regression cases cover overlapping updates, both update/uninstall orderings, source persistence after failed reloads, concurrent source mutations, source cleanup without live registration, timestamp advancement, and invalid uninstall paths. Tests extend existing files.ruff format .,ruff check ., andgit diff --checkpassed.Checklist
Summary by Sourcery
Serialize plugin lifecycle operations and make installation source persistence safe across concurrent updates, reload failures, and uninstall operations.
Bug Fixes:
Enhancements:
Tests: