Repository navigation
[PR] Two installations differing by one version no longer deadlock on the same port; traffic is no longer sent in the clear ( | 两份安装差一个版本不再死锁在同一端口上,流量不再裸奔(#4125) - #5303
Conversation
…cked around (#4125) Two installs (global tree vs host-managed copy) drift apart by exactly one auto-update: attach rejects the holder's foreign bytes (#1225), rotation only reaches strictly OLDER residents (#3544), and every fresh spawn loses the bind race to the one holder nobody may adopt — model traffic goes direct, uncompressed, until a manual full restart. All three facets land together: - P1: the spawn boundary now carries the spawner's own code digest (BILI_SPAWN_FINGERPRINT; the child trusts it only if it is a well-formed hex64, else re-hashes locally — #1225's "never trust a stranger's claimed identity"; stripped from inherited env with every other launcher channel, #2195). "Same build" compares bytes, not names. - P2-parent: before rejecting a fingerprint-drifted candidate, ask the LIVE holder once for its build version (health response, not stale registry files). Strictly newer + same lane + same shape + proven alive => adopt and ride instead of reject. Cross-lane and user-zone holders stay rejected even when newer — they have no bili fallback behind them. - P2-child: on EADDRINUSE against a PROVEN strictly-newer same-lane same-shape holder, the child stops laddering ports (which forks a shadow instance nobody routes to) and exits with the existing #3654 adoption signal so the spawner rides the newer build. Probes cached per port; manual starts (no launch token) and upgrade-replacement keep their legacy semantics untouched. Tests: new tests/issue4125-two-install-deadlock.test.ts (9 cases) plus extended listen-policy / issue3654 decision tables.
…tly newer holder (#4125) Upward adoption in pickAttachable cleared the fingerprint veto without a shape re-check: instanceCompatible reports the fp reason first, so a config-shape drift on a foreign-bytes holder was masked and the launch would ride a daemon whose model windows/max outputs differ from what this launch requested — contradicting the stated invariant (and the explicit re-check the adoptServingTwin path already performs). pickAttachable now mirrors that re-check: adoption proceeds only when instanceShapeMismatch stays clean, otherwise the candidate is skipped with the real shape reason. Pinned by a new findLiveAttachableInstance case (newer + same-lane + drifted model window must stay rejected).
ranxianglei
left a comment
There was a problem hiding this comment.
评审结论:可合并(一个洞已在 a06dad81 直接修掉并钉测试,等新 head CI 绿即可)
核验(本地独立跑过,不依赖 CI 与自述)
| 项 | 结果 |
|---|---|
| 分支状态 | ✅ 干净 rebase 在 master tip(e193861);真实增量 9 文件 +506/−14,与描述一致(无 #5163 那类 diff 失真) |
tsc --noEmit |
✅ exit 0 |
新套件 tests/issue4125-two-install-deadlock.test.ts |
✅ 9/9(修复后 10/10) |
| listen-policy / issue3654 / port-owner / giveup-reason | ✅ 7+24+27+5 全绿 |
回归大户 tests/launcher.test.ts |
✅ 344 例 0 fail |
机制面认可点:P1 spawn 指纹对齐的动机成立(自动更新若在 spawner 哈希与子进程自重算之间换掉 dist,同一 bring-up 会分裂成两个身份;env 已进继承清理名单,#2195);子进程侧判定四重闸门(launchToken+非升级替换+注册表 pid 与活监听应答一致+严格更新)是正证明不是口号,isVersionNewer 对不可解析版本号保守判 false;newerHolderHolds 缺省 false,决策表旧行逐位不变,手动启动与升级替换语义未动;exit-3 复用既定采纳信号(#3654/#4341),探测按端口缓存且进程决策后即退,无状态残留。信任面记录在案:向上采纳采信健康端点自报版本,但需注册表 pid 一致性+同车道+同形状+存活,与既有端口归属纪律(#4982)同级,未扩面。
⚠️ 发现并已修:pickAttachable 向上采纳漏了配置形状守卫(a06dad81)
adoptServingTwin 采纳前显式补查了 instanceShapeMismatch,但 pickAttachable 只清指纹否决——而 instanceCompatible 里指纹检查排在形状检查前面,字节不同的候选其形状漂移被完全掩盖。后果:一个配置形状不同(如 model windows/max outputs 差异,双安装配置漂移时很现实)的更新版持有者会被骑上,流量走一个用别家配置起的守护进程——恰好违背本 PR 注释里「config shape still has to match」的声明。原测试矩阵没有「更新+形状不符」组合,所以没被钉住。
修复:照抄 adoptServingTwin 的补查——形状不符时跳过并给出真实原因(不再是含糊的 code-fingerprint-mismatch);新用例「newer + same-lane + drifted model window 必须拒」验证为修复前红、修复后绿。提交:a06dad81(launcher.test.ts 344 + listen-policy 7 复跑全绿,typecheck 0)。
非阻塞备注
- 若用户 shell 恰好导出过
BILI_SPAWN_FINGERPRINT,手动启动会登记别人的摘要→后续 attach 报指纹不符(自愈、可诊断);顶多在变量注释里提醒一句别手动 export。 - CHANGELOG 文案人话到位,无修改意见。
CI
a06dad81 推送后重新触发中;旧 head(14672f8)评审时尚在 queued。触及 attach 门槛语义,按惯例走人工层合并,不 auto-merge。
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7417-pr.5303.9ba8b3eThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5303.tgz
npm install -g packageInstall instructions are refreshed on each push. |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.941-master.fb5b916 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Previous head conflicted (add/add on src/pack-install.ts): this branch pre-dated PR #5331, which added that file to master while the branch carried its own copy. Sandbox cannot clone full objects, so the branch is reconstructed as one clean commit on today's master via the Git data API. Contents unchanged from the reviewed work: workflows - ci-janitor: feed the sweep loop its run list (it was never wired up — zombie cancels were dead code since 10-30); add backlog breaker (starvedQueueLimit warn + starvedQueuedMaxMinutes pruning, push-to-master exempt) - concurrency groups: master-build, release, release-kernel (no-cancel), theorem (skip-lane suffix per house rules) - timeout-minutes on six workflows left on the 6h default (release 90, release-kernel 90, release-bugfix 90, release-manual 90, advisories 30, pages 30, ci-gate-plugins 30) master-reds fixed here so every gate passes - LIFECYCLE.md: register BILI_SPAWN_FINGERPRINT (#5303/#4125) and BILI_SESSION_CONTENT_STORE_PIN (#5292 phase2) - src/codex-models.ts: drop unused `export` on CodexWindowSource (zero named references; tsconfig has no declaration emit) - CONFIGURATION{,.zh-CN}.md: restore promptPack row to generator output ("chat" is host-shipped, not builtin; follow-up for #5320: add chat to website/config-reference/compress.yaml and regenerate) - src/pack-install.ts: PackInstallOptions -> internal (callers pass options structurally) latent test fixes (surfaced once gates went green) - src/launcher.ts: #4125 rewrite dropped the phrase tests/issue5103 asserts verbatim; restored - tests/store.test.ts: move fault injection to the real write point so adopt() runs before the disk sabotage
…whitelist buildRecord persists stats via spread (costUsd rides to disk), but buildSession rebuilt stats from a hand-picked whitelist that dropped costUsd — every cold load (restart, LRU eviction) silently zeroed the historical USD ledger, and the next save wrote that loss into BOTH stores (JSON envelope + index.db stats_json projection). Restore it through a shared validator (billing.validCostUsd, also used by the panel): finite non-negative fields survive, partially-valid blobs zero-fill missing lanes, all-invalid reads as no-ledger. Absent stays absent for pre-billing files.
[PR] fix(#5303): restore the costUsd spend ledger on session reload
… persist field The unpriced-token ledger (#5647 item 3) now persists stats.unpricedTokens for sessions whose model has no resolvable price. The storage-render corpus (tests/golden-storage-drive.ts) is driven with setRegistryForTest({}) - an empty price registry - so every turn in it is unpriced and the new field enters the persisted stats blob. viewStateDigest digests that stats sub-object, so the four committed state digests shift. costUsd already sits in the same digested stats (added in #4899/#5303 with a matching golden regen), so regenerating is the consistent remedy. Regenerated under the script's documented parity pins (BILI_IMAGE_RESCALE=0 / BILI_SNAPSHOT_SHADOW=0 / BILI_MESSAGE_TIMESTAMPS=0); verified green locally under the preload launch (storage-engine-proofs + golden-storage-render + both #5647 suites, 28/28). Priced-traffic behavior stays byte-identical.
这是啥问题?(现象+触发条件)
一台机器上 bili 本来就有两份合法安装:npm 全局树(会自己自动升级)和宿主管理器自带的独立副本(升级节奏各走各的)。当全局树恰好领先一个版本时,整个车道卡死,模型流量全部直连、不压缩,直到有人整机重启。
真实事故(0.1.209 报告,#4125 家族):宿主插件还是 208,全局树已被自动更新推到 209。宿主重启后:
三条路全堵死,没有一条自愈路径,只能人工重启对齐版本。
根本原因(代码级+机制链)
决策表缺了一格:对方是更新的同车道实例。三个环节各自的行为单看都合理,合起来正好互相否决:
src/launcher.tspickAttachable:候选因指纹不一致被跳过——它只信「字节完全相同」;src/launcher.tsrotateStalePredecessor(安装新版本后旧代理永远不换新:detach 代理躲过应用退出,重启只是重新挂上旧进程(「永远更新不了」) #3544):只置换严格更老的 resident(isVersionNewer);src/server.tsEADDRINUSE 处理:撞口子进程要么逐级换端口(造出没人路由到的影子实例),要么向持有者让位退出(exit 3,既定的采纳信号)。而「让位退出」这个信号原本只有同指纹持有者才配收到(#3654/#4341),于是拿着正确信号的子进程死了,正确的接管动作却永远不会发生。
如何解决的(修复思路+关键改动)
三面一起修(缺任何一面都会把问题顶到另一个出口):
是否能合并?(结论+依据)
**可以合并。**依据:
tests/issue4125-two-install-deadlock.test.ts钉住三面:摘要透传与防泄漏、宿主侧向上采纳的正反例(含跨车道/用户区拒绝边界)、子进程 exit-3→宿主接管的完整链路;newerHolderHolds缺省 false,所有旧用例原样通过;手动启动(无 launch token)与 upgrade-replacement 路径行为逐位不变;剩余验证交给 CI。
URL