Skip to content

feat: make takeover-attribution failures visible (panel + /__bili/status) | 压缩接管失效可见化 - #3593

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-17_attribution-health-visibility
Oct 17, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-17_attribution-health-visibility

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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

Closes #3581

What

When a host plugin's injection breaks at runtime (#3578 shape: disposed agent scope after a version swap), model traffic silently goes direct and uncompressed until the host restarts — requests succeed, sessions never register, injected tools 404, and the panel just shows "0 running". This makes the failure visible on all three surfaces the issue asks for, plus the docs line.

How

Proxy side

  • New src/server/attribution-status.ts (mirrors src/storage/runtime-status.ts): latest-report-wins registry keyed by agent name.
  • New loopback endpoint POST /__bili/plugin/attribution (validated: agent ≤64 chars, state ∈ ok|none|threw; 400 malformed) → handlePluginAttribution in src/plugin.ts.
  • /__bili/status and /__bili/overview both gain the additive field attribution: Record<agent, {state, refusals, since}> (empty {} until the first report). The issue spec sketched a single object; keyed by agent so multiple plugin lanes can coexist without clobbering each other — same per-entry shape.

Plugin side (dsh-native gate)

Web panel

Docs: README Self-update + AGENTS.md KDD #3 state that auto-update replaces disk files/proxy process only; injected code takes effect after a host restart, and since #3581 the broken state is visible via banner + status.

Behavior changes (old → new)

Surface Old New
/__bili/status, /__bili/overview no attribution info additive attribution field ({} until first report)
plugin endpoints none new POST /__bili/plugin/attribution (loopback-gated like siblings)
dsh-native threw settle-retry retried every request forever after 3 consecutive exhausted-thrown requests, retries stop (per-request cost 4→3 initiator probes on permanently-broken hosts); self-heal preserved
_setThrewRetryForTest full-replace with given cfg merges partial cfg over defaults (test-hook robustness)
stale banner text 「重启 bili 生效」/ "restart bili to apply" 「重启宿主后新代码才生效」/ "restart the host to load the new code"

No new config surface: giveUpStreak is an internal constant exposed only through the existing test hook. No kernel/ or pi-subagents/ changes. No version bump.

Tests

  • tests/issue3581-attribution-health.test.ts (new, proxy-side): endpoint validation incl. malformed bodies, status/overview parity, default {}, page ships the banner element, client renders it escaped.
  • tests/dsh-native.test.ts: two new tests — dead-scope episode (reports captured event-driven, latch arms at streak 3, per-request probe cost drops 4→3, give-up log line) and recovery (episode reset, settle-retry re-armed, ok report). All 57 pass, including the untouched 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 L2 exact log-count assertions and #2924a/#2924b.
  • Targeted local runs green: dsh-native (57/57), issue3581, native-intercept, web-storage-banner, web-update-banner, advisory-endpoint-parity, issue2861-host-plugin-notice, web-sessions, web-i18n + all other WEB_CLIENT-executing suites. Full-suite verdict: CI.

When a host plugin's injection breaks at runtime (#3578 shape: disposed
agent scope after a version swap), model traffic silently goes direct and
uncompressed until the host restarts — requests succeed, sessions never
register, tools 404, and the panel just shows "0 running".

- /__bili/status + /__bili/overview gain an additive `attribution` field:
  per-agent { state: ok|none|threw, refusals, since }, latest report wins
  (src/server/attribution-status.ts, mirrors runtime-status.ts).
- New loopback endpoint POST /__bili/plugin/attribution accepts the
  reports (validated; 400 on malformed bodies).
- The dsh-native gate reports event-driven only: first refusal, state
  change, refusal-count doubling, give-up latch, recovery. Healthy lanes
  never POST — zero healthy-path overhead, no polling, no per-request
  disk writes.
- Give-up latch: after giveUpStreak=3 consecutive requests whose
  settle-retry exhausted still threw, the gate stops re-settling (a
  disposed ctx stays disposed for the host's lifetime, #3578); the
  per-request attributionOf probe keeps self-heal alive.
- Web panel: new attribution banner when an agent is degraded AND no
  session is live; stale-banner wording now says "restart the host"
  (injected code lives in the host process).
- Docs: README/AGENTS auto-update sections state that injected code only
  takes effect after a HOST restart.
@ranxianglei
ranxianglei force-pushed the 2026-10-17_attribution-health-visibility branch from 6641d29 to 3e0fe5a Compare October 17, 2026 15:34
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_attribution-health-visibility (b2f19cd)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4245-pr.3593.4c4d0d2

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 检索了 open/closed issue 与 PR(关键词 attribution / 接管 / 可见化):本 PR 是「压缩接管失效可见化」(#3581)的唯一在途实现。最接近的邻居都不重叠——#3595 只改 dead-scope 拒绝文案、不碰可见化面;#2940(已合并)是本 PR 在其上扩展的 settle-retry 机制;#3333 是 acp-cache 报告面,不同域。无重复立项。

当前状态:

  • 分支此前与 master 冲突,conflict-worker 已 rebase 完毕(head b2f19cd),mergeable=true;
  • CI:静态门禁全绿(version-guard / kernel-guard / config-surface-guard / docs-sync / lock-sync 等),7 条测试 lane(ubuntu 22/24 × windows 22)仍在跑。

接下来:拉取分支对 master 做完整 diff 回归审计,本地跑定向测试(dsh-native、issue3581-attribution-health、web banner 相关套件,遵循本地只跑定向的纪律),等 CI 全量判定后按八问体例给结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

审核完成:可合并 ✅

CI 最终判定 @ b2f19cd:30 passed / 14 skipped / 0 failed。静态门禁全绿(version-guard、kernel-guard、config-surface-guard、docs-sync、docs-coverage、unused-exports、lock-sync、build-artifact、lane-guard 等);全量测试矩阵(ubuntu 22×3 + ubuntu 24 + windows 22×2)全绿;skipped 的是需要 env 变量的真实客户端 e2e lane(PR 上正常)。本地定向验证:typecheck + build + 9 个相关套件共 191/191 通过(含 dsh-native 57/57,其中未改动的 #1158 精确日志计数断言与 #2924a/b 均在列)。

diff 已对当前 master(merge-base b10c525)逐行通读,12 文件 +578/−30,两提交(feat + unused-exports 门禁修正),无跑题改动。

结构化八问

  1. 是什么问题:宿主插件注入在运行时坏掉后([Bug][dsh-native] 运行中自动换版后接管静默失效:旧 fetch hook 持有已 dispose 的 ctx,currentInitiator() 永久 threw,重启才恢复 #3578 形态:版本切换后 agent scope 失效),模型流量静默直连不压缩,直到重启宿主——请求都成功、会话不注册、注入工具 404、面板只显示「0 running」,用户完全无法察觉压缩已失效。本 PR 让该失效状态在面板横幅、/__bili/status、日志三处可见。
  2. 什么原因导致的:两层。根本原因是架构约束——注入代码活在宿主进程里,它坏了代理侧没有任何通道能知道,[Bug][dsh-native] 运行中自动换版后接管静默失效:旧 fetch hook 持有已 dispose 的 ctx,currentInitiator() 永久 threw,重启才恢复 #3578 暴露了这个盲区;叠加一层是 gate 自 fix(dsh-native): threw gate attribution gets a bounded settle-retry; provably-oversized bodies fail locally #2940 起假设「threw 是瞬态的」,对永久失效的 scope 每个请求无限重试 settle,既浪费探测也不上报任何东西。
  3. 影响范围与严重程度:只影响注入已坏掉的插件模式用户([Bug][dsh-native] 运行中自动换版后接管静默失效:旧 fetch hook 持有已 dispose 的 ctx,currentInitiator() 永久 threw,重启才恢复 #3578 形态);修复前是静默的功能丢失(请求全部成功但不压缩,极难发现);修复后面板明确提示「接管已失效——重启宿主可恢复」,status 暴露结构化字段,日志一行标记。健康用户零影响(健康路径完全不发报告)。
  4. 怎么修复的:事件驱动上报(仅首次拒绝 / 状态变化 / 拒绝数翻倍 / give-up latch 置位 / 恢复时 POST,fire-and-forget 走既有 5s 超时,不碰请求路径)+ 新 loopback 端点 POST /__bili/plugin/attribution(与兄弟端点同一 loopback+trusted-origin 门禁,严格校验 400)+ status/overview 纯增量 attribution 字段(按 agent 键控,多 lane 互不覆盖)+ 面板新横幅(仅在 degraded 且 live===0、即流量确实在直连时显示)。gate 侧加 give-up latch:连续 3 次 settle-retry 耗尽仍 throw 后停止重 settle(disposed ctx 在宿主生命周期内保持 disposed),每请求省一次探测;同时保留每请求一次的廉价探测维持自愈能力(首个 ok 清 streak、重置 episode、恢复正常重试)。
  5. 是否有回归问题:无。逐项审计过既有行为:拒绝决策逐字节不变(同样 verdict,只加簿记);健康路径成本为零(ok 时不发任何 POST);latch 前 threw 时序与 fix(dsh-native): threw gate attribution gets a bounded settle-retry; provably-oversized bodies fail locally #2940 完全一致(未改动的 方式一安装的dsh 原生插件:llm-pi-ai 传输(OpenAI SDK + options.fetch 注入)绕过 globalThis.fetch 拦截,模型请求不进代理、压缩完全不生效 #1158 精确日志计数测试通过);status/overview payload 纯增量(advisory-endpoint-parity 通过);_setThrewRetryForTest 从整体替换改为合并,对传完整 cfg 的旧调用方结果不变;wire/tool-call 路径未触碰(plugin-lane-only 功能,两种压缩模式都已推理);无 kernel/、无 pi-subagents/、无 version bump、无配置面变更。唯一有意行为变更均已在 PR 正文披露:永久坏掉的宿主 latch 后每请求省 (attempts−1)×delayMs(默认 500ms/请求);stale 横幅文案「重启 bili」→「重启宿主」(注入代码在宿主进程里,旧文案有误导)。
  6. 是否破坏缓存:不涉及——未触碰前缀缓存、cache ledger、增量游标或去重键。
  7. 是否改了设计方向:无架构/边界/数据流转向,纯新增遥测面,沿用既有 runtime-status 模式([web] advisory banner 是死代码:/__bili/overview 不含 advisory 字段,web 客户端从不调用 /__bili/status #2152 parity:一个 wire helper 同时喂两个面)。
  8. 是否引入新配置:无。giveUpStreak=3 是内部常量,仅经既有 test hook 暴露;无新增 env/config/CLI(config-surface-guard 门禁确认)。

已知限制(不阻塞):attribution 表为内存态,standalone 代理重启会丢外部宿主进行中 degradation episode 的记录,需等下一次事件驱动报告补回(有界、自愈;插件模式下代理与宿主同进程,重启本来就两边一起重置);fire-and-forget 乱序时可能短暂陈旧值(latest-wins,下一事件纠正);面板只展示第一个 degraded agent。

判定:可合并。 代码、测试、CI、文档全部通过,行为变更完整披露。请自行合并:#3593

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

上游冲突已解决,分支已 rebase 到当前 master 并推送,CI 全绿。

做了什么

结构化八问

  1. 是什么问题:PR 分支与 master 产生合并冲突(merge state dirty),无法合入。
  2. 什么原因导致的:master 侧(release v0.1.198 #3534/fix(agent): follow the live intercept state across host hot-reimport (#3394) #3395)与本 PR 同时改动了 dsh-native.ts 同一行的 import,文本冲突;非语义冲突。
  3. 影响范围与严重程度:仅一条 import 行的合并冲突 + 一个既有静态门失败,无外部用户面影响。
  4. 怎么修复的:rebase + import 并集解冲突 + 去掉三个内部类型的多余 export 过 unused-exports 门。
  5. 是否有回归问题:无。typecheck 干净、build 干净、定向套件 121/121 通过;远程 CI 全量 30/30(16 success + 14 个 gated e2e skip,0 failure)。[BUG] DSH 插件热替换后 fetch 拦截仍绑在旧模块实例上 → 模型请求全部直连、压缩静默失效直到重启 #3394 的 slot 拆除逻辑与 压缩接管失效后完全静默:面板与 /__bili/status 看不出压缩已停,用户全价直连直到重启才恢复 #3581 的上报路径都完整保留。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及,纯 rebase + 冲突消解 + 门禁小修。
  8. 是否引入了新的配置:不涉及。

行为变更披露:无运行时行为变更(未动 wire/config/persistence/阈值/时序)。唯一动作是去掉三个仅内部使用类型的 export 关键字,编译期擦除,不影响任何产物字节。

判定:可合入。所有必需检查已绿,merge state 为 blocked 仅因等待人工 review/merge(按规约 merge 由人来执行)。请人工合并:#3593

@ranxianglei
ranxianglei merged commit dcea82a into master Oct 17, 2026
44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.541-master.dcea82a (rolling master tag).

npm install -g billion-context@0.0.541-master.dcea82a  # 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.

压缩接管失效后完全静默:面板与 /__bili/status 看不出压缩已停,用户全价直连直到重启才恢复

1 participant