Skip to content

[PR] fix(dsh): recover boot-race model-info cache on llm/adapters-updated - #1946

Closed
ranxianglei wants to merge 3 commits into
masterfrom
2026-10-03_dsh-model-info-adapters-ready
Closed

ranxianglei wants to merge 3 commits into
masterfrom
2026-10-03_dsh-model-info-adapters-ready

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1945

What

The dsh native plugin's first refreshModelInfo can run before the selected provider's adapter is registered in the host, where dsh throws no adapter registered for provider (NO_ADAPTER) and latches a failure-shaped cache ({provider, model}, no window). #1836's cooldown recovers it within ~30s, but every request in that window after a host restart ships without x-bili-plugin-context-window, so the proxy sizes against its fallback.

Fix

Subscribe to dsh's llm/adapters-updated host event (emitted by dsh-llm's commitRoutes on every adapter register/replace/dispose) through the plugin's existing ctx.on surface. When it fires while a failure-shaped cache is latched, drop modelInfo.retryAt to now so the NEXT headersFor -> refreshModelInfo re-resolves immediately instead of waiting out the 30s cooldown.

  • Deferred re-resolution (next request) rather than resolving from the event handler: reuses the existing live-selection guard and avoids an async race mid-selection-switch.
  • The listener only touches failure-shaped entries (no contextWindow) - a resolved cache stays final (pinned by test).
  • Best-effort: hosts without ctx.on or without the event keep fix(dsh): retry failed model-window resolves — one boot race no longer strips x-bili-plugin-context-window #1836's cooldown as the recovery path (graceful no-op).
  • _resetRegisterForTest now also resets modelInfo.retryAt (completes the lifecycle reset the new path relies on for test isolation).

Behavior change (disclosed)

Old: after a host restart, if the first resolve hits NO_ADAPTER, sessions send no context-window header for up to 30s (cooldown) and the proxy sizes against its fallback window.
New: recovery happens on the request right after the provider's adapter registers (typically seconds after boot); the 30s cooldown is unchanged as fallback for hosts that never emit the event. No config-surface change, no default changed.

Verification

  • Verified against the installed dsh build's sources: dsh-llm/lib/index.js emits llm/adapters-updated (no payload) from commitRoutes (register/replace) and dispose; the dispatch carries no thisArg, so cordis applies no context filter and plugin listeners receive it; dsh's own dsh-llm/lib/invariant.js subscribes with exactly ctx.on("llm/adapters-updated", ...).
  • New regression test (dsh model-info: boot-order race — first ~30s after host restart send no context window (event-driven cache invalidation) #1945): 60s cooldown configured, first resolve fails, fire llm/adapters-updated, assert the window header lands on the next stamp with exactly one extra resolve, and that later events do not disturb the final cache. Confirmed discriminating: the test fails with the source change stashed.
  • npm run typecheck clean; tests/dsh-native.test.ts green (43/43); npm run build OK. Full suite left to CI.

Scope: single-module fix (src/agent/dsh-native.ts, client-side header stamping only; proxy mode unaffected). No config schema / persistence / wire-shape / cross-repo changes.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-03_dsh-model-info-adapters-ready (d21befa)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2013-pr.1946.bbb54e3

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

PR #1946 审核完成 — 可合并(mergeable)。

结构化七问

  1. 是什么问题:dsh native 插件在 host 重启后,若第一次 model-info resolve 跑在该 provider 的 adapter 于 dsh 内注册之前,dsh 抛 NO_ADAPTER,插件 latch 一个 failure-shaped cache({provider, model},无 window)。fix(dsh): retry failed model-window resolves — one boot race no longer strips x-bili-plugin-context-window #1836 的 cooldown 会在 ~30s 内自愈,但这段窗口内的每个请求都不带 x-bili-plugin-context-window,proxy 按 fallback window 定容。

  2. 什么原因导致的:顺序问题,不是 resolve 逻辑问题——boot 时第一个 model 请求可能早于 provider adapter 注册。既有重试机制(130k上下文窗口被占满触发无效压缩越压越大 #1812/fix(dsh): retry failed model-window resolves — one boot race no longer strips x-bili-plugin-context-window #1836)只按 30s 墙钟节奏复查,而 host 自己明明知道 adapter 就绪的确切时刻,恢复延迟却被动地等于最长 30s。

  3. 怎么修复的:通过插件既有的 ctx.on 订阅 dsh 的 llm/adapters-updated 事件(dsh-llm 的 commitRoutes 在每次 adapter register/replace/dispose 时发布);当 failure-shaped cache 处于 latch 状态时把 modelInfo.retryAt 清到 now,让下一次 headersFor → refreshModelInfo 立即重新解析,而不是等 cooldown。刻意采用「延迟到下一个请求」而非在事件回调里直接 resolve:复用既有 live-selection guard,避免 selection 切换中途的异步竞态。cooldown 原样保留为不发该事件的 host 的回退路径。

  4. 是否有回归问题:未发现。触碰路径上的既有行为逐项清点:

  5. 是否破坏缓存:否。proxy 侧 prefix/session 缓存未触碰;header 契约不变(window header 仅在有 window 时出现),变的只是 boot 后首个 window 何时可用。模块级 modelInfo 状态只多了一个 reset 触发源(事件),无其他失效。

  6. 是否改了设计方向:否。架构不变(client stamp、proxy consume),在既有 cooldown 上叠加事件驱动的提前恢复,正是 dsh model-info: boot-order race — first ~30s after host restart send no context window (event-driven cache invalidation) #1945 提出的方向。与 open PR fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window #1943(receiver bind 修复,同文件不同区域)任意顺序合并都可组合——两者产生同样的 failure-shaped cache,本恢复逻辑不依赖 fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window #1943 先行。

  7. 是否引入了新的配置:无 config surface 变更。无新 env/config/CLI flag,默认值全部不变。

验证证据

  • 对照已安装的 dsh 0.1.1-rc.2 build 源码核实了事件机制:commitRoutes 是路由集的唯一变更点,register/replace/dispose 均发布 llm/adapters-updated;dispatch 不带 scope carrier,cordis 因此不做 context filter,插件 listener 必然收到;ctx.on 混入每个 cordis context(headless profile 同样可用,并非 web-only);listener 随插件 fiber 自动 dispose,且 listener 失败被 contain(本 listener 只读+赋值,不可能抛错)。
  • 本地 A/B:把源码改动还原为 base master 版本(保留新测试)→ 新回归测试失败(42 pass / 1 fail);PR head → 43/43 全绿。测试确实钉住了修复。typecheck clean。
  • CI:head 6e19bf3 上 14 项检查全绿——ubuntu-22/24 + windows-22/24 全量测试、e2e、real-client lanes(opencode native / dsh headless / codex / pi)、hermetic registry(ubuntu + windows)、version-guard、build-artifact。
  • base == 当前 master tip(无 stale-base);diff 两文件 +82/−3,单一线性提交,每行都在目的范围内。

一个审过但判定为非缺陷的点:PluginContext.on 的 TS 签名仍把 listener 参数类型写为 (table: WebServerTable) => void;新的零参 listener 在 TS 规则下可赋值成立,更新后的注释也说明了两种用法——属措辞精度问题而非缺陷,保持现状(不另开 commit、不立项)。

结论:可合并。 §7.4 auto-merge gate 各项均满足(单模块 fix、有辨识度的回归测试、当前 base 上 CI 全绿、无 config/persistence/wire/cross-repo 变更、纯 fix: 且 Closes #1945、diff 干净、未触碰 load-bearing infra)。按仓库规则 merge 本身仍归人工:#1946

ework-agent added 2 commits October 3, 2026 22:56
… adjacent-insertion tests: #1942 receiver binding from master + #1945 adapters-updated)
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #1945 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

@ranxianglei ranxianglei changed the title fix(dsh): recover boot-race model-info cache on llm/adapters-updated [PR] fix(dsh): recover boot-race model-info cache on llm/adapters-updated Oct 24, 2026
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.

dsh model-info: boot-order race — first ~30s after host restart send no context window (event-driven cache invalidation)

1 participant