Skip to content

[PR] feat(diagnostics): /__bili/memory exposes cumulative CPU time + core count - #3455

Open
ranxianglei wants to merge 10 commits into
masterfrom
2026-10-17_memory-cpu-fields
Open

ranxianglei wants to merge 10 commits into
masterfrom
2026-10-17_memory-cpu-fields

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

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

Part of #3437(不 Closes——该 issue 按 owner 要求保留为资源占用与覆盖范围的跟踪问题,本 PR 只是其对照协议的组件)。

背景

#3437 的内存/CPU 对照协议需要同一采样点同时拿到进程内存、CPU 时间增量与存储路径计数。此前 GET /__bili/memory 只有内存字段,CPU 侧要各平台各写一套 OS 工具,口径还容易对不上任务管理器;sidecar 的 delta/full 摄取计数也只在内部,现场无法确认稳态保存是否走在增量快路径上。

改动(两笔提交)

① /__bili/memory CPU 字段(src/server/admin.ts)——process 对象新增三个纯增量字段:

字段 含义
cpuUserNs 进程启动以来的累计用户态 CPU 纳秒(process.cpuUsage().user)
cpuSystemNs 进程启动以来的累计内核态 CPU 纳秒(process.cpuUsage().system)
cpus 逻辑核数(os.cpus().length),归一化分母自描述

采样器契约(写在端点 docstring):计数器是累计值,取两次 poll 的差;核当量 = Δns / Δwall_ns(1.0 = 一核打满);任务管理器风格百分比 = Δns / (Δwall_ns × cpus)。

② sidecar 摄取计数上 wire(src/storage/runtime-status.ts)——storage 载荷新增两个扁平计数字段 ingests(本进程总摄取数)与 deltaIngests(走 #3133 O(新尾) 快路径的次数),出现在 /__bili/status 与 overview。沿用 master 上 verifyDrift(#3135④/#3818)的既有惯例:扁平 number、无侧车时 ?? 0。现场读 deltaIngests/ingests ≈ 1 即确认稳态保存在走增量路径。

相对上一版的收敛(rebase 说明)

分支已 rebase 到 master 146b34f27(#4590 train)。期间 master 并入了 #3919/#4323(shadow drift forensics):DIGEST DRIFT 日志行已自带字段级诊断(describeViewDivergence:漂移维度 + 首个分歧尾槽位,仅指纹不含正文)、连续漂移标记与 N 连漂升级(冻结本进程 envelope 写)。因此原第三笔提交(drift-parts 日志点名)被 master 方案取代,已移除;原 ingestStats {ingests, deltaIngests, verifyDrift} 对象也与先行的 verifyDrift 扁平字段重叠,按 PR 初版声明的「先合入者为准」收敛为只补 ingests/deltaIngests 两个扁平字段。

行为变更披露

  • GET /__bili/memory 响应 process 对象新增 3 个 JSON 字段(旧版没有 → 新版有);
  • /__bili/status + overview 的 storage 载荷新增 2 个加性计数字段(消费端兼容)。
  • 无配置面变更、无 kernel 变更、无 wire 协议变更、无阈值/时序变化、无日志格式变化。

测试

  • tests/issue3437-memory-cpu.test.ts:真实起服(port 0)GET 两端点,断言 CPU 三字段存在且为非负整数、cpus ≥ 1、跨两次 poll 单调不减、既有内存字段完好;storage 载荷断言 verifyDrift/ingests/deltaIngests 形状(delta ≤ total)。
  • 本地定向验证:typecheck 干净;issue3437-memory-cpu + memory-diagnostics + acp-status-storage-degraded + web-storage-banner 共 13/13 过。全量回归以远程 CI 为准(head 1dc5f7fbf)。

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_memory-cpu-fields (9d11dc8)

Latest build — install this exact version

npm install -g [email protected]

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
9d11dc8 [email protected] build
92a94b7 [email protected] build
cd4af82 [email protected] build
a7b38af [email protected] build
39156a6 [email protected] build
eef76eb [email protected] build
d58eedf [email protected] build
1dc5f7f [email protected] build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3455.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 检索「__bili/memory / cpuUserNs / CPU 时间诊断」无其他条目;仅父跟踪 issue #3437(开放,资源占用跟踪)。本 PR 是 #3437 对照协议的组件,不 Closes(符合 owner 对该 issue 的保留要求)。

审核范围与方向(①):#3437 的内存/CPU 对照协议要求同一采样点同时拿到进程内存与 CPU 时间增量。此前端点只有内存字段,CPU 侧要各平台各写 OS 工具且口径易漂移——补字段的方向正确:纯增量、同源(Node 自身计时)、同一采样点。

回归审查(②,既有行为清单):

  • GET /__bili/memory 响应:ok/process/pool/breakdown/sessions 五段中仅 process 增 3 字段;rssBytes/heapUsedBytes/heapTotalBytes/externalBytes/peakRssBytes 原样保留;状态码 200 不变;loopback 门控不变;其余端点不变。
  • grep 确认 sendMemoryReport(src/server/admin.ts:708)是该响应对象的唯一构造点;全仓无代码/测试对 process 对象做精确形状断言(tests/memory-diagnostics.test.ts 测的是 src/session.ts 的 memoryReport() 池报告,非 HTTP process 对象)→ 纯增量不会破坏任何既有消费者。
  • 行为变更披露齐备(旧版无 → 新版有 3 字段),无配置面、无 kernel、无 wire 变更,version 未动(内容分支正确)。

代码审查(③):src/server/admin.ts 加 import os + 一行字段构造 + docstring 写明采样器契约(累计值取两次 poll 之差;核当量 = Δns/Δwall_ns;百分比 = Δns/(Δwall_ns×cpus))。命名达意、注释讲用法而非复述代码、风格与文件一致。语义核对:process.cpuUsage() 计当前进程(含其全部线程)、不含子进程,与 docstring「进程启动以来」一致,正是对照任务管理器进程行要的口径。os.cpus().length 每请求一次,loopback 诊断端点上开销可忽略。

测试有效性(④):tests/issue3437-memory-cpu.test.ts 真实起服(port 0 临时端口,确定性),断言三字段为非负整数、cpus ≥ 1、跨两次 poll 单调不减、既有内存字段完好。断言有牙:字段被删或变非数值时 Number.isInteger(undefined) 直接失败,能抓住回归。本地复跑:新测试 1/1 过,tests/memory-diagnostics.test.ts 4/4 过,tsc --noEmit 干净。

diff 整洁度(⑤):2 文件,+102/-2,每行都与本 PR 目的相关,无跑题/空白噪音。

CI 现状:静态门禁全绿(gate/build-artifact/kernel-guard/version-guard/config-surface-guard/docs-sync/unused-exports/pi-subagents-guard/lane-guard/test-import-graph/lock-sync/plan/docs-coverage);test 泳道 6 条(ubuntu 22×3、ubuntu 24×1、windows 22×2)仍在跑,e2e 泳道按路径条件 skip(未触碰管线路径,符合预期)。全量回归以 CI 为准。

结构化八问

  1. 是什么问题:/__bili/memory 只有内存字段,CPU 侧对照要各平台各写一套 OS 工具,口径还容易和任务管理器对不上。
  2. 什么原因导致的:不是缺陷——该端点原为常驻池诊断设计(#R3),当时不需要 CPU 计时;[perf][Codex/Responses WS] Peak memory for active long-lived session processes is ~1.26GiB; please confirm whether R3/in | [perf][Codex/Responses WS] 活跃长会话进程内存峰值约 1.26GiB,请确认 R3/增量模式是否覆盖这条路径 #3437 的对照协议新需要同采样点的 CPU 增量,故补齐字段。
  3. 影响范围与严重程度:仅 GET /__bili/memory 的消费方(loopback 诊断端点);纯新增,既有字段/状态码/其他端点零影响;对外部用户无行为变化,只是多了一份可用信息。
  4. 怎么修复的:把 process.cpuUsage() 累计纳秒(user/system)+ os.cpus() 逻辑核数直接放进响应 process 对象,采样器契约写进端点 docstring,由消费方自行差分归一化。
  5. 是否有回归问题:无。逐项核过:响应既有字段、200 状态码、loopback 门控、pool/breakdown/sessions 段、其余端点——全部保持;无语义漂移、无阈值/时序/输出格式变化。
  6. 是否破坏缓存:不涉及——无缓存/重试/增量游标/去重键参与。
  7. 是否改了设计方向:否——纯增量诊断字段,架构/边界/数据流不变。
  8. 是否引入了新的配置:无——没有新 env/config/默认值。

判定:代码与测试已本地定向验证通过,静态门禁全绿;待 CI 6 条 test 泳道转绿即可合并(feat 类,按 §7.4 由人工合并)。

@ranxianglei
ranxianglei force-pushed the 2026-10-17_memory-cpu-fields branch from 4b16135 to 1dc5f7f Compare October 24, 2026 19:24
…xports gate

Inherited master-red (#4545 added client-build-note.ts after the 4d34abf
gate repair): ClientBuildCheck is referenced only inside its own file, so
drop the leading export (INTERNAL_ONLY fix, same pattern as the 3 symbols
de-exported in 4d34abf). No behavior change — pure visibility narrowing.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI auto-fix lane attempt 1/2:unused-exports 红已修复,新 head d58eedf32(push 1dc5f7fbf..d58eedf32),等 CI 重触发。

七问

  1. 是什么问题:unused-exports 门禁判 src/agent/client-build-note.ts:32 的 ClientBuildCheck 为 INTERNAL_ONLY(带 export 但只在本文件内被引用),check 失败。
  2. 什么原因导致的:不是本 PR 引入的回归——[PR] dsh lane: note in-session when running an unverified @deepseek-ai/dsh client build (soft, exact-match) #4545(client build note)在 master 的去导出清扫(4d34abfaf)之后把该文件带进 master,漏掉一个零外部引用的 type-only 导出;此后 master 自身在该行常红(master run 40134589260 的 unused-exports=failure 已核实),凡 rebase 到 146b34f27 的 PR 都继承。全仓 grep 验证:ClientBuildCheck 的全部引用都在其本文件内,master 与本分支状态一致。
  3. 影响范围与严重程度:仅信号级——检查矩阵一项假红、遮蔽本 PR 的真实状态;对运行时行为零影响(纯可见性收窄)。
  4. 怎么修复的:去掉 type ClientBuildCheck 的前导 export(与 [PR] fix(ci): clear the two master-red gates in one branch — unused-exports (#4602) + the #3890 LIVE_FILES tripwire (#4604) #4606 提交 1 / 4d34abfaf 对其余三个符号的处理同法),独立标注 commit d58eedf32;本地门禁复跑 ✓ unused-export gate: clean (6 waived)。
  5. 是否有回归问题:无。该模块的外部消费者(src/agent/dsh-native.ts、tests/client-build-note.test.ts)只导入其他符号,此类型无外部引用(全仓 grep 验证);去 export 不改任何类型语义、wire 形状或配置面。
  6. 是否破坏缓存:不涉及。
  7. 是否引入新配置:没有。

备注:CI 重触发后如仍有其他红(如 test 分片命中 LIVE_FILES tripwire),均属已列档的 master 风暴(#4599,修复载体 #4606),不在本车道范围;#4606 合入后 rebase 时丢弃本修复 commit,避免重复 commit 进 master。

ci-check added 7 commits October 25, 2026 10:09
master window commits 293ae65/de5e03659 bumped kernel/package.json to
0.0.165 without regenerating the lockfiles; lock-sync re-resolution then
rewrites the stale recorded versions (root 0.0.163, kernel 0.0.164) and
fails. Pure recorded-version sync via npm install --package-lock-only;
no dependency or semantic change.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant