Skip to content

fix(#1803): converge stale dsh profile copies from the periodic update check - #1804

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-01_dsh-profile-converge-1803
Oct 1, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-01_dsh-profile-converge-1803

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1803

Root cause

dsh's CLI reads the bili bundle yml from the global install but resolves the entry module from each profile's own node_modules (#1590 mixed resolution). When a profile copy is left behind the global version, the bare-name entry resolves to the old package's CLI root — a module with zero exports — and the whole dsh boot crashes (invalid plugin, expect function or object with an "apply" method, received object).

Three ways to get into that state, all converging on one missing mechanism:

  1. Manual npm i -g — never triggers any profile refresh (the post-install hook only runs on a self-update event).
  2. Self-update + failed refresh (Windows PATH — [update] dsh profile bundle refresh fails on Windows: bare dsh not resolvable on PATH — profile copy stays frozen (#1196 contract) #1732/refreshDshProfileCopy 依赖 PATH 里的 dsh 命令:PATH 缺失时 host-channel 刷新失败,profile bundle 暂时滞留旧版本 #1730): the refresh is best-effort, warns, and never retries (it only fires once per install event).
  3. Self-update + refresh succeeded → no crash (in step).

The crash also blocks the #1196 self-heal: the profile copy's own proxy never starts, so nothing inside dsh can fix it.

Fix (this PR, the missing half)

checkForUpdate's up-to-date branch now calls the new convergeDshProfileBundles(installDir, diskVersion):

  • scans DSH_HOME/profiles for registry-pinned copies whose installed version < the global disk version (dev pins link:/file: are left alone — manual by design);
  • if any are stale: log, acquire the shared update lock, drive refreshDshProfileBundles(globalVersion) — dsh's own plugin channel, single-writer safe;
  • retries every cycle (~3 min + the ~10 s startup check) — closes the never-retries gap from case 2;
  • silent and spawn-free while everything is in step (no per-cycle cost on healthy machines).

refreshDshProfileBundles additionally skips profiles already at the target version, so a permanently-stale sibling (PATH-broken box) can't cause in-step profiles to re-spawn dsh plugin add every cycle. Declared-but-missing mounts still install (#1196: every declared copy has a live path).

UpdateOptions.installDir mirrors runAdvisoryCheck's seam so the up-to-date path is testable in-process. No config-surface change (internal option only; no BILI_*, no config.json field).

The Windows dsh-binary resolution half is already on master via #1734 (resolveDshBinary probes %APPDATA%\npm, pnpm dirs, node dir, …). This PR makes the trigger live so those resolutions actually get driven.

Tests

tests/update-dsh-converge.test.ts (5 cases): stale-copy + declared-missing refresh with dev-pin/in-step untouched; silent in-step world; undefined-args no-op; and the full checkForUpdate integration (registry stub, installDir seam) proving the up-to-date branch converges — the #1803 regression path. Pre-flight: typecheck ✓, full suite 379 files / 3365 tests / 0 fail ✓, build ✓.

Live verification (real artifact)

npm install -g . --install-links (repo = 0.1.176 == npm latest), fixture DSH_HOME with web@0.1.175, BILI_DSH_BIN recorder, bili start:

[update] dsh profile bundle(s) behind the global copy (web@0.1.175 < 0.1.176) — converging via dsh's plugin channel (#1803)
recorder: dsh plugin --profile web add billion-context@0.1.176
[update] refreshed 1 dsh profile bundle(s) to 0.1.176 — restart dsh to load it

Release note (§5)

This touches src/update.ts check logic, so per AGENTS.md §5 it must ship behind a no-op release first — ship the next routine patch bump, confirm a real auto-update goes through, then release this. Until then affected users can manually run dsh plugin add billion-context@0.1.176 in each profile (or reinstall the profile bundle).

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_dsh-profile-converge-1803 (da65538)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1781-pr.1804.4df4d86

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-pr1804.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

[bot] 🏷 PR review 完成(PR #1804,fixes #1803)。核对了分支代码、跑了本地 pre-flight、查了 CI;发现一个小问题已直接在 PR 分支修掉(见第 4 问),新 head d507f42f CI 正在跑。

验证过程

  • base == 当前 master HEAD(be637485),无 stale-base 问题,无需 rebase;
  • 本地 pre-flight(原 head cfe6c12c):typecheck ✓ / 全量测试 3476 tests / 0 fail / build ✓;
  • CI(cfe6c12c)全部 12 项绿:ubuntu 22/24、windows 22/24、codex/opencode/dsh/pi e2e lanes、hermetic registry e2e、version-guard、build-artifact。

结构化七问

  1. 是什么问题:「全局 ≥0.1.176 + profile ≤0.1.175」混装后 dsh 启动直接崩溃(invalid plugin … received object)——dsh 从全局安装读 bili bundle yml、却从各 profile 自己的 node_modules 解析入口模块(给deepseek定制一个跳转到状态的链接 #1590 mixed resolution);feat: dsh web-profile settings entry opening the bili Web UI (#1590) #1619 把 yml 改成裸名 + exports 映射后,跨副本混装从「降级」变成「致命」。且崩溃使 profile 副本自己的 proxy 起不来,dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196 self-heal 也被连带堵死。
  2. 什么原因导致的:profile 刷新只在 install 事件时触发(post-self-update hook)——手动 npm i -g 完全不触发任何 profile refresh(dsh boot crash on mixed copies: global >=0.1.176 bundle yml (bare name) + profile copy <=0.1.175 (exports["."]=CLI) — window opened by manual npm i -g, self-heal blocked by the crash itself #1803 case 1),self-update 后的刷新又是 best-effort、失败永不重试(Windows PATH,[update] dsh profile bundle refresh fails on Windows: bare dsh not resolvable on PATH — profile copy stays frozen (#1196 contract) #1732/refreshDshProfileCopy 依赖 PATH 里的 dsh 命令:PATH 缺失时 host-channel 刷新失败,profile bundle 暂时滞留旧版本 #1730,case 2)。根因是缺一个「由全局副本驱动的周期性收敛机制」,本 PR 补的正是这一半。
  3. 怎么修复的:在 checkForUpdate 的 up-to-date 分支加 convergeDshProfileBundles(installDir, diskVersion)——每周期(~3 min + 启动 ~10 s)扫 DSH_HOME/profiles,找 registry-pinned 且落后于全局 disk 版本的副本(dev pin link:/file: 不动);有落后则 log + 拿共享 update lock,走 dsh 自己的 plugin channel 驱动 refreshDshProfileBundles(globalVersion)(single-writer safe,dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196 契约);对齐时静默、零 spawn。配套:refreshDshProfileBundles 跳过已在目标版本的 profile,永久落后的 sibling(PATH 坏机器)不再让对齐的 profile 每周期重复 spawn dsh plugin add。触发侧激活后,fix(#1732): resolve dsh binary beyond bare PATH name; decode GBK subprocess output #1734 的 Windows dsh-binary 解析才有实际驱动对象。
  4. 是否有回归问题:无阻塞性回归。触碰路径的既有行为逐项过:up-to-date 分支原为 log+return,现增加一次 fs scan(廉价)+条件 spawn,throttle/时序/registry 逻辑未动;skip 语义作用于 refreshDshProfileBundles 全部 5 个调用点(self-heal/converge/post-self-update/advisory/bili plugin update dsh),消除冗余 respawn,declared-but-missing 挂载仍会照装(dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196);边界:版本匹配但文件损坏的副本,此前会被后续事件顺带重装修复,现在要等下个版本 bump 或 self-heal——可接受,已记录。触发条件是「仅落后」,动作却是把全部 registry-pinned profile 对齐到全局——包含把超前 sibling 降回全局(罕见瞬态窗口:self-heal 曾把某 profile 拉到 registry latest > global)。这与既有 post-update 路径「profiles follow global」语义([dsh bundle] boot crash window: stale pnpm metadata installs 0.1.117 copy while global 0.1.120 declares the bundle #953/[dsh] unify install lanes: bili plugin install dsh should go through the bundle channel + auto-update rewrite #966)一致,判定为设计一致,不改。顺手直接修掉的小问题(独立标注 commit d507f42f):新 skip 让 bili plugin update dsh 的摘要行虚报数量(旧文案把全部依赖 profile 都算成 "refreshing N",实际只刷了一部分)——改为返回实际刷新数并打印 N/M。行为变更披露:CLI 状态输出文案变化,旧 dsh: refreshing ${before} profile bundle(s) to … → 新 dsh: ${refreshed}/${before} profile bundle(s) refreshed to …(信息更准,非协议/配置变更)。wire/compression 路径零改动(两种压缩模式均不受影响),persistence 格式零改动。
  5. 是否破坏缓存:不涉及。不触碰 prefix cache 键路径、session refs、压缩游标或去重键。
  6. 是否改了设计方向:没有。在既有 update loop 内加周期性收敛 pass,仍走 dsh 自己的 plugin channel(dsh plugin-market installs never auto-update: the refresh chain's only trigger is a global bili self-update #1196 single-writer 契约),不引入第二 writer;host-managed/profile-copy 进程在该调用前就 return,只有全局副本收敛,advisory-active 时正常循环让位但 advisory 路径自带 refresh,无缝隙。
  7. 是否引入新的配置:没有。无新 BILI_* env、无 config.json 字段;UpdateOptions.installDir 是内部测试 seam(镜像 runAdvisoryCheck 的做法)。

测试有效性:tests/update-dsh-converge.test.ts 5 例,断言有牙——recorder runner 只 stub spawn,断言精确的 dsh plugin add 调用列表(stale + declared-missing 被刷,dev-pin + in-step 不动)、in-step 世界断言零调用且零日志、undefined-args no-op,外加完整 checkForUpdate 集成(registry stub + installDir seam)钉死 #1803 回归路径。不是测 mock 本身,是测行为。

发布顺序(§5):此 PR 动 src/update.ts check 逻辑,须先发一个 no-op release 确认升级链路健康再发它(PR body 已写明,人工排期)。受影响用户的 interim workaround:每个 profile 手动 dsh plugin add billion-context@<latest>。

结论:方向正确(补的是缺失机制而非打补丁)、测试钉住行为、本地 pre-flight 与旧 head CI 全绿;新 head d507f42f(含顺手小修)CI 12 项已起、e2e/version-guard/build 已绿、4 个 test job 运行中。待新 head CI 转绿即可合并(合并由人执行;请按 §5 先排 no-op release)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 跟进:新 head d507f42f(含顺手小修)的 CI 已全部跑完 —— 12/12 全绿(ubuntu 22/24、windows 22/24、codex/opencode/dsh/pi e2e lanes、hermetic registry e2e、version-guard、build-artifact)。PR #1804 现在处于可合并状态,等人工合并即可;发布时请按 §5 先排 no-op release。

…skip-aware)

The new in-step skip in refreshDshProfileBundles made the 'refreshing N profile bundle(s)' summary over-count when some profiles were already at the target. Return the refreshed count and print N/M so the CLI output stays honest in the degenerate all-in-step state.
@ranxianglei
ranxianglei force-pushed the 2026-10-01_dsh-profile-converge-1803 branch from d507f42 to da65538 Compare October 1, 2026 02:16
@ranxianglei
ranxianglei merged commit 54c246c into master Oct 1, 2026
12 checks passed
ranxianglei pushed a commit that referenced this pull request Oct 1, 2026
Runs only when a release is published (or via workflow_dispatch). Packs
the released tree twice with identical content at N-1/N into a local
verdaccio, boots a live proxy on N-1, and drives the full receive path:

- pre-update dsh profile convergence (#1803/#1804 path, fake dsh bin)
- in-place flip to N: 'installed N-1 → N. Restart to finish.'
- case-3 refresh + post-flip convergence of a profile seeded stale
  after the flip, then silence (no redundant dsh plugin spawns)
- live proxy keeps serving during the swap window
- restart at N: ACP smoke — model turn, plugin compress fold, post-fold
- 'plugin install opencode' entry survives the update

registry-fixture: pass NPM_ALLOW_DANGEROUS through to npm so guarded
dev machines can publish to the loopback fixture (CI is unaffected).
@ranxianglei
ranxianglei deleted the 2026-10-01_dsh-profile-converge-1803 branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant