Skip to content

[PR] fix(hermes): self-heal after bootstrap failure and routed-origin death - #4646

Merged
ranxianglei merged 5 commits into
masterfrom
2026-10-25_hermes-selfheal
Oct 26, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
2026-10-25_hermes-selfheal

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4644

Stacked on #4642 (branch cut from its head 65a9a6a4d): #4642 removes the cold-start failure mode (plugin lost when bootstrap outlived the host's load deadline); this PR adds the recovery surface for what happens AFTER a bootstrap fails or a routed proxy dies. If #4642 merges first, this rebases cleanly onto master.

Behavior changes (disclosed)

Bootstrap retry (new policy). A failed bootstrap stage no longer settles failed until host restart: up to 4 attempts with 10/30/60 s backoff, each attempt on a fresh 90 s budget; an already-succeeded stage is not re-run (no re-probe of a healthy origin, no re-fetch of registered tools). An unload mid-backoff still settles stopped — the late failed write path was removed so _shutdown owns the record.

Origin watchdog (new mechanism). Old behavior: none — a routed proxy that died left HTTPS_PROXY et al. pointing at a dead port for the whole host lifetime (silent direct connection, connect-refused storms). New: 30 s probe x 3 consecutive misses (our own child exiting = instant detection) unroutes the process env — RESTORING the values present before routing, so a user's own proxy config survives; keys without a prior value are dropped — then re-bootstraps inline in the watchdog thread. Tool registration is re-armed, not repeated (the host session snapshot keeps the tools; their handlers follow the new origin). One loud warning per episode.

Starting marker gains lane (#1225 alignment, additive field). Our claims now declare lane: "hermes"; undeclared lanes wildcard both sides, so pre-#1225 markers stay compatible. Semantics mirror src/launcher.ts: a same-lane starter is honored (wait for its instance + attach); a live DIFFERENT-lane starter is neither waited on nor removed — we spawn without coordinating and leave its marker intact; stale markers are removed and re-claimed. Note: the old python code waited behind ANY non-stale marker regardless of lane; it now waits only behind same-lane/legacy ones.

Non-changes

Tests

Five new hermes-native driver scenarios: retry-land (attempt 2 succeeds after a blocked first), retry-exhaust (4 attempts -> failed + "after 4 attempts" + direct traffic with settled ready-event), origin-death (env gap restores the user's prior proxy value, recovery re-routes, each tool registered exactly once), marker-foreign (foreign-lane starter untouched, we spawn anyway), marker-same-lane (wait + attach, no double-spawn, starter marker kept). Local targeted run: 48/48 green; typecheck clean. Full-suite verdict deferred to CI on this head.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-25_hermes-selfheal (99ab5f3)

Latest build — install this exact version

npm install -g billion-context@0.0.6032-pr.4646.2274ac4

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
99ab5f3 billion-context@0.0.6032-pr.4646.2274ac4 build
f74c28d billion-context@0.0.5937-pr.4646.e8a0149 build
5e7e912 billion-context@0.0.5686-pr.4646.96d54eb build
fcda407 billion-context@0.0.5683-pr.4646.5cad634 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4646.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(hermes): self-heal after bootstrap failure and routed-origin death [PR] fix(hermes): self-heal after bootstrap failure and routed-origin death Oct 25, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 本 PR 是 #4644 的修复 PR(分支 2026-10-25_hermes-selfheal,head fcda4071e),stacked 于 #4642(head 65a9a6a4d,base = 当前 master bd29924d4)。open/closed 全量检索后相关项:

标签: bug + hermes + scope/wiring + p1(理由:压缩核心承诺静默停摆、UI 无感知、持续到宿主重启 = p1 可用性档,与 #4644 标签一致)。

开始审核:精读本 PR diff(65a9a6a4d..fcda4071e)与重构后的 hermes-plugin/__init__.py 全文 → 既有行为回归清单逐项判定 → 测试有效性审查 → 本地定向跑 hermes-native 场景 → CI 状态核查。结论按八问体例回复。

@ranxianglei ranxianglei added bug Something isn't working hermes 改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签 p1 scope/wiring labels Oct 25, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

审核完成:通读本 PR 全部 diff(hermes-plugin/__init__.py + tests/hermes-native.test.ts),marker 语义与 src/launcher.ts #1225 参考实现逐行对照,本地定向复跑 48/48 绿(PR head,含 5 个新场景,复现作者声明)。发现 1 处镜像保真缺陷已直接修掉并推送(commit 5e7e91269,见第 5 问)。全量套件结论以新 head 的 CI 为准(旧 head fcda4071e:各 e2e 车道最新批次全绿,主 CI 审核时仍在跑)。

1. 是什么问题:hermes 原生车道三个缺陷——① bootstrap 失败一次性落定 failed,压缩承诺静默停摆直到宿主重启;② 路由出去的代理死掉后 HTTPS_PROXY 等四个 env 永久指向死端口(静默直连 / connect-refused 风暴);③ starting marker 缺 lane 字段(与 TS launcher #1225 不一致),hermes 启动会卡在不相关车道 starter 身后最多一个 TTL。

2. 什么原因导致的:① 失败路径没有重试机制(一次性 fail-fast 早于自愈需求);② env 路由是单向写入、无反向路径——没有任何东西检测 origin 死亡并清理路由;③ Python 侧写 marker 时未跟进 #1225 的 lane 协议。三者都是「机制缺失」,不是参数错误。

3. 影响范围与严重程度:p1 可用性档。① 任何瞬时 bootstrap 失败(端口竞争、磁盘繁忙)即触发,影响 = 整个宿主生命周期无压缩;② 会话中途代理死亡即触发,影响 = 模型流量风暴报错或静默直连直到重启;③ 仅多车道并发启动时触发,影响 = hermes 冷启动被无关车道 marker 阻塞。

4. 怎么修复的:三个机制都打在产生层,不遮症状——① 有界重试:失败阶段按 10/30/60 s 退避重试,每次尝试全新 90 s 预算,共 4 次;已成功阶段不重跑(origin/env/tools 各有守门);耗尽后响亮落定 failed(record、日志、/acp 三处可见)。② origin 看门狗:30 s 探测 × 3 连失(自家子进程退出 = 即时判定)→ unroute 恢复用户原有 env 值(无原值则删键,用户自己的代理配置存活)→ 看门狗线程内联重新 bootstrap;工具只 re-arm 不重复注册(handler 闭包按调用动态跟 _state["origin"],已验证)。③ marker 对齐 #1225:声明 lane:"hermes"、未声明双向通配、同车道等待+attach、异车道不等也不动其 marker、stale 删除后重抢。

5. 是否有回归问题:触碰路径的既有行为逐项清点——register() 仍 4 s 内返回(REGISTER_WAIT_S 未动);首请求闸门 105 s 语义不变(ready_event 在 _bootstrap finally 对所有终态必 set,耗尽后流量不会悬停);冷启动成功路径的操作序列与改前一致;unload 中途 bootstrap 仍落定 stopped(退避 sleep 对 stop_event 即时响应,迟到的 failed 写路径已移除、_shutdown 独占记录——已披露);marker 的 O_EXCL 仲裁、token 守卫清理、单写者契约(#707/#991)保持;子进程 spawn env 仍剥离代理变量;工具 handler 闭包不变。高危模式过完:无 fail-fast 变吞错(每次重试都有响亮警告)、无阈值漂移(新常量均已披露)。一处输出格式变化补披露:/acp 的 starting 文案由「budget 90s」变为「budget 90s per attempt」(N>1 时加「, attempt N」)——外观级,PR 描述未单列,此处补齐。发现并已直接修复一处缺陷:同车道等待循环在 deadline 边界退出时没有最后一次 discovery pass,而 TS 参考实现(waitForStarterInstance)刻意有这一发终探(starter 成功路径会清 marker,边界时刻的 attach 与放弃不可区分 → 双 spawn);7 行修复已作独立 commit 5e7e91269 推上本分支,定向测试仍 48/48。另顺带记录一个既有问题(不在本 PR diff 内,未动):BILLION_CONTEXT_ATTACH 轮询循环存在同类边界 sliver(超 deadline 直接 break 回退本地 bootstrap,没有终探),系 #4642 带入,建议 #4642 合并前顺手处理或另行立项。

6. 是否破坏缓存:不涉及。不动会话存储/fold 状态/缓存键;恢复换新 origin 后由磁盘状态继续服务(fold 状态跨代理存活)。

7. 是否改了设计方向:不改。三个机制都在既有架构内(bootstrap 线程 + lifecycle lock + marker 仲裁)补自愈面,无新层、无数据流转向。一条依赖声明:恢复生效依赖 hermes 在请求时读取进程 env(纯 env 驱动路由,middleware 只打 header)——driver 测试验证的是进程内 env 迁移,真实 hermes httpx 的行为在宿主侧,建议合并后实测一次(会话中途 kill 代理,观察 ~90 s 内恢复)。

8. 是否引入了新的配置:无。BOOTSTRAP_RETRY_BACKOFF_S/ORIGIN_WATCH_INTERVAL_S/ORIGIN_WATCH_FAIL_LIMIT 是模块常量,非配置面(与 PR 声明一致)。

测试有效性:5 个新场景断言有牙——重试计数(attempt==2 / ==4)、「after 4 attempts」错误文本、env 恢复为用户原值而非删键、register_calls==3 钉死「恢复不重复注册」、foreign marker 完好且我们照常 spawn、同车道等待+attach 无双 spawn。缺口(不拦合并):无场景专门钉「退避期间 unload 落定 stopped」(现有 slow-boot-unload 部分覆盖,且退避对 stop_event 即时响应,风险低);无原值键的 pop 路径未被直接采样(只采样了 HTTPS_PROXY)。

判定:可合(等新 head 5e7e91269 的 CI 转绿)。stacked 顺序两种都行:#4642 先合,或本 PR 直接合(分支包含 #4642 的提交,GitHub 按整支合并)。

yanhuojiyusheng and others added 4 commits October 26, 2026 09:57
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.
#4644)

A failed hermes bootstrap was terminal until host restart: one transient hiccup settled state 'failed' forever, and a routed proxy that died later left the process env pointing at a dead port for the whole host lifetime (silent direct connection, connect-refused storms).

- bootstrap retries failed stages with backoff (10/30/60s, 4 attempts total), each attempt on a fresh 90s budget; already-succeeded stages are not re-run; an unload mid-backoff still settles 'stopped', never clobbered by a late 'failed'
- origin watchdog: 30s probe x 3 consecutive misses (or our own child exiting) unroutes the process env — restoring the values present before routing — and re-bootstraps inline, re-arming the registered tools without re-registering them
- starting marker gains the lane field (#1225 alignment, additive): our claims declare lane 'hermes'; undeclared lanes wildcard both sides; a same-lane starter is honored (wait + attach), a live foreign-lane starter is neither waited on nor removed, stale markers are removed and re-claimed

Tests: 5 new hermes-native scenarios (retry-land, retry-exhaust, origin-death, marker-foreign, marker-same-lane); local targeted suite 48/48 green, typecheck clean.
… sliver (#4644)

Review fix on 2026-10-25_hermes-selfheal: the same-lane marker wait loop in
ensure_origin exited at the shared deadline without a last discovery pass,
while the reference implementation (waitForStarterInstance, src/launcher.ts)
probes once more first — its success path clears the starting marker, so an
attach landing right at the boundary is indistinguishable from a failure bail
without that look, and we double-spawn over the starter's bring-up instead of
attaching. Add the single-shot pass (no deadline arg = pure one-shot) before
the post-wait claim, mirroring the TS lane.
…ed spawn poll (#4646, #4656)

Rebase follow-up on #4646: the branch rewrote the spawn-poll loop inside the
background _bootstrap and thereby dropped the #4656 fix that #4658 implements
on master's structure. Port it into the new loop:

- _find_spawned_in_registry(child_pid) (latest started_at among same-pid
  markers, #4658 review hardening) after the shared-pointer token check and
  before the child-exit check, with the manifest health probe before adoption
- adoption now also records instance_id (the #4658 review nit — /acp panels
  show the adopted instance instead of a blank id)
- tests ported under the new structure: spawn-clobber waits on the bootstrap
  readiness event (register() returns early now) and pins the instance_id;
  registry-find keeps rf_own/rf_foreign/rf_dead/rf_none plus the dup-pid
  aaa-stale vs zzz-own started_at tie-break
@ranxianglei
ranxianglei force-pushed the 2026-10-25_hermes-selfheal branch from 5e7e912 to f74c28d Compare October 26, 2026 02:07
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.844-master.257afab (rolling master tag).

npm install -g billion-context@0.0.844-master.257afab  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hermes 改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签 p1 scope/wiring

Projects

None yet

2 participants