Repository navigation
fix(launcher): attach to late-publishing instance after fast child death (#1903) - #1907
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1901-pr.1907.67c7809This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1907.tgz
npm install -g packageInstall instructions are refreshed on each push. |
511ec36 to
1d5afcf
Compare
1d5afcf to
9a0f360
Compare
[bot] 🏷 PR #1907 review 结论:可合并(请人工 merge) 已按 review 规范完整过审(方向关 → 回归清点 → 代码 → 测试有效性 → diff 整洁度),并把分支 rebase 到最新 master( 结构化七问:
测试有效性:有牙。 diff 整洁度:纯新增 150 行 / 0 删除,三个文件每行都与修复目的相关,干净。 本地验证(rebased head
判定:方向正确、修法打在根因、无回归、测试有牙、diff 干净——建议合并(merge 操作按规范由人工执行:https://github.com/ranxianglei/billion-context/pull/1907)。 |
[bot] 🏷 CI 跟进确认:rebase 后的新 head 结论不变:可合并,merge 按规范由人工执行:#1907 |
What & why
CI flake (#1903, found while analyzing PR #1896):
hook e2e: manual bili start on the pinned port is attached, not refusedfailed once on an unrelated PR head (run 36973824451 / job 110733254556), then went green on the identical head with zero code change.Mechanism, confirmed from the failing job log: the squatter daemon's TCP socket was accepting (the harness's TCP-only
waitForPortgate passed) but its identity record — proxy-origin file + registry marker, written inside the server'slisteningcallback — had not been published yet when the hook ran its one-shot discovery. Zero candidates → spawn path → strict-port child dies on EADDRINUSE → exit 1 → misleading "bring-up failed / NOT served by a session-managed proxy". The hook stderr in the failing run contains ONLY that bring-up line — nonative-attach: drop/skipdiagnostics — proving the discovery snapshot was empty (identity-publication lag), not a health-probe timeout.Two sides contributed; this PR fixes both:
1. Launcher — mechanism owner (
src/launcher.ts). Production analogue: a user starts a manual daemon and opens claude within milliseconds of boot. Previously a spawned child dying before becoming healthy threw immediately. Now: that fast death proves port occupancy, soensureProxyRunningre-runs the SAME discovery+attach pipeline (probeLiveInstances+pickAttachable— all existing compatibility / code-fingerprint / #1335 / #1660 gates apply unchanged) on a bounded budget ofPOST_EXIT_REDISCOVERY_MS = 3000msat the existing 200ms health-poll cadence. If a compatible instance publishes during the window, bring-up succeeds by attaching; otherwise the original error is thrown byte-identical.2. Test harness (
tests/claude-native.test.ts). The squatter gate was TCP-connect-only — strictly weaker than what the hook's discovery consumes. AddedwaitForProxyVisible(): the squatter must answer/__bili/healthwithok:trueAND have a parseable proxy-origin record before the hook runs. All pre-existing assertions untouched.3. Deterministic regression tests (
tests/launcher.test.ts). Two deps-injected cases under an injected clock: (a) child exits code 1 before healthy, instance appears on the first retry tick → resolves attached (with the #1322refusedWatcherflag carried through); (b) nothing republishes within the budget → originalexited before becoming healthy (code 1)error, exactly 1 initial + 15 budget probes.Behavior change (disclosure)
Config surface
Not applicable — no new/renamed/re-semantics config fields, env vars, or CLI flags.
POST_EXIT_REDISCOVERY_MSis a private module constant (no env knob; the window is bounded by design and 3s covers the publication lag with wide margin).Pre-flight
npm run typecheckclean (src); full-project tsc diff vs master: zero new errors (991 pre-existing test-file errors identical before/after, verified via stash)node --import tsx --test tests/launcher.test.ts: 255 pass, 1 skip, 1 pre-existing env-dependent dsh failure (runLaunch dsh: non-loopback upstreams ride proxy envs… #535 phase 4) — fails identically on clean master, unrelated to this diffnode --import tsx --test tests/claude-native.test.ts: 42 pass, 8 skipped (live-gated), 0 failnpm run buildcleanACP_TEST_CLAUDE_NATIVE=1 … --test-name-pattern "pinned port is attached"): PASS, 15.8sFixes #1903