Skip to content

[PR] dsh Context tab: bind the embedded frame to THIS conversation (#4117) - #4118

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-21_dsh-ctx-tab-bind
Oct 21, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-21_dsh-ctx-tab-bind

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4117

症状

#4086(0.1.204-ctxembed.1)装机后用户复现:有 acp_delegate 子 agent 运行时,dsh 客户端「上下文」页签的内嵌帧反复切换成子 agent 的会话页,主 agent 恢复活动又切回,来回闪烁。

根因

页签轮询 /__bili/plugin/status?conversationId=dsh&fallback=latest。服务端 conversations map 的 key 是宿主真实 session id(dsh lane 打进 x-bili-plugin-conversation 的 initiator.session.id,src/agent/dsh-native.ts:2024/1428),字面量 "dsh" 精确查几乎永不命中 ⇒ 每次读都落 fallback=latest = 全代理进程最近活跃会话(src/plugin.ts:1552,L1567)。子 agent 是独立 pi 进程、带自己的会话 id 打流量 ⇒ 其 lastSeen 变最新 ⇒ 页签被劫持;主 agent 恢复又切回 = 闪烁。

同一 fallback 歧义还波及 /acp 命令(fetchStatusLatest)与 MCP 重试 lane——本 PR 只修用户可见的页签面,二者留档为后续(见"已知余留")。

修复(纯客户端,server 零改动)

dsh core 给每个 conversation.view 条目传 props——同 slot 的 dsh-cost-meter 直接读 props.sessionId(并与 DOM [data-conversation-session] 比对),与 lane stamp 的 sid 是同一条身份链。于是:

  1. 精确绑定:有 props.sessionId ⇒ 按它精确查询(conversationId=<id>&fallback=latest;保留 fallback 只为让 pre-first-request 面板在首个请求前仍可解析)。
  2. 渲染时所有权门:viaFallback===true && conversationId !== 本会话id(或无 conversationId 字段可证)的行拒绝出帧,落「暂无上下文数据」诚实提示;精确命中无条件信任;旧响应体缺这两个字段 ⇒ viaFallback=false,历史行为不变。
  3. 兼容:旧宿主不传 props ⇒ 字面量老路径逐字节保留(测试 subMount 全部无 props,钉住 legacy URL)。

验证

  • tsc --noEmit 0 错;npm run build rc=0(含 dist-import-annotations / dist-external 门)。
  • tests/dsh-settings-ui.test.ts #3862 重写扩展:主用例改以宿主身份挂载,钉住 exact-id status URL + iframe src/title/polling(10s)/refresh/unmount;新增劫持拒绝子例(外来 via-fallback 会话 ⇒ 无 iframe + not-yet 提示);既有降级态子例保持无 props 钉 legacy 路径。全绿。
  • issue3862-context-view.test.ts + dsh-panel-embed-cors.test.ts 合跑 7/7 绿。
  • 双门 clean:tools/gen-config-docs.mjs generate 零 diff、scripts/check-unused-exports.mjs rc=0。
  • 同电池其余 5 红(给deepseek定制一个跳转到状态的链接 #1590×2/dsh web端和桌面端点击bili设置显示未启动 #1809×3)在干净 master 同红(环境性,已 stash 对照,同 [PR] #3862: Context tab embeds the web UI's own session page #4086 结论)。
  • tests/dsh-native.test.ts 不加载客户端 bundle(grep 确认仅 mock /__bili/plugin/status 服务端侧),失败集与 master 基线一致(此前电池已钉 IDENTICAL FAILURE SETS)。

已知余留(后续 issue 候选)

  • /acp 命令与 MCP 重试 lane 仍用 latest fallback:CommandsService handler 签名无参拿不到宿主会话 id("Host's command API passes no arguments"),需另找通路。
  • 若某宿主版本的 slot props 不含 sessionId(理论上 dsh-cost-meter 已在用,风险极低),页签自动退化为老行为——失败模式安全(无闪烁,最坏显示 waiting/hint 而非错帧)。

The per-session Context tab polled /__bili/plugin/status?conversationId=dsh&fallback=latest. The conversations map is keyed by the host's REAL session id (the value the dsh lane stamps on x-bili-plugin-conversation), so the literal "dsh" exact lookup never hits and every read fell through to fallback=latest = most-recently-active session across the WHOLE proxy process. While an acp_delegate sub-agent (its own pi process, its own conversation id) is active, its session wins that pool: the iframe re-navigates to the child's page and flips back when the main agent resumes — the reported flicker.

Fix (client-only; server byte-for-byte unchanged):
- The host names this conversation to every conversation.view entry (props.sessionId — the same identity dsh-cost-meter reads from the slot props and from [data-conversation-session]); poll for THAT exact id. fallback=latest stays only so the pre-first-request panel still resolves before our own first request.
- Ownership gate at render: a row resolved via the fallback pool whose conversationId is not ours (or carries none) is refused instead of framed — the not-yet hint stands. Exact hits are trusted unconditionally.
- Hosts passing no props keep the historical behaviour bit-for-bit (legacy literal path + render unchanged).

Tests: the embed pin now mounts with the host conversation identity, pins the exact-id status URL, and adds the refusal case (foreign via-fallback session ⇒ no iframe, not-yet hint); subMount cases stay prop-less and pin the legacy path.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_dsh-ctx-tab-bind (00e3db5)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4915-pr.4118.fa0b08e

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title dsh Context tab: bind the embedded frame to THIS conversation (#4117) [PR] dsh Context tab: bind the embedded frame to THIS conversation (#4117) Oct 21, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 全仓 open+closed issue/PR 检索(plugin/status fallback latest、conversationId、dsh Context tab、viaFallback/embedded frame 等失败签名)均无同症状同机制条目;本 PR 是 #4117 的首个修复,#4086 只是触发复现的装机版本,不是独立缺陷。

先报一个 阻断性发现(正在修 + 定向验证,随后给完整八问结论):

PR 把「渲染时所有权门」列为核心机制之一,但客户端读的是响应字段 viaFallback,而服务端实际下发的键名是 fallback:

  • 服务端 src/plugin.ts:1737 → fallback: viaFallback || undefined(viaFallback 只是内部变量名);
  • 既有消费者 src/mcp.ts:219 读的就是 data.fallback !== true + data.conversationId——同一套门逻辑,证明线上契约的键名是 fallback。

两者对不上 ⇒ 客户端 status.viaFallback 恒为 false ⇒ 所有权门 sessionOurs 恒为 true ⇒ 该门在生产上永不触发,是死代码。新增的「劫持拒绝」子测试之所以绿,是因为它自己伪造了 viaFallback:true 的假响应体——测的是客户端自己的错误假设,不是真实契约(假测试)。

影响分层:

  • 主场景(主/子 agent 都在打流量)靠「精确 id 查询」仍能修好——精确命中永远优先于子会话,报告里的闪烁大概率消除;
  • 首个请求前的窗口(主 agent 还没发请求、子 agent 已发)仍会把子 agent 的会话页嵌进帧里——而这正是所有权门要堵的洞,现在没堵住。

修法明确、无需决策:客户端 o.viaFallback === true → o.fallback === true;测试伪造体 viaFallback:true → fallback:true。已在此 PR 分支补 commit 并跑定向测试,稍后给完整八问结论与合并判定。

@ranxianglei
ranxianglei merged commit 357c694 into master Oct 21, 2026
45 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.715-master.357c694 (rolling master tag).

npm install -g billion-context@0.0.715-master.357c694  # 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

1 participant