Repository navigation
[PR] fix: verify responder identity before claiming a settled proxy origin (#4125) - #4622
ranxianglei wants to merge 12 commits into
Conversation
…#4125) The ensureProxyRunning settle loop trusted any healthy /__bili/health answer at the child's claimed origin in its two primary branches (launchToken match, registry-by-pid), while only the stale-record fallback verified the responder pid (#1753). A foreign listener positively answering with a different pid therefore counted as success: the launcher would hand that origin out as our own (single-writer violation) or burn the full spawn budget probing a contested port. Both primary branches now use fetchHealthInfo and accept only when the reported pid is absent (legacy fail-open preserved) or equals the spawned child's pid; a positive foreign-pid answer is rejected with a once-diagnostic naming both pids. Terminal paths unchanged. Also corrects the stale libuv-issue citation in port-owner.ts (libuv omits SO_REUSEADDR on Windows precisely because setting it allows stealing another application's port). Tests: tests/issue4125-settle-identity.test.ts pins accept/reject/fail-open per branch (both gate directions, #3617 discipline); launcher suite green.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7498-pr.4622.398f227This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4622.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ed-exports #4545's dsh-lane-only trim removed every external use of the type; it is now referenced only inside client-build-note.ts, which trips the INTERNAL_ONLY gate on clean master (reproduced locally). Drop the leading export per the gate's prescribed fix — a future lane re-adds it when it actually opts in.
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复——本次红线的根因是 master 上遗留的僵尸导出,master 侧已有专门修复在途(#4606,sentinel 在 #4599 接管);按「几行级小修」政策在本 PR 分支直接顺手修(独立标注 commit),跨 PR 重复修复明确允许。 结构化八问:
修复已推送:commit |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复(同机制家族、不同位置)。 本 PR 把 #1753/#1758 早已确立的「认领某个 origin 前先核对应答方 pid」纪律,从 spawn-wait 的 preferred-port 兜底分支,补齐到 settle 循环的两个主分支(launchToken / registry-by-pid)。相关既有工作:#1758(spawn-wait 兜底)、#2947(bind 后端口所有权)、#1756(launcher 生命周期两侧)——都属同一 responder-identity 机制家族,各修各的位置。本 PR 补的是「主分支一直没对齐到 #1753 标准」这个真实缺口,不是重复劳动。 标签: bug + dsh + scope/wiring + p1 —— 修的是单写者/可用性误路由(p1 级机制缺陷的部分切片),宿主来自 #4125 的 dsh 桌面车道。 1. 是什么问题:settle 循环的 launchToken 与 registry-by-pid 两个主分支,原来只要「child 声称的那个 origin 上有人健康应答 2. 什么原因导致的:根因是把「健康应答」当成了「身份证明」。preferred-port 兜底分支在 #1753 就吃过亏、改成必核 pid,但两个主分支一直沿用旧的宽松判定(只看布尔 3. 影响范围与严重程度:触发条件 = 同一地址上存在第二个活着、能健康应答且带不同 pid 的实例(多实例 / 旧版本残留 / 跨车道混淆)。严重度 = p1 级机制缺陷:命中时要么静默误路由(用户侧完全看不到,正是 #4125 排障成本高的根源),要么烧满 60s 预算后杀自己孩子、bootstrap 长时间失败。本 PR 只覆盖 settle 循环这一处切片,#4125 的多实例根因仍待 reporter 的日志证据(原线程已索取)——PR 正文也如实标注 partial slice。 4. 怎么修复的:两个主分支改用 5. 是否有回归问题:审过的既有行为逐项——
6. 是否破坏缓存:不涉及(纯 launcher/bootstrap 路径,不碰前缀缓存 / 压缩 / 存储游标)。 7. 是否改了设计方向:不涉及架构转向,是把既有 #1753 身份纪律在同类位置补齐,方向一致。附带把 8. 是否引入了新的配置:不涉及(无新 env / config / 默认值)。 CI 状态:head 测试有效性: 合并判定:可合。 建议 owner 在 #4603 清掉 master 红之后 rebase + retrigger 再合。提醒一句:这是 spawn-settle 身份逻辑,落在 load-bearing 的 bootstrap 路径上,按 §7「identity/session-binding logic」应留人工合入、不走 auto-merge。我作为 agent 不执行合入,以上为独立审核结论。 |
…ot this PR's master 146b34f fails the unused-exports gate on this exact line (INTERNAL_ONLY src/agent/client-build-note.ts: ClientBuildCheck): the type-only export #4545 introduced was missed by the 4d34abf de-export sweep. This PR touches none of it — every PR rebased past that master inherits the red (#4599 storm log). Same one-word fix as #4606 commit 1 and the in-branch precedents (#4607/#4595/#4540/#4618/#4622): drop the leading export on a symbol referenced only within its own file. Drop this commit when rebasing after #4606 merges.
…rent-gone watchdog (#4125) The watchdog had two disagreeing liveness signals: the identity-blind kill-0 existence probe (death streak of confirmTicks, #3890) and the identity-anchored owner heartbeat (#3544). The streak ran regardless of heartbeat freshness, so three consecutive transient OpenProcess failures against a LIVE host burned the whole confirm window and force-exited a healthy proxy mid-session. Field case 2026-10-25 (DSH web host, reported in #4125): parent-gone fired for a pid that was alive throughout; the shutdown reason carried no [stale-heartbeat] suffix, pinning it to the kill-0 path. A FAILED probe on a heartbeat-opted owner no longer counts while its last beat is within the grace window: the beat is the stronger proof (only the true owner posts its own pid over loopback). The disagreement is logged once per episode with the probe errno. Stale-heartbeat removal (#3544) and legacy kill-0-only semantics for non-heartbeat pids are unchanged (pinned in tests). Behavior change: a truly dead parent whose last heartbeat was delivered moments before death now keeps the proxy alive up to the heartbeat grace (15s) plus idle grace (5s) instead of ~11s — bounded orphan-lifetime extension in exchange for not killing live sessions on transient probe flaps.
…ort state (#4125) The port log (%TEMP%/bili-proxy-<port>.log) is shared across spawns (append fd, size-based rotation only). A zero-output failed child left the PREVIOUS spawn's content behind and every quoted sample misattributed it — field case 2026-10-25: a week-old EADDRINUSE line quoted as the current failure's evidence. Nothing recorded what the port was doing at SPAWN time, while the failure-time diagnosis only sees the END state; 'predecessor still draining' and 'child wedged elsewhere' read identically at the end. Each spawn now appends a '=== bili spawn <ts> launcherPid childPid port ===' header; size reports and head samples are scoped to this spawn's segment ('N bytes since this spawn'); every terminal failure message (slow-start notice, early exit, timeout) carries '(at spawn: <port state>)'. Rotation policy and on-disk content are unchanged — only the quoting and the new fields. Also fixes a fake gap this PR exposed: the #3544 bring-up harness modeled the spawned child through the bare probe seam but not the health-info seam, so the settle-identity commit in this PR starved its settle loop. The fake now models a real child whose /__bili/health names its own pid post-spawn. Behavior change: failure/diagnostic messages gain fields (additive); the empty-log wording changes from '0 bytes — EMPTY' to '0 bytes since this spawn — EMPTY'.
heartbeat veto; publish spawn-log header pre-spawn Merge resolution (origin/master into 2026-10-25_4125-settle-identity): - tickWatchedPid: union of master's #4994 dual-axis signature (hbStreak + heartbeatConfirmTicks) and this branch's #4125 fresh-heartbeat veto; the veto resets hbStreak too, and the call site clears the kill-0 streak on a vetoed tick. - spawn log: folded the branch's parallel spawnLogStartBytes into master's spawnLogOffset. The '=== bili spawn ===' header now publishes BEFORE spawnImpl (same discipline as #707's starting marker): a spawned child can write before a post-spawn append lands, which would push its earliest bytes (crash tails, listen lines) below the offset into 'previous spawn' territory. The header drops childPid (unknown pre-spawn); the child names itself in its pid-tagged listen line (#4994). - terminal failure messages keep BOTH features: master's structured diagnosePort().text + failureHint() AND this branch's '(at spawn: <port state>)' annotation. - tests adapted to the merged contracts: issue4125-watchdog-heartbeat-veto (6-arg signature + #4994 confirmed-tick pin replacing the immediacy pin), issue4125-spawn-log-segment (header asserts port= instead of childPid), issue4811 (zero-output wording pin). Local: typecheck clean; all 12 affected suites green serially (82 tests).
(ai: vllm-qwen/qwen3.8-27b) Merged current master into this branch and resolved all conflicts — the PR is 1. 2. Spawn-log segment (src/launcher.ts) — master independently built #4811/#4816 sampling on 3. Terminal failure messages — master restructured Tests adapted to the merged contracts: |
Related to #4125 (partial slice — the root cause of the multi-instance episode still awaits the reporter's log evidence requested in-thread). This PR now holds three facets of the same bootstrap-failure mechanism family; each is its own labeled commit.
Facet 1 — verify responder identity before claiming a settled origin (commit 3ededa8)
ensureProxyRunning's settle loop has three branches that can declare "our child is up":Branches 1 and 2 trusted any healthy answer at the claimed origin. If a foreign listener positively answers
/__bili/healththere with a different live pid, the old code handed that origin out as ours (single-writer violation, #991/#1225) or burned the full 60 s spawn budget probing a contested port and then killed its own child — one concrete way bootstrap fails for hours while another instance keeps running, which is the shape #4125 reports.Both primary branches now use
fetchHealthInfoand accept only when the reported pid is absent (legacy fail-open preserved for older children) or equals the spawned child's pid. A positive foreign-pid answer is rejected with a once-only diagnostic naming both pids. Terminal paths (kill +diagnosePort) are unchanged — they already name this situation at decision time.Also corrects a stale citation in
src/port-owner.ts: it pointed at libuv issue #1360 (an unrelateduv_get_process_titlesegfault fix) for the Windows bind-exclusivity claim; the actual basis is in libuv source (src/win/tcp.c,uv__tcp_try_bind): libuv deliberately omitsSO_REUSEADDRon Windows because setting it would allow stealing a port held by another application.Facet 2 — fresh owner heartbeat vetoes transient kill-0 failures in the parent-gone watchdog (commit aebbafb)
Field evidence from #4125 (DSH web host, 2026-10-25):
parent-gone (pid 14852) receivedfired against a LIVE host and forced a healthy, mid-compression proxy to exit ~10 s later. The quoted shutdown reason carried no[stale-heartbeat pids: …]suffix — which the code appends ONLY for heartbeat-staleness removals — so the false death ran the kill-0 confirmation path: three consecutive transientOpenProcessfailures against a live pid burned the whole #3890 confirm window (~4–6 s) plus the idle grace.The watchdog now has two liveness signals: the identity-blind kill-0 probe and the identity-anchored owner heartbeat (only the true owner posts its own pid over loopback). A failed probe on a heartbeat-opted watcher whose last beat is within the heartbeat grace window (15 s) no longer counts towards the death streak; the disagreement is logged once per episode with the probe errno. Stale-heartbeat removal (#3544) and the legacy kill-0-only semantics for non-heartbeat pids are unchanged (both pinned).
Behavior change: a truly dead parent whose last heartbeat landed moments before death now keeps the proxy alive up to heartbeat grace (15 s) + idle grace (5 s) instead of ~11 s — a bounded orphan-lifetime extension in exchange for not killing live sessions on transient probe flaps.
Facet 3 — scope spawn-log evidence to this spawn + record the at-spawn port state (commit 4537b63)
The port log (
%TEMP%/bili-proxy-<port>.log) is shared across spawns (append fd, size-based rotation only). A zero-output failed child left the PREVIOUS spawn's content behind, and every quoted sample misattributed it — field case: a week-old EADDRINUSE line quoted as the current failure's evidence. And nothing recorded what the port was doing at SPAWN time, while the failure-time diagnosis only sees the END state — "predecessor still draining" and "child wedged elsewhere" read identically at the end.Each spawn now appends a
=== bili spawn <ts> launcherPid=<pid> childPid=<pid> port=<p> ===header; size reports and head samples are scoped to this spawn's segment ("N bytes since this spawn"); every terminal failure message (slow-start notice, early exit, timeout throw + console.error) carries(at spawn: <port state>)— healthy bili instance (pid N) / foreign HTTP answer / nothing listening / HTTP nnn / busy (TCP up, no health answer). Rotation policy and on-disk content are otherwise unchanged.Also fixes a test-fake gap this PR exposed: the #3544 bring-up harness modeled the spawned child through the bare-probe seam but not the health-info seam, so facet 1 starved its settle loop; the fake now models a real child whose
/__bili/healthnames its own pid.Branch note
Head builds on
ff3564d4b(sentinel help-merge bringing ci-fixes into this branch per the #4599 inherited-red policy); facets 1–3 were rebased onto it cleanly.Behavior change disclosure (all facets)
/__bili/healthresponse at the child's claimed origin (branches 1–2). New: a response that positively reports a different pid is rejected (loop continues, once-diagnostic logged); absent-pid responses behave exactly as before.(at spawn: …)); empty-log wording changed from0 bytes — EMPTY, the child produced no output of its ownto0 bytes since this spawn — EMPTY …; per-spawn header lines appended to the shared port log.Tests
tests/issue4125-settle-identity.test.ts(6): own-pid accepted / foreign-pid rejected (+ diagnostic fired exactly once) / absent-pid fail-open / legacy boolean-probe fallback — per branch, both gate directions (Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617 discipline).tests/issue4125-watchdog-heartbeat-veto.test.ts(5): veto across consecutive failures, grace boundary (<=), reset/resume semantics, legacy no-beat pin, alive-branch pins.tests/issue4125-spawn-log-segment.test.ts(4): stale content never quoted again, zero-output wording, early-writer quoting, at-spawn port-state buckets.tests/issue3116-spawn-failure-diagnostics.test.ts: wording pins updated.tests/issue3544-stale-proxy-rotation.test.ts: fake gap fixed (restores 7 tests that would have been red under facet 1).tests/launcher.test.ts343 pass / 1 pre-existing skip / 0 fail + watchdog/watcher/dsh/native-intercept sets 139 pass; typecheck clean. Full-suite verdict = CI on this head.