Skip to content

[PR] fix: log mid-stream abort origin — distinguish client hangup from bili-initiated abort (#7661) - #7670

Open
ranxianglei wants to merge 3 commits into
masterfrom
2026-11-24_abort-origin-observability
Open

ranxianglei wants to merge 3 commits into
masterfrom
2026-11-24_abort-origin-observability

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

What this fixes

The client aborted mid-stream log line fired for BOTH a client that hung up AND a bili-initiated abort (runaway guard / upstream watchdog), because both surface as a generic AbortError on a destroyed/ended response. The log could not say who initiated the abort — the exact observability gap #7661's ~20% DSH mid-stream aborts were stuck on (the user's report: "bili 侧没有记录中断原因,只有'客户端断开'").

This PR adds abort-origin attribution so the log can distinguish the two.

What changed

  • src/logger.ts — new ABORT_ORIGIN (a global Symbol.for property) + setAbortOrigin / getAbortOrigin / abortMidStreamLine. The symbol rides the global registry so the tag is readable across module boundaries without an import cycle (logger is the one leaf every abort site already imports).
  • src/server/relay.ts, src/server.ts — set the origin at the initiation sites: the client close handler (client-disconnect), the output-side runaway guard (runaway-guard), and the request-idle watchdog in armRequestWatchdog (bili-internal — it aborts the client's own controller via requestAborts, so its dispatch catch was the third site still mislabeled client aborted mid-stream). This also puts the previously-unused bili-internal origin value to work.
  • src/server.ts, src/inline-engine.ts, src/plugin.ts — the catch sites render the line by origin via abortMidStreamLine.

A bili-initiated abort now logs bili-initiated abort mid-stream ... [origin: runaway-guard] instead of the mislabeled client aborted mid-stream.

Behavior change (intended)

  • Old: every mid-stream abort on a destroyed/ended response logged client aborted mid-stream.
  • New: bili-initiated aborts (runaway guard, request-idle watchdog) log bili-initiated abort mid-stream ... [origin: X] (runaway-guard / bili-internal); client-initiated and unknown-origin cases keep the exact old string (grep-stable).

Only the log attribution changes — when/whether an abort happens is untouched.

Test

tests/issue7661-abort-origin.test.ts pins the abortMidStreamLine attribution (all 4 origins + unknown), the setAbortOrigin/getAbortOrigin round-trip on a real ServerResponse, and the global-symbol identity.

Not covered (follow-up, noted in #7661)

The upstream watchdog (fetch-util.ts fetchWithTimeout) aborts its own controller, not the client's, and needs res plumbed in to tag the origin — a bigger change. It is already diagnosable via its own upstream watchdog fired (phase, budget) line, and its 12–24 min budget makes it a non-trigger for #7661's 1–5 s aborts.

Refs #7661

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-24_abort-origin-observability (5395894)

Latest build — install this exact version

npm install -g billion-context@0.0.12586-pr.7670.654a391

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
5395894 billion-context@0.0.12586-pr.7670.654a391 build
0c50b98 billion-context@0.0.12489-pr.7670.aa41426 build
9c56d4f billion-context@0.0.11823-pr.7670.5358c77 build
77b05ab billion-context@0.0.11821-pr.7670.fd3db48 build
38c7981 billion-context@0.0.11818-pr.7670.34813fe build
d4ea03f billion-context@0.0.11813-pr.7670.9c42245 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7670.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

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 #7670 修的是「bili 主动 abort 被误标成 client-disconnect」(mid-stream abort 日志行);在途的 #5601 修的是相反方向——client-disconnect 被上游失败分类器误标成 upstream-timeout(ref #5598,走 describeUpstreamFailure/recordUpstreamConnection/formatUpstreamError)。两者同属 abort 归因家族,但表面不同(日志行 vs 上游失败分类)、方向不同,非重复。

Independent review of #7670(rebased head 77b05ab1f87,CI 绿——0 failed / 0 pending,镜像缓存实测 sha 一致):

核心机制成立,逐点核对过:

  • res 身份一致:打标签的 res(setAbortOrigin)与 catch 点读的 res(getAbortOrigin)是同一个 ServerResponse,贯穿 relay → handle → catch 以及 pipe / inline-engine / plugin 路径;set-before-abort 顺序成立(同步 setAbortOrigin 在 clientAbort.abort() 之前)。
  • 无 cache-ledger 回归:abortCorrelated 走内存 noteClientAbort(session)(30s 窗口,非日志 grep),PR 未在 runaway-guard 加 noteClientAbort,语义不变;cache-ledger.ts:2806 的提示串仍准确(只跟踪 client-disconnect)。
  • 6 处 client aborted mid-stream 日志点全部转换为按 origin 渲染;client-disconnect 与未知 origin 保持原字符串(grep-stable)。

顺手修(commit 77b05ab1f87):请求空闲看门狗 armRequestWatchdog(src/server.ts:393)abort 的是客户端的 controller(requestAborts.get(res)),不是它自己的——所以它的 dispatch catch 是第三处仍被误标成 client aborted mid-stream 的发起点。PR「not covered」的理由(上游看门狗「abort 的是它自己的 controller,不是客户端的」)不适用于请求看门狗。我在 abort 前补了 setAbortOrigin(res, "bili-internal")——顺带把之前定义了却从未使用的 bili-internal origin 值用起来。纯日志归因,看门狗是否/何时触发不变。

行为变更(有意,已写进 PR 描述):请求看门狗触发的 abort 现在记 bili-initiated abort mid-stream ... [origin: bili-internal],而不是 client aborted mid-stream。上游看门狗(fetch-util.ts)仍是唯一未打标的点(它 abort 自己的 controller,需要把 res 穿进去;已有自己的 upstream watchdog fired 日志行可诊断)。

标签:PR #7670 已带 bug + p1 + dsh + scope/other(最低标准满足);源 issue #7661 带 p1 + dsh + scope/other。按「只加不删」规则两者都未动。一点提示供你定夺:PR 自身 diff 是纯可观测性(严格按分级算 p3),但 p1 也站得住(它是诊断 p1 级 #7661 的前置)——不擅自改,留你判断。

8问(中文):

  1. 是什么问题:billion-context 0.1.216 issue caused approximately 20% of DSH streaming requests to be interrupted | billion-context 0.1.216 问题导致 DSH 约 20% 流式请求中断 #7661 的 ~20% DSH 流式请求被中断,bili 侧日志只记「客户端断开」,分不清是客户端真挂起还是 bili 自己(runaway guard / 请求看门狗)主动 abort——可观测性缺口。
  2. 什么原因导致的:客户端挂起和 bili 主动 abort 在已销毁/已结束的响应上都表现为同一个泛化 AbortError,日志无法区分发起方。
  3. 影响范围与严重程度:纯日志归因,不改变 abort 是否/何时发生;影响所有车道的 mid-stream abort 日志可读性。严重度:诊断瑕疵(不阻断可用性),但它是诊断 billion-context 0.1.216 issue caused approximately 20% of DSH streaming requests to be interrupted | billion-context 0.1.216 问题导致 DSH 约 20% 流式请求中断 #7661(p1)的前置。
  4. 怎么修复的:用一个全局 Symbol.for 属性在 res 上打 origin 标签(client-disconnect/runaway-guard/bili-internal),在三个发起点(客户端 close、runaway guard、请求看门狗)打标签,catch 点按 origin 渲染日志行。
  5. 是否有回归问题:无。cache-ledger 语义不变(走内存非日志 grep);6 处日志点全部转换;client-disconnect 与未知 origin 保持原字符串;res 身份一致、set-before-abort 顺序成立。
  6. 是否破坏缓存:不涉及。纯日志,不动缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及。沿用既有日志管道,只加一个跨模块可读的 origin 标签(走全局 Symbol 避免 import 环)。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

结论:机制成立、res 身份一致、无回归、CI 绿。我补上了请求看门狗这一处漏标的 abort 发起点(commit 77b05ab1f87)。mergeable_state: blocked 是分支保护/人工 review,不是 CI 红。可合并,等你 review + merge(合并权在你)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI fix complete — unused-exports is green; the full matrix now passes (40 success / 16 skipped / 0 failures).

What I did this run:

  • Re-verified live first: the reported failing check was on the older head d4ea03fb37; the branch had already moved to 77b05ab, where unused-exports was still failing (every other gate green; that head's test/e2e lanes were skipped by its skip-scoped run). So an earlier wake had not actually fixed it.
  • Root cause: the PR's new AbortOrigin union type at src/logger.ts:77 was declared export type but is referenced only inside src/logger.ts (the three exported function signatures) and imported by no other module → the gate classifies it INTERNAL_ONLY.
  • Fix: dropped the leading export (export type AbortOrigin → type AbortOrigin). The type still names the union at its definition site; no consumer imports it (the test uses string literals directly), so this is behavior-neutral. Did not add a WAIVERS entry — this is an internal type, not a wire/plugin contract.
  • Verified locally: node scripts/check-unused-exports.mjs → clean; tests/issue7661-abort-origin.test.ts → 3/3 pass; npm run typecheck → clean.
  • Pushed as the final head 9c56d4f7dc0 (no [ework:ci-held] marker → triggered the one full CI pass). Confirmed live on that head: 0 failures, unused-exports green.

八问:

  1. 是什么问题:CI 的 unused-exports 门禁红了——PR 新增的 AbortOrigin 类型被 export 却没有任何模块 import,属于「只在本文件内使用」的多余导出。
  2. 什么原因导致的:PR 在 src/logger.ts:77 把 AbortOrigin 联合类型声明成 export type,它只在同文件三个函数签名里被引用、跨文件零引用,命中 INTERNAL_ONLY 判红。
  3. 影响范围与严重程度:仅 CI 门禁层面,零运行时影响——类型可见性变化不改变任何字节/行为;严重程度 = 挡合并的体验瑕疵,不影响功能。
  4. 怎么修复的:去掉 export 关键字,把 AbortOrigin 降为文件内类型(不删,它仍在三个导出函数签名里被用);不加 WAIVERS,因为它不是对外契约/线格式,只是内部类型。
  5. 是否有回归问题:无。改动是单个 export 关键字;类型仍在本文件内被引用、无外部 import,行为字节级不变;本地跑了对应测试(3/3)与 typecheck 均绿。
  6. 是否破坏缓存:不涉及——纯类型可见性,无缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及——无架构/边界/数据流变化。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

判定:CI 已全绿,unused-exports 修复完成。PR 当前 mergeable_state: blocked 是分支保护/评审门禁(非 CI 失败,上一 head 同样为 blocked),按规则我不合并,留待 owner/评审。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Already green — no further work needed.

This event reported unused-exports failing on head 38c7981556, but that is a stale ancestor (2 commits behind the current head). The branch head is now 9c56d4f7dc0, which already carries the fix (dropped the stray export on the AbortOrigin type in src/logger.ts:77).

Live re-verification on the current head 9c56d4f7dc0 (this run, fresh check-run query): 56 check runs — 40 success + 16 skipped, 0 failures; unused-exports = success. The full matrix is green.

Stopping here per the "already green" path.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed(reviewer: 本机 dog,非人类不合并,合并留给人)。结论:机制正确、CI 全绿、新测试本地 3/3 通过,可合并——合并前请先 rebase:master 已前进 29 个提交(其中 4 个动过 src/plugin.ts),文本无冲突但建议基于最新 master 再合。

验证过的点:

  1. Symbol.for 标签机制成立:logger 是叶子模块、所有 abort 位点本来就 import 它,跨模块读标签无循环依赖;writable: true 意味着重复写后写覆盖,我核对了各触发顺序(runaway guard → pipe finally res.end() → close handler 被 !res.writableEnded 守卫跳过;watchdog fire() → 先 end → 同样跳过),无误覆盖路径。
  2. 覆盖完整:client aborted mid-stream 全部 7 个输出位点(server.ts dispatch ×1、inline-engine ×3、plugin.ts chat/jsonl/responses ×3)都改走了 abortMidStreamLine;relay.ts:1155 的 client disconnected mid-stream 按构造只在「客户端先断且 res 未 end」时触发(bili 主动断都会先 res.end() 被守卫挡掉),不需要也改不了。
  3. 最坏竞态无害:close 事件先于标签写入前 write() 已报错时,输出的是旧措辞 client aborted mid-stream——而那个场景恰恰是客户端先断,标签仍正确。

两个非阻塞备注:

  • upstream-watchdog origin 定义了但暂无写入点(前向兼容没问题);将来若加上游看门狗 abort 路径,记得补 setAbortOrigin。
  • 这个 PR 解决的是 #7661 里「谁先断的」从 bili 视角的判定(ask #1 的前半)。如果现场日志打出 client-disconnect(或无标签的旧措辞),即坐实 DSH 侧先断;但 DSH 侧被吞掉的那个真正传输错误(deepseek-harness adapter.ts:80 的 TRANSPORT 捕获把 cause 丢弃、消息里不可见)还得 DSH 仓库跟一个小改动才能看到全貌,建议另开 issue 跟踪。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Merge conflict resolved — PR is now mergeable (no conflict), and the rebased head is fully green (27 success / 19 skipped / 0 failures).

What I did this run:

  • Verified live first: the PR was genuinely conflicting (mergeable: False, mergeable_state: dirty). master had moved 277 commits ahead of the PR's base (256df56f153 → 5bb3eb2cd9a).
  • Detected the conflict: only src/server.ts conflicted (plugin.ts / relay.ts auto-merged). It was at the import region — the PR extended the logger.js import line (added setAbortOrigin, getAbortOrigin, abortMidStreamLine) while master added a new import { kernelWarnSink } from "./kernel-warn-channel.js"; line directly after it. Two sides, one region → text conflict.
  • Resolved by rebase: rebased the 3 PR commits onto current master. At the conflict I kept both sides (the PR's extended import line + master's kernelWarnSink import). Commits 2 and 3 applied cleanly with no further conflicts.
  • Verified locally on the combined tree: check-unused-exports.mjs → clean; tests/issue7661-abort-origin.test.ts → 3/3 pass; npm run typecheck → clean (exit 0).
  • Force-pushed (--force-with-lease) after confirming no other agent had pushed (remote head unchanged). Final head 0c50b98ad08, no [ework:ci-held] marker → one full CI pass.
  • Confirmed live: mergeable: True (conflict gone); CI 27 success + 19 skipped, 0 failures.

八问:

  1. 是什么问题:PR 分支与 master 合并冲突(merge state: dirty)——master 在 PR 基线之后前进了 277 个提交,双方在 src/server.ts 的 import 区做了相邻改动。
  2. 什么原因导致的:PR 扩展了 logger.js 的 import 行(加 setAbortOrigin/getAbortOrigin/abortMidStreamLine),master 在同一行正后面新增了一行 kernelWarnSink import;两边改同一区域 → 文本冲突。
  3. 影响范围与严重程度:仅挡合并(冲突导致 PR 无法 merge);零运行时影响——冲突是 import 行的文本重叠,不涉及逻辑;严重程度 = 挡合并的问题。
  4. 怎么修复的:把 3 个 PR 提交 rebase 到当前 master,冲突处保留双方改动(PR 扩展 import 行 + master 的 kernelWarnSink import 行),--force-with-lease force-push(先确认无其他 agent 并发推送)。
  5. 是否有回归问题:无。rebase 只移动提交、不改逻辑;冲突解决是「取并集」(两行 import 都保留);本地在合并后的整树上跑了 unused-exports(干净)、对应测试(3/3)、typecheck(干净)。
  6. 是否破坏缓存:不涉及——纯 import 行合并,无缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及——无架构/边界/数据流变化。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

判定:冲突已解决(mergeable: True),rebase 后 CI 全绿(27 success / 19 skipped / 0 failure)。mergeable_state: blocked 是分支保护/评审门禁(非冲突,需人工 approve),按规则我不合并,留待 owner/评审。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

1 similar comment
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

ci-check added 3 commits November 30, 2026 19:55
…i-initiated abort (#7661)

"client aborted mid-stream" fired for BOTH a client that hung up and a
bili-initiated abort (runaway guard / upstream watchdog): both surface as a
generic AbortError on a destroyed/ended response, so the log could not say
who initiated it. #7661's ~20% DSH mid-stream aborts were stuck on exactly
this observability gap.

Tag each response with its abort origin (a global Symbol.for property, set
at the initiation sites — the client close handler and the runaway guard)
and render the line by origin in the catch sites. A bili-initiated abort now
logs "bili-initiated abort mid-stream ... [origin: X]"; client-initiated and
unknown-origin cases keep the exact old string (grep-stable).

Behavior change (intended): bili-initiated mid-stream aborts log a distinct
"bili-initiated abort mid-stream" line (was mislabeled "client"); client
aborts are byte-identical to before.
The request watchdog (armRequestWatchdog) aborts the CLIENT's controller
(requestAborts.get(res)), so its dispatch catch was mislabeled 'client
aborted mid-stream' — the same observability gap #7661 closes for the
runaway guard. Tag it 'bili-internal' (the previously-unused origin value)
so the catch site renders 'bili-initiated abort mid-stream [origin:
bili-internal]' instead. Pure log attribution; when/whether the watchdog
fires is untouched.
…#7661)

The unused-exports gate flagged AbortOrigin as INTERNAL_ONLY: the union
type is referenced only within src/logger.ts (the three exported function
signatures) and imported by no other module. Drop the leading export so the
gate passes; the type still names the union at its definition site and no
consumer imports it (the test uses string literals directly).
@ranxianglei
ranxianglei force-pushed the 2026-11-24_abort-origin-observability branch from 0c50b98 to 5395894 Compare November 30, 2026 11:58
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

Merge conflict resolved — PR #7670 is now mergeable (no conflict); rebased head pushed, static gates green.

What I did this run:

  • Verified live first: the PR was mergeable_state: dirty (conflict) on the old head 0c50b98ad08 — master had moved ahead again (to c18f6b7dece).
  • Rebased the 3 PR commits onto current master c18f6b7dece. Only conflict was the src/server.ts import region (same spot as last time: the PR's extended logger.js import line vs master's new kernelWarnSink import line); resolved by keeping both sides (union).
  • Verified locally on the combined tree: check-unused-exports.mjs → clean; tests/issue7661-abort-origin.test.ts → 3/3 pass; npm run typecheck → clean (exit 0).
  • Force-pushed (--force-with-lease) after confirming no concurrent push (remote head unchanged). New head 5395894a6c7.
  • Confirmed live (mirror cache, fresh fetch on 5395894a6c7): mergeable_state: blocked (conflict gone — blocked is the branch-protection/review gate, not a CI failure); 11 static gates success (incl. the previously-red unused-exports), 0 failed / 0 pending.

Full test matrix is skipped — why, and what re-arms it:
This run was scoped to skip by the stale-PR gate (#7785): the PR was created 2026-11-24 (>72h old by creation date, STALE_HOURS=72), so the main test matrix + static-gates + all 19 e2e/lane lanes are skipped (not failed). Importantly, staleness is age-based, not base-based — my rebase onto current master does NOT clear it, so a plain re-run / next push will ALSO skip the matrix. The only way to get a full green pass is the ci:force label on the PR. Note: skipped checks do not satisfy required-status-checks, so the PR cannot merge on a skipped-matrix green — a full pass is needed before merge.

Local verification is green (typecheck + targeted abort-origin test + unused-exports on the combined tree) and the 11 fast static gates pass — so there is no red item. The authoritative full-regression verdict is pending a ci:force-triggered full matrix.

八问:

  1. 是什么问题:PR 分支与 master 再次合并冲突(merge state: dirty)——master 在 PR 基线之后又前进到 c18f6b7dece,双方在 src/server.ts 的 import 区有相邻改动。
  2. 什么原因导致的:PR 扩展了 logger.js 的 import 行,master 在同一区域新增 kernelWarnSink import 行;两边改同一区域 → 文本冲突(与上一轮同位置)。
  3. 影响范围与严重程度:仅挡合并(冲突导致无法 merge);零运行时影响;严重程度 = 挡合并。
  4. 怎么修复的:把 3 个 PR 提交 rebase 到当前 master,冲突处保留双方改动(取并集),--force-with-lease 推送(先确认无并发推送)。
  5. 是否有回归问题:无逻辑回归——rebase 只移动提交、不改逻辑;本地在合并后整树上跑了 unused-exports(干净)、对应测试(3/3)、typecheck(干净)。注意:本轮 CI 被 stale-PR 门禁([CI] every label fires a no-op CI run, and PRs older than 72h still pay a full matrix per push — | 任意 label 都触发一轮空转 CI,且超过 72 小时的老 PR 每次推送仍跑完整矩阵 #7785,PR 创建已 >72h)判为 skip,主 test 矩阵与 e2e 车道全部跳过(非红),全量回归待 ci:force 触发的完整矩阵确认;staleness 按创建时间算,rebase 不清除,普通重跑/再推同样会跳过。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

判定:冲突已解决(mergeable_state: blocked,非冲突),静态门禁 11 项全绿(含之前红的 unused-exports),无红项,本地验证全绿。主 test 矩阵本轮被 stale-PR 门禁跳过,全量回归需 ci:force 标签触发完整矩阵(跳过的 check 不满足 required-status-checks,合并前需全绿)。blocked 是分支保护/评审门禁,按规则我不合并,留待 owner/评审 approve + merge;如需全量 CI 确认,给 PR 加 ci:force 标签即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p1 scope/other

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant