Skip to content

fix: window credibility as first-class state on every surface (#1849) - #1929

Closed
ranxianglei wants to merge 8 commits into
masterfrom
2026-10-02_window-authoritative-1849
Closed

ranxianglei wants to merge 8 commits into
masterfrom
2026-10-02_window-authoritative-1849

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1849

Problem

When no authoritative context window reaches the proxy (plugin header, runtime-info, launcher env, operator-configured route model, tier negotiation), sizing falls back to published guesses (registry-peek / built-in table / default) — and every downstream percentage (nudge bands, /acp panel, Web UI bars, stats) silently becomes estimate-grade. The dsh web-profile flavor is the worst case (#1849): the host structurally never produces a window, a 1M model gets sized against 253725 (~25%), and the only trace is one info line in bili.log.

Design (per the issue's two open points)

  1. Granularity + boolean — windowAuthoritative: boolean, derived per request from the winning source: authoritative = plugin / runtime-info / launcher / configured / anthropic-beta / model-suffix, or operator tuning (compress.modelContextLimit), or the codex REQ: codex 压缩预算协调 + 匿名代理模式拦截伪造(根本解决方案) #321 clamp. Guess = registry-peek / table-or-registry / default.
  2. All three surfaces — stats JSON, Web UI session detail, /acp panel.

Changes

Config surface

None. No new config fields, env vars, or CLI flags — the verdict is derived from data the proxy already resolves per request.

Compression modes

Wire behavior unchanged in both modes: this adds observability fields (JSON) + a human-only panel line inserted before the stripper's footer anchor. Request bodies are byte-identical.

Tests

  • tests/issue1849-window-authoritative.test.ts (7): classification unit tests + e2e — guess path marked estimate-grade on status JSON + panel + stats with info-grade log; plugin-present-but-silent escalates to warn; plugin header and runtime-info authoritative with no banner.
  • tests/dsh-native-window-warn.test.ts (3): resolver-without-window warns once durably; no-resolver warns; services-never-bind warns after 3 stamps while healthy services never warn.

Gates

Out of scope

The dsh host-side root cause (web profile structurally producing no window — the issue's candidates a–d) needs a live dsh web instance and belongs to the dsh host; this PR guarantees the degradation is VISIBLE everywhere it lands.

Note for reviewers running locally

Under a bili-proxied shell, BILI_PROVIDER_REWRITES / BILLION_CONTEXT_PROXY leak into dsh-native suites and make planNativeDsh return off (attach tests burn their 15s poll budgets). Scrub them (env -u …) when running those suites locally.

When no authoritative context window reaches the proxy (plugin header,
runtime-info, launcher, operator-configured, tier negotiation), sizing
falls back to published guesses (registry-peek / built-in table /
default) and every downstream percentage silently becomes
estimate-grade. Persist and surface the verdict:

- server: lastWindowAuthoritative on session metadata; sendStats
  carries windowSource + windowAuthoritative; the window-absence log
  splits — plugin-present-but-silent escalates to warn, a plain client
  stays info-grade with guess wording
- plugin /acp: status JSON gains windowAuthoritative; the panel shows
  an ESTIMATE banner (before-footer slot, stripper-safe) exactly when
  non-authoritative
- web UI: session detail badges estimate-grade windows with the source
  named in the tooltip (zh/en)
- dsh-native client: three degradation branches (no resolver, resolver
  without a window, services never binding) each warn once via
  console.warn + persistClientEvent (GUI hosts swallow stderr, #1158)

No config surface changes. The dsh host-side root cause (web profile
structurally producing no window) stays out of scope — this PR makes
the degradation visible everywhere it lands.
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-02_window-authoritative-1849 (86f13e8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1940-pr.1929.bd3fb4b

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

Install instructions are refreshed on each push.

…less flavor rejects every resolve (#1849)

Live-machine e2e (real dsh 0.1.5-rc.2, throwaway profile, npm-pack tarball):
resolveModelInfo exists but rejects every call with
'Cannot read properties of undefined (reading resolveModelInfoFor)' —
master's .catch committed a windowless cache silently, so none of the
client-side #1849 warnings ever fired. The reject branch now warns with
the host's own error (once per process; retryAt-driven retries continue).

Also: dsh-native + dsh-settings-ui suites redirect XDG_STATE_HOME — their
persistClientEvent output was polluting the developer's real bili.log
(40+ stray [dsh-client] lines per full run).
@ranxianglei

Copy link
Copy Markdown
Owner Author

Live e2e verification + one real gap found & fixed (follow-up commit 7219ab3, rebased onto the master sync merge).

Ran the real thing: dsh 0.1.5-rc.2 headless, throwaway profile, npm pack tarball of this branch, isolated XDG_STATE_HOME, real sglang upstream.

1. Proxy-side warn fires live. settings.yaml declares contextWindow: 262144 for the model, yet the plugin never stamps the header — bili.log now says so:

[window] model=qwen3.8-27b source=registry-peek native=262144 effective=262144 ...
[warn] [window] model=qwen3.8-27b agent=dsh sent no context window (x-bili-plugin-context-window absent, no matching runtime-info) — host-configured limit not reaching the proxy; sizing against registry-peek (#1849)

2. Client-side warn had a hole, now closed. Branch-by-branch instrumentation on the live host showed resolveModelInfo EXISTS but its promise rejects on every call, and master's .catch(() => { modelInfo.cached = {provider, model} }) committed the windowless cache silently — none of the three client warning branches (no-resolver / success-without-window / services-never-bound) cover the reject path. The reject branch now warns with the host's own error, and the live run surfaced the actual #1849 host-side root cause in the process:

[dsh-client] bili-native-dsh: host resolveModelInfo rejected for deepseek-official/deepseek-flash: Cannot read properties of undefined (reading 'resolveModelInfoFor') (retries continue) — x-bili-plugin-context-window goes unstamped ...

i.e. dsh's own model-catalog registry is uninitialized in this host flavor — their resolver throws instead of returning. That upstream defect stays out of scope here (candidates a–d in the PR description), but our plugin now names it verbatim on both client surfaces.

3. Test hygiene: the dsh-native / dsh-settings-ui suites were leaking persistClientEvent output into the developer's real bili.log (40+ stray [dsh-client] lines per full run — pre-existing for the attach diagnostics, extended by #1849). Both suites now redirect XDG_STATE_HOME to a throwaway dir.

Gates after rebase: typecheck ✓, 60/60 targeted (window-warn 4 + dsh-native 42 + dsh-settings-ui 7 + issue1849 7) ✓, build ✓.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

按 PR Review 规范完整过了一遍,对照的是当前 head 7219ab3d(含 reject 分支修复 + master sync)。结论先行:可合并(人工合并)——方向严格落在 #1849 已拍板的设计内,wire 零改动、无配置面、测试有牙。两条非阻塞备注见文末。

结构化七问

  1. 是什么问题:没有任何权威窗口到达代理时(plugin header / runtime-info / launcher / configured / tier 协商全空),sizing 落到公开猜测(registry-peek / table-or-registry / default),下游每个百分比(nudge 分母、preflight target、UI 进度条、stats)都静默变估算级,唯一痕迹是 bili.log 一行;dsh 客户端侧还把 resolver 的 reject 路径一并静默吞掉。
  2. 什么原因导致的:窗口来源虽每会话都采到(lastWindowSource 9 值粒度 + effectiveContextLimit),但没作为一等状态统一暴露到三个面;dsh-native 的 model-info 失败路径提交「无窗口缓存」时客户端零信号。
  3. 怎么修复的:按 宿主从不推送上下文窗口时(modelWindows:{})只有一行 warn,未作为一等状态暴露;dsh 原生插件从不写 x-bili-plugin-context-window #1849 拍板的「粒度+布尔」——每请求派生 windowAuthoritative(src/server/context-window.ts 的 AUTHORITATIVE_WINDOW_SOURCES 六权威源 vs 三猜测态;显式 flag 优先、legacy 会话回退按源分类)。三面对齐:/__bili/stats + /__bili/plugin/status 各加 windowSource+windowAuthoritative;Web UI 会话页对估算级窗口打 badge(tooltip 点名来源,escapeHtml 包裹防属性逃逸);/acp 面板走 before-footer slot 插一行 ESTIMATE banner(守 LLM-context 剥离锚点)。窗口缺失日志按插件在场与否分流(在场但沉默→warn、纯客户端→info 且措辞区分「这是设计的回退」)。dsh 侧四条降级分支全接一次性客户端告警(no-resolver / 解析成功但无窗口 / 服务三次未绑定 / reject),console.warn + persistClientEvent 双写(GUI 吞 stderr,方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158)。
  4. 是否有回归问题:wire 两模式字节不变(请求体未动;改动全是 JSON 加键 + 面板人读行 + 日志 + 元数据持久化)。唯一行为变更是日志:warn 从「仅 runtimeAgent 在场」扩到「runtimeAgent 或 runtimeEntry 在场」(omp 式身份 agent 不发 header 也会 warn),并新增纯客户端猜测场景的 info 行——PR 描述已披露旧→新。JSON 全是加键,既有消费者安全。legacy 持久化会话(无 flag)回退按源分类,下个请求即重盖自愈。压缩阈值 / 前缀缓存 / 去重键均未触碰。
  5. 是否破坏缓存:不涉及。纯可观测性 + 只读展示 + 一条日志,不动前缀缓存 / 压缩状态 / 去重键 / 重试游标。
  6. 是否改设计方向:否。仅把既有每会话状态提升为一等可见性,架构 / 边界 / 数据流不转向。
  7. 是否引入新配置:不涉及。无 config/env/CLI flag,判定完全由代理本就逐请求解析的数据派生(避开 config-discipline 陷阱)。

非阻塞备注(不拦合并)

测试有效性

两份新测试有牙、非恒真/mock-only:分类单测覆盖全部 9 源 + flag 双向优先 + 空/null 边界;e2e 起真代理 + mock upstream,断言 status JSON / stats / 日志三面一致且含否定断言(纯客户端不升级 warn、健康服务绝不 warn、新增 reject 分支用例);dsh 侧断言精确行数 + 消息正则。

CI

build-artifact、version-guard、全部 e2e lane(codex / pi / opencode / dsh / real-image)、hermetic registry 均绿;head 7219ab3d 上 4 个全量 test job(ubuntu/windows × 22/24)仍在跑,落地后我再确认一句。你本地 60/60 targeted 已过。

判定:可合并(人工)。方向对、范围干净(11 文件每一行都服务于目的,无跑题 / 无 whitespace churn / 无 lockfile churn)、wire 忠实、无配置面。上面两条 🟡 都不构成阻塞。

, review #1929)

A single boot-race reject that recovers on the next cooldown retry must
not leave a misleading 'host's model config is NOT reaching the proxy'
line; the counter resets on any successful resolve. Warn text now
carries the consecutive count.
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 失败定性 + 两条 🟡 已处理。

**CI(test (windows-latest, 22) on 7219ab3):跨 PR 的既有 flake,与本 diff 无关。**挂的是 tests/logger-session-tag.test.ts(enterSessionContext tags sync... — "missing line sync-tagged")——我的 11 个文件不碰 logger;同一测试在另一条分支的 run(job 110836255690,同为 windows-latest/22)同样挂;近期其余失败 run 挂的都是 #1870 acp_status UPDATE READY(update-notes,另一已知 flake,与本 PR 无关)。新 head 4e3afd77 的 CI 已在跑。

🟡 reject 首次即告警 → 已修(4e3afd77):reject 分支现在累计 3 次连续失败才告警(对齐 noteUnstampedStamp 的阈值思路),任何一次成功 resolve 即清零计数;告警文案带 (xN consecutive)。测试同步改为:前 2 次拒绝零输出、第 3 次落行、恢复后盖出窗口且无新行。定向 85/85 绿(window-warn 4 + dsh-native 42 + dsh-settings-ui 7 + issue1849 7 + runtime-info 25)+ build ✓。

🟡 #1849 Defect B 跟踪 → 已拆独立 issue #1932(dsh 插件窗口上报不感知真实请求模型/多档位——refreshModelInfo 只读全局默认选择、headersFor(_url) 不收请求体真实 model、单条缓存多模型互相覆盖;含待拍板的三个设计点)。Fixes #1849 保持,可见性诉求由本 PR 收口。

另:#1849 的宿主侧根因(dsh headless resolveModelInfo 每次抛 Cannot read properties of undefined (reading 'resolveModelInfoFor'))已在 #1932 里注明属 dsh 侧缺陷、另案处理。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

复核了最新 head 4e3afd77(含 reject 计数修复),代码与 CI 都逐条核过。两条 🟡 都收口且验证通过;但新 head 冒出一个本 PR 自带新用例的定时 flake,当前红在 test (ubuntu-latest, 22) —— 这是现在唯一挡合并的点。

七问(增量复核,未变者简述)

  1. 是什么问题:同前(窗口可信度作为一等状态暴露到三个面)。本轮无新增代码问题。
  2. 原因:无变化。
  3. 怎么修的:reject 分支由「首次即告警」改为「连续 3 次失败才告警、任一次成功清零」——核过代码正确:.catch 里 consecutiveResolveFailures += 1 位于 selectionStillCurrent 守卫之后(跨模型的陈旧回调不计入)、>= 3 触发(前 2 次静默、第 3 次带 (x3 consecutive),off-by-one 对);.then 成功路径 = 0 复位;_resetWindowWarningForTest() 也清了这个计数(测试隔离完整)。CI 日志里 x3 告警行确实落出来了。
  4. 回归:无。wire 两模式字节不变维持;JSON 加键消费者安全;日志行为变更已在 PR 描述披露旧→新。
  5. 缓存:不涉及。
  6. 设计方向:不转向。
  7. 配置:不涉及。

两条 🟡 处置确认

新问题:本 PR 新增用例定时 flake(唯一挡合并项)

head 4e3afd77 全量 CI:14/15 绿,仅 test (ubuntu-latest, 22) 红。失败的是本 PR 自己的新用例:

not ok 763 - #1849 apply(): a resolver that REJECTS warns after three consecutive failures
error: 'timeout waiting for recovery resolve'   # waitFor 命中 15s 上限
tests/dsh-native-window-warn.test.ts:232   (POLL_DEADLINE_MS = 15000)

判读:测试定时敏感,不是产品逻辑回归。证据链:

  • 计数那一半是对的——日志紧挨着就有 (x3 consecutive) 告警行,说明「3 连拒→告警」成立;挂的是后面的 recovery 阶段(把 mock 切成成功后,只调一次 headersFor 再 waitFor(attempts >= 4))。
  • 同一份代码同一 OS 家族:ubuntu/24、windows/22、windows/24 全绿,本地你 85/85 也绿——确定性 bug 会四个 cell 全挂;只有一个 cell 挂 + 本地过 = 负载/时序相关。
  • 该用例构造上就吃时序:真实 setTimeout(10/50/60ms) + 15s 轮询 + 依赖那一次 headersFor 调用恰好落在异步刷新状态之外。CI 并行 60+ 测试文件抢 CPU 时,recovery 调用没能在 15s 内让 attempts 到 4。

按 §7.2「测试必须确定性、不得依赖环境运气」,这条新用例本身要修,而不是靠重跑碰运气。建议(任选,作者定):

  • recovery 阶段别只调一次 headersFor——短循环调几次直到 attempts >= 4,或先 await _settleNativeForTest() 排空在途链再断言;或
  • 给这条断言单独放宽 deadline(现在和整个用例共用 15s)。

它是全新用例,就地修掉最干净,免得合进去后某次 run 又红。需要的话我可以给具体 patch。

判定

代码方向对、两条 🟡 已验证收口、wire 忠实、无配置面——逻辑上可合并。但当前 head 因这条 flaky 测试红着 ubuntu/22,建议先把该用例改成确定性(或至少重跑转绿)再合。修好即合。

…ow to the proxy (#1849)

The headless flavor's llm.resolveModelInfo rejects every call (its model
catalog is never initialized) and the web-profile flavor binds neither
model service — in both shapes x-bili-plugin-context-window went unstamped
forever and the proxy silently sized against registry-peek. The host's
own launch config (~/.dsh/settings.yaml) declares this session's model
and its contextWindow; read it (line-based, dependency-free, READ-only —
same discovery discipline as parseDshSettingsYaml) as the fallback:

- resolve rejected / resolver absent / resolved-without-window → the
  current selection's window from settings.yaml lands in modelInfo.cached,
  so the existing header stamp (:860) and the #955 runtime-info report
  carry the REAL number; the degradation warn only fires when even the
  file cannot supply one
- services never bound at all (web profile) → settings.yaml's
  agent-default-model states the model + window directly
- live-verified on real dsh 0.1.5-rc.2 headless: session metadata flips
  winSrc=registry-peek/auth=false → winSrc=plugin/auth=true
@ranxianglei

Copy link
Copy Markdown
Owner Author

#1849 送达修复已并入本 PR(38abfd96,rebase 在最新 sync-merge 之上,typecheck/build/定向 85/85 绿)。

按 owner 方向落地(不建每模型清单,只取当前 session 所选模型的窗口):~/.dsh/settings.yaml 本来就声明着本会话模型和它的 contextWindow——插件现在把它作为兜底读进来(行解析、无新依赖、READ-only,与 parseDshSettingsYaml 同一发现纪律):

  • resolveModelInfo 被 reject(headless flavor 每次必炸)/ resolver 缺失 / resolve 成功但无窗口 → 当前 selection 的窗口从 settings.yaml 落入 modelInfo.cached,既有的 :860 盖头与 [native] runtime-info protocol: plugins report real model config (model / contextWindow / maxOutput) to the proxy #955 runtime-info 上报自动带上真实数字;降级 warn 只在连文件都给不出数时才响
  • 服务从未绑定(web-profile flavor)→ agent-default-model: 直接给出模型+窗口
  • 服务路径健康时行为零变化(service 值优先,fallback 只补位)

真实 dsh 0.1.5-rc.2 headless 活体验证(宿主 resolver 仍每次抛 undefined.resolveModelInfoFor):

  • 修复前:winSrc=registry-peek, auth=False(猜的)
  • 修复后:会话 winSrc=plugin, auth=True —— x-bili-plugin-context-window: 262144 送达,代理按权威窗口计量
  • 客户端留痕一行:[dsh-client] settings.yaml contextWindow 262144 for local-vllm/qwen3.8-27b used as fallback — the host's llm service could not serve it (#1849)
  • 首请求存在一次竞速(fallback 在 reject 落定后才进缓存,首个请求仍走 registry-peek)——这与健康 desktop flavor 的首请求竞速同病,第 2 个请求起即盖戳;如需消除可后续在 boot 早读

测试:tests/dsh-native.test.ts +3(reject 兜底盖头+上报 / 无服务兜底 / 未声明模型保持降级 warn)、tests/launcher.test.ts +1(parseDshContextWindows 解析矩阵:多 provider 块/引号 id/内联注释/窗口先于 id/非数值/块闭合边界)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

复核了最新 head 38abfd96(#1849 送达修复并入)。这轮把 PR 从「纯可观测性」推进到「真正把权威窗口送达」——我逐行核了新增代码(parser + refreshModelInfo 接线 + 服务端 source 归类)与测试。CI 15/15 全绿(含上轮 flaky 的 reject-recovery 用例,四个 test cell 都过了)。结论:可合并(人工)。

结构化七问

  1. 是什么问题:dsh headless flavor 里宿主 llm.resolveModelInfo 每次 reject(模型目录未初始化),代理拿不到窗口只能对 registry 猜测计量;本轮让插件从宿主自己的 ~/.dsh/settings.yaml 兜底读出本会话模型的 contextWindow,把窗口真正送达。
  2. 什么原因导致的:服务侧取不到值时缺一个可信兜底源;settings.yaml 正是宿主启动模型所用的同一份真源。
  3. 怎么修的:新增 parseDshContextWindows / readDshContextWindows / readDshSelectionWindow(src/client-config.ts,行扫描、无新依赖、READ-only、解析失败→空 map 安全降级);refreshModelInfo 三条失败路径(无 resolver / resolve 成功但无窗 / reject)落 cache 前先查 settings.yaml,查到就带真实数字进 modelInfo.cached,既有的 :860 盖头 + [native] runtime-info protocol: plugins report real model config (model / contextWindow / maxOutput) to the proxy #955 runtime-info 自动带上;service 值始终优先、fallback 只补位;文件按进程读一次(memoized,非每请求 fs)。web-profile(两服务都没绑)走 agent-default-model: 直接给模型+窗。
  4. 是否有回归问题:wire 仍字节不变(盖的是同一个 header、同一个 runtime-info 形状,只是降级场景现在带真值)。服务端 source 归类我专门核了:src/server.ts:1726 按通道判 wsSource(header→plugin、runtime-info→runtime-info,两者都在权威集),lastWindowSource(:2588)同样来自通道而非客户端上报的 "client-config" 字符串——不存在「client-config 被当估算态」的降级风险,与你实测 winSrc=plugin, auth=True 一致。「停重试」注释也对:base refreshModelInfo:182 同 provider/model 短路,settings 一旦填进 cached 就不再打坏掉的服务。健康服务路径零变化(service 优先);未声明模型保持降级 warn(有否定测试钉住)。
  5. 是否破坏缓存:不涉及。前缀缓存 / 压缩状态 / 去重键未触碰;settings 读取是进程级 memoize,不引入请求级 IO。
  6. 是否改设计方向:否。严格落在 宿主从不推送上下文窗口时(modelWindows:{})只有一行 warn,未作为一等状态暴露;dsh 原生插件从不写 x-bili-plugin-context-window #1849 拍板范围——只取当前会话所选模型的窗口,不做每模型清单(那是 Defect B,已拆 dsh 插件窗口上报不感知真实请求模型/多档位(#1849 遗留 Defect B,待设计拍板) #1932)。READ-only 发现宿主配置,契合既有 client-config 纪律(Key Design fix: post-merge review fixes + per-route context window + XDG config #6)。
  7. 是否引入新配置:不涉及。读的是宿主 dsh 的 settings.yaml(READ-only),bili 侧没加任何 config/env/CLI。

行为变更(旧→新,你已披露、我确认成立)

  • dsh headless、且 settings.yaml 声明了本会话模型 contextWindow 时:窗口来源 registry-peek(auth=False,猜的) → plugin(auth=True,权威)。本 PR 核心收益。
  • 健康服务路径 / 未声明模型:不变。

非阻塞备注(均不拦合并)

  • 🟡 首请求竞速(你已注明):fallback 在 reject 落定后才进 cache,第 1 个请求仍走 registry-peek、第 2 个起盖戳。与健康 desktop 首请求竞速同病,可选后续在 boot 早读消除。
  • 🟡 行扫描耦合 dsh 格式:parser 是 best-effort 行解析,若 dsh 改 settings.yaml 布局,兜底会静默退回降级(安全不崩,但能力悄悄失效)。已有较全边界矩阵(多 provider 块 / 引号 id / 内联注释 / 窗口先于 id / 非数值·0·负数 / 块闭合边界 / 空串),风险可控;仅提示这条隐式耦合。
  • ⚪ web-profile flavor 用 agent-default-model 作模型身份:若实际运行模型≠默认,盖的是默认的窗。该 flavor 下无其它真源,属固有局限,已标为 fallback。
  • ⚪ readDshSelectionWindow 为查一个模型整份重跑一次 parseDshContextWindows(O(n) 冗余);settings.yaml 很小,可忽略。

测试有效性

三份新用例都有牙、含否定断言:reject 兜底断言 header 具体值 131072 + runtime-info 带值 + #1849 warn 数为 0;无服务兜底断言 65536;未声明模型断言 header undefined(不发明窗口);parseDshContextWindows 矩阵覆盖块边界 / 引号 / 注释 / 非数值 / 空串。非恒真、非 mock-only。

CI

head 38abfd96:15/15 绿(ubuntu/windows × 22/24 四个全量 test、build-artifact、version-guard、全部 e2e lane、hermetic registry)。上轮 ubuntu/22 那条 flaky reject-recovery 用例本轮四个 cell 全过。

判定

可合并(人工)。范围干净(14 文件每一行服务于目的)、wire 忠实、无 bili 配置面、无缓存影响、测试有牙、CI 全绿。这轮把 #1849 从「看得见」推进到「送得到」,方向与实现都对。上面几条 🟡/⚪ 均不构成阻塞。

…indows (#1849)

settings.yaml only carries models the user declared. When the headless
host never initializes the pi-ai catalog, resolveModelInfo rejects and
the settings file may not contain the selected model either (e.g. dsh
alias ids like deepseek-flash). Read the host's own bundled sources -
@earendil-works/pi-ai dist/providers/all.js (1354 models) and
@deepseek-ai/dsh-llm-deepseek resolveAdapterOptions - as a second
fallback tier, mirroring what the in-memory route resolution would
have served. Settings win over catalog; both are best-effort.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Follow-up to 38abfd9 — second fallback tier: the host's bundled model catalog.

Why: settings.yaml only carries models the user declared. Two real gaps remain when the headless host never initializes the pi-ai catalog:

What memory actually serves is the merge of settings-declared models and the bundled catalog (resolveRouteModels: route without a models list uses the builtin catalog wholesale). The fallback now mirrors that merge.

Sources (read-only, best-effort, absolute-path require of the host's own dist files — no exports-map games):

  • @earendil-works/pi-ai/dist/providers/all.js — 1354 models with contextWindow (walk-up from the plugin's own dirname/cwd to node_modules);
  • @deepseek-ai/dsh-llm-deepseek/lib/index.js → resolveAdapterOptions({}, undefined) — the 4 deepseek-official defaults (deepseek-flash / v4-flash / v4-pro / v4-flash-vision-exp, window 1000000).

Priority: service/memory (unchanged, authoritative) → settings.yaml → bundled catalog → previous warn-only behavior. Every tier reports through both existing channels (per-request stamp header + #955 runtime-info table), so the proxy's [window] model=… native=… effective=… line gets the real number either way.

Live verification (throwaway dsh profile, global settings backed up/restored, diff-verified identical):

  • loader probe: both sources load from the real dsh install tree, 1354 + 4 entries;
  • provider deepseek-official + deepseek-flash: dsh's own adapter route resolves successfully in-memory (it is self-contained) — proxy sized native=1000000 effective=1000000 from the runtime-info table; no fallback note fired (correct: service path won, design intends it to);
  • provider deepseek + deepseek-flash still hard-fails at dsh boot (UNKNOWN_MODEL) — host-side validation, out of our reach.

Known edge (unchanged): first-request header race — the stamp header is computed before the reject lands; the runtime-info report lands during flight and the proxy sizes from the table (second request onward carries the header). Same shape as the desktop healthy path.

Gates: typecheck ✅ · dsh-native 48/48 + launcher 266/266 ✅ · build ✅

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

复核了最新 head fbfdd808(第二兜底层:宿主捆绑模型目录)。这轮是整条 PR 里安全面最需要盯的一块(绝对路径 require 宿主 dist 文件),我逐行读了 loader + 接线 + 三条失败路径 + 新测试。代码正确、best-effort 防崩、优先级对、测试确定性且带牙。CI 目前 13/15 绿,仅剩两个 windows 全量 test job 在跑。结论:可合并(人工)——待那两格落地转绿即合。

结构化七问(本轮增量)

  1. 是什么问题:settings.yaml 只带用户声明过的模型;headless 宿主从不初始化 pi-ai 目录时还有两个真实缺口——①所选模型走的是无 models: 列表的 pi-ai route(文件里没有,如规范 id deepseek-v4-flash);②dsh 自己的 alias id(deepseek-flash)只存在于 dsh-llm-deepseek 的 route 默认值。本轮按「memory 实际服务的是 settings ∪ 捆绑目录」把这两个也补上。
  2. 原因:见上——单一 settings 源覆盖不到纯目录服务的模型与 dsh alias。
  3. 怎么修的:新增 loadBuiltinWindowIndex()(src/agent/dsh-native.ts)从宿主自身安装树读两份源:@earendil-works/pi-ai/dist/providers/all.js(getBuiltinProviders/getBuiltinModels,1354 模型)、@deepseek-ai/dsh-llm-deepseek/lib/index.js(resolveAdapterOptions({}, undefined) 的 4 个 deepseek-official 默认值)。fileWindowFor() 串成 service → settings.yaml → 捆绑目录 → 原 warn-only 四级链;每条命中都走既有两通道(盖头 + [native] runtime-info protocol: plugins report real model config (model / contextWindow / maxOutput) to the proxy #955 runtime-info)。
  4. 回归:wire 仍字节不变(同一 header/runtime-info 形状,只是更多降级场景带真值)。优先级我三条路径都核了:.then 成功 svc 优先;svc 无窗 / reject / 无 resolver 才进 fileWindowFor(settings 先于 catalog);scoped-id 查询先于 bare-id,避免跨 provider 撞 id。惰性确认:loadBuiltinWindowIndex 只在降级路径经 fileWindowFor 触达,健康服务路径零成本(不 require、不读盘)。服务端 source 归类同前轮已核(通道判 plugin/runtime-info,均权威)。
  5. 缓存:不涉及。前缀缓存/压缩状态/去重键未动;目录索引进程级 memoize(builtinWindowIndex),非每请求。
  6. 设计方向:不转向。仍是「只取当前会话所选模型的窗口」的 READ-only 发现,未做每模型清单(Defect B = dsh 插件窗口上报不感知真实请求模型/多档位(#1849 遗留 Defect B,待设计拍板) #1932)。
  7. 配置:不涉及。createRequire 是 node:module 内建,无新 npm 依赖、无 bili config/env/CLI。

⚠️ require 宿主文件的定性(本轮核心风险,已评估为可接受)

  • 执行的是宿主自己的 dist(launch 我们的那个 dsh 安装树),与宿主同信任域,不是第三方/不可信代码。
  • 防崩完备:每次 createRequire(…)(absPath) 都在 try/catch 里,失败→下一候选→空索引→优雅降级。模块缺失 / 形状漂移 / ESM 在旧 Node 上 require(esm) 失败,任何一条都不会把插件打崩。
  • 类型干净:只用 as {…} 具名对象断言,无 as any / @ts-ignore。
  • 一个前提假设(值得写明):假定这些宿主模块加载时无副作用(纯数据/定义模块)。合理,但若某宿主版本给 all.js/index.js 加了加载期副作用,会在插件进程里执行——属可接受但需知晓的边界。

非阻塞备注(均不拦合并)

  • 🟡 deepseek 循环 break 时机:首个候选 index.js 只要 require 成功 就 break(不看是否拿到 models),若该文件能加载但 models 为空(形状漂移)就不会再试更深的候选;与 pi-ai 循环的 if (index.size>0) break 不一致。影响小(通常只有一个该包),建议对齐成「拿到非空才 break」。
  • 🟡 bare-id 撞车:provider 未知时 catalogWindowFor 落到 bare ${model},跨 provider 同名 id 取「先见者」(迭代序不定)可能选错窗。provider 已知(常态)走 scoped 无误。边界情形。
  • ⚪ walk-up 布局耦合:从 argv[1]/cwd 向上 6 层找 node_modules,与上轮 settings 行扫描同类——dsh 改安装树会静默退回降级(安全不崩)。已有活体验证(1354+4)佐证当前布局成立。
  • ⚪ 首请求竞速维持不变(你已注明)。

测试有效性

三份新目录用例 + 保留的 settings 用例都带牙且确定(_setBuiltinCatalogForTest 直接注入索引,无需真 pi-ai 安装):断言具体值 1000000、262144(证明 settings 压过 catalog 的优先级)、日志点名 bundled model catalog … deepseek/deepseek-v4-flash(钉住 source 归属)、以及未声明模型 → header undefined 的否定断言。_resetWindowWarningForTest 同步清 builtinWindowIndex,隔离完整。

活体验证(你做的,我认可其严谨度)

throwaway 画像 + 全局 settings 备份/还原并 diff 验证一致(没污染真实配置);loader probe 1354+4;deepseek-official/deepseek-flash 内存解析成功(service 路径赢、无 fallback note——符合设计意图);deepseek/deepseek-flash 仍在 dsh boot 硬挂(UNKNOWN_MODEL,宿主侧校验,out of scope)。

CI

head fbfdd808:build-artifact、version-guard、全部 e2e lane、hermetic registry、ubuntu×{22,24} 全量 test 均绿;剩 windows×{22,24} 两个全量 test job 在跑,落地后我确认一句。

判定

可合并(人工)。范围干净(14 文件每行服务于目的)、wire 忠实、无 bili 配置面、无缓存影响、测试确定且有牙、require 风险已评估可控。这轮把 #1849 的送达面补到「settings ∪ 宿主目录」的完整 memory 语义。上面 🟡/⚪ 均不构成阻塞;待最后两格 CI 转绿即可合。

…er for dsh context windows (#1849)

dsh-llm-pi-ai resolves a model's window as entry.contextWindow ??
builtin-by-id ?? request.defaultContextWindow — the route's declared
default. Mirror that order: scoped settings declaration, bare
declaration, bundled catalog, then the route's defaultContextWindow
(or the host's 262144 mirror when unset), gated on the model being
declared windowless under that provider. Provider-aware parsing now
records scoped/bare windows, provider-level defaults, and the
declared-but-windowless set (parseDshWindowSources), fixing the old
parser's providers-mode swallow of deeper models: blocks.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Fourth tier — the route's defaultContextWindow (#1849 follow-up to the catalog layer).

Gap. dsh-llm-pi-ai resolves a model's window in memory as entry.contextWindow ?? builtin-catalog-by-id ?? request.defaultContextWindow. The first two hops are covered (settings declaration, bundled catalog) but the third — a route-level defaultContextWindow — was missing, and it is the REAL common shape for /v1/models-sourced entries: listing endpoints usually return ids without window fields, so the whole route rides its declared default.

Fix. parseDshWindowSources (new, provider-aware) records three things per settings file: scoped+bare model windows, provider-level defaultContextWindow, and the declared-but-windowless model set (models listed under a provider without a contextWindow). The fallback chain in dsh-native.ts now mirrors the host's memory order: scoped settings → bare settings → bundled catalog → route default (providerDefaults.get ?? 262144, the host's DEFAULT_CONTEXT_WINDOW mirror; only served when the model is declared windowless under that provider — an unknown id never gets a fabricated default). Also fixes a parser bug found on the way: the providers-mode branch swallowed deeper models: blocks.

Tests. tests/dsh-native.test.ts 48→52: declared default stamps 400000 + runtime-info + note; unset default mirrors 262144; catalog beats route default for a catalog-known id (memory order); scoped declarations disambiguate one id across two providers. 52/52 green, launcher+dsh-settings-ui+dsh-profile 273 green, typecheck+build green.

Live (real dsh 0.1.5-rc.2, throwaway profile, windowless qwen3.8-27b + defaultContextWindow: 400000): client note [dsh-client] settings.yaml defaultContextWindow 400000 for local-vllm/qwen3.8-27b used as fallback (#1849) and the outbound header carries x-bili-plugin-context-window: 400000. First-request race (header computed before the rejecting resolve lands) unchanged from the previous tier — 2nd request onward stamps; runtime-info still delivers.

Env note for reproducers: the plugin's planNativeDsh returns mode:"off" when BILI_PROVIDER_REWRITES is in the environment (double-compressor guard) — probe shells inside a bili-launched agent must env -u BILI_PROVIDER_REWRITES -u BILLION_CONTEXT_PROXY dsh … or the plugin silently no-ops.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

复核了当前 head 86f13e8a(第四层:route defaultContextWindow + 顺带修了 parser 里 providers-mode 吞嵌套 models: 块的 bug)。这层最关键的正确性我重点核了——**「未知模型绝不发造默认窗」**这条保证,代码与测试双双成立。CI 15/15 全绿(mergeStateStatus=clean)。结论:可合并(人工)。

结构化七问(本轮增量)

  1. 是什么问题:dsh 内存里解析窗口是 entry.contextWindow ?? builtin-catalog-by-id ?? request.defaultContextWindow;前两级上轮已覆盖,第三级 route 级 defaultContextWindow 缺着——而它正是 /v1/models 来源条目的常见形态(listing 只给 id、整条 route 骑在声明的默认值上)。
  2. 原因:单一 source 覆盖不到 route 默认这一跳。
  3. 怎么修的:新增 provider-aware 的 parseDshWindowSources(src/client-config.ts)一次扫出三样:scoped+bare 窗口、provider 级 defaultContextWindow、「声明但无窗」的模型集合;fileWindowFor(src/agent/dsh-native.ts)把链排成 scoped settings → bare settings → 捆绑目录 → route 默认,严格对齐宿主内存顺序。
  4. 是否有回归问题:wire 字节不变(同 header/runtime-info 形状)。核心保证我逐行核了:route 默认只在 providerModels.get(provider)?.has(model)(该模型确实在该 provider 下被无窗声明)时给出,取 providerDefaults.get(provider) ?? 262144;未在任何 provider 下声明的 id 到不了这个分支 → 返回 undefined → 走降级 warn,绝不发造。健康服务 / settings 声明 / 目录路径全部不变(service 仍最优先)。
  5. 是否破坏缓存:不涉及。前缀缓存 / 压缩状态 / 去重键未动;sources 与目录索引都进程级 memoize。
  6. 是否改设计方向:否。链之所以这么长,是因为它逐跳镜像宿主自己的内存解析——目标是「交付宿主真正会用到的那个数」,不是堆料。仍是 READ-only 发现宿主配置,未做每模型清单(Defect B = dsh 插件窗口上报不感知真实请求模型/多档位(#1849 遗留 Defect B,待设计拍板) #1932)。
  7. 是否引入新配置:不涉及。无新 npm 依赖 / bili config / env / CLI。

parser bug 修复确认

providers-mode 之前会吞掉更深的 models: 块;新版用 providersIndent/providerLevel/modelsIndent/blockProvider + sectionProvider() 把每个 models: 块正确归属到外层 provider。测试「scoped declarations disambiguate one model id across two providers」钉住此点。我 trace 了 commitPending:有窗的 id 记录后即清 current,不会漏进 providerModels;只有真正无窗声明的才进集合——与「declared windowless」语义一致。

非阻塞备注(均不拦合并)

  • ⚪ ?? 262144 是宿主 DEFAULT_CONTEXT_WINDOW 的硬编码镜像:若 dsh 改其默认值会静默漂移。已有注释标注;长期若能从宿主侧读出该常量更好,否则保持注释同步即可。
  • ⚪ parser 复杂度/耦合已明显增长:parseDshWindowSources 跟踪 6 个缩进态,实为 dsh settings.yaml 布局的一个 bespoke 子集解析器。best-effort + 安全降级 + 有测试,风险可控;但 dsh 一旦改配置 schema,兜底会静默退回降级。前瞻看,值得评估让 dsh 暴露一个稳定程序化接口,替代 bili scrape 它的 config + require 它的 dist(后者上轮已评估为可接受风险)。
  • ⚪ parseDshWindowSources(providerDefaults/providerModels 抽取)目前仅经 dsh-native e2e 间接覆盖,没有像 parseDshContextWindows 那样的独立矩阵单测。可选增强,非必须。
  • ⚪ 首请求竞速维持不变(你已注明)。

测试有效性(本轮新用例都带牙且确定)

  • route 默认给声明无窗模型 → header 400000 + runtime-info + 日志点名 route-default 层;
  • 未设 defaultContextWindow → 镜像 262144;
  • 目录压过 route 默认(catalog-known id)→ 1000000,钉死「catalog 先于 route default」的内存顺序;
  • 关键否定断言:local-vllm/qwen-undeclared(任何地方都没声明)→ model id 照盖但 x-bili-plugin-context-window === undefined(不发明窗口)+ 降级 warn 照响——端到端验证「未知 id 绝不发造」;
  • parseDshContextWindows 矩阵覆盖多 provider 块 / 窗口先于 id / 非数值·0·负 / 块边界 / 空串。非恒真、非 mock-only。

活体验证(你做的,认可)

真实 dsh 0.1.5-rc.2 throwaway 画像,windowless qwen3.8-27b + defaultContextWindow: 400000 → 客户端 note 点名 route-default 层、出站 header 带 x-bili-plugin-context-window: 400000;全局 settings 备份/还原并 diff 验证一致。BILI_PROVIDER_REWRITES 那条 env 提示很实用(probe shell 要 env -u 掉,否则插件 mode:"off" 静默 no-op)。

CI

head 86f13e8a:15/15 全绿(ubuntu/windows × 22/24 四个全量 test、build-artifact、version-guard、全部 e2e lane、hermetic registry),mergeStateStatus=clean。

判定

可合并(人工)。范围干净(14 文件每行服务于 #1849)、wire 忠实、无 bili 配置面、无缓存影响;核心保证(不发造未知模型窗口 + 目录先于 route 默认的内存顺序)代码与测试双钉、CI 全绿。四层兜底把 #1849 的送达面补到与宿主内存解析完全对齐。上面几条 ⚪ 均为前瞻/可选,不构成阻塞——可以合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

看到你的评审说有阻塞性问题 麻烦修复 另外注意到#1943
是同一类别吗 还是同一个修复

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

先直接回答 #1943:同一类别、不同修复——而且 #1943 是根因修复,#1929 的四层兜底相当一部分是在给它「治标」。 这个关系值得在合并前想清楚。

#1943 修的是什么(diff + CI 都核过了)

src/agent/dsh-native.ts 的 refreshModelInfo:

const resolve = svc.llm?.resolveModelInfo;   // 旧:把方法从宿主 llm 对象上摘下来
…
resolve(provider, model)                      // 调用时 this === undefined

宿主 dsh-llm 的 resolveModelInfo 是类方法,首句 return this.resolveModelInfoFor(this.registration(provider), model, signal)。detach 调用后 this 变 undefined,于是每个模型/每个 provider/每次进程启动都 reject:

Cannot read properties of undefined (reading 'resolveModelInfoFor')

#1943 一行修复即补回接收者:const resolve = svc.llm?.resolveModelInfo?.bind(svc.llm);。回归测试用类形状 stub(方法经 this 读自身状态)精确复现——普通对象字面量测不出,这正是 #955/#956/#1812 那批套件对着坏代码也全绿的原因。CI 14/14 绿、mergeStateStatus=clean。诊断与观测报错逐字吻合,可信。

与 #1929 / #1849 的关系(关键)

关于「阻塞性问题」——澄清

我最近一轮(round 5)对 #1929 的结论是可合并、无未决阻塞项(仅几条 ⚪ 前瞻备注)。历史上唯一我标过「挡合并」的是 round 2 那条 flaky 测试,之后几个 head 的 CI 都转绿(当前 86f13e8a 15/15 绿),已解决。就我的评审而言,#1929 现在没有卡着的阻塞项。若你指的是某一条具体的,指给我,我去查。

建议怎么推进

  1. 先落 fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window #1943(根因、一行、低险、CI 全绿、测试到位)。它是外部贡献者 Dclef 的 PR——按规范我只做 review/验证,不会去推它的分支、接手或建议关闭它来换我自己的 PR;合并由人来。
  2. 再协调 fix: window credibility as first-class state on every surface (#1849) #1929 集成:两 PR 动的是 refreshModelInfo 同一行。后合的那个 rebase 时给那行加上 .bind(svc.llm) 即可(fix: window credibility as first-class state on every surface (#1849) #1929 重写过的函数里仍留着 const resolve = svc.llm?.resolveModelInfo;)。
  3. 重估 fix: window credibility as first-class state on every surface (#1849) #1929 范围:fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window #1943 落地后 resolver 正常返回真实窗口,fix: window credibility as first-class state on every surface (#1849) #1929 里「reject 告警 + settings/目录/route 默认几层文件兜底」对常见 headless 场景就从主路径退成次要安全网。真正独立仍有价值的是:三处面的窗口可信度可观测性(与 resolver 无关)+ 无服务档(web-profile flavor,那里根本没有 llm 服务,bind 帮不上,必须靠文件兜底) + boot race(fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window #1943 也说那是另一缺陷)。要不要据此把 fix: window credibility as first-class state on every surface (#1849) #1929 收敛得更瘦,你拍板。

我能做什么

一句话:同类别;#1943 是根因,#1929 是(部分为它治标的)可观测性+兜底;先合 #1943,再 rebase 集成 #1929 并按需瘦身。

@ranxianglei ranxianglei added the dsh label Oct 3, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

#1943 在本pr没有存在的意义 关闭

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

Projects

None yet

1 participant