Repository navigation
[PR] fix(hermes): bootstrap the proxy off the host's load deadline - #4642
yanhuojiyusheng wants to merge 2 commits into
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复——open+closed issue/PR 检索无 hermes 加载超时/bootstrap 机制的在先条目(#4641 为唯一相关项;最接近的 hermes 系 PR #3934/#3705/#4275/#3730/#2217 等均已关闭且机制不同)。 审核结论:方向正确、实现闭环,代码可合(附两个前置条件,见文末判定)验证过的证据(不是照抄 PR 描述)
行为变更披露(旧→新,均有披露义务)
wire 形状、 审核发现
--- a/hermes-plugin/__init__.py
+++ b/hermes-plugin/__init__.py
@@ -7,8 +7,11 @@
model traffic through it via ``HTTPS_PROXY`` + ``SSL_CERT_FILE`` (combined CA bundle) —
the same wire path the ``bili hermes`` launcher uses (CONNECT + certificate MITM);
* registers the proxy's ACP tools (compress / decompress / acp_status) as native Hermes tools;
-* stamps plugin-mode headers on every LLM request once the tools are ready — round 1 rides
- wire mode so strict backends see a clean head;
+* keeps register() inside the host's plugin-load deadline — discovery, spawn and tool
+ registration run on a background thread, and the first model request waits (bounded) for
+ readiness instead of slipping out uncompressed;
+* stamps plugin-mode headers only on requests carrying the registered ACP tools — a session
+ whose tool snapshot predates the registration rides proxy mode (server-side compression);
* reports runtime info (model + max output tokens) to the proxy via bootstrap POSTs.
@@ -93,7 +93,7 @@
-# bootstrap: {"state": "starting"|"ready"|"failed"|"stopped", "started_at", "deadline", "error"} —
+# bootstrap: {"state": "starting"|"ready"|"failed"|"stopped", "started_at", "error"} —
CI 现状head 八问
判定:代码可合 —— 待 (a) 应用上述两行 doc patch(或给账号 fork push 权限,commit |
register() no longer waits on discovery/spawn/manifest inside the host's 10s load budget; a daemon thread bootstraps under one 90s deadline, the first model request is held for readiness (falling back to proxy mode, never a silent direct turn), /acp reports starting/failed/unloaded, and unload can no longer be raced by a late registration or env write.
f517ea4 to
62fb5c0
Compare
Fixes #4641
问题
Hermes 冷启动后
/acp、/acp-cache与 bili 工具整体消失(宿主 capability 检查 deny)。根因不在插件注册顺序,而在宿主加载器的 10s 预算:超时后_dispose_registrations()+_forget_registrations()会把整个插件判失败并回收已注册项,之后任何register_tool都是空操作。旧版register()同步跑ensure_origin(10s)+apply_env+ manifest(5s),冷启动必超。文件
hermes-plugin/__init__.pyregister(ctx)只做廉价注册(middleware、pre_api_request、/acp、/acp-cache、on_unload)+ready_event.wait(REGISTER_WAIT_S = 4.0),低于宿主 10s 预算;_bootstrap()用单一单调 deadlineBOOTSTRAP_BUDGET_S = 90.0贯穿 attach 轮询 / marker 仲裁 / spawn / 健康探测(原实现按阶段各算一份等待,最坏情况相加);on_llm_request等就绪,上限FIRST_REQUEST_WAIT_S = BOOTSTRAP_BUDGET_S + 15.0;等不到则以 proxy 模式继续并明确告知,不再静默直连;BOOTSTRAP_SPAWN_WAIT_S/FIRST_REQUEST_WAIT_S、discover_instance内_stopped(stop)的 TypeError(真机每次挂接必败)、_stopped()与register_tool/apply_env的 TOCTOU、re-enable 时stop_event未重置导致新一轮 bootstrap 立即自杀。tests/hermes-native.test.ts:新增 slow-boot-restart 与 re-enable 场景;改动前用mod.BOOTSTRAP_SPAWN_WAIT_S = …动态赋值掩盖了未定义常量,现改为真实常量名。两种压缩模式
只动插件侧加载/引导时序与 env 注入时机,不动 wire 形状、不动
acp_summary处理,plugin 模式与 proxy 模式的语义差异未涉及。验证
node --import tsx --test tests/hermes-native.test.ts→ 43/43 pass(负向控制:删掉代数重置即红)npm run typecheck/npm run build/python -m py_compile hermes-plugin/__init__.py通过upstream/masterbd29924(behind 0,ahead 1)范围边界
一个 86s 量级的冷启动不再丢掉插件,但首个请求仍需等待。冷启动本身(3.26GB
index.db启动期quick_check)与代理落 failed 后的自愈,另开 issue 处理。