Skip to content

fix(#2082): dsh 插件工具消失 — 注册卡死自愈 + 桌面副本 boot smoke 门 - #2091

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-04_dsh-desktop-update-recovery
Oct 4, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-04_dsh-desktop-update-recovery

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

修复 #2082(dsh 中工具会突然消失,0.179→最新回归,桌面版)。

机制(承接 issue 两份排查/复现评论)

复现证实换代边界(#1575 原地替换)只造成一次性 404,下一回合模型请求 re-bind 自愈;要变成用户那种持续消失,必须叠加注册侧卡死 = B×A 交集。本 PR 两端都堵:

A. 注册生命周期自愈(src/agent/dsh-native.ts)

三个卡死缺口,全部修复:

  1. register.dead 永久毒化:teardown 期间一次 "inactive context" 拒绝把 dead 置 true,此后没有任何复位点——cordis 停用/重激活(桌面文件变更可触发)后工具永不恢复。→ apply() 每次激活先 register.dead = false。
  2. respawn 未武装时裸 return:maybeRetry 的 base-less 分支在 state.respawn === undefined 时直接返回,之后没有任何驱动。→ 自行武装 fallback(singleFlight(_spawnForTest ?? bootstrap))。
  3. 恢复纯事件驱动:没有模型流量(用户已被错误劝退、停止调用)就没有 maybeRetry 调用点。→ 自清恢复定时器:每 tick 检查 dead/toolsReady,就绪即 clearInterval,unref() 不阻退出。旋钮:BILI_DSH_RECOVERY_INTERVAL_MS(默认沿用 RETRY_INTERVAL_MS=10s)、BILI_DSH_RETRY_INTERVAL_MS(测试可缩,生产语义不变)。

B. 桌面副本 boot smoke 门(src/update.ts)

verifyEntries 只证明入口可解析,不证明可启动——top-level throw 语法合法能穿过。桌面副本是运行中 dsh 在 proxy 死后 respawn 的目标,提交不可启动的副本 = respawn 无限失败。→ installViaTarball 新尾参 opts.bootSmoke:post 验证通过后、成功清理(删备份)前,spawn node <installDir>/<main> --version(env 剔除 BILI_/BILLION_CONTEXT_/ACP_*/NODE_OPTIONS/NODE_TEST_CONTEXT/NODE_ENV,超时 20s);非零退出/超时/spawn 失败 → restoreFromBackup() 回滚到旧版本 + 响亮失败。refreshDshDesktopCopy 启用该门,成功日志同时讲清换代边界("restart dsh to load it … across the handoff bili tools may fail once until dsh restarts, #2082")。

七问速答

  1. 断言行为的测试:tests/issue2082-dsh-recovery.test.ts(dead 复位恢复 / respawn fallback + timer 零流量自愈)+ tests/issue2082-desktop-boot-smoke.test.ts(坏入口→ok:false+回滚;好入口→落地;refreshDshDesktopCopy 坏 tarball→磁盘保留旧版+warn)。
  2. mock 边界:manifest 走本地 http mock;boot smoke 是真 node 子进程(fixture throw vs export)。
  3. 竞态面:timer 自清 + unref;_resetRegisterForTest 清 timer 防跨测试泄漏;NODE_TEST_CONTEXT 下未设旋钮不 arm(防测试噪声)。
  4. 回滚面:bootSmoke 失败路径 = 既有 restoreFromBackup(backupDir/pnpmOldLink),顺序在删备份之前。
  5. 性能:无流量时每 10s 一次轻量重试;就绪后零开销;boot smoke 仅在桌面更新路径 +20s 上限一次。
  6. 日志:成功行扩为含 handoff 提示;失败行含 stderr 过滤尾行(去 at 帧)。
  7. 文档:无需——内部恢复行为,旋钮列入代码注释。

兼容性

发布说明

touch src/update.ts(load-bearing)+ src/agent/dsh-native.ts(dsh lane)→ §5:先合本 PR 再发版;合后建议 dispatch ci-release-canary(ref=master)走一遍自更新链路。

按 §7.4 由人工合并(改 wire 行为相关的 load-bearing 文件)。

…p copy

Two compounding mechanisms kept bili tools from coming back on desktop:

A. dsh register lifecycle could wedge permanently:
   - one "inactive context" rejection during teardown poisoned
     register.dead forever (a later re-activation never re-registered);
   - with register.base unset (proxy died before first bind) and
     state.respawn not armed, maybeRetry returned early on every call —
     with no model traffic there was no other driver, so the plugin
     never recovered.

   apply() now clears register.dead on every activation, maybeRetry arms
   the spawn fallback itself, and a self-clearing recovery timer (env
   knob BILI_DSH_RECOVERY_INTERVAL_MS) keeps retrying while the register
   is neither dead nor ready. RETRY_INTERVAL_MS is also overridable via
   BILI_DSH_RETRY_INTERVAL_MS so tests do not need to wait 10s.

B. refreshDshDesktopCopy (#1575) replaced the desktop profile copy in
   place with zero coordination: verifyEntries proves entries parse but
   not that the package boots, so a top-level throw could commit an
   unbootable copy — the running app then respawns from it forever and
   the tools vanish until dsh restarts.

   installViaTarball gains opts.bootSmoke: after post-install
   verification (and before dropping the backup) it spawns
   node <installDir>/<main> --version with a scrubbed env; any nonzero
   exit, timeout, or spawn error rolls the copy back to the previous
   version and fails the update loudly. refreshDshDesktopCopy enables
   it and its success log now explains the handoff boundary.
@ranxianglei

Copy link
Copy Markdown
Owner Author

补充:与 #1632(install-dir-resolution)无冲突面——其 findInstallDir/describeInstallLocation 不触 installViaTarball 失败分支语义;若后合并者是我方可 trivial rebase。

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-04_dsh-desktop-update-recovery (ad82c9c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2130-pr.2091.c6caae1

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2091.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

已核实,且比「无冲突面」更强一步:#1632 已经合进 master(merge commit 61670eb6,今天 14:58 +08),而本 PR 分支的 base 就是当前 master tip(3c84d74e,与 origin/master rev-list --left-right --count = 0/0)——即本分支已包含 #1632,连 trivial rebase 都不需要,分支从切出起就是在 #1632 之上构建并跑过回归的(update-tarball / update-desktop-inplace / dsh-native 等 65 项回归均在此 base 上)。

代码层面复核了你的判断:

CI 现状(head d9fca570):真实客户端各 lane(codex / opencode-v2 websocket / dsh headless / pi)、hermetic registry e2e(ubuntu+windows)、version-guard、build-artifact、e2e 全绿;剩 4 个 test 矩阵任务(ubuntu/windows × node 22/24)还在跑。mergeStateStatus: blocked 仅因这 4 个任务未完成,非冲突。

无其他待办:按 §7.4 等人工合并(touched src/update.ts load-bearing);合后按发布说明建议 dispatch ci-release-canary(ref=master)走一遍自更新链路。

@ranxianglei
ranxianglei merged commit d8d1f8a into master Oct 4, 2026
15 checks passed
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.5-master.d8d1f8a (rolling master tag).

npm install -g billion-context@0.0.5-master.d8d1f8a  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Oct 4, 2026
…INTERVAL_MS in CONFIGURATION.md en+zh

The #2091 recovery knobs shipped without CONFIGURATION.md entries while every sibling dsh-plugin knob (incl. the adjacent BILI_MODEL_INFO_RETRY_MS) is documented — 'document or don't ship' (env-var discipline #2030, hard rule 4). Both are test/ops hooks with unchanged defaults; production behavior is untouched.
@ranxianglei
ranxianglei deleted the 2026-10-04_dsh-desktop-update-recovery branch October 15, 2026 05:32
Louie0806 pushed a commit to Louie0806/billion-context that referenced this pull request Nov 12, 2026
…elf in place (ranxianglei#2082)

The ranxianglei#2082 boot smoke (PR ranxianglei#2091) was wired into refreshDshDesktopCopy only,
the lane where another bili process refreshes the dsh desktop profile copy.
When the running proxy IS that copy, hostManagedInstall exempts the layout
(ranxianglei#1575) and the copy updates itself through the plain self-update lanes:
checkForUpdate (periodic check, `bili update`) and forceInstallVersion
(advisory force-install, web-panel install). Both called installViaTarball
without bootSmoke, so a tarball whose entry parses but throws at load was
swapped into the copy dsh respawns its plugin from.

Arm the smoke on both lanes when the install dir is the dsh desktop copy.
Other install layouts keep their current behaviour.

(cherry picked from commit 4e7ac09)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant