Repository navigation
fix: close dead-port race in zcode-native + upstream-alerts tests (#2548) - #2551
Conversation
) zcode-native's deadOrigin() released its listen(0)+close port and assumed it stayed dead; under parallel 'npm test' another process could rebind it inside the 300ms health window, so probeProxyHealth saw a live answer and the expected refusal flipped to an active attach (the #2547 CI flake). Replace it with a live server bound for the whole test that answers 500 - probeProxyHealth judges a 500 answer unhealthy - so the unhealthy expectation is constructed, not assumed: the race is closed rather than narrowed. upstream-alerts' freePort() feeds a connect-refused assertion, which cannot be constructed with a live server (hang = connect-timeout, 500 = a real response); guard its real consumer with assertPortDead right before the first dial, matching log-mask (#1689). The banner site never dials the port (/__bili/overview reads fs/in-memory state only), so it is left unchanged - adding a guard there would introduce a new flake. Closes #2548
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2731-pr.2551.11eabf2This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2551.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 已审 PR #2551(分支 查重:按机制关键词(released-port race / deadOrigin / freePort / #1689 follow-up)检索 open+closed issue——无重复项;#2548 是该机制家族(#1689 后续)的唯一定向 issue,单 issue → 单 PR,loop guard 合规。 ① 原 issue 方向关:#2548 的诊断成立。因果链从代码复核过: 结构化八问:
验证证据(均在 rebase 后的 head 上本地执行):
diff 整洁度:2 文件 +37/-14,每行都服务于本 issue,注释均引 #2548/#1689 且与代码事实相符;无无关改动、无空行/重排噪音。 判定:可合并——纯测试确定性修复,零生产行为变更,issue 两层计划完整落地,唯一偏离有代码证据支撑,本地定向验证(含抢占压测)全部通过。等人工合并:#2551 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.195-master.47dd1b1 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2548
What
The CI flake from #2547's run —
bootstrapZcodeNative fails closed on an unhealthy attach target— is a released-port race, not a product bug. Two test helpers hand out alisten(0)+closeport and assume it stays dead; under parallelnpm testanother process can rebind it before the consumer acts.Fix (per the issue's two-layer plan)
zcode-native (
deadOrigin()→withUnhealthyOrigin(), 3 sites) — deterministic. The helper no longer releases the port; it keeps a live server bound for the whole test that answers 500.probeProxyHealthjudges a 500 answer unhealthy (it returnstrueonly for a2xx/404JSON body whose text starts with{and contains"ok"), so the "unhealthy" expectation is constructed, not assumed. The race is closed rather than narrowed — a lateassertPortDeadstill has the residual window its own header comment admits ("a squatter can still land in the final gap"). Mirrors the existingwithHealthServeridiom in the same file.upstream-alerts (
freePort(), 1 of 2 sites) — transitional guard. Its consumer assertskind === "connect-refused", which cannot be constructed with a live server (a hung socket isconnect-timeout; a 500 is a real HTTP response). So this site usesassertPortDead(port, { label })immediately before the first dial, matchinglog-mask.test.ts(#1689).Deliberate deviation from the issue checklist
The issue lists 5 unguarded sites (deadOrigin ×3, freePort ×2). This PR guards 4 and leaves
tests/upstream-alerts.test.ts:399unchanged, because verification shows that site is not actually vulnerable:recordUpstreamAlert(...)and only polls/__bili/overview.sendOverview(src/server/admin.ts) reads fs/in-memory state only (sessions, alert table, advisory, in-flight, blind-tunnel stats) — it never connects to the configured upstream. The VM harness never clicks the upstream-test button either.assertPortDeadwould introduce a new flake: if a squatter takes the port, the guard throws even though the test does not care whether the port is dead.Guarding a port the test never consumes would create the very flake class this PR removes.
Behavior change / config surface / cache
src/,kernel/, wire protocol, config schema, or persistence touched.Verification
Rebased onto current master (
4b5666406). On the rebased head:npm run typecheckclean (rebuildskernel/+pi-subagents/).node --import tsx --test tests/zcode-native.test.ts tests/upstream-alerts.test.ts: 42 pass / 0 fail. These two files are the only ones changed; the full suite is left to CI.