Repository navigation
fix: wait out a same-lane upgrade predecessor before laddering zone ports (#1723) - #1726
Conversation
…orts (#1723) An upgrade-restart overlap (the new build's child binding while the OLD build's instance of the same lane is still draining) made the EADDRINUSE handler ladder +1 without identifying the holder, and settleZonePort wrote the drifted port back sticky — a monotonic ratchet burning one port per auto-update. - instance.ts: findSameLanePredecessor() identifies the EADDRINUSE holder from the registry markers (lane + codeFingerprint + pid): a live same-lane instance running DIFFERENT code is a being-replaced predecessor (missing fingerprint = pre-#1232 = different build); a same-code peer or a foreign/undeclared-lane holder never is. - server.ts: on EADDRINUSE at the lane's port, wait for the predecessor to release (500ms ticks, 5s total budget) and rebind the SAME port; budget exhaustion falls through to the existing +1 ladder, so worst case equals today's behavior plus a bounded delay. A lane'd launch settling ABOVE its preferred port now logs a drift warning instead of drifting silently. - Tests: unit decision-table for the predicate + live e2e against real dual processes with a byte-different build copy (takeover rebinds the same port, sticky stays put; a holder that never leaves still ladders +1 as before). - Docs: README/CONFIGURATION/TECHNICAL-NOTES, en+zh.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1678-pr.1726.a22fad3This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1726.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR Review #1726 — 可合并 ✅ 一句话中文摘要:修复了升级重启竞态导致的 sticky 端口单调棘轮(EADDRINUSE 时凭 lane+codeFingerprint 识别同 lane 旧 build,限时 5s 等其释放后重绑原端口,超时落回原阶梯),已按五关审完、在当前 master 上独立复验全绿,可以合并。 ① 原 issue(方向关)— 通过#1723 的机制分析准确:棘轮由两个生产者构成——(a) EADDRINUSE 决策点不识别持有者,把「正在退场的同 lane 前代」当外部占用者阶梯 +1;(b) ② 回归审查(既有行为清点)Diff 触碰路径的既有行为逐项判定:
唯一新增输出:一行 drift warn(lane'd launch 落在 preferred 之上时)——纯日志增量,每进程至多一次(单次成功 bind 触发一次 ③ 代码审查(主关)
④ 测试有效性
⑤ diff 整洁度单 commit,10 文件 +238/-11,每一行都与本 PR 目的相关(谓词 + 接入 + 测试 + en/zh 文档镜像);无空白噪音、无 lockfile/生成物连带、无 version 触碰。干净。 合并前验证(我在当前 master 上独立复跑)
未发现需要补修的问题,无需追加 issue。建议合并。 |
Fixes #1723
Problem
An upgrade-restart overlap (the new build's child binding while the OLD build's instance of the same lane is still draining) made the EADDRINUSE handler ladder +1 without identifying the holder, and
settleZonePortwrote the drifted port back sticky. Result: a monotonic ratchet burning one port per auto-update — the sticky guarantee failing systematically exactly at the version boundary, where it matters most.Approach
Issue directions 1 + 3 adopted (identify-before-ladder, bounded wait); direction 2 (launcher drain barrier) rejected — the launcher cannot know when the old build finished flushing, and the bounded wait already degrades gracefully; direction 4 (version epoch) deferred — the fingerprint identity check covers the real case without a new sticky schema.
src/instance.ts:findSameLanePredecessor(entries, port, lane, ownFingerprint)— identifies the EADDRINUSE holder from registry markers: a LIVE same-lane instance running DIFFERENT code (codeFingerprint, lane-aware instance discovery — single proxy-origin file breaks same-client reattach under concurrent multi-client use #1232) is a being-replaced predecessor; a missing fingerprint (pre-lane-aware instance discovery — single proxy-origin file breaks same-client reattach under concurrent multi-client use #1232 marker) counts as a different build; a same-code peer or a foreign/undeclared-lane holder is never a wait target.src/server.ts: on EADDRINUSE at the lane's port, when the holder is such a predecessor, wait for it to release (500ms ticks, 5s total budget) and rebind the SAME port. Budget exhaustion falls through to the existing +1 ladder, so worst case equals today's behavior plus a bounded delay. A lane'd launch settling ABOVE its preferred port now logs a drift warning instead of drifting silently.tests/port-zone.test.ts, 7 cases) + live e2e against real dual processes with a byte-different build copy (tests/port-zone-live.test.ts): takeover rebinds the same port and sticky stays put; a holder that never leaves still ladders +1 as before.Behavior change (old -> new)
~/.config/billion-context/config.json, noBILI_*env var, no CLI flag).Pre-flight (rebased head: master d27dc34 + this commit 33d0acb)
npm run typecheck— cleannpm test— 3290 pass / 0 fail / 19 skippednpm run build— OKACP_TEST_CLAUDE_NATIVE=1 node --import tsx --test tests/port-zone-live.test.ts— 7/7 pass (incl. both new port-zone 重启竞态:sticky 端口单调漂移,升级依附与无界自增互相矛盾(#1660 后续) #1723 cases and the unchanged squatter-ladder case)E2E_UPSTREAM_URLrefused connections mid-run (ECONNREFUSED; the proxy under test booted fine and correctly surfaced the upstream failure in its 502 detail). This PR touchessrc/server.ts, soci-e2e.ymlauto-runs on the PR and is the authoritative e2e signal here.