Repository navigation
fix(zcode): shared-store dead-port repair — exit handoff, watchdog drift fix, attach visibility - #1624
fix(zcode): shared-store dead-port repair — exit handoff, watchdog drift fix, attach visibility#1624ranxianglei wants to merge 1 commit into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1564-pr.1624.b43d60aThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1624.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ift fix, attach visibility (#1623) A zcode native instance that dies leaves the shared provider store pointing at its dead port (last-writer-wins rewrite, no handoff); fresh readers then route into ECONNREFUSED until the next bootstrap happens to rewrite it. - mcp-entry: SIGTERM/SIGINT/beforeExit handoff under the config lock — re-point the store at a live compatible instance, or revert to direct - watchdog: every tick also repairs a dead store pointer left by ANY instance (covers hard kills whose JS handlers never run) - launcher: reason-coded diagnostics for every attach drop/skip/refusal (previously silent); findLiveAttachableInstance probe-only export; fix boolean-coercion bug in the squatter check - mcp-entry logs now tee into the shared bili.log (zcode drops stderr) - docs: lifecycle section updated in CLIENTS.md / CLIENTS.zh-CN.md incl. the client-cache boundary (repairs help fresh reads only) Behavior change: store semantics move from 'last writer wins (incl. dead)' to 'last LIVE writer wins; dead pointers auto-repair within ~90s'.
44a21e3 to
007ead4
Compare
[bot] 🏷 Review complete — mergeable (human merge; not auto-merge eligible per §7.4: shared multi-client ① Direction (vs #1623) — correct, root-cause level, not symptom masking. All four verified layers of #1623 get a fix at the right decision point: death-without-handoff → exit handoff under lock; watchdog-only-watches-self → per-tick drift repair (covers hard kill); silent attach rejections → reason-coded diagnostics; client baseURL cache → documented boundary + structural workaround (pinned ② Regression inventory — existing behaviors on every touched path:
Declared behavior changes all match what the code actually does (verified each against the diff): ≤5 s exit delay on SIGTERM/SIGINT (hard-bounded — ③ Code — clean throughout. Type-safe, proper test seams ( Known boundary (not a defect): in attach mode with ④ Tests — the 13 claimed are all there and real: 9 in tests/zcode-native.test.ts (detect round-trip through actual files; all six drift outcomes incl. byte-equality assertions proving the no-op branches truly don't touch the store; all three handoff outcomes), 4 in tests/launcher.test.ts (probe-only contract pinned via a spawn-flag trap; three reason-code diagnostics). Assertions have teeth — exact outcome enums, store-content checks ( ⑤ Diff cleanliness — 8 files, single commit, every line on-purpose, no lockfile/whitespace churn. One cosmetic nit I'm leaving alone: a continuation line in CLIENTS.md gained one space of indent (2→3, zero rendering impact). Gates: full local gate green on rebased head 中文摘要:修复了 zcode 共享 provider store 在实例死亡后残留死端口导致 ECONNREFUSED 的问题(退出交接 + 看门狗漂移修复 + attach 拒绝可见性),方向正确、四处落点均针对根因、回归清点无意外行为漂移,已在 PR 分支上 rebase 到最新 master 并全量验证通过,可以合并。 |
Fixes #1623
问题
zcode 原生模式下共享 provider store 与代理实例生命周期脱钩:每个实例自举都无条件改写 store(last-writer-wins,attach/spawn 皆然),而实例死亡时没有任何交接——MCP 子进程无退出 handler,
unrouteZcode只在失败路径调用。结果:实例死后 store 残留死端口,之后所有新读取者(新会话/新查询)路由进 ECONNREFUSED;叠加 ZCode 客户端按会话缓存 baseURL,在途会话重试也打不到新端口。两次独立复现(issue 主链 + floor 1 补充证据)。改动(单一根因,四处落点)
src/zcode/mcp-entry.ts):MCP 子进程安装 SIGTERM/SIGINT/beforeExit handler,退出前在配置锁下检查共享 store——仍指向自己则优先改写到存活兼容实例(复用probeLiveInstances+pickAttachable判定),否则移除受管改写回退直连。5 s 超时兜底,绝不阻塞退出。src/zcode/native.tsrepairSharedStoreDrift+ mcp-entry 看门狗):每 tick(30 s)额外检查 store——指向「非自己且已死」的端口时接管修复(自己存活→改到自己;否则找存活替代;都没有→回退直连)。覆盖硬杀场景(Windows TerminateProcess 跳过 JS handler,交接跑不成)。只在 store 指向死端口时动手,绝不从存活实例抢路由(双活写者不抖动;锁内串行,收敛到任一活端口)。src/launcher.ts):probeLiveInstances/pickAttachable 的所有静默拒绝分支(pid 死亡/健康探测失败/instanceId 不符/code-fingerprint/lane/host-or-passthrough/mitm-domains/model-windows/model-max-outputs 不匹配/port mismatch/gate 拒绝)现在带 reason code 写入 bili.log;新增导出findLiveAttachableInstance(只探测、不 spawn、不注册 watcher)供 zcode 侧复用同一套判定。顺带修了 squatter 检查的 boolean coercion bug(instanceCompatible(...) === undefined)。src/zcode/mcp-entry.ts):mcp-entry 事件从裸 stderr 改为经configureLogger(defaultLogFile())tee 进共享 bili.log(stderr 同时保留),时间戳可与其他实例对齐——zcode 不捕获该子进程 stderr,裸 stderr 等于黑洞。CLIENTS.md/CLIENTS.zh-CN.md):生命周期一节补交接/漂移修复语义与客户端缓存边界(ZCode 按会话缓存 baseURL,修复只对之后的新读取生效);推荐把BILLION_CONTEXT_PROXY钉到常驻代理做结构性规避。行为变更声明(old → new)
[bili-zcode] ...→ 带时间戳、tee 进共享 bili.log。单行文本不变,多了时间戳前缀。src/update.ts、版本字段、acp-kernel pin。验证
detectCurrentZcodeOrigin往返;漂移修复六分支(unmanaged/self/foreign-live/repointed-self/repointed-replacement/reverted-direct);退出交接三分支(not-ours/handed-off/reverted-direct);findLiveAttachableInstance只探测不 spawn + 三类 reason code 诊断(owner process gone / code-fingerprint-mismatch / refusing to attach)。server.ts/src/loop/adapters/stream/persist);CI e2e hot-file 列表不含launcher.ts/src/zcode,如需 e2e-codex 请手动 dispatch。已知边界(不在本 PR)