Repository navigation
[PR] fix(hermes): stop losing /acp and all tools on cold start — move the slow proxy boot off register() - #4645
ranxianglei wants to merge 14 commits into
Conversation
…kground bootstrap (#4641) The host gives each plugin a fixed load budget (plugins.load_timeout_seconds, default 10s) around import+register; exceeding it makes the host discard the ENTIRE plugin (every registration disposed), so a cold-start whose proxy took longer than 10s silently lost /acp, /acp-cache and every tool. register() now only wires the cheap always-on surfaces (llm_request middleware, pre_api_request hook, /acp + /acp-cache, unload hook) and returns inside a bounded wait; the attach-or-spawn + manifest + tool registration runs on a daemon thread under ONE monotonic deadline (BOOTSTRAP_BUDGET_S). Each register()/re-enable mints a fresh bootstrap generation (stop/ready Events) so an unload aborts an in-flight boot and a re-enable boots fresh. The first LLM request blocks a bounded window for the boot, then rides wire mode only if it has not landed.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.5976-pr.4645.5b4292bThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4645.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。#4645 是修复 #4641(hermes 冷启动后 /acp + 全部 bili 工具消失)的 PR。与既有 hermes 条目 #2714(spawn 临时端口后 HTTPS_PROXY 指向死端口)、#4282(全局自更新不刷新 Python 侧插件副本)症状/机制都不同——本 PR 针对的是「冷启动时 register() 同步阻塞超过宿主 10s 加载预算,整个插件被宿主回收」。 标签: 已打 独立审核(不复读 issue/PR 描述,逐行读了 diff;base=bd29924d4,单 commit 8694b20): 方向对、主修复成立。把 但发现一个真实的正确性缺口——本 PR 自己宣称的机制没完全兑现:
epoch = _state.get("epoch")
if epoch is None or epoch["ready"].is_set():
epoch = _new_epoch(); start_thread(...)竞态:第一次冷启动还在后台跑( 现有 re-enable 测试用 fast attach(首启瞬间 settle),unload 时 修法很小且无决策依赖:守卫加一项 另两处小问题(非阻塞):
CI: head 8694b20 上 static gates/guards/build 全绿;test 分片里失败的 shard 全部落在 node-22(ubuntu+windows 都有),node-24 分片在跑——这个分布不像 hermes 改动引起(那会让含 hermes-native.test.ts 的分片在两个 Node 版本上都红),更像 node-22 级或继承性红。推完修复后复核 #4599/master 确认归因。 下一步: 先在本 PR 分支落 epoch 守卫修复 + 回归测试,本地定向跑 |
…ap generation (#4641) Review of #4645: register()'s generation-mint guard only fired on `epoch is None or epoch["ready"].is_set()`. An unload sets stop but NOT ready, so when a re-enable lands while the aborted boot has not yet settled (ready still unset), no fresh generation was minted and no bootstrap thread started — the re-enabled plugin sat in wire mode with no ACP tools until the NEXT re-enable. The existing re-enable test used fast attach (boot settles before unload), so it never covered this window. Add `or epoch["stop"].is_set()` so an aborted-but-unsettled generation also triggers a fresh mint+thread; a healthy in-flight boot (stop unset) still does not double-boot. Deterministic regression test seeds exactly that state and asserts a new generation is minted and the tools land; verified red without the one-line change.
(ai: vllm-qwen/qwen3.8-27b) 独立审核完成(查重结论见上一条回复:不重复)。结论:代码方向对、可合,但我发现并已在 PR 分支修掉一处 PR 自身引入的新竞态。以下为结构化八问。 结构化八问
审核补充
交付状态
|
…ment #4316 PR3/3 (restampRefsToLedger) re-homes citation numbers once on every full-mode cold load; goldens pinning exact ref numbers are born-red. Re-pin the 7 storage-lane tests (engine-proofs x6 + orphan-recovery x1) modulo that renumbering — zero production code touched. - golden-storage-drive.ts: per-turn citation-normalized digest (shaCiteNorm) and state digest modulo stripOneTimeAlignment (stateDigestAligned); the deep-sort helper is hoisted into golden-canonical.ts for sharing. - corrupt-index-child.ts: new stripOneTimeAlignment normalizer — strips the refLedgerAligned stamp and re-homes refs onto canonical raw-id order so a clean full-mode read and the legacy fallback load compare equal. - storage-engine-proofs.test.ts: wire legs assert shaCiteNorm equality vs the legacy restart leg and the committed goldens; state legs assert stateDigestAligned; rollback leg now spells BILI_STORAGE_UNIFIED=legacy explicitly (#3818 flip: absent resolves to full, deleting the env would vacate the legacy path). - storage-orphan-recovery.test.ts: pins the content-addressable byRaw->byRef round-trip instead of a counter-era m00003 literal. - golden/storage-render/*.json regenerated with shaCiteNorm/stateDigestAligned. Converges the master-red storage-lane family (#4599 plan A, owner directive).
…dger parity masks The #4316 one-time renumbering restamped messageRefs but left state.tokenSnapshot keyed by the OLD refs, so post-restart bodies carried stale per-message token counts (1.3K vs 1.4K) and the full-mode-restart wire drifted off the legacy baseline (#4599). persist.ts: two-pass remap (stage moves, delete old keys, then write new keys) so entries whose new ref collides with another move's old ref survive; fires only when superseded refs exist. Aligned normalizer (corrupt-index-child.ts): the cacheLedger's segment bookkeeping (be/bl/bs, unfinalized tail line), the derived agg block, and per-line miss-attribution (prov/seam) are restart experience, not content — no-restart and restart legs legitimately differ there. Masked in the aligned view only; raw digests keep full accounting. Goldens regenerated (stateDigest + aligned). storage-engine-proofs 12/12, golden-storage-render 5/5 locally.
…persisted state (#4599) The fork-survival test asserted immediately after the compress tool response, but the fold lands in the live session state asynchronously (#3573 replay semantics). Slow CI runners persisted the pre-fold state ('0 block(s) (compressions=0)' cold load) and the deepEqual diverged. Bounded 5s wait on the in-memory fold; fast machines exit on the first iteration. Product semantics unchanged.
The #4316 cold-load alignment reads the unified sidecar; its ingest of just-flushed records completes asynchronously. Slow runners compared the pre-ingest state and saw refLedgerAligned missing while the fold itself had landed. Poll (bounded 5s) until the loaded state carries the flag; fast machines exit on the first probe.
Git-for-Windows autocrlf checks the bundled .md posts out with CRLF; the exact-match '---' fences then failed to parse and every post lost its title/excerpt/date frontmatter (Windows CI: 'bundled meet-bili post found' assertion). Normalize CRLF to LF inside parseFrontmatter when the fence is CRLF-shaped; LF content is byte-identical as before. Regression test with a CRLF fixture.
… storage mode (#4599) The #4316 cold-load alignment sets refLedgerAligned only when the unified store is available; config-clean machines (CI runners) run legacy mode where it is an honest skip. The test asserted the flag unconditionally, so every shard carrying this file was born-red on CI while unified-config machines passed. Expectation now mirrors store.replicasAvailable(); verified 49/49 in BOTH modes locally.
…mspec wrap on win32 (#4599)
The ci-check lane's expectation change (c496cfb) exposed a real Windows bug: stripInheritedProxy builds inlineEnv as a spread copy of process.env, which keeps the original key casing (ComSpec) — Windows env vars are case-insensitive but plain objects are not. planClientSpawn's exact env.COMSPEC probe then missed it and silently degraded every wrapped spawn to the bare-name 'cmd.exe' fallback (verified by repro on a real win32 box: childEnv.COMSPEC=undefined while process.env.COMSPEC was set). Fix: probe COMSPEC/ComSpec/comspec in planClientSpawn and planDshSpawn. Verified on real Windows (Node 22): launcher-opencode-inline + fix-679 + dsh-refresh 37/37; host tsc clean, 35 pass / 2 win32-skips.
…OMSPEC case-probe c496cfb re-derived the win32 expectation from ambient process.env, which still mismatches production: Node's process.env member access is case-insensitive on Windows while the child env handed to the planner is a plain object whose key keeps the OS casing (ComSpec), so the exact env.COMSPEC probe fell through to the bare-name fallback. The assertion now derives from the child's OWN captured env/options and probes COMSPEC/ComSpec/comspec exactly like planClientSpawn does post-dfeea8a11 — self-contained under any concurrent-test env churn in single-process CI shards — and additionally pins windowsVerbatimArguments=true on the wrap.
|
closing as superseded by #4646. this variant lacks the tools-visibility gate (_plugin_tools_visible): stamping plugin-mode headers whenever tools_ready is true lets sessions whose tool snapshot predates registration run silently uncompressed — the exact #4641 defect class. the per-epoch generation design is worth a follow-up refactor if desired. |
Summary
Hermes cold start (no running bili proxy to attach to) loses
/acp,/acp-cacheand every bili tool entirely. The host gives each plugin a fixed load budget (plugins.load_timeout_seconds, default 10s) around import+register; a coldregister()always exceeds it (health-poll up toSPAWN_WAIT_S=10s, thenGET /manifestup to 5s), so the host discards the whole plugin (disposes every registration) and laterregister_toolcalls become no-ops. Attaching to an already-running proxy is millisecond-level — which is exactly why "start bili manually first, then hermes" always worked.Fix
Split
register()into a fast path and a background path:register()now only wires the cheap always-on surfaces (llm_requestmiddleware,pre_api_requesthook,/acp+/acp-cache, anunloadhook), starts the slow work on a daemon thread, and returns inside a bounded wait (REGISTER_WAIT_S = 4.0) — comfortably under the host's 10s budget._bootstrap()(daemon thread) runs attach-or-spawn + manifest fetch + tool registration under one monotonic deadline (BOOTSTRAP_BUDGET_S = 90.0), replacing the old per-stage waits that summed in the worst case.FIRST_REQUEST_WAIT_S = BOOTSTRAP_BUDGET_S + 15.0) for readiness, then rides wire mode only if the boot has not landed — never a silent direct-connect.register()/re-enable mints a fresh bootstrap generation (stop/readythreading.Events): an unload aborts an in-flight boot, and a re-enable boots fresh instead of dying on a stale stop signal.Also fixes latent defects on this path: two never-defined constants (
BOOTSTRAP_SPAWN_WAIT_Swould have been aNameError; the other caused the silent direct-connect), and the TOCTOU where an unload could still land a lateregister_tool/apply_envon a dead plugin.Behavior change (old → new)
register()latency (cold)/acp+ all tools silently goneunloadhook (best-effort; skipped on hosts that reject it)All intentional — this is the fix. Worst case (boot genuinely stuck) the first request waits at most
FIRST_REQUEST_WAIT_Sthen proceeds in wire mode, so availability is preserved.Tests
tests/hermes-native.test.ts(targeted; runs the real plugin in a subprocess):REGISTER_WAIT_S). Assertsregister()returns in <4s (stays under the host budget) and the tools land once the background boot finishes — the regression pin.hooksassertion now includes the newunloadhook.Local, on the rebased head (current master):
node --import tsx --test tests/hermes-native.test.ts→ 40/40;npm run typecheckclean;python -m py_compile hermes-plugin/__init__.pyclean.Scope
hermes-plugin/__init__.py+ its test). No other client lanes touched.kernel/change, no persistence change.Closes #4641