Skip to content

fix: dsh settings panel pre-flights the embed route before framing (#3100) - #3117

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-14_dsh-stale-proxy-guard
Oct 14, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-14_dsh-stale-proxy-guard

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3100

What & why

After a profile auto-update, the dsh settings panel showed raw JSON (no such management endpoint) inside its embedded frame while model proxying and compression kept working.

Root cause: the profile bundle refreshes on DISK (0.1.187 → 0.1.196 in the report) while the long-running proxy child keeps serving the build it booted with (#1603 semantics — restarting the proxy means restarting the host). The browser half of the panel always runs the freshest on-disk code, so right after an update it frames /__bili/?embed=1&lang=... — the query-form UI route that only exists in servers >= v0.1.189 (#2321) — and a frozen older server answers it with a 404 rendered verbatim inside the iframe. Old-client + new-server works (the route accepts both forms); new-client + old-server breaks — exactly the transient state after every auto-update until the host restarts.

(The reported port move 18787 → 18796 is separate and by design: lane migration #1660/#1723; the client already follows the live origin, #2288.)

Changes

  1. Client pre-flight (src/agent/dsh-native-client.ts) — probe the exact embed URL once per origin BEFORE mounting the frame:
    • HTTP 200 + text/html ⇒ mount the frame (as today);
    • any other answer ⇒ the running build predates the route ⇒ bilingual "restart dsh" notice instead of a broken frame; the existing open-in-browser button stays and targets the bare /__bili/ form, which every build serves;
    • network error ⇒ no verdict; the origin poll re-probes on its regular ticks (connecting placeholder meanwhile).
    • Verdicts cache per origin for the page lifetime: a frozen process cannot gain routes mid-session.
  2. Server diagnostics (src/server/admin.ts) — the unknown-admin-path 404 now carries version/commit (running) plus best-effort diskVersion/stale from detectStaleInstall (local-only fs, cannot hang), so the skew is readable from the error itself instead of log archaeology.
  3. Tests — tests/dsh-settings-ui.test.ts: shared mountClient harness (fresh vm realm per mount, React-semantics stubs) now drives every panel scenario; all blocks assert the pending-first-paint contract; new dsh admin UI returns no such management endpoint after profile auto-update #3100 regression test pins stale-server notice, transient-failure recovery, and verdict caching. tests/admin-origin.test.ts: pins the enriched 404 body (message byte-identical).

Behavior changes (old → new)

No config surface change. No kernel change. No wire change to model or compression paths.

Verification

Local targeted runs (full-suite verdict = CI on the pushed head):

  • npm run typecheck — green
  • node --import tsx --test tests/dsh-settings-ui.test.ts — 13/13 pass, clean exit
  • node --import tsx --test tests/dsh-settings-ui.test.ts tests/admin-origin.test.ts — 17/17 pass

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_dsh-stale-proxy-guard (3050167)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3562-pr.3117.e7cbd7d

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-14_dsh-stale-proxy-guard branch from eaf66bc to 9267e56 Compare October 14, 2026 04:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #3117 独立审阅 —— 没照抄 issue 侧结论,把 head(9267e56) 的完整 diff 逐段读完并对照 master 改动前的实现核对了既有行为。代码与行为层面已审完:方向正确、无回归、测试有牙。 唯一还没落地的是 4 条全量 test lane 仍在跑,绿了我再给最终八问收工判定。

审了什么、怎么审

  • 拉了完整 diff(4 文件 +511/-309),精读 src/agent/dsh-native-client.ts、src/server/admin.ts 与两个测试文件;每处改动都回看 master 上的原实现,不是只读 diff。
  • 依赖核实:detectStaleInstall(name, runningVersion) 返回 {diskVersion, stale},只做本地 fs(findInstallDir / isGitWorkingTree / readDiskVersion),无网络、try/catch 兜底——它和 /__bili/status 是同一个 helper(feat(update): surface stale-install state to the human + opt-in self-restart (#806 §3) #811),不是新造机制;VERSION/BUILD_COMMIT/PACKAGE_NAME 都从 version.ts 正常导出。

关键行为核对(对照 master 既有行为,逐项过回归)

  • 挂载时序:旧=origin 一知道就挂 iframe;新=一次性预检答到 HTML 才挂,健康宿主 ≤1 个 loopback RTT。这是本 PR 唯一有意的时序变化,PR 正文已如实披露。
  • 【ui】dsh 嵌入面板不跟随宿主深色主题——深色底上文字不可读 #2559 防闪保持:调色板仍是首帧同步采样(useState 惰性初始化走 detectHostTheme),随第一个 iframe 一起带出——预检只推迟 iframe 出现,不推迟采样。
  • 设置面板「打开 Web UI」按钮显示错误的 origin(过时的 __BILI__ 启动快照 / 硬编码默认值 8787)— probeOrigin 被防护逻辑跳过 #2288 live-origin 权威保持:master 的 probeOrigin 注释明确「解析后永不停止轮询(endless slow phase)」,所以「网络错误 → 下一 tick 自动重试」这条成立;onTick 每次有效 tick 都重驱预检,命中判定缓存就是纯内存读、零额外网络。
  • 判定缓存安全:per-origin Map、页面生命周期有效;冻结进程不会中途长出新路由,缓存不会过期;liveEmbed 还校验 embed.origin === origin,跨 origin 重绑时不会误读上一个 origin 的判定。
  • 404 body:message 字符串逐字节不变(测试专门断言钉死),只在 error 里新增 version/commit/diskVersion/stale;diskVersion 为 undefined 时被 JSON.stringify 丢弃,正好对上「未知则省略」。
  • 后备按钮:始终指向裸 ${origin}/__bili/(master line 315 确认),stale 态下依然可用——旧服务端也服务裸路径,所以重启前有真实兜底。
  • 一个可接受残差:纯 snapshot-only 宿主(live /bili/origin 根本不存在)若恰好首次挂载预检就遇网络错误,没有重试兜底会停在 connecting。但那种子场景里代理刚在启动时上报过 origin,同一 loopback 同时断连概率极低,而且旧代码在这个位置渲染的本就是坏 iframe——不算回归,属可忽略边角。

测试有效性(质量关)

  • 两个测试都跑真实发布 bundle(esbuild 直接吃 tsup.config.ts 的 banner/footer/externals),在 vm realm 里用 React hook 语义仿真驱动,不是 mock 掉组件逻辑——断言的是可观察输出(渲染树、文案、按钮目标、fetch 计数)。
  • dsh admin UI returns no such management endpoint after profile auto-update #3100 回归测试确实有牙:stale 用例断言「非 HTML 应答绝不挂帧」+ 出现重启提示 + 只剩裸路径按钮且点击开的是 /__bili/;transient 用例断言网络错误读作 connecting(而不是 stale)、逐 tick 重试直到成功、判定落地后 fetch 计数钉死不再重取。修复一旦回归,这些断言会真红。
  • admin-origin.test.ts 新增断言 message 字节不变 + 三个新字段类型,把 404 契约钉住了。

当前门禁状态(head 9267e56)

  • ✅ 静态门(typecheck/build/static-gates,ubuntu/windows × node 22/24 全绿)、kernel-guard / pi-subagents-guard / version-guard / config-surface-guard / lock-sync / docs-sync / unused-exports / build-artifact / test-import-graph / lane-guard
  • ✅ 全部 e2e lane(real dsh / codex / pi / opencode-v2 / hermetic registry 等)
  • ⏳ 仅剩 4 条全量 test lane(ubuntu/windows × node 22/24)in_progress,目前 0 失败

结论(暂)

代码审查通过:修的是根因(新前端对着冻结旧服务端发只有新版才有的 query 路由 → 一次性预检区分「构建太老」和「网络没就绪」),不打症状补丁;无回归、无缓存破坏、无设计转向、无新配置(除已披露的挂载时序)。等 4 条 test lane 转绿我给最终八问判定 + 合并建议。

…3100)

After a profile auto-update, the browser half of the dsh settings panel always runs the freshest on-disk code while the long-running proxy child keeps serving the build it booted with. Right after an update the new client frames /__bili/?embed=1&lang=... — a query-form route that only exists in servers >= v0.1.189 (#2321) — and a frozen older server answers it with a raw JSON 404 rendered inside the iframe ("no such management endpoint") while model proxying and compression keep working.

- client: one-shot HTTP pre-flight to the exact embed URL per origin before mounting the frame. HTML answer => mount; any other answer => running build predates the route => bilingual restart-dsh notice instead (the backup button targets the bare /__bili/ form every build serves); network error => pending placeholder retried on the regular origin-poll ticks. Verdicts cache per origin for the page lifetime (a frozen process cannot gain routes mid-session). Panel gains connecting/stale states.

- server: unknown-admin-path 404 carries the running version/commit plus best-effort diskVersion/stale from detectStaleInstall (local-only fs) so the skew is readable from the error itself. Message byte-identical for existing consumers.

- tests: shared mountClient harness (fresh vm realm per mount) drives all panel scenarios; every block asserts the pending-first-paint contract; new #3100 regression pins stale-server notice, transient-failure recovery and verdict caching; admin-origin suite pins the enriched 404 body.

Behavior changes (disclosed): the embedded frame now mounts only after the pre-flight verdict (<=1 loopback RTT on healthy hosts); previously it mounted as soon as an origin was known. Theme-flash guarantee (#2559) preserved: palette still sampled synchronously on first render. Unknown /__bili/* and /__acp/* 404 bodies gain additive fields (version, commit, diskVersion, stale) inside error; message unchanged. No config surface change, no kernel change, no wire change to model or compression paths.
@ranxianglei
ranxianglei force-pushed the 2026-10-14_dsh-stale-proxy-guard branch from 9267e56 to 3050167 Compare October 14, 2026 04:43
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

更新:那 4 条 test lane 确实红了,但不是这个 PR 的锅——是基线过期(stale base)。我查清了根因、把分支 rebase 到当前 master,新 CI 正在跑。完整结论如下。

CI 为什么红:根因是基线过期,不是本 PR

我做了什么

把 PR 分支 rebase 到当前 master b5b73b396(带上那个 golden 修复)。干净无冲突——我核对过 merge-base 两侧 diff 交集为空(PR 与 master 新增改动零文件重叠)。已推回分支,新 head 305016773,diff 相对 master 仍精确等于原 4 个文件。新 CI 正在跑。

代码本身:结构化八问(独立审过 diff + 对照 master 现有实现)

  1. 是什么问题:profile 自动更新后磁盘变新、长驻代理进程还是旧构建,而新前端去请求只有新版才有的 /__bili/?embed=1 query 路由,旧服务端回原始 JSON 404 被渲染进 iframe。
  2. 什么原因:版本/生命周期错配——浏览器侧永远跑磁盘最新代码,代理子进程冻结在启动构建(plugin 模式重启 bili=重启宿主,auto-update installs but never activates on long-lived plugin hosts; unwritable install dir retries every 3-min cycle for 11+ days #1603);query 路由 v0.1.189 才引入(dsh设置位置提供真的设置面板 #2321)。
  3. 影响范围/严重度:仅「自动更新后→重启 dsh 前」窗口内打开内嵌设置页的用户;模型/压缩主路径不受影响(不同路由);有绕行(重启 dsh 或裸 /__bili/)。特定条件下的功能受损。
  4. 怎么修的:客户端挂 iframe 前对精确 embed URL 发一次性预检——HTML⇒挂帧;其他应答⇒判定构建太老⇒双语「重启 dsh」提示(保留指向裸 /__bili/ 的后备按钮);网络错误⇒connecting 占位、由 origin 轮询下 tick 重试;判定按 origin 缓存整页生命周期。服务端 404 body 附加 running version/commit + 尽力而为 diskVersion/stale(复用 feat(update): surface stale-install state to the human + opt-in self-restart (#806 §3) #811 的 detectStaleInstall,纯本地 fs)。修的是根因(区分「构建太老」vs「网络没就绪」),不打症状补丁。
  5. 回归问题:逐项核过——404 message 逐字节不变(仅 error 内加字段);【ui】dsh 嵌入面板不跟随宿主深色主题——深色底上文字不可读 #2559 防闪保持(调色板首帧同步采样随首帧带出);设置面板「打开 Web UI」按钮显示错误的 origin(过时的 __BILI__ 启动快照 / 硬编码默认值 8787)— probeOrigin 被防护逻辑跳过 #2288 live-origin 权威保持(probeOrigin 解析后永不停轮询,网络错误能靠下 tick 重试);判定缓存按 origin 隔离、跨 origin 重绑不误读;模型/压缩 wire 路径未触碰。唯一有意时序变化=挂载推迟 ≤1 个 loopback RTT(已披露)。可忽略残差:纯 snapshot-only 宿主首次预检恰遇断网会停在 connecting(旧行为此处本就是坏 iframe,非回归)。
  6. 是否破坏缓存:否。per-origin 判定缓存是页面生命周期内的纯内存 Map,不落盘不跨进程,不影响任何既有缓存/重试/游标/去重键。
  7. 是否改设计方向:否。无架构/边界/数据流转向。
  8. 是否引入新配置:否。无新 env/config/默认值。

行为变更披露(旧→新,同 PR 正文)

  • iframe 首帧:origin 已知即渲染 → 一次性预检答 HTML 后渲染(健康宿主 ≤1 RTT)。
  • 面板新增 connecting / stale 两个显示态。
  • 未知 /__bili/*、/__acp/* 404:message 不变,error 内新增 version/commit/diskVersion(未知则省略)/stale。

结论

代码审查通过、无回归、无缓存破坏、无设计转向、无新配置;红 CI 纯属基线过期(master 上的 #3119 已修好),我已 rebase 清除。等 rebase 后的 test lane 转绿我给最终合并放行——预期必绿:master 在这 4 个 golden 上本就全绿,且 PR 与其零文件重叠。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

放行确认:rebase 后新 CI(head 305016773)全绿 18/18,包括全部 4 条 test lane —— 之前那 4 个 storage-render golden 失败随 rebase 一起消失,证实红 CI 纯属基线过期、与本 PR 无关。

最终状态

结论

可以合并。 若想让我把分支再 rebase 到最新 master 让状态变 clean 也行,但那会再触发一轮完整 CI(~15 分钟共享算力)而收益为零——当前直接合并即可。合并动作按规矩留给你:#3117

@ranxianglei
ranxianglei merged commit 9db9cb1 into master Oct 14, 2026
33 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.412-master.9db9cb1 (rolling master tag).

npm install -g billion-context@0.0.412-master.9db9cb1  # 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dsh admin UI returns no such management endpoint after profile auto-update

1 participant