Skip to content

fix(dsh): retry failed model-window resolves — one boot race no longer strips x-bili-plugin-context-window - #1836

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-01_dsh-window-retry
Oct 1, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-01_dsh-window-retry

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Part of #1812 — the dsh→bili window handshake root cause. The error-text extraction rework stays in #1818.

Root cause

The #1812 session sized everything against bili's unconfigured 200k fallback even though the client knew the real window. The handshake chain:

  • dsh's catalog always knows a window (user-set models[].contextWindow or the built-in default), and headersFor stamps x-bili-plugin-context-window from the ModelInfoCache.
  • But refreshModelInfo cached {provider, model} (no window) whenever resolveModelInfo failed once, and the early-return only compared provider+model — so a single boot-time race (catalog still loading) latched the process headerless: every request of the whole session sized against the fallback, and the proxy only survived via a lucky registry-peek match (or not at all behind relays with unknown models → 130k上下文窗口被占满触发无效压缩越压越大 #1812's 400 loop).

Live evidence

Same dsh install, same model, three proxy runs:

  • two runs: x-bili-plugin-model present, no context-window header on any request (proxy warned #1569, window recovered only by models.dev peek);
  • third run: header on every request.

Intermittency = the boot race.

Fix

Test

New dsh-native unit test: resolve fails twice → model id still stamped, window absent; after the cooldown the next stamp carries x-bili-plugin-context-window: 262144 (attempts ≥ 3). Suite: 42/42.

Config surface

New env var, test-hook species (same class as BILI_UPDATE_CHECK_INTERVAL_MS, #1153):

  • BILI_MODEL_INFO_RETRY_MS — cooldown (ms) before a failed / window-less dsh model-window resolve retries. Default 30000; non-numeric or negative values fall back to the default. Unset in production; the dsh-native unit test shortens it to 1 so the cadence is exercised without wall-clock waits.
  • Why the existing surface cannot express it: there is no user-facing knob for an internal retry cadence — this is a test seam, not a product setting. Docs row mirrored into CONFIGURATION.md en/zh in 7046efab.

Intended behavior change (disclosed): a failed or window-less resolve used to latch headerless for the whole process lifetime; it now retries every 30s until the catalog yields a window. Minor side effect during persistent failure: the best-effort runtime-info report repeats each retry cycle instead of once per process/model (payload unchanged — no window claim).

…r strips x-bili-plugin-context-window for the process lifetime

Root cause of the #1812 mis-sizing handshake gap: dsh's catalog always
knows a window (user-set models[].contextWindow or the built-in default),
and headersFor stamps x-bili-plugin-context-window from the
ModelInfoCache — but refreshModelInfo cached {provider, model} (no
window) whenever resolveModelInfo failed once, and the early-return only
compared provider+model, so a single boot-time race (catalog still
loading) latched the process headerless. Every request of the session
then sized against bili's unconfigured 200k fallback.

Observed live on the same dsh install against the same model: two proxy
runs sent x-bili-plugin-model without any context-window header (proxy
warned #1569 and only survived via a lucky registry-peek match), a third
run sent the header on every request — intermittency = the boot race.

Fix: a matching cache entry is final only when it carries a window; a
failure-shaped entry retries after a 30s cooldown (test hook:
BILI_MODEL_INFO_RETRY_MS). Successful resolves with a window clear the
retry state; selection-change semantics from #956 are untouched.

Test: new dsh-native unit test — resolve fails twice, model id still
stamped, window absent; after the cooldown the next stamp carries
x-bili-plugin-context-window: 262144 (attempts >= 3).

Part of #1812 (handshake root cause; the error-text extraction rework
stays in #1818).
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_dsh-window-retry (7046efa)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1820-pr.1836.73deb36

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-pr1836.tgz
npm install -g package

Install instructions are refreshed on each push.

#1836)

The retry-cooldown env var introduced by the fix commit was left out of the
env-var tables; BILI_UPDATE_REGISTRY/BILI_UPDATE_CHECK_INTERVAL_MS set the
precedent that test-hook seams get a CONFIGURATION.md row (en + zh mirror).
@ranxianglei ranxianglei added the p1 label Oct 1, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(代码 + CI + 本地定向验证),结论:可合并,等新 head 的 test 矩阵收尾即可人工合并。

审核前置(方向关 / 复现查证)

结构化七问

  1. 是什么问题:dsh native 插件在模型窗口解析偶发失败一次后永久 latch 成无 header 状态,x-bili-plugin-context-window 整个会话生命周期缺失,proxy 只能靠 200k fallback 或 registry peek 兜底(130k上下文窗口被占满触发无效压缩越压越大 #1812 事故里就是它把窗口打成了 200k)。
  2. 什么原因导致的:最终性判定放错了位置——「缓存条目匹配当前选择」被当作终态,但失败形条目(无 window)根本不是终态;启动期 catalog 未就绪的竞态让一次失败变成了终身判决。
  3. 怎么修复的:终态条件从「匹配」收紧为「匹配且携带 window」;失败形条目进入 30s 冷却重试(由每次请求的 headersFor → refreshModelInfo 驱动),成功带 window 时清除重试态。refreshing 标志防重入、selectionStillCurrent 双守卫(feat: runtime-info protocol — plugins report real model config to the proxy (#955) #956 切换语义)原样保留。
  4. 是否有回归问题:逐项过过触碰路径的既有行为——① header stamping 逻辑本身未变(空缓存不发 model/window header,同前);② feat: runtime-info protocol — plugins report real model config to the proxy (#955) #956 mid-resolve 切换丢弃 stale commit:保持;③ runtime-info 上报:持续失败期间由「每进程每模型一次」变为「每 30s 一次」——重试的必然副产物,payload 诚实(不带 window 声明)、幂等 POST,已按行为变更披露(非回归);④ resolver 成功但不带 window 的场景:旧行为 latch 无 window,新行为每 30s 重试(dsh catalog 查询成本可忽略)——符合「final only when it carries a window」的设计声明;⑤ plugin/proxy 双压缩模式:改动全在 client 侧 stamping,wire 形状与 proxy 行为零变化。无无意回归。
  5. 是否破坏缓存:不涉及。前缀缓存键、会话身份、去重/游标均未触碰;重试只影响 client→proxy 的 header,不影响 proxy 内部任何失效策略。
  6. 是否改了设计方向:没有。沿用 [native] runtime-info protocol: plugins report real model config (model / contextWindow / maxOutput) to the proxy #955 runtime-info 管线,只是移除了永久 latch 这一个错误终态;30s 固定冷却是保守默认,不引入新的调节面。
  7. 是否引入了新的配置:是,一个测试钩子类 env var BILI_MODEL_INFO_RETRY_MS(默认 30000,非数字/负值回退默认;生产 unset)——与 BILI_UPDATE_CHECK_INTERVAL_MS(test: 自带本地 npm registry 的 hermetic 测试基建——解锁自更新/钉版本/解析全链路 e2e #1153)同族。已补 CONFIGURATION.md en/zh 两行文档(review 中发现的缺口,直接修掉)。

Review 中直接补的两处小修(已推到 PR 分支,commit 7046efab):

  • CONFIGURATION.md + zh-CN 镜像补 BILI_MODEL_INFO_RETRY_MS 行(此前缺失,违反 env var 镜像纪律);
  • PR 正文按 config-surface 纪律补了 "Config surface" 小节 + 行为变更披露(old: 失败即永久 latch → new: 30s 冷却重试;含 runtime-info 上报频率副产物)。

验证证据

  • 本地定向:typecheck ✅;tests/dsh-native.test.ts 42/42 ✅(含新测试;全量交给 CI)。
  • 新测试有效性:有牙——pre-fix 代码下 waitFor(window) 会超时(latch 永不恢复);断言链(model id 先落、window 后到、attempts≥3)时序确定(1ms 冷却 vs 10ms 轮询 tick;window-absent 断言同步执行,不可能被 in-flight 重试抢先);withEnv 正确还原 env,无污染。
  • CI(旧 head 1aa0fd36):9/13 绿——e2e(真实 codex 全生命周期)、四条真实客户端 lane(dsh/pi/opencode/codex vs 假上游)、hermetic registry e2e、build-artifact、version-guard;剩 4 个 test 矩阵 job(ubuntu/windows × node 22/24)当时在跑。我推的 docs commit 使 head 变为 7046efab,检查正在重跑。

判定:代码审查通过、无回归信号、测试真实有效;等 7046efab 的 test 矩阵转绿即可人工合并:#1836

@ranxianglei
ranxianglei merged commit c0fd62e into master Oct 1, 2026
13 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 1, 2026
@ranxianglei
ranxianglei deleted the 2026-10-01_dsh-window-retry 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant