Skip to content

fix: dsh plugin — stop the re-registration self-lock after a failed proxy respawn (#3380) - #3393

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-16_dsh-rereg-selflock
Oct 17, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-16_dsh-rereg-selflock

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3380

修的是什么

DSH 桌面会话运行中失去 bili proxy、且第一次 respawn 失败(onGiveUp)后,register.toolsReady 被连同 register.base 一起清掉。但工具注册活在宿主进程的工具层里,proxy 死了它们还在(execute 闭包读 live base,#983)。于是下一次 respawn 成功后被迫重注册,而 DSH 对自己已经注册过的名字一律拒绝(tool "compress" is already registered)——toolsReady 永远回不到 true,所有请求永久丢失 x-bili-plugin* 身份头:wire 模式、匿名零折叠账本、大会话 413 preflight_compress_failed,重启 dsh 前不会自愈。事故现场同一失败按固定 10s 重试了 145 次/小时。

查重:不重复。 #3177 是 host 层工具不可见的另一机制(已由 #3287 修);#2101/#2103 是反方向的 stale-true(本修复保留其重置路径);#2082/#2091 是本修复所依赖的恢复循环本身;#2708/#1268 分别是 pi lane 与 boot 期问题。

修法(疏不堵)

  1. 生命周期归位(根因):5 处 proxy-death/give-up 路径不再清 toolsReady——只有 dsh-native: apply() on a re-activated context doesn't reset register.toolsReady — tools stay registered only on the dead context #2101 的 context-change 路径才重置它。respawn 成功后身份头直接恢复,不再有注定失败的注册请求。
  2. 幂等注册(纵深防御):本进程已持有的名字走 adopt 而非抛错,部分注册的脏状态也能收敛;每进程记一次事件日志。
  3. P2 升级式退避:连续失败 10s→20s→…→5min 封顶(REG_RETRY_MAX_MS 具名常量,无新配置面);连续 5 次失败发一条醒目通知告知用户重启 dsh;重试永不终止——瞬态故障仍自动愈合(永久自降级正是 [dsh] native proxyEnvOrigin() 把临时 origin 冻结进 BILLION_CONTEXT_PROXY,绕过 ensureProxyRunning() 的 instance 验活;工具调用全部 fetch failed,需重启宿主 #983/dsh中工具会突然消失 #2082 的 bug 类)。issue 原文 P2 建议「N 次后放弃」,此处有意保留后台重试,理由见上。
  4. P3 可见性:/acp 在 proxy 应答但工具未注册时明确给出 wire-mode 警告行(含最后错误与恢复动作);曾健康服务的 proxy 失联时显示「temporarily unreachable … recovering」而不是误导性的 install 提示。
  5. maybeRetry 门放宽:baseless-but-toolsReady 状态现在也能驱动 respawn/恢复(旧合取门会把这种状态搁浅)。

行为变更披露(旧 → 新)

项 旧 新 原因
toolsReady 清除时机 5 处 proxy-death/give-up 路径都会清 仅 #2101 context-change 清 身份应跨 respawn 存活——这就是 bug 本身
注册失败重试节奏 固定 10s 指数 10s→5min 封顶 停止烧注定失败的请求,同时保留自动恢复
连续失败提示 静默 第 5 次起一条醒目通知(含重启动作) 事故静默了 1 小时无人知晓
/acp 输出 wire-mode 无警告;proxy 临时失联误报 install 新增 wire-mode 警告行;临时失联显示 recovering P3 可见性
注册事件 无 每进程一条 adopted N pre-existing registration(s) 收敛可追溯

回归审查(触碰路径的既有行为逐项过)

本地(rebased head f766689 + 4eacd44):新套件 6/6;dsh-native / issue2082 / issue2101 / issue2187 / native-intercept 共 119/119 绿;typecheck + build 绿。全量回归交 CI(§7.2)。

八问

  1. 是什么问题:DSH 插件的 proxy 死过一次且首次重生失败后,身份头永久丢失,请求静默地以匿名会话跑(无压缩),大会话直接 413。
  2. 什么原因导致的:proxy 死亡清理把「工具注册就绪」当成 proxy 生命周期的一部分一起清了;注册实际属于宿主 context、会存活 → 重注册被 DSH 自己拒绝 → latch 永久卡 false。症状(413/wire 模式)← 身份头丢失 ← 重注册自锁 ← 生命周期混同。
  3. 影响范围与严重程度:任何 bili proxy 运行时死亡且首次 respawn 失败的 DSH 桌面用户——压缩+缓存静默失效直到重启 dsh;大会话硬失败 413。特定条件触发,触发即完全不可用(压缩面)。
  4. 怎么修复的:latch 归位到正确的生命周期(根因)+ 幂等注册收敛脏状态 + 退避封顶与一次性用户通知 + /acp 暴露状态。
  5. 是否有回归问题:上表逐项过,未见破坏;唯一语义变化是有意的 latch 寿命变更,已披露。
  6. 是否破坏缓存:否——不动 cache key/游标/去重/fold state。
  7. 是否改了设计方向:否——同模块同架构,只纠正了生命周期归属;无新配置/env 面(两个常量为内部具名常量)。
  8. 是否引入了新的配置:否。

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_dsh-rereg-selflock (3cddfd9)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3998-pr.3393.c294af5

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-pr3393.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] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重:不重复。 这是 [PR] 镜像(PR #3393,分支 2026-10-16_dsh-rereg-selflock @ 4eacd442d,Closes #3380)。核对了在途 open PR 与相关历史 issue:#3177(host 层 unknown-tool,另一机制,已由 #3287 修,closed)、#2101/#2103(反向 stale-true,closed)、#2082/#2091(恢复循环本体,closed)均无重叠;无第二个 PR 触碰同一「respawn 失败后重注册自锁」机制。

本 issue 是已完成工作的镜像,按规范不重做——现在做的是 PR 审核:拉分支核对代码、跑定向测试、查 CI 状态,最后按八问给结论。

…roxy respawn (#3380)

A proxy-death/give-up path cleared register.toolsReady even though tool
registrations belong to the host CONTEXT (they survive proxy death; execute
closures read the live base, #983). The next successful respawn then forced a
re-registration that DSH rejects ('tool X is already registered'), the retry
loop burned the identical doomed failure forever (145x/h in the incident),
toolsReady stayed false permanently, and every model request lost its
x-bili-plugin* identity headers — wire mode, anonymous zero-fold ledgers, and
413 preflight_compress_failed on large sessions until the host restarted.

- proxy-death paths no longer clear toolsReady (only the #2101 context-change
  path resets it); a respawn therefore restores identity with NO doomed
  re-registration flight
- registration is idempotent: a name this process already holds is adopted
  instead of thrown on (converges partial/dirty states), logged once
- consecutive failures escalate: capped exponential back-off (10s -> 5min,
  REG_RETRY_MAX_MS) + one loud client-event notice with the recovery action
  after 5 failures; retries never stop (#983/#2082)
- /acp exposes wire-mode identity loss (warning line + last error) instead of
  staying silent; a previously-serving proxy reads as 'temporarily
  unreachable ... recovering', not 'install'
- maybeRetry gate widened so a baseless-but-toolsReady state can still drive
  respawn/recovery

Tests: tests/issue3380-dsh-rereg-selflock.test.ts (incident repro, idempotent
adoption, back-off schedule + integration heal, one-time notice, /acp surface).
@ranxianglei
ranxianglei force-pushed the 2026-10-16_dsh-rereg-selflock branch from 4eacd44 to 3cddfd9 Compare October 16, 2026 09:55
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

审核结论:可合并(待 rebased head 的 CI 全绿;其余门禁已全部通过)。

先说两个操作项:

  1. 分支落后 master 15 个提交(master 期间经 Incremental lane: one transient failure (5xx/409) permanently demotes the conversation to full resend; built-in recovery hook is dead code | 增量通道:一次瞬时故障(5xx/409)就把会话永久打回全量重发,内置的恢复钩子是死代码 #3369 改过 src/agent/dsh-native.ts)。已本地 rebase 到当前 master——零冲突;并验证新旧 head 的 delta 只含 master 自身演进(Incremental lane: one transient failure (5xx/409) permanently demotes the conversation to full resend; built-in recovery hook is dead code | 增量通道:一次瞬时故障(5xx/409)就把会话永久打回全量重发,内置的恢复钩子是死代码 #3369 ack 通道等)、不含本 PR 变更漂移;rebased head 3cddfd966 已推上 PR 分支(force-with-lease),让 CI 在「将要合入的那棵树」上做全量判定。
  2. 以下所有代码核对都在 rebased head 上进行,不是对着原 base 读的。

既有行为回归清单(逐项结论):

触碰点 结论
#2101 context-change 重置 保持——apply() 保留 toolsReady && activeCtx!==undefined && activeCtx!==ctx → 重置,另加 failStreak/error/adopt 日志归零(新激活 = 干净的注册周期,正确)
#983 live-base execute 闭包 不变——execute 仍调用时读 register.base(dsh-native.ts:616);respawn 成功后旧注册直接可用
#1783 stale-base back-off scope 保持——retryAt 武装仍有 if (register.base === base) 门
#2082 恢复定时器/流量驱动重试 等价或更优——四态矩阵逐一核过:dead→no-op(同旧)/ baseless+!ready→respawn(同旧)/ base+!ready→registerTools(同旧)/ baseless+ready→respawn(新增修复路径,正是本事故的搁浅态)
#1268 首请求 gate 未动
#1130/#1365 attach 探测/pinned wait/routed 证据 未动——5 处 proxy-death 路径只删了 toolsReady 清除,origin 处理逐字未变
#3248 incremental-turn ack 链(master 侧 #3369 改动,同文件共存) 无交互——不同区域(onResponse vs 注册生命周期),rebase 后 150/150 绿实证

独立追查的关键风险点(PR 未明说的):搁浅态(baseless + toolsReady=true)由谁驱动 respawn?detached 恢复定时器在 toolsReady===true 时首个 tick 就自清(dsh-native.ts:736),后台循环驱动不了这个状态。我走了完整请求路径:routed lane(桌面 settings overlay,即事故形态)的每个模型请求在 send 前都会过 headersFor(native-intercept.ts:705)→ maybeRetry(放宽后的门恰好放行此路径)→ respawn 分支;respawn 成功后身份头立即恢复、无需重注册。所以持续流量下自动恢复成立;空闲期本就没有需要 proxy 的请求,恢复后的第一个请求即驱动 respawn。raw lane 在 give-up 后本来就没有自动恢复驱动(此 PR 之前就如此,属既有缺口,未被本 PR 恶化)。无回归。

测试有效性:6 个新测试全部有牙——incident repro 直接钉住修法(manifestRequests()===0 证明没有注定失败的重注册飞行发生;give-up 后 toolsReady===true 是修发的核心断言);adopt 测试钉住部分脏状态收敛 + 一次性日志;backoff 测试钉住阶梯档位与成功归零;notice 测试用计数断言钉住「恰好一次」;/acp 测试钉住两个显示面。不是假测试。

八问:

  1. 是什么问题:DSH 的 proxy 死过一次且首次重生失败后,身份头(x-bili-plugin*)永久丢失,所有请求静默地以匿名会话跑 bili(无压缩);大会话硬失败 413 preflight_compress_failed,重启 dsh 前不自愈。
  2. 什么原因导致的:生命周期混同——proxy-death 清理把「工具注册就绪」当成 proxy 生命周期的一部分一起清掉,而注册实际活在宿主进程的工具层、会存活于 proxy 死亡之后(execute 闭包读 live base)→ respawn 成功后被迫重注册 → DSH 拒绝本进程已持有的名字 → latch 永久卡 false。症状(413/wire 模式)← 身份头丢失 ← 重注册自锁 ← 生命周期混同,每一环都在代码里核实过。
  3. 影响范围与严重程度:任何 bili proxy 运行时死亡且首次 respawn 失败的 DSH 桌面用户——压缩+缓存静默失效直到重启;大会话硬失败。特定条件触发,触发即完全不可用(压缩面);事故现场同一失败按 10s 烧了 145 次/小时且全程静默。
  4. 怎么修复的:latch 归位到正确生命周期(根因,疏不堵——从此不再有注定失败的注册请求)+ 幂等 adopt 收敛脏状态(纵深防御)+ 封顶指数退避 10s→5min + 连续 5 次失败一条醒目通知(含重启动作)+ /acp 暴露 wire-mode 状态。有意保留「重试永不终止」(偏离原 issue「N 次后放弃」建议):永久自降级正是 [dsh] native proxyEnvOrigin() 把临时 origin 冻结进 BILLION_CONTEXT_PROXY,绕过 ensureProxyRunning() 的 instance 验活;工具调用全部 fetch failed,需重启宿主 #983/dsh中工具会突然消失 #2082 的 bug 类,瞬态故障仍须自动愈合——偏离合理且已披露。
  5. 是否有回归问题:无。逐项结论见上表;唯一语义变化是有意的 latch 寿命延长(已披露)。两个小发现,均判定非缺陷:① failStreak 在 manifest fetch 飞行中 register 已换 base 的小概率竞态下也会累加——retryAt 武装已有正确 scope,影响至多多一档退避 + 陈旧错误文本,且跨 base 累计本身是 P2 的本意(事故场景正跨 respawn 累计);② 正常启动窗口(<1s)内 /acp 可能短暂显示 wire-mode 警告行("Last error: unknown")——文本属实(工具确实尚未注册完),显式优于隐式的取舍,接受。
  6. 是否破坏缓存:否——不动 cache key/游标/去重/fold state/会话身份。
  7. 是否改了设计方向:否——同模块同架构,只纠正生命周期归属。一个残留假设值得记下:宿主若在不换 context(同 ctx 对象)的情况下重建工具层,latch 不会自愈(保持 true → plugin 模式但本地工具缺失)——此类症状的已知实例已由 fix: stop telling DSH to call an unreachable compress tool (#3177) #3287 另行修复,且修复前的行为同样依赖「后续恰好发生 proxy 死亡」这种巧合才能愈合,非本 PR 引入的回归。
  8. 是否引入了新的配置:否——REG_RETRY_MAX_MS / REG_GIVE_UP_NOTICE_STREAK 为内部具名常量;BILI_DSH_RETRY_INTERVAL_MS / BILI_DSH_RECOVERY_INTERVAL_MS 是既有 knob。

行为变更披露核对:PR 表格 5 项(latch 清除时机 / 重试节奏 / 失败提示 / /acp 输出 / adopt 日志)全部在代码中逐一确认,旧→新值与实际一致,无遗漏项。

证据:

  • 本地(rebased head 3cddfd966):typecheck + build 绿;定向套件 150/150 绿(新套件 6/6 单独复核 + dsh-native + issue2082×2 + issue2101 + issue2187-dsh-spawn-retry + native-intercept×2)
  • CI:旧 head 4eacd442d 29/30 绿(检查时 1 个 shard 仍在跑);rebased head 已推送,全量判定以它的 CI 运行为准(§7.2)

判定:可合并。 rebased head 的 CI 转绿后即可合并:#3393

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 状态更新(rebased head 3cddfd966):首轮运行里主 CI workflow(run 38883821817)整体被取消——6 个 test shard 全部在开跑约 4 分钟后统一被 cancel,其余所有 job(static-gates、各 guard、build-artifact)通过;同 head 的其余 workflow(e2e-native-dsh / e2e-dsh-plugin-lane / e2e-local-registry / e2e-fake-codex / e2e-codex-persona / e2e-pi-codex-ws / e2e-native-pi / e2e-native-opencode / E2E-real-codex 等 11 条)全部绿。取消发生在运行中途且同一时刻批量发生,属基础设施侧调度取消(当时另一在途 PR fix/dsh-incremental-marker-race 的 CI 正在占用 runner),不是代码失败。已触发该 run 的整体重跑(rerun 已被接受),test shard 重跑完成后我会再报最终判定。代码审核结论不变:可合并(待全量 CI 转绿)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 全绿,最终判定:可合并。 ✅

rebased head 3cddfd966 的主 CI workflow(run 38883821817,重跑 attempt 2)completed success——全部 guard/gate + 6 个 test shard(ubuntu 22×3 / ubuntu 24×1 / windows 22×2)通过;同 head 的其余 11 条 e2e workflow(e2e-native-dsh、e2e-dsh-plugin-lane、e2e-local-registry、e2e-fake-codex、e2e-codex-persona、e2e-pi-codex-ws、e2e-native-pi、e2e-native-opencode、E2E real-codex、PR Build Artifact、CI Windows codex overlay)此前已全部 success。首轮被基础设施取消的只是调度问题,代码零失败。

审核结论汇总(完整八问见上一轮回复):

可以合并了:#3393 (合并动作按规范由你执行。)

@ranxianglei
ranxianglei merged commit fa41483 into master Oct 17, 2026
54 of 60 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.512-master.fa41483 (rolling master tag).

npm install -g billion-context@0.0.512-master.fa41483  # 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment