From 7bc5e01afd1f8b50fd618f0b3dc9982a84669233 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 22 Aug 2026 13:07:32 +0800 Subject: [PATCH] refactor: expand async and type safety gates --- app/adapters/external/market.py | 13 +++++- app/agent/middleware/activity_log.py | 23 +++++++--- app/api/dependencies/subscription.py | 4 +- app/application/scheduling.py | 10 ++--- app/runtime/event/errors.py | 2 +- app/runtime/extensions/module/dispatcher.py | 4 +- .../backend-architecture-next-stage.md | 6 +++ mypy.ini | 6 ++- scripts/architecture/async_blocking.py | 42 +++++++++++++++---- .../architecture/async-blocking-baseline.json | 4 +- tests/test_async_blocking_gate.py | 16 ++++++- tests/test_type_gate.py | 6 ++- 12 files changed, 103 insertions(+), 33 deletions(-) diff --git a/app/adapters/external/market.py b/app/adapters/external/market.py index c3d935180..34c8ddd71 100644 --- a/app/adapters/external/market.py +++ b/app/adapters/external/market.py @@ -2772,8 +2772,11 @@ class PluginHelper(metaclass=WeakSingleton): await async_dest_path.mkdir(parents=True, exist_ok=True) continue await async_dest_path.parent.mkdir(parents=True, exist_ok=True) - with zf.open(info, 'r') as src: - data = src.read() + data = await asyncio.to_thread( + self.__read_release_zip_member, + zf, + info, + ) async with aiofiles.open(dest_path, 'wb') as dst: await dst.write(data) wrote_any = True @@ -2784,6 +2787,12 @@ class PluginHelper(metaclass=WeakSingleton): logger.error(f"解压 Release 压缩包失败:{e}") return False, f"解压 Release 压缩包失败:{e}" + @staticmethod + def __read_release_zip_member(zf: zipfile.ZipFile, info: zipfile.ZipInfo) -> bytes: + """在线程池读取并解压单个 Release 文件,避免阻塞事件循环。""" + with zf.open(info, "r") as source: + return source.read() + # 公开 Release 查询的缓存管理统一指向仓库级分页缓存。 PluginHelper.get_plugin_release_versions.cache_clear = PluginHelper._get_plugin_repo_releases.cache_clear diff --git a/app/agent/middleware/activity_log.py b/app/agent/middleware/activity_log.py index 3ea9ac2b0..d0a25a260 100644 --- a/app/agent/middleware/activity_log.py +++ b/app/agent/middleware/activity_log.py @@ -87,6 +87,17 @@ SUMMARY_PROMPT = """请判断以下 AI 助手与用户的对话是否值得写 ACTIVITY_ENTRY_PATTERN = re.compile(r"^-\s+\*\*(?P