Repository navigation
fix(#1753): verify responder identity in spawn-wait pre-handshake fallback - #1758
ranxianglei wants to merge 1 commit into
Conversation
…lback The fallback trusted any healthy response on the preferred port once the instance record went stale, exporting clients to a foreign squatter instance (e.g. an older build holding the lane zone) while our own child laddered off to another port and was orphaned — bypassing the #1225 fingerprint gate that had just refused the same instance on the attach path. The fallback now only accepts a /__bili/health response whose pid equals child.pid; anything else keeps waiting for the launch-token handshake record and announces the foreign occupant once via attachDiag. - HealthInfo gains pid, parsed from /__bili/health (server already returns it) - success-path tests updated mechanically to inject fetchHealthInfo with the fake proxy child's pid; no assertions changed - new regression suite tests/fix-1753-spawn-fallback-squatter.test.ts pins squatter rejection, no-pid rejection, and the fast path
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1710-pr.1758.9eb86d3This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1758.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR review — fix(#1753): verify responder identity in spawn-wait pre-handshake fallback Reviewed head ① Issue direction — correct#1753 names the right root cause: the spawn-wait pre-handshake fallback had its OWN trust channel ( Verified the load-bearing premise: ② Regression audit — existing behaviors touched by the diff
One edge I checked beyond the PR's list: the old fallback comment covered "an old pre-handshake binary". Under the new code such a child (health without a usable pid) times out instead of being accepted. That's safe: the wrapper spawns the same script build it runs ( Behavior changes match the disclosure table in the PR body (foreign squatter → wait ≤20s + export child's real laddered origin + one-time diag naming the squatter pid; non-bili listener → rejected; our-child fast path → unchanged immediate settle; handshake record → still first priority). Old→new stated with rationale; no silent drift. ③ Code — cleanMinimal, follows the file's existing injection pattern ( ④ Test effectiveness — real teeth, verified by bite-check
⑤ Diff cleanliness — good5 files, every line related to the fix; no whitespace churn, no generated/lock-file churn, no unrelated files. Pre-flight & CILocal (on PR head): 中文摘要:修复了 spawn-wait 预握手回退把首选端口上任意健康响应都当成自己子进程、导致客户端被静默导出到占用端口的陌生实例(#1753)的问题——现在用 |
|
Closing as superseded: merged PR #1756 landed the same root-cause fix for #1753's defect 1 ( |
Closes #1753
What changed
ensureProxyRunning's spawn-wait pre-handshake fallback (src/launcher.ts) trusted any healthy HTTP response on the preferred port once the instance record went stale (stale && probeHealth(preferred)— a bare{ok}probe). When a foreign healthy instance squatted on the preferred port — exactly why our child laddered off it — the wrapper exported the client to the squatter's origin within ~200ms and orphaned our own child on its laddered port. This bypassed the #1225 code-fingerprint gate, which had just refused the same instance on the attach path.The fallback now verifies responder identity:
/__bili/healthalready returns the responder'spid, and the wrapper holdschild.pid. The fallback only accepts the preferred origin whenhealth.pid === child.pid. Anything else (foreign squatter, non-bili listener with no pid) keeps waiting for the child's launch-token handshake record (its real origin/port), and announces the foreign occupant once viaattachDiag:Changes:
HealthInfogainspid?: number;fetchHealthInfoDefaultparses it (the server already returnspid: process.pid— no server change)stale && typeof child.pid === "number"→fetchHealthInfo(preferred)→ accept only ifinfo.pid === child.pid(thensettleZonePortas before); otherwise one-time announce + keep waitingtests/fix-1753-spawn-fallback-squatter.test.ts(3 tests: squatter rejected + announced, no-pid responder rejected, our-child fast path settles immediately)fetchHealthInfowith the fake proxy child's pid. No assertions changed or weakened; rejection tests untouched.Behavior changes (intended)
Degenerate-case trade-off: broken state dir + laddered child now fails loudly at the 20s deadline instead of being silently misdirected — the old "success" there was never a success (client pointed at a process we did not spawn).
Regression audit (existing behaviors touched by the diff)
probeLiveInstances/pickAttachable, Launcher proxy reuse (ensureProxyRunning) breaks per-run isolation: shared-fate lifecycle + no code/client identity in compatibility check #1225 fingerprint gate, fix: surface claude-native attach-to-daemon watcher refusal (#1322) #1330/claude-native hooks must not attach to a lifecycle-less proxy — attach gate + self-managed fallback #1335 watchdog gate): untouched.settleZonePortsemantics: unchanged; now only reachable for verified-own origins.Pre-flight
npm run typecheck: cleannpm test: 3361 tests, 3342 pass, 0 fail, 19 skippednpm run build: success