Skip to content

session self-heal: zombie plugin lanes degrade to proxy tools, idle nudges suppress, 524 summaries learn streaming (#2155) - #2246

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-06_session-self-heal
Oct 6, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-06_session-self-heal

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

会话卡死自愈机制(#2155)

实现 #2155 的三方检测器 + 两档补救,按 owner 拍板方向:检测层照 ework 设计,补救层主档=僵尸会话降级为 proxy 注入(把工具还给会话),降级不可用才落抑制档;D3=524/504 首中即学流式摘要。

检测与补救(src/session-self-heal.ts,常量 SELF_HEAL_WINDOW=5)

  • D2 僵尸插件车道:plugin 已卸载但已开客户端窗口仍带绑定(粘滞 metadata.pluginAgent)。信号=连续 5 轮"被 nudge ∧ 无 x-bili-plugin 头 ∧ 线上无 bili 工具 ∧ 零压缩缩减"。补救=降级为 proxy 模式:单点翻转 pluginMode = pluginAgent !== undefined && !pluginLaneDegraded(session)(src/server.ts),ACP 工具线上回注、压缩 rewriter/CCR/absorb 全部自动跟随、nudge 保留(工具有用了)。compress.injectTool=false 时降级不可用→落 suppress-nudge。恢复=活的插件头(pluginLaneRestore 提到 pluginMode 翻转之前,首个带头请求即恢复 plugin 模式;恢复信号绝不能用粘滞 pluginAgent —— 否则降级一轮后自己清掉,已修)。绑定永不抹除。
  • D1 nudge 空转(非插件泛化):连续 5 轮被 nudge 零缩减零工具调用→四处 willInjectNudge 门加 && !nudgeSuppressed(session)(覆盖 emergency 路径)。恢复=任一压缩缩减或 bili 工具调用。
  • D3 网关杀摘要:非流式 preflight 摘要 524/504 首中即停(不再烧 3×100s transient 重试),置 metadata.preflightStreamSummary 并 SSE 重取 —— 与 preflightStreamSummary 自学习永远不会触发——上游在 Cloudflare(HTTP 524)后面时,非流式长摘要必然失败且无法自愈 #2133 手动旋钮同一学习存储,自动武装。

可观测

  • metadata.selfHeal {detected, action, since} 进 /__bili/sessions + web UI "自愈"徽标 + 详情行;每次转换一行 [self-heal] 日志(检测+恢复)。
  • bili plugin remove <client> 尽力查活代理(instance 文件→GET /__bili/sessions,2.5s 超时失败静默),该 client 近 10 分钟有活跃会话则打印提示。

验证

  • tests/issue2155-self-heal.test.ts 12/12:状态机单测 8(武装窗口/降级不可用落抑制/健康头永不武装/工具调用清 streak/reduction 解除/四协议工具形状)+ 集成 4:僵尸降级全链路(r1 绑定→r2-r6 僵尸→r7 tools=[compress,decompress,search_context,acp_status,acp_cache] 回注→r8 头回归即恢复 plugin 模式且 selfHeal 清)、nudge-idle(第 6 轮武装、第 7 轮消息数回落)、524(恰 1 次 524+重试 stream:true+metadata 置位+救援 200)、CLI remove 提示。
  • 回归:issue453 8/8、e2e-overflow-selfheal 3/3、preflight 六件套 40/40、plugin-agent/bypass/fake-completion/install-opencode 93/93、web-i18n+text-safe 18/18;tsc build+root 双 rc=0。
  • 真实行为锚点:应急 nudge 72%(57.6k/80k 预留窗)每轮注入——集成测试全靠它驱动;plugin 管道同样记 usage([plugin] [acp-usage])故基线在 r1 后即可用。

设计权衡(已按 #2155 评论讨论落定)

  • 恢复判定去抖:degrade 状态的恢复信号只认插件头,不认"线上有 bili 工具"——降级后工具是我们自己注的,若认它会在首轮降级后立刻清除导致震荡(已修+注释钉住)。
  • wire 注入的工具是 kernel 裸名(compress),僵尸会话历史里可能是 mcp__bili__compress 前缀名;模型可能先叫旧名一轮(客户端报 unknown tool)再被 nudge/工具描述引导到裸名——可接受一轮抖动,upstream 不校验历史 tool_use 与 tools 声明一致性。
  • 不新增配置项(阈值常量见 TECHNICAL-NOTES.md);CLI 提示为 best-effort 礼貌,代理侧检测才是防线。

Closes #2155

…udges suppress, 524 summaries learn streaming (#2155)

- src/session-self-heal.ts: per-request detector (SELF_HEAL_WINDOW=5).
  D2 zombie plugin lane (plugin removed, session still bound: headerless +
  no bili tools on the wire + no reduction across 5 nudged rounds) degrades
  to proxy mode — one pluginMode flip re-injects the ACP tools wire-side,
  keeps the nudge; falls back to suppress-nudge when injectTool is off.
  pluginLaneRestore() runs BEFORE the pluginMode flip so the first
  header-bearing request is already plugin mode (the sticky pluginAgent must
  not be the restore signal). D1 nudge-idle (5 nudged rounds, zero
  reduction) suppresses the nudge at all four willInjectNudge gates until a
  reduction/tool-use resumes.
- preflight: a non-streaming summary killed by HTTP 524/504 stops burning
  in-place retries — first hit learns metadata.preflightStreamSummary and
  re-requests as SSE (#2133 lane, auto-armed).
- observability: metadata.selfHeal {detected, action, since} in
  /__bili/sessions + web UI heal badge + one [self-heal] log line per
  transition; bili plugin remove best-effort warns about live sessions of
  that client seen in the last 10 minutes (2.5s timeout, silent on failure).
- tests/issue2155-self-heal.test.ts: 12 tests (state machine unit + zombie
  degrade/recover e2e + nudge-idle e2e + 524 learn e2e + CLI warn).
- docs: CLIENTS.md en/zh (zcode open sessions after removal),
  TECHNICAL-NOTES.md en/zh (detector constants + remedies).
@ranxianglei

Copy link
Copy Markdown
Owner Author

stack: none — based on master (bd33b11 + #2157/#2201 etc. already in). wire-shape 级改动(pluginMode 翻转影响注入/管道选择)——按 §7.4 需人工合并。

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-06_session-self-heal (04e027c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2328-pr.2246.31a0813

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

Install instructions are refreshed on each push.

…#2155 D3 × #2133)

The first-hit 524/504 SSE learn flipped the UNSET default, but #2133's
explicit cascade FALSE must stay the operator's 'never stream summaries'
opt-out: streamSummaryOff (PreflightDeps) blocks the 400 'stream required'
learn, the new 524/504 first-hit learn, and ignores an already-armed flag.
The two #2133 e2e tests now pin the explicit-OFF contract (unset routes
auto-learn — covered by issue2155-self-heal tests).
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 修复披露(#2133 × #2155 默认语义):首个 commit 把"未设置 streamSummary"的默认行为改为 524/504 首中即学 SSE,推翻了 #2133 钉住的"无旋钮→永不学、fail-fast"契约,CI 两个 e2e 红。修正为级联双向尊重:显式 false(任一级) = 操作员 opt-out,两条学习路径(400 stream-required + 524/504 首中)都不武装、已学旧标志被忽略;未设置(默认)= 首中 524/504 自动学(#2155 新默认,owner 已拍板方向);显式 true = 首次即流式(#2133 原行为)。两个 #2133 测试改为钉显式 OFF 契约,未设置路由的自动学由 issue2155 测试覆盖。TECHNICAL-NOTES 同步。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论(head 04e027ce6,CI 全绿 25/25)

1. 是什么问题:插件被卸载但已开客户端窗口仍带粘滞 pluginAgent 绑定——nudge 每轮照注入、模型侧 bili 工具已不存在,会话无限空转重发 MiB 级历史(#2155 主诉);同机制族的两个面:D1 nudge 空转(零缩减零工具调用仍持续注入)、D3 网关 524/504 杀死非流式 preflight 摘要(旧行为每次烧 ~100s 重试且永不学习,#626 学习路径只认 400)。

2. 什么原因导致的:三个独立根因——(a) pluginMode 只由粘滞 metadata 推导、无存活性检查,死车道永远不回注工具;(b) nudge 注入无"是否真的在起作用"的门;(c) preflight 把网关超时当 transient 重试,而唯一的学习信号是 400 "stream required" 正则,死网关永远学不到 SSE。

3. 怎么修复的:每请求一次、仅 nudge-active 轮求值的自愈钩子:src/session-self-heal.ts 状态机(计数 WeakMap 不持久化、状态入 metadata.selfHeal 可审计)。D2 连续 5 轮僵尸 → 单点翻转 pluginMode(server.ts:2768)回注 ACP 工具并重新接管压缩管道;恢复信号只用活的插件头(不用声明的工具——降级后我们自己的线上注入会自我振荡,注释已钉住这个坑);injectTool=false 时退化为静默 nudge。D1 连续 5 轮空转 → 四处 willInjectNudge 门加抑制,任一次缩减或 bili 工具调用即解除。D3 首中 524/504 → 学 metadata.preflightStreamSummary=true 改 SSE 重取(与 #2133 手动旋钮同一存储),非流失败不再烧 replay 预算。另:bili plugin remove 后尽力查询活代理打印提示(2.5s 超时、失败静默)。测试 12 个有牙:窗口边界精确到第 5 轮、健康车道 window+4 轮不武装、振荡恢复、真实 startServer+mock 上游的 524 双 body false→true 断言,端口全部 listen(0)。

4. 是否回归问题:逐路径审过既有行为——pluginMode 翻转与 4 处 nudge 门只在新增 selfHeal 状态下激活,对存量流量零影响;持久化纯增量字段,旧文件可读。已验证你披露的 CI 红:从 ubuntu-24 job 日志确认恰好是两个 #2133 测试(default behavior must still fail fast ... got 200),与披露一致。修正 commit d9ed351e1 我已逐行核对:级联双向语义实现正确(显式 false 任一级 = 两路都不武装 + 旧标志忽略;未设置 = 首中学;显式 true = 首次流式),两个 #2133 测试改为钉显式 OFF 契约而非削弱断言(502 fail-fast、全非流、零转发都还在),未设置路由的自动学由 issue2155 集成测试覆盖。一处需点名的行为扩展:显式 OFF 现在也封掉 #626 的 400 "stream required" 学习路径(此前设了 false 也可能被 400 教会)——与"操作员说这条上游永不流式摘要"的 opt-out 语义自洽,TECHNICAL-NOTES 已写明,判定为有意变更非回归。我补了一个 commit 04e027ce6(小问题直接修):披露里"已学旧标志被忽略"这一条款此前无测试钉住,加了 stale-flag e2e(先短请求建会话 → 直接种 preflightStreamSummary=true → 显式 OFF 路由长请求 → 断言全非流 + 502 + 标志原样存活),本地 6/6 + typecheck 绿后推上分支——该测试通过本身即证明修正代码守住了这条契约。CI 现 25/25 全绿(含之前红的四个 test job)。

5. 是否破坏缓存:降级会话回注 ACP 工具会触发 Anthropic tools 前缀缓存 miss,但只发生在本已坏掉的僵尸会话上,健康会话不受触达;nudge 抑制只删尾部注入消息,头部字节稳定;524 学习翻转的是代理内部摘要调用形式,不动客户端前缀缓存。持久化去重键/游标均未动。

6. 是否改了设计方向:无转向——单写者/插件归属契约不变(绑定保留、永不抹除,降级是模式切换不是身份改写);自愈层叠在既有会话状态机之上,恢复路径保证可逆(wire-shape 级改动属实:pluginMode 翻转改变注入与管道选择)。

7. 是否引入了新的配置:无新配置面——SELF_HEAL_WINDOW=5 为内部常量,不加 env、不加 config key(符合配置面纪律);新增的可观测面是 metadata.selfHeal 进 /__bili/sessions + web UI 徽标,属只读展示。

判定:方向正确、实现干净、回归面已审、CI 全绿。按 §7.4(feat + wire-shape)需人工合并:#2246 ——可以合。

@ranxianglei
ranxianglei merged commit 48b53f3 into master Oct 6, 2026
25 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.75-master.48b53f3 (rolling master tag).

npm install -g billion-context@0.0.75-master.48b53f3  # 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.

会话卡死自愈机制:卡死模式检测与代理侧主动补救

1 participant