Repository navigation
[PR] fix(launcher): refuse attach to orphaned armed proxies and reap them before spawn (#6257) - #6427
ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.9328-pr.6427.94fce7cThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr6427.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 — open [PR] rows checked (115 total); this PR is the only one targeting #6257. Related-but-distinct: #6358 (stale helper config on re-attach, #4705) and #5835 (reap wedged orphaned proxies off-loop, #5449) touch adjacent lifecycle surfaces but different mechanisms/issues — no overlap with this thread's scope. Status as I pick this up:
Now doing the full review (code + regression audit against the touched paths). Will follow up with the structured conclusion. |
…before spawn (#6257) An armed resident whose declared spawner (BILI_PARENT_PID) is dead and which has no other live watcher is a zombie: on macOS a detached proxy has lost Local Network authorization, so every LAN upstream fails with EHOSTUNREACH while it keeps running -- and a host restart re-attaches to it, so it never heals. The #1335 attach gate only checked watchdog.armed, which stays true forever for such a proxy. - HealthInfo.watchdog now carries parentPid (the server already reports it; the launcher dropped it) and parses it. - New isOrphanedWatchdog(health, selfPid, isAlive): armed + parent dead + no other live watcher. Self is excluded (a previous bring-up may have registered us); a live co-owner or live parent keeps the candidate attachable; a missing parentPid on older builds is unverifiable and not orphaned. - pickAttachable refuses orphaned candidates after the #1335 gate (logged once per origin with the #6257 reason and the attachExternal escape hatch); attachExternal stays fully permissive. - New reapOrphanedPredecessor: before the spawn, a same-lane orphan holding the target port gets a supervised graceful shutdown (/__bili/shutdown, re-probe first, poll until a fresh connection is refused, no raw kill) so the spawn binds the canonical port instead of laddering to a sticky port drift (#1660). Any doubt falls through to the untouched spawn ladder. - The strictPort squatter check no longer throws 'kill that process' for an orphaned armed holder (it is not lifecycle-less; the reap or the #1903 rediscovery converges it). - The server watchdog logs one warning when the declared parent dies but adopted watchers keep the proxy serving (the detached-proxy hint). Related: #4367 (attach gate owner-liveness design), #4705 (re-attach reuses stale helper), #5663 (macOS Local Network authorization).
e616266 to
21e3423
Compare
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Review complete. Pulled the branch, read the full diff against master, verified every claimed pre-existing symbol, and audited the touched paths for regressions. What I did to the branch: it was 43 commits behind master, so the full test/e2e CI lanes were skipped (only the fast guards ran — all green). I rebased the single commit onto current master (clean, no conflicts) and pushed it back to the PR branch ( Code review (the main gate):
Regression audit (existing behaviors on the touched paths):
Tests: 7 new tests cover the truth table (7 rows), gate refusal + diag assertion, live co-owner, live parent, 8问 (structured checklist):
判定: 代码正确、测试扎实、回归面已逐项清点,唯一窄行为变更可接受且已披露。可合——待 rebase 后 CI 全量 test lane 落绿(当前 12 pending / 0 failed)。分支已 rebase 到当前 master 并推送( |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI landed green on the rebased head ( PR state: |
What this fixes
A resident proxy whose declared spawner (
BILI_PARENT_PID) has died and which has no other live watcher is a zombie. On macOS a detached proxy has lost Local Network authorization, so every LAN upstream fails withEHOSTUNREACH(cloud upstreams are fine) while the process keeps running — and a host restart re-attaches to it, so the condition never heals. The only user-side recovery is killing the proxy pid by hand. Reported three times on one machine (0.1.213, DSH desktop lane).Root cause: the #1335 attach gate (
attachGateAllows) checks onlywatchdog.armed, which is a boot-time constant (armed: initialWatcherPid !== nullinsrc/server/admin.ts) — it staystrueforever after the parent dies. The launcher'sHealthInfoeven dropped theparentPidfield the server already reports, so the liveness check was impossible at the gate.Closes #6257. Related: #4367 (attach gate owner-liveness design), #4705 (re-attach reuses stale helper), #5663 (macOS Local Network authorization, root cause 2).
Changes
HealthInfo.watchdogcarriesparentPid— the server already reports it; the launcher now parses it (typeof wd.parentPid === "number"; absent on pre-[Bug][dsh lane] 0.1.213 macOS: a detached proxy that outlives the host keeps running but loses Local Network authorization (all LAN upstreams EHOSTUNREACH, cloud fine), and host restart re-attaches to it so it never heals | 守护进程跨宿主存活后失去本地网络授权,attach 复用旧进… #6257 builds = unverifiable).isOrphanedWatchdog(health, selfPid, isAlive)(exported, pure):armed === trueANDparentPidpresent ANDparentPiddead AND every other watcher dead. Self is excluded (a previous bring-up may have registered us); a live co-owner or live parent keeps the candidate attachable (legitimate multi-host sharing, kimi native 共享代理存在与 #1183 同类的「首 owner 退出杀共享代理」暴露面(无 watcher 注册) #1190).pickAttachablerefuses orphaned candidates after the claude-native hooks must not attach to a lifecycle-less proxy — attach gate + self-managed fallback #1335 gate, logged once per origin with the reason and the escape hatch.native.attachExternal/BILI_NATIVE_ATTACH_EXTERNAL=1stays fully permissive (explicit opt-out, unchanged).reapOrphanedPredecessor(new): before the spawn, a same-lane orphan holding the target port gets a supervised graceful shutdown — re-probe right before acting (abort if a live owner appeared in the meantime),POST /__bili/shutdown, then poll a fresh (no-keep-alive) connection until it is refused orSTALE_ROTATION_WAIT_MS(12s) elapses. No raw kill (the pid could be reused). Any doubt falls through to the untouched spawn ladder. This exists because a bare gate refusal would leave the pinned port held: the spawn would hitEADDRINUSEand ladder to a sticky +1 port drift ([Design] 定死端口 lane(claude 48787 / zcode 48789)端口被占时的 0 配置解法 #1660).Behavior changes (old → new)
watchdog.armed === true→ attachattachExternal: true)EADDRINUSE→ port ladder +1 drift (#1660)killon a proxy that may serve other sessions is wrong; the new reap is the sanctioned pathUnchanged:
attachExternalsemantics (fully permissive); the #1335 gate for non-orphaned residents; the #3544 version-strictly-newer rotation (orthogonal, still runs before the reap); the #5955 wedged-holder takeover; the watchdog's own shutdown logic (a proxy that loses ALL watchers still shuts down as before).Windows pid-reuse caveat:
kill-0is existence-blind — a recycled pid can read as "alive", making the orphan undetectable in that window (miss, not false-positive). Same limitation as the existing watchdog probes; the #4367 heartbeat design is the root fix and this gate is its strict subset.Tests
tests/launcher.test.ts:isOrphanedWatchdogtruth table (orphan / self-only watcher / live co-owner / live parent / unarmed / armed-without-parentPid / no-watchdog); gate refusal with diag assertion; live co-owner attachable; live parent attachable;attachExternaloverride;ensureProxyRunningreap happy path (shutdown called, spawn on canonical port); reap abort when a live owner appears (no shutdown, spawn proceeds).tests/launcher.test.ts: 360 pass / 0 fail / 1 pre-existing skip.npm run typecheckclean.Review tier
Touches session-binding / lifecycle default behavior — human review required (§7.4), no auto-merge.