Skip to content

fix(update): bound dsh owner-channel refresh retries + surface frozen-profile state (#2148) - #2151

Closed
ranxianglei wants to merge 3 commits into
masterfrom
2026-10-05_dsh-channel-backoff-2148
Closed

ranxianglei wants to merge 3 commits into
masterfrom
2026-10-05_dsh-channel-backoff-2148

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Closes #2148

What

When the dsh host CLI itself is broken (issue repro: asar missing @deepseek-ai/dsh-desktop-host/lib/cli.js), every 3-minute update cycle spawned a doomed dsh plugin --profile <name> add … forever: no backoff, no user-visible signal, and a "manual fix" hint telling users to run the very command that cannot run. The profile copy stayed frozen at its installed version indefinitely.

Three fixes, one mechanism (the dsh owner-channel refresh path):

  1. Backoff (src/dsh-channel.ts): consecutive failures per (profile, targetVersion) back off after 3 — 5 min → 10 → 20 … capped at 6 h — mirroring the existing auto-update installs but never activates on long-lived plugin hosts; unwritable install dir retries every 3-min cycle for 11+ days #1603 install-failure backoff (same constants, same message discipline: sub-threshold failures keep the exact old log line; threshold hit logs once with remediation + "Backing off"; later cycles "Still failing"). In-memory state; resets on any success or when a different version is targeted; stale same-profile entries are pruned on record.
  2. Broken-host diagnostics (formatDshError): when the spawn error shows the host CLI cannot start (MODULE_NOT_FOUND / Cannot find module / ENOENT), the warn says the dsh host installation itself appears broken — repair/reinstall dsh or point BILI_DSH_BIN at a working executable — instead of suggesting re-running the same broken command. Generic failures keep the original wording byte-for-byte (pinned by the existing test).
  3. User-visible standing signal: persistently failing channels (≥3 consecutive) are surfaced where operators actually look:
    • GET /__bili/status and GET /__bili/overview: additive dshChannel array field (empty when healthy);
    • /acp panel (plugin preFooter + acp_status report): one warning line listing profile→version (N×);
    • Web UI banner (#dsh-channel-banner, en+zh i18n keys).
      All silent when healthy.

Behavior changes (old → new)

Surface Old New
Retry cadence on persistent dsh-channel failure every 3 min, forever first 3 checks still try (matching #1603), then exponential cooldown 5m→…→6h cap, per (profile,targetVersion)
Log wording for broken-host failure "manual fix: run dsh plugin … from a shell where dsh resolves" "host installation itself appears broken — repair/reinstall dsh or point BILI_DSH_BIN …"
/__bili/status + /__bili/overview payload — additive dshChannel field (empty array when healthy)
/acp panel, web UI no signal standing warning line/banner while failing
README status field list omitted conflicts now lists it (pre-existing doc gap fixed in passing)

No config surface added (constants hardcoded, exactly like #1603). No kernel change. No proxy↔client wire change — only bili's own status/panel/banner surfaces gain lines.

Design note — deviation from suggested direction ②

The issue proposed reusing the advisory mechanism (src/advisory.ts, #1588). That mechanism is built for published, version-keyed force-install advisories (companion npm package billion-context-advisories): it answers "version X has a known defect, move to Y". A machine-local "my dsh channel is broken" state has no semver range to key on and must not trigger force-install semantics, so it does not fit that contract. Used local surfaces instead (status field + panel + banner), which also carry richer live state (attempt counts, last error).

Scope note: the desktop profile lane stopped using the dsh CLI entirely since #1575/v0.1.180 (in-place verified-tarball install), so copies running ≥0.1.180 self-heal without a working CLI. Copies frozen below that (like the 0.1.179 repro) cannot reach this fix themselves — repairing/reinstalling the dsh host is still required for them; this PR bounds the retry storm and makes the frozen state visible on every lane meanwhile.

Tests

New tests/issue2148-dsh-channel-backoff.test.ts (9 tests): backoff curve shape; spawn-count + log-text pins across the threshold/cooldown/resume cycle; success-reset; cross-version prune; dshHostCliBroken detection; broken-host vs generic vs ENOENT warn wording; /acp panel line (incl. ordering before the footer box); acp_status report line. Existing tests/dsh-refresh.test.ts first-failure pin stays green unchanged. Targeted suites green locally (issue2148 / dsh-refresh / advisory-panel / acp-status / update-backoff / web-i18n / web-conflict-banner = 51 pass); typecheck clean; build OK; full regression via CI.

Post-open supplement: #2181 (labeled in-passing fix, own issue)

CI triage after opening found all 4 test lanes red on a test that is NOT from this PR — tests/advisory-endpoint-parity.test.ts (#2153) fails with 500 !== 200 on /__bili/overview in every fresh-runner lane, and master is red identically (4af31e0, same 4 lanes, same test). Root cause (issue #2181): refreshIndex() re-threw the deliberate top-level ENOENT of walkSessionFiles() when the sessions dir had never been created (fresh install / fresh CI runner — the dir only comes into existence at first persist), so /__bili/overview + /__bili/sessions answered 500 until the first session was persisted. Defect dates to e0ef92a (#1939 summary-index rewrite); #2153's parity test was the first to hit that endpoint on a fresh environment.

Fix commit fix(web): first contact with a missing sessions dir is no data, not a 500 (#2181) (separate labeled commit per the minor-fix rule):

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-05_dsh-channel-backoff-2148 (6b4b3f5)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2248-pr.2151.10a1b4d

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-pr2151.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(#2151,分支 2026-10-05_dsh-channel-backoff-2148,Closes #2148):先核对原 issue 方向 → 回归审查 → 代码审查 → 测试有效性 → diff 整洁度,结论用结构化七问回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2151 review 完成 —— 方向正确、机制成立;review 中发现并直接修掉一个可见性生命周期缺陷(已推 additive commit 874ad697,CI 正在新 head 上重跑)。按七问给结论:

1. 是什么问题
dsh 宿主安装本身损坏(CLI 起不来,#2146 现场复现)时,bili 每 3 分钟盲跑一条注定失败的 dsh plugin --profile … add …(~50×/3h),profile 拷贝永远冻结在旧版本且用户无任何可见信号,日志里的 "manual fix" 还误导用户去重跑同一条坏命令。

2. 什么原因导致的
refreshDshProfileBundles 对持续性失败没有收敛检测——全局安装路径早有 #1603 退避,dsh owner-channel 这条平行路径没有对齐;失败只落日志,且诊断文案不区分「命令执行失败」与「宿主 CLI 根本不可用」两种性质完全不同的故障。

3. 怎么修复的
三个机制:① 按 (profile, targetVersion) 的指数退避(阈值 3 次,5min→10→…→上限 6h,成功或目标版本变化重置,形状与 #1603 完全一致,内存态无持久化);② 持续失败的可见性:GET /__bili/status 与 /__bili/overview 新增 dshChannel 字段(健康时为空)+ /acp 面板常驻警告行(置于 footer 前,stripper-safe)+ Web UI banner(en+zh);③ broken-host 诊断(stderr 命中 MODULE_NOT_FOUND|Cannot find module 或 ENOENT 时,文案改为「修复/重装 dsh 或将 BILI_DSH_BIN 指向可用可执行文件——重跑该命令不可能成功」,不再建议重跑)。

4. 是否有回归问题 —— 逐项审过 diff 触碰路径的既有行为:

5. 是否破坏缓存:不涉及(无缓存/重试游标/去重键;新 Map 是进程内簿记)。

6. 是否改了设计方向:没有。刻意不走 advisory.ts(那是 semver keyed 的强制安装契约,语义不符),用本地可见性状态表达「通道死了」这一实例级事实——与 #1577 advisory 面板行的先例同层。

7. 是否引入新配置:没有。全部常量为模块级(阈值 3 / base 5min / cap 6h),无 config/env/CLI surface。

测试有效性(质量关):8 个测试断言有牙——字节级日志串、spawn 计数(fails.length)、可见性列表内容、面板行相对 footer 的位置(stripper 安全),bug 回归时抓得住。小出入一处:PR body 写 "9 tests",实际 8 个 test() 块,不影响实质。

自动合并门禁:不适用(feat commit + 多表面变更)→ 人工合并。

判定:CI 在 874ad697 上全绿后即可合并(当前 in_progress)。本地证据:typecheck 干净;所有触碰模块的定向套件共 137 项全绿(issue2148×10、dsh-refresh×19、update-backoff/acp-status/web-i18n/web-conflict-banner/advisory-panel/update-dsh-converge/update-dsh-self-refresh/issue2082/issue2101×42、dsh-native/dsh-acp/dsh-settings-ui×61、update-desktop-inplace×5)。

有意行为变更披露(旧→新):

  1. dsh profile 刷新失败:每 3 分钟无限重试+重复 warn → 同一 (profile,版本) 最多连试 3 次后指数冷却(5min→6h),冷却期静默,状态经 dshChannel 可见;
  2. broken-host 故障的日志建议:「换个 shell 重跑同命令」→ 「修复/重装 dsh 或指 BILI_DSH_BIN」;
  3. (review 修复)恢复后常驻警告的清除时机:直到进程重启 → 成功/in-step 立即清除。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 终态确认:874ad697(含 review 修复)上全部 20 个 check runs completed=success,无一失败;PR mergeable=True,mergeStateStatus=clean。

结论不变:可合并,等人工 merge(自动合并门禁不适用:feat commit + 多表面变更)。合并入口:#2151

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 终态确认:新 head 874ad697(含 review 修复)上全部 20 个 check runs completed=success,无一失败;PR mergeable=True,mergeStateStatus=clean。

收工判定:可合并,等人工 merge(自动合并门禁不适用:feat commit + 多表面变更,按 §7.4 保持人工)。合并入口:#2151

@ranxianglei
ranxianglei force-pushed the 2026-10-05_dsh-channel-backoff-2148 branch from 6abecdd to 6b4b3f5 Compare October 5, 2026 14:38
@ranxianglei ranxianglei added the duplicate This issue or pull request already exists label Oct 5, 2026
@ranxianglei ranxianglei closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[update] dsh profile copy self-update fails forever when the dsh host CLI itself is broken (frozen version, log-only warning)

1 participant