Skip to content

fix: dumpSse covers plugin lane and non-injected streaming turns (#2347) - #2351

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-07_dump-sse-plugin-lane
Oct 8, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-07_dump-sse-plugin-lane

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

问题(#2347 bug2)

配置了 dumpSse / ACP_DUMP_SSE 后,plugin mode 回合与 proxy 非注入回合零 -raw.sse 文件——静默停止无法定案。

根因(已在 master 逐行核实):存在两层独立封锁,不止一层——

  1. 既有 tee 位于 useRewriter 分支内部(旧 src/server.ts:7107)。useRewriter = compressInjected && …,非注入回合恒 compressInjected=false ⇒ 早退,永远到不了 tee;
  2. 真正的 plugin lane 是 if (prepared?.pluginMode) 独立分支(src/server.ts:6830,自带 pluginBody + 自己的 resolveFakeCompletion + 带 session 的 pipe 调用),在 :6926 return——它根本不经过下方任何共享代码。只修第 1 层,用户通道(dsh)依然拿不到原始字节。

修法

每条 lane 在各自 resolveFakeCompletion 替换完成后、分支分裂前各放一个 tee() + dumpStreamToFile()(twin pair):

  • plugin lane:pluginBody 定型后 tee,第二支落盘;
  • 非 plugin lane:responseBody 定型后同样处理,覆盖 rewriter / 非 rewriter 全部子分支;
  • 两条 lane 的 finally / 回合收尾处 await dumpRaw——客户端提前断开也保证完整上游尾部写盘(取证价值所在);
  • 删除 useRewriter 分支内的旧 tee(防双份 dump),runCompressLoop(streamToRead, …) → runCompressLoop(responseBody, …)。

关键坑(原 issue 亦指出):tee 必须在 resolveFakeCompletion 之后——该函数整体替换 responseBody(bufferToStream(resolvedBuf)),提前 tee 会 dump 掉被丢弃的流。

行为变更披露(旧 → 新)

  • dumpSse 覆盖面:OLD = 仅 compress-injected 流式回合(proxy mode)→ NEW = 所有 prepared 流式回合(两模式、注入/非注入、含 side request)。默认 OFF,仅显式配置时生效。
  • 零新增 config/env key(复用现有 dumpSse/ACP_DUMP_SSE);零 wire 变更(纯本地文件写);压缩语义不变。

与 #2328 的分工

本 PR 完成 #2328 checklist 的 Q1(raw-SSE dump),机制与原提案不同:不改任何 pipe 签名(原方案是给两个 strip pipe 追加 diag 参数),改为 server 侧各 lane 一处 tee。Q2(终止元数据诊断)/ Q4(区分「上游没发终端」vs「终端到了被拒」)继续在 #2328 下实现,动 src/plugin.ts / src/stream-error.ts,与本 PR 无文件交集。

已知 v1 限制(与 #2328 floor 2 一致):只 dump 首次尝试的上游流;refetch/degenerate retry 的第二条流不回灌(截断发生在首次尝试,够用)。

测试

新增 tests/issue2347-dump-sse-plugin-lane.test.ts(hermetic mock upstream,4 cases):

  • A plugin-mode 流式回合 → 恰好一个 -raw.sse,内容与上游字节一致(修前为零文件——本 bug 回归钉)
  • B 非注入 proxy 流式回合 → 有 dump
  • C 注入 proxy 回合 → 仍恰好一份(防删旧 tee 后的双份 dump)
  • D 未设 dumpSse → 无文件(默认关闭不变)

本地已验证:typecheck ✅ build ✅ 定向测试 4/4 ✅ 相邻 plugin-lane 套件(plugin-terminal-usage 9/9)✅。全量回归交 CI。

Closes #2347
Related: #2328

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-07_dump-sse-plugin-lane (fc297cc)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2515-pr.2351.454e13d

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-pr2351.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

收到。确认 PR #2351(head 2026-10-07_dump-sse-plugin-lane @ c022666,base master,mergeable)即 #2347 下已完成的工作——本条是它的 [PR] 镜像,我不重做。现在拉分支逐段核对代码与 issue 主张、审既有行为回归面、查 CI 状态,随后按七问体例回最终结论。

…iter throw paths)

The non-rewriter branch awaited dumpRaw inline, so a rejecting pipe would skip it and leave the raw-SSE dump half-written — while the plugin lane and the rewriter lane both await in their own finallys. Move the non-rewriter await into the shared safety-net finally (idempotent for the rewriter lane) so all three lanes honor the 'full upstream tail before turn close' contract on every exit path. Success-path behavior unchanged.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成:可合(review 中发现一处小缺口已顺手修掉,commit 已备好但因 GitHub 远端推送故障暂未推上,见文末)

审查范围:对照当前 master 逐行核对(PR base 74cf524,期间 master 前进 3 个 merge);diff 触碰路径的既有行为逐项审计;测试有效性核验(不只看过不过);CI + 本地定向验证。

结构化七问:

  1. 是什么问题:配置 dumpSse/ACP_DUMP_SSE 后,plugin mode 回合与 proxy 非注入回合零 -raw.sse 文件——静默停止无法取证定案。
  2. 什么原因导致:两层独立封锁叠加。① 旧 tee 位于 useRewriter 分支内,非注入回合 compressInjected=false ⇒ 早退,永远到不了 tee;② plugin lane 是独立的 if (prepared?.pluginMode) 分支(src/server.ts:6831),自带 body/fake-completion/pipe,在共享代码之前 return。只修第 ① 层,dsh 用户通道依然拿不到原始字节。
  3. 怎么修复的:每条 lane 各放一个 tee()+dumpStreamToFile() twin pair,位置统一为「resolveFakeCompletion 替换 body 之后、分支分裂之前」(避开 dump 被丢弃的流);删除 useRewriter 内旧 tee 防双份;runCompressLoop 入参 streamToRead→responseBody(拓扑不变)。
  4. 是否有回归问题:无。逐项审计:
  5. 是否破坏缓存:否。纯本地文件写;发往客户端的 wire 字节不变(tee 不改内容);prefix cache 不受影响。
  6. 是否改了设计方向:否。不动 pipe 签名、压缩语义、wire 格式;以 server 侧 per-lane tee 实现 [Enhancement] plugin-lane 流终止可观测性:Responses/Chat pipe 缺 raw-SSE dump 开关 + 终止元数据诊断 #2328 checklist 的 Q1(机制与原提案 diag 参数不同,爆炸半径更小);Q2/Q4 继续在 [Enhancement] plugin-lane 流终止可观测性:Responses/Chat pipe 缺 raw-SSE dump 开关 + 终止元数据诊断 #2328,无文件交集。
  7. 是否引入新配置:否。复用现有 dumpSse / ACP_DUMP_SSE。行为变更披露(正文已写):覆盖面 OLD=仅 compress-injected 流式回合 → NEW=所有 prepared 流式回合(两模式、注入/非注入、含 side request),默认 OFF。

测试有效性(重点核查):

  • case A 确实走 plugin lane:x-bili-plugin header → pluginAgentHeader(src/plugin.ts:120,纯 header 读取,无注册门槛)→ pluginMode = pluginAgent !== undefined && !pluginLaneDegraded(src/server.ts:2467)。修前 case A 零文件 → 真回归钉,不是假测试。
  • waitForDump 断言「全程 ≤1 个文件 + 内容与上游字节逐字一致」——抓得住双份 dump 和错流 dump;端口 listen(0) 确定性合规。
  • 已知 v1 缺口(可接受):无客户端断开/尾部完整 case;无 fake-completion 真触发替换的 case(mock upstream 不触发 retry)。

验证证据:

  • CI @ c022666:27/27 checks 全绿(ubuntu/windows ×22/24 全矩阵、e2e、hermetic registry、real-client lane 套件、kernel-guard、version-guard);
  • 本地定向:typecheck ✅、新测试 4/4 ✅、相邻 plugin-terminal-usage 9/9 ✅(全量回归交 CI)。

Review 发现的小问题 — 已直接修(小问题直接修):
non-rewriter 分支的 await dumpRaw 原写在 inline(仅成功路径执行)——若某条 pipe reject 会被跳过,dump 留半截文件;而另外两条 lane(plugin / rewriter)都在自己的 finally 里 await。本 PR 正文承诺「两条 lane 的 finally / 回合收尾处 await dumpRaw」,实现与此略有出入。修法:把 non-rewriter 的 await 移入外层 safety-net finally(对 rewriter lane 幂等),三条 lane 在所有退出路径上一致地「等完整尾部再收尾」。成功路径行为不变。本地验证 typecheck + 13/13 通过。
Commit:fc297cc5a(+7/-3,src/server.ts 单文件)。⚠️ 推送受阻:GitHub 远端对所有 push 返回 Internal Server Error(10 分钟内 5 次尝试,含全新分支名与空 ASCII commit 对照实验,读 API 全部正常)——判定为远端瞬时故障,按纪律停止重试。commit 已在 agent worktree 本地留存(review-fix-2351-pending 分支),恢复后重推 git push origin fc297cc5a:refs/heads/2026-10-07_dump-sse-plugin-lane 即可。该 commit 只是 opt-in 诊断功能的错误路径收尾增强,不阻塞 c022666 本身的合并,但建议远端恢复、push 上且 CI 转绿后连同一起合。

结论:可合。 修复打中根因(两层封锁分 lane 各自处理),diff 收敛于 2 个文件,行为变更已披露,回归审计通过,测试是真测试。请 owner 合并 #2351 —— 远端推送恢复后可等 fc297cc 转绿同合;若急用,c0226662a 现状亦可合。

1 similar comment
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成:可合(review 中发现一处小缺口已顺手修掉,commit 已备好但因 GitHub 远端推送故障暂未推上,见文末)

审查范围:对照当前 master 逐行核对(PR base 74cf524,期间 master 前进 3 个 merge);diff 触碰路径的既有行为逐项审计;测试有效性核验(不只看过不过);CI + 本地定向验证。

结构化七问:

  1. 是什么问题:配置 dumpSse/ACP_DUMP_SSE 后,plugin mode 回合与 proxy 非注入回合零 -raw.sse 文件——静默停止无法取证定案。
  2. 什么原因导致:两层独立封锁叠加。① 旧 tee 位于 useRewriter 分支内,非注入回合 compressInjected=false ⇒ 早退,永远到不了 tee;② plugin lane 是独立的 if (prepared?.pluginMode) 分支(src/server.ts:6831),自带 body/fake-completion/pipe,在共享代码之前 return。只修第 ① 层,dsh 用户通道依然拿不到原始字节。
  3. 怎么修复的:每条 lane 各放一个 tee()+dumpStreamToFile() twin pair,位置统一为「resolveFakeCompletion 替换 body 之后、分支分裂之前」(避开 dump 被丢弃的流);删除 useRewriter 内旧 tee 防双份;runCompressLoop 入参 streamToRead→responseBody(拓扑不变)。
  4. 是否有回归问题:无。逐项审计:
  5. 是否破坏缓存:否。纯本地文件写;发往客户端的 wire 字节不变(tee 不改内容);prefix cache 不受影响。
  6. 是否改了设计方向:否。不动 pipe 签名、压缩语义、wire 格式;以 server 侧 per-lane tee 实现 [Enhancement] plugin-lane 流终止可观测性:Responses/Chat pipe 缺 raw-SSE dump 开关 + 终止元数据诊断 #2328 checklist 的 Q1(机制与原提案 diag 参数不同,爆炸半径更小);Q2/Q4 继续在 [Enhancement] plugin-lane 流终止可观测性:Responses/Chat pipe 缺 raw-SSE dump 开关 + 终止元数据诊断 #2328,无文件交集。
  7. 是否引入新配置:否。复用现有 dumpSse / ACP_DUMP_SSE。行为变更披露(正文已写):覆盖面 OLD=仅 compress-injected 流式回合 → NEW=所有 prepared 流式回合(两模式、注入/非注入、含 side request),默认 OFF。

测试有效性(重点核查):

  • case A 确实走 plugin lane:x-bili-plugin header → pluginAgentHeader(src/plugin.ts:120,纯 header 读取,无注册门槛)→ pluginMode = pluginAgent !== undefined && !pluginLaneDegraded(src/server.ts:2467)。修前 case A 零文件 → 真回归钉,不是假测试。
  • waitForDump 断言「全程 ≤1 个文件 + 内容与上游字节逐字一致」——抓得住双份 dump 和错流 dump;端口 listen(0) 确定性合规。
  • 已知 v1 缺口(可接受):无客户端断开/尾部完整 case;无 fake-completion 真触发替换的 case(mock upstream 不触发 retry)。

验证证据:

  • CI @ c022666:27/27 checks 全绿(ubuntu/windows ×22/24 全矩阵、e2e、hermetic registry、real-client lane 套件、kernel-guard、version-guard);
  • 本地定向:typecheck ✅、新测试 4/4 ✅、相邻 plugin-terminal-usage 9/9 ✅(全量回归交 CI)。

Review 发现的小问题 — 已直接修(小问题直接修):
non-rewriter 分支的 await dumpRaw 原写在 inline(仅成功路径执行)——若某条 pipe reject 会被跳过,dump 留半截文件;而另外两条 lane(plugin / rewriter)都在自己的 finally 里 await。本 PR 正文承诺「两条 lane 的 finally / 回合收尾处 await dumpRaw」,实现与此略有出入。修法:把 non-rewriter 的 await 移入外层 safety-net finally(对 rewriter lane 幂等),三条 lane 在所有退出路径上一致地「等完整尾部再收尾」。成功路径行为不变。本地验证 typecheck + 13/13 通过。
Commit:fc297cc5a(+7/-3,src/server.ts 单文件)。⚠️ 推送受阻:GitHub 远端对所有 push 返回 Internal Server Error(10 分钟内 5 次尝试,含全新分支名与空 ASCII commit 对照实验,读 API 全部正常)——判定为远端瞬时故障,按纪律停止重试。commit 已在 agent worktree 本地留存(review-fix-2351-pending 分支),恢复后重推 git push origin fc297cc5a:refs/heads/2026-10-07_dump-sse-plugin-lane 即可。该 commit 只是 opt-in 诊断功能的错误路径收尾增强,不阻塞 c022666 本身的合并,但建议远端恢复、push 上且 CI 转绿后连同一起合。

结论:可合。 修复打中根因(两层封锁分 lane 各自处理),diff 收敛于 2 个文件,行为变更已披露,回归审计通过,测试是真测试。请 owner 合并 #2351 —— 远端推送恢复后可等 fc297cc 转绿同合;若急用,c0226662a 现状亦可合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 更新:GitHub 远端推送已恢复,review 小修 commit fc297cc(fix: #2347 review — await dumpRaw in the safety-net finally,+7/-3,src/server.ts)已推上 PR 分支,c0226662a..fc297cc。该 commit 本地已验证 typecheck ✅ + 定向测试 13/13(新测试 4/4 + plugin-terminal-usage 9/9);CI 正在新 head 上重跑,转绿后即可合并。结论不变:可合。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 已在新 head fc297cc 上全部转绿:27/27 checks success(全矩阵 test、e2e、hermetic registry、real-client lane 套件、kernel-guard、version-guard)。PR 分支现为「原始修复 + review 小修」两 commit、完整绿。七问结论不变:可合,请 owner 合并 #2351 #2347;#2328 的 Q2/Q4 不受影响,继续在其下推进)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 已在新 head fc297cc 上全部转绿:27/27 checks success(ubuntu/windows 全矩阵、e2e、hermetic registry、real-client lane 套件、kernel-guard、version-guard)。PR 现为「原始修复 + review 小修」两个 commit、完整绿。七问结论不变:可合,请 owner 合并 #2351 #2347;#2328 的 Q2/Q4 不受影响,继续在其下推进)。

@ranxianglei
ranxianglei merged commit 9d6df16 into master Oct 8, 2026
27 checks passed
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.124-master.9d6df16 (rolling master tag).

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

【bug2】plugin lane 缺失流终止可观测性:dumpSse 不生效 + 拿不到原始响应字节,静默停止无法定案

1 participant