Repository navigation
更新后旧代理进程永不替换:新会话启动时自动换血旧代理(版本感知 rotation + 看门狗心跳) - #3562
Conversation
…ching to them
A detached proxy outlives its owner by design, but nothing ever replaced it:
attach paths compared health only, never generation, so after an update the
new session re-attached to the old process forever (and on Windows the
watchdog's kill(pid,0) cannot tell a recycled pid apart from the original).
- discovery bring-up: when nothing attachable exists but a shape-compatible,
watchdog-armed, non-user-zone resident holds our canonical port and reports
a strictly older version, request its graceful shutdown (new loopback-only
POST /__bili/shutdown) and wait bounded for the port before spawning onto it
- pinned attach (dsh-native): a healthy-but-strictly-older target is rotated
the same way before falling back to spawn; equal/newer/unverifiable versions
attach as today
- watchdog identity: owners may opt into liveness heartbeats (/__bili/watcher
{pid, hb:true}); hb-opted pids additionally age out past WATCHER_HEARTBEAT_GRACE_MS
so a recycled pid can no longer read 'alive' forever. Legacy registrations
keep kill-0-only semantics, both directions compatible
- regression suite: tests/issue3544-stale-proxy-rotation.test.ts (16 cases)
The stale banner prescribed 'fully quit and relaunch dsh' — useless for a detached proxy (relaunch just re-attaches the old process). Now states that a new session swaps in the new proxy automatically, manual kill works immediately, and relaunch is only needed when the app itself still runs the old build. zh/en.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4247-pr.3562.f06e849This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3562.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复 —— 独立检索(英文 stale/rotation/watchdog/heartbeat/shutdown 与中文「旧代理/换血/版本/心跳」两组关键词,open+closed):无同症状条目。相邻前作 #1723/#1225/#1335/#3044(升级换代端口交接、code-fingerprint attach 门、watchdog attach 门)均为已合并的局部机制,本 PR 在其上补「换血通路」而非重复实现;原 issue #3544 的 triage(floor 2)已独立核实两层根因,方向与本 PR 一致。 开始按 PR review 规范审查:①原 issue 方向 → ②回归清点 → ③代码 → ④测试有效性 → ⑤diff 整洁度。注意到 PR 当前 |
…oxy-rotation Sync the PR branch with current master (v0.1.198 line) ahead of the review fixes below; the textual merge was conflict-free.
… probe cannot resurrect a cleared base
CI regression found during review: tests/issue3380-dsh-rereg-selflock.test.ts
("#3380 incident repro") fails on ubuntu-22/windows-22 shards — after the
preset proxy is killed and the owner gives up, register.base is resurrected
with the dead origin.
Root cause: the new rotation branch in verifyAttachAndRecover inserts extra
awaits (the /__bili/shutdown round-trip) between the version probe and the
base commit, widening a pre-existing race where an in-flight recovery chain
commits register.base AFTER onGiveUp already cleared it. A resurrected base
stamps x-bili-plugin at a dead origin until the next recovery tick.
Fix: a monotonic giveUp generation (register.giveUpSeq) bumped by every
onGiveUp callback; chains capture it at entry and skip their
(state.origin, register.base) commits when it has moved — the chain simply
resolves undefined ("nothing came up"), which is the documented contract
and lets maybeRetry drive the next attempt with fresh bookkeeping. All three
commit families in verifyAttachAndRecover plus the spawnFallback landing are
guarded.
Also corrects a factually wrong comment: /__bili/plugin/manifest has reported
a version since long before #3544, so "pre-#3544 builds report no version"
was false; the unverifiable case is an unreachable target (dead-target path).
Verified locally: issue3380 file 6/6, issue3544 suite 16/16, watchdog-health,
native-intercept, issue2954 green; typecheck clean.
CI regression found during review: tests/launcher.test.ts ("a lane'd launch
with port 0 binds the zone preference and settles it sticky (#1660)") fails
on all three OS shards — the injected zonePreferredPort spy was called twice
instead of once.
Root cause: the rotation call site resolved the lane's preferred port
eagerly on EVERY lane'd bring-up, even when nothing would rotate. The zone
preference resolver is stateful (sticky settlement); touching it adds a
second settlement call beyond the spawn ladder's own.
Fix: rotateStalePredecessor takes a resolveTargetPort thunk and narrows by
every gate except the port first (armed, non user-zone, shape-compatible,
strictly older); the resolver is only invoked when a strictly-older candidate
actually exists. Selection semantics are unchanged (the stale candidate must
still hold our canonical port).
(ai: vllm-qwen/qwen3.8-27b) 审核结论:发现 2 个真实回归,已在 PR 分支直接修复(3 个新提交),待 CI 复绿后可合独立重审了本 PR(未照抄 issue 结论)。方向正确、机制设计合理(换血三闸门 + 心跳身份判定 + 失败一律回落,严格更旧才动手),测试有牙。但 CI(run 39029473489)暴露了 PR 自身引入的 2 个确定性回归,均已定位到根因并修复推送到 PR 分支( 修复 1 — zone-preference 双调用(3 平台红): 修复 2 — giveUp 竞态复活死 origin(u22/w22 两平台红): Windows-only 挂起(w22s1): 结构化八问
一个必须在发布说明里写明的边界(FINDING A)换血要求驻留方有 判定:推送头 |
…n commits Round-2 CI (u24s1) timed out '#983 maybeRetry self-heals a base-less register after a failed respawn' (15s waitFor). The giveUp generation guard was also applied to the spawnFallback landing, but a fresh-spawn landing is live by construction — it cannot resurrect anything — and the self-heal contract (#983/#1783) requires exactly these late landings to re-base a given-up register. A giveUp that lands between fallback start and landing must not suppress the heal. The guard now covers only verifyAttachAndRecover's three commits of an EXISTING origin (equal/newer branch, rotation-refusal branch, pinned-recovery branch), whose liveness was probed earlier and may be stale at commit time — the exact #3380 resurrection hazard, proven by the measured incident-test timeline (giveUp T589.23 < refusal commit T592.18). Local: dsh-native.test.ts 55/55, #983 self-heal 20x stable, issue3380 6/6, issue3544 16/16, native-intercept 62/62, launcher 313/313, typecheck clean.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI 跟进(接上条结论):head 第 3 轮 CI(run 39046188052,head 41f00fb)全部通过:test 分片 ubuntu-22 ×3、ubuntu-24 ×1、windows-22 ×2 全绿(包括第 2 轮挂掉的 u24s1 和第 1/2 轮抖动的 w22s1),kernel/pi-subagents/version/config-surface/lane/docs 等 guard 车道与全部 e2e 车道均 success。分支已同步到当前 master(合并提交 第 2 轮 u24s1 的 #983 超时——定性为环境性,但顺手收紧了一处语义第 2 轮 u24s1 上
不过排查中发现 spawnFallback landing 处的守卫语义上确实收得太宽(新 spawn 落地的 origin 天生是活的,#983/#1783 契约要求迟到的落地必须能重新基化已放弃的 register,先前的 giveUp 不该压制它)——已收窄:giveUp 失效守卫只作用于「attach 到既有 origin」的三个提交点,spawn 落地不再受压( 两个非阻塞观察
结论维持上条:回归已修、行为变更已披露(含 FINDING A——首个包含本 PR 的版本仍需一次手动杀进程退役旧代际驻留代理,建议进 release notes)、无 config surface 变更。可合;合并留给你。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.540-master.7c2920c # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #3544
修的是什么(一句话)
插件升级到新版本后,常驻的旧代理进程永远不被替换:attach 路径只查健康、从不比版本,应用重启只是重新挂上旧进程;Windows 上看门狗的
kill(pid,0)纯存在性检查还分不清被回收的 pid——两层叠加 = 「永远更新不了」。本 PR 让新会话启动时自动换掉严格更旧的驻留代理,并给看门狗加上基于心跳的身份判定。修法(机制层面,三个子缺陷一个闭环)
src/launcher.ts):pickAttachable落空后、spawn 之前,若有一个形状兼容(配置/lane/host/passthrough 全同)、看门狗已武装、非 user-zone、且占用我们 canonical port 的驻留实例报告了严格更旧的version,则向它请求优雅退出(新增 loopback-only 管理端点POST /__bili/shutdown,走既有 graceful-shutdown + 10s 强制退出兜底),有界等待端口释放后在新进程上绑定同一端口。任何疑点(版本不可比/请求被拒/超时)都回落到既有 spawn 阶梯,行为不劣于现状。src/agent/dsh-native.tsverifyAttachAndRecover):健康但严格更旧的 pinned target 先请求退出再走 spawn fallback;等值/更新/版本不可考一律照旧 attach;换血失败也照旧 attach(不劣化)。src/server.ts+src/server/admin.ts):owner 可带{pid, hb:true}注册心跳并周期性重发;hb 注册的 pid 在WATCHER_HEARTBEAT_GRACE_MS(15s,容忍 3 次丢失)内无心跳即判死——回收的 pid 不再永远「活着」。未 opt-in 的 legacy 注册保持 kill-0 语义,新旧两端双向兼容。src/agent/dsh-native-client.ts):stale 提示不再给无效的「完全退出重启 dsh」处方,改为说明新会话自动换血、手动杀进程立即生效、仅当应用本身还是旧版才需重启(zh/en)。行为变更披露(old → new)
触发面:所有 native 宿主在「磁盘已更新、旧代理常驻」场景;只有严格更旧的驻留会被触碰,user-zone daemon、外 lane、等值/更新版本一律不动。
config surface
无新增/重命名/改语义的配置字段、env 或 CLI flag。新增常量均为模块内部(
STALE_ROTATION_WAIT_MS/WATCHER_HEARTBEAT_GRACE_MS等);POST /__bili/shutdown与/__bili/watcher的可选hb字段是 loopback-only 管理线协议扩展,不是用户配置面。kernel-change
不涉及(kernel/ 零改动)。
测试
tests/issue3544-stale-proxy-rotation.test.ts(16 例,本地全绿):换血 happy path / 等值版本不动 / user-zone 不动 / unarmed 不动 / 拒绝退出立即回落 / 错误端口不动 / 无版本字段(pre-安装新版本后旧代理永远不换新:detach 代理躲过应用退出,重启只是重新挂上旧进程(「永远更新不了」) #3544)保持共存;心跳自证与 foreign-pid 拒收;pinned 换血两分支;/__bili/shutdown路由(loopback 202 / 非 loopback 403 / tunnel 头 403);watcherIsDead四象限。tests/issue2954-launcher-clobber.test.ts(2/2)、tests/watchdog-health.test.ts(1/1);typecheck 干净。全量以 CI 为准。查重
查重: 无(open+closed issue/PR 按 detach/stale/rotation/watchdog-pid/版本错位多组关键词检索均无同症状条目;相关前作 #1723/#1225/#1335 均已在本 PR 的机制中兼容复用)。