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 plugin.reserved: | ||
| raise Exception("该插件是 AstrBot 保留插件,无法更新。") | ||
|
|
||
| await self._updater.update( |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `astrbot/core/star/star_manager.py` at line 1967:
**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.| EventType.OnPluginErrorEvent: "插件报错时", | ||
| } | ||
| self._logo_cache: dict[str, str] = {} | ||
| self._install_source_lock = asyncio.Lock() |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `astrbot/dashboard/services/plugin_service.py` at line 113:
**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`.| 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.| **new_source, | ||
| "root_dir_name": TEST_PLUGIN_DIR, | ||
| "updated_at": record["updated_at"], | ||
| } |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `tests/test_plugin_manager.py` at line 2212:
**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.
Two plugin update requests can replace the same directory before either reload finishes. In addition, reloading the replacement can remove the plugin from the runtime registry, so the old source record remains even though the new files are installed.
Follow-up to the concurrency and install-source findings in #11072. Entry discovery and entry-name changes remain in that PR.
Modifications / 改动点
Serialize download, replacement, dependency installation, and reload for the same installation directory. Different plugins can still download in parallel. Ignore repeated names in one batch, in input order.
Persist the source by installation directory once replacement succeeds, without relying on the plugin being re-registered. A failed download or replacement does not advance the record.
Return the existing update error on reload failure, remove the extra single-update reload, and sync skills after attempted updates. This does not add rollback of the updated files.
This is NOT a breaking change.
Test Results / 测试结果
python -m pytest tests/test_plugin_manager.py tests/test_fastapi_v1_dashboard.py tests/test_updater_socks.py -q— 375 passed (one existingaudioopdeprecation warning). The focused update tests were rerun on the latestmasterbase and all 8 passed.ruff format --check .,ruff check ., andgit diff --checkpassed. The tests extend an existing file.Checklist
Summary by Sourcery
Serialize overlapping plugin updates and persist installation sources based on successful file replacement.
Bug Fixes:
Enhancements:
Tests: