Skip to content

fix(dsh): /acp and /acp-cache target the invoking session via the host-passed invocation (#1677) - #1684

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-29_dsh-acp-invocation-session
Sep 29, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-29_dsh-acp-invocation-session

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

In plugin/native mode (dsh profile bundle), /acp and /acp-cache showed the proxy's most-recently-active session instead of the current one — silently. Root cause is plugin-side only: DSH's command executor hands the invoking agent to the handler through the invocation object but does not establish the AsyncLocalStorage boundary that currentInitiator() reads, so sessionIdOf() was always empty on the command path and both commands fell back to fetchStatusLatest.

What changed

src/agent/dsh-native.ts:

  • New CommandInvocation type mirroring the DSH command-execution contract ({ commandId, agent, rawInput, attachments, signal }, all optional so older dsh degrades gracefully).
  • commands.register handler signature now accepts (invocation?: CommandInvocation).
  • statusOutcome / cacheOutcome resolve the session as invocationSidOf(invocation) ?? sessionIdOf(ctx) — invocation first, keeping ALS attribution and latest as fallbacks (backward-compatible with an older dsh that passes nothing).
  • When the chain falls back to fetchStatusLatest because the requested session is unknown to the proxy, or no session could be identified at all, the output now prepends an explicit banner naming the shown session (latestSessionNote) instead of presenting foreign data silently.

tests/dsh-native.test.ts: 3 regression tests (below).

Behavior change (old → new)

Old New
Session shown by /acp / /acp-cache Always the most-recently-active session (the command path never carried a session id) The invoking session (invocation.agent.session.id); falls back to ALS attribution, then latest
Fallback-to-latest visibility Silent — a foreign session's panel shown with no indication Prepends ⚠️ bili: session <id> is not known to the proxy — showing <shown> instead. (or could not identify the current session — showing <shown> instead. when no session at all)

Why: the first row is the bug fix (a different session's panel was being rendered); the second row implements the issue's "the fallback must not be silent" requirement. Neither affects the proxy wire or the acp_status / acp_cache tools, which already read exec.agent?.session?.id.

Scope & safety

  • Proxy side untouched. The per-conversation status index already worked correctly (issue evidence: GET /__bili/plugin/status?conversationId=X returns distinct panels; unknown id → 404; fallback=latest → most-recently-active). Only the two plugin-side command handlers changed.
  • Pre-first-request state preserved. Before the first model request the real session id is unregistered (404), so it still falls back to latest, which answers from the agent-keyed runtime table (panel=null, runtimeInfo present) → hits the existing runtimeInfo branch with no banner (that is the intended armed/idle state).
  • No config surface change. No new/renamed/re-semantics config field, env var, or CLI flag. The only user-visible addition is an optional banner line in the fallback output.

Tests

New regression coverage in tests/dsh-native.test.ts:

  1. /acp resolves the invoking session from the invocation (asserts the specific panel; asserts no fallback=latest query).
  2. /acp-cache binds acp_cache to the invoking session id (asserts the forwarded conversationId).
  3. Invocation wins over ALS attribution; an unknown session and a no-session call each fall back to latest with the annotation (never silent).

Pre-flight on the rebased head (v0.1.172 base): typecheck clean · build OK · 3231 pass / 0 fail (12 skipped = E2E-gated).

Auto-merge

Not eligible per §7.4 — touches src/agent/* (hot file) and changes /acp output shape (banner added in the fallback path). Stays human merge.

Fixes #1677

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-29_dsh-acp-invocation-session (40278db)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1631-pr.1684.b174321

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

Install instructions are refreshed on each push.

…t-passed invocation

In plugin/native mode the DSH command executor hands the invoking agent to the handler through the invocation object but does NOT establish the AsyncLocalStorage boundary that currentInitiator() reads, so sessionIdOf() was always empty on the command path and both commands fell back to fetchStatusLatest - silently showing the most-recently-active session's panel instead of the current one.

The handlers now read invocation.agent.session.id first (zero DSH-side change), keeping the ALS attribution and latest as fallbacks. When they fall back to latest because the requested session is unknown/unidentifiable, they prepend an explicit banner naming the shown session instead of presenting foreign data silently.

Fixes #1677
@ranxianglei
ranxianglei force-pushed the 2026-09-29_dsh-acp-invocation-session branch from 7ad554a to 40278db Compare September 29, 2026 10:11
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到 PR #1684(fix(dsh): /acp 与 /acp-cache 通过 host 传入的 invocation 定位调用方 session)。正在按 review 规范走:先审原 issue #1677 → 回归审查 → 代码审查 → 测试有效性 → diff 整洁度。结论稍后在此线程给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:可以合并(按 §7.4 留给人工合并——触碰 src/agent/* 热文件且改变 /acp 输出形状)。

① 原 issue(#1677,方向关)✅

issue 排查扎实:四次跨会话调用 MD5 逐字节一致证明「静默显示别的会话」;根因追到 DSH 源码层(命令执行器不建立 currentInitiator() 依赖的 AsyncLocalStorage 边界,而 invocation.agent.session.id 才是权威身份源);代理侧按会话索引已用直查接口排除。PR 实现的正是 issue 建议修复的第 1、2 条(用 invocation + 兜底不静默),第 3 条(上游 DSH 包 withInitiator)明确标为非必要、未做——方向正确,修的是根因(丢弃了权威身份源)不是症状。

② 回归审查(既有行为清点)

既有行为 结论
/acp·/acp-cache 会话解析 有意变更(即本 bug 修复),PR 正文已披露旧值→新值
/acp 输出形状 有意变更:仅 latest-fallback 命中 panel 时前置 banner;正常解析路径输出字节不变
pre-first-request armed/idle 态(#955 runtimeInfo 分支、「No model request seen yet」分支) 保持:banner 只挂在 panel 分支内(src/agent/dsh-native.ts:464-467),runtimeInfo/version 分支未动;已知会话无 panel 或 latest 返回 panel=null 均无 banner,与 PR 声明一致
acp_status/acp_cache 工具路径(读 exec.agent?.session?.id) 保持,未触碰
请求路径归因(headersFor 打 x-bili-plugin-conversation、takeover gate,src/agent/dsh-native.ts:672-689) 保持——模型请求路径上 ALS 由 dsh-agent-loop 的 withInitiator(kick()) 建立,本来就有效,不该动;issue 日志里的 takeover 告警是 agentless/background/stale 等另一类场景,不在本 PR 范围
旧版 dsh 不传 invocation 的向后兼容 保持:参数可选,退化为原 ALS→latest 链(外加新 banner,正是 issue 要求的非静默兜底)
同族文件 src/agent/dsh-acp.ts(同样恒走 latest) 核实为遗留死代码:已被 dsh-native.ts 吸收(src/agent/dsh-native.ts:5 头注「used to carry dsh-acp.ts」),launcher 实际注入的是 dsh-native.js(src/launcher.ts:2158),仅 tsup 还构建它以兼容旧安装——不是漏修的活路径
代理侧/两种压缩模式 保持,零 wire 改动

③ 代码审查 ✅

  • invocationSidOf(src/agent/dsh-native.ts:428-431)类型守卫齐全,畸形形状 → undefined → 逐级回退,永不抛错;运行时即使 dsh 传入类型外的形状,可选链也能安全降级。
  • 优先级链 invocation > ALS > latest 合理:invocation 是「谁敲的命令」的权威来源;将来若 DSH 给命令路径也包上 withInitiator,两者并存时 invocation 胜出也是对的(stale attribution 场景下更可信)。
  • fetchStatus 对未知会话是 soft-fail 返回 undefined(src/agent/shared.ts:249-253),所以未知会话 → latest 回退链成立,不会把 404 变成命令报错。
  • 无 as any/@ts-ignore,无新增 console.error,注释均为带 issue 溯源的仓库惯例风格。

④ 测试有效性 ✅

三个新测试是真回归测试——我把 master 的 dsh-native.ts 换回去跑了一遍:3 个全红,失败信息正是 bug 症状(expected the invoking session's panel, got: PANEL-LATEST;cache 测试转发到了 conv-latest);换回 PR 代码后全绿。断言有牙:不仅看输出文本,还在 URL 层钉死了行为(可解析会话不得出现 fallback=latest 查询;acp_cache 转发的 conversationId 用 deepEqual 钉死)。
小缺口(不拦):invocation 存在且该会话仅有 runtimeInfo(无 panel)的 armed/idle 组合没有专门用例——但 banner 挂载在结构上只属于 panel 分支,且既有 #955 用例覆盖了无 invocation 变体,风险很低。

⑤ diff 整洁度 ✅

2 文件 +197/−13,单 commit,base 即当前 master tip(v0.1.172,c0e9e65f,0 behind),每一行都与本修复相关。

验证记录

  • CI(head 40278db):13/13 check runs 全绿(含 ubuntu/windows 双平台测试、build-artifact、e2e、real-lane、hermetic registry、version-guard)。
  • 本地:PR 分支 npm run typecheck 干净;tests/dsh-native.test.ts 38/38 通过;红绿对照如上。
  • 分支新鲜度:基于 v0.1.172 release 后的 master,无 stale-base 风险。

中文摘要:修复了 dsh 插件模式下 /acp、/acp-cache 静默显示「最近活跃会话」而非当前会话的问题(命令 handler 丢弃了 host 经 invocation 传入的会话身份、误依赖命令路径上恒为空的 ALS 归因);现优先用 invocation 的会话 ID,逐级回退 ALS→latest,且 latest 兜底不再静默、会显式标注实际显示的会话;回归测试红绿对照成立,既有行为(pre-first-request 态、工具路径、请求路径归因)逐项核对无回归,可以合并。

@ranxianglei
ranxianglei merged commit a425f88 into master Sep 29, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-29_dsh-acp-invocation-session 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 插件模式下 /acp 显示的是「最近活跃会话」的状态面板,而非当前会话(/acp-cache 同)

1 participant