Skip to content

[PR] fix(diagnostics): enforce final UTF-8 byte cap on 4xx dumps - #4299

Closed
ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-10-22_dump-byte-cap
Closed

ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-10-22_dump-byte-cap

Conversation

@ReineLan

Copy link
Copy Markdown
Contributor

Closes #4297

Category N — diagnostics. With a 1024-byte dump4xxMaxBytes setting, a 1025-character ASCII request produced a 1058-byte file, and a multibyte summary exchange produced 2494 bytes. The old code counted UTF-16 units before formatting and independently capped the two summary sides, excluding JSON escaping, the envelope and truncation markers.

Budget the final UTF-8 output, including the truncation marker. Summary request/response strings share the remaining envelope budget; small sides remain complete and truncated envelopes remain valid JSON. Use the existing surrogate-safe prefix helper. Keep temporary serialization bounded when rejecting a large body. This restores the documented per-file byte cap; no config schema or default changes.

Validation: new regressions first failed on the old implementation (3 failures), then all 63 related tests passed across error-dump, text-safe, issue1993-preflight-400, reasoning-echo-400, state-gc and knobs-config-precedence. Tests inspect actual disk byte sizes and parse summary envelopes; cases include Chinese, emoji, Buffer input, JSON pretty-print growth, escaped controls, both oversized sides, exact-limit and one-byte-over boundaries, and small-body/disabled gates. Two code-review passes completed. npm run typecheck and npm run build pass against current master 94f75cc. Existing kernel sideEffects and pi CONFIG_DIR_NAME build warnings remain. Full-suite validation belongs to the remote CI lanes on this pushed head.

@ranxianglei ranxianglei changed the title fix(diagnostics): enforce final UTF-8 byte cap on 4xx dumps [PR] fix(diagnostics): enforce final UTF-8 byte cap on 4xx dumps Oct 22, 2026
@ReineLan

Copy link
Copy Markdown
Contributor Author

(ai: openai/gpt-6)

CI triage for head 8f3a9331: run 39772097371, Windows Node 22 shard 2 job 119802057572, failed outside the changed diagnostic-dump paths. The log contains:

The other five test lanes and both static-gate lanes passed. This PR's local 63 targeted tests, typecheck and build passed. Full-suite CI is still red: an upstream maintainer must rerun the failed job after addressing the CI prerequisites. Both the connector and Git credential REST rerun attempts returned permission errors (Must have admin rights to Repository. for REST).

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 — 本 PR 就是 #4297 的修复 PR(一一对应)。检索 open+closed 中 4xx dump / dump4xxMaxBytes 相关条目:#2412/#2575 是聚合保留策略(目录级 size/age retention,不同机制)、#1994 只是引入了 summary dump writer、#2037 是 knob 解析层——均不覆盖「单文件最终 UTF-8 字节上限」这个契约。无并列在途修复。

标签: bug + scope/other + p3(诊断 dump 文件超出配置的每文件字节上限;opt-in 功能、默认关闭、无可用性影响;N 类服务端杂项)

审核进行中,先报阶段性结论:

@ranxianglei ranxianglei added bug Something isn't working p3 scope/other labels Oct 23, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 本 PR 对应 #4297(单文件 4xx dump 的 UTF-8 字节上限契约)。检索 open+closed 中 dump4xxMaxBytes / error-dump byte cap / 4xx dump size:

三者都不覆盖「最终落盘文件 ≤ 配置字节数」这条契约,#4297 是它们都没碰的新机制面,独立成立;也没有第二个 issue/PR 在修同一机制。

正在做独立审核(不复用 issue 侧结论):① 把新回归测试回放到旧实现验证「先红后绿」;② 逐行核对字节预算数学(含 marker 预留、envelope overhead、两侧分账);③ 清点既有行为回归面;④ 定向跑相关测试 + typecheck,全量交给 CI。结论稍后按结构化八问回复。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Review 结论:可合(待当前 CI 重跑完成确认)

查重:不重复(首条回复已给理由,此处不重复展开)。

是什么问题:文档承诺「单个 4xx 诊断 dump 文件不超过 dump4xxMaxBytes 字节」被打破——旧代码在序列化之前按字符数(UTF-16 单元)截断,预算里不含 JSON 转义、文件头信封和截断标记,summary 两侧还各自独立限额。cap 设 1024 时中文内容实际能写出 3000 字节的文件。

什么原因导致的:预算维度错位——承诺的是「最终落盘 UTF-8 字节数」,实现数的却是「格式化前的字符串长度」;多字节膨胀、转义膨胀(控制字符最多 6 倍)、信封开销全部游离在预算之外。

影响范围与严重程度:只影响显式打开 BILI_DUMP_4XX 的用户(默认关);后果是诊断文件超出文档上限、磁盘占用略超,不影响功能与转发链路。p3。

怎么修复的:改为对「最终输出字节」做预算——先算出固定信封开销,剩余预算在 request/response 间分配(request 优先、保底一半),每侧用既有的 surrogate-safe 前缀助手按字节截断,并预留最长截断标记的空间;body 美化打印仅在原文就装得下时进行(防止拒绝大 body 时临时序列化失控)。数学上保证 文件 = 信封 + 两侧 ≤ cap 恰好成立。

独立验证(不依赖作者声明,均在本机 PR head 上重跑):

行为变更披露(全部限定在「用户已开启 4xx dump」的前提下):

  1. 字符数在 cap 内但字节数超限的多字节 body:旧行为写出超限文件(即本 bug)→ 新行为截断至 cap 内;
  2. summary 两侧都很大时:旧行为各自独立限额(总和可超 cap)→ 新行为共享单一信封预算,截断更紧;
  3. 截断不再劈开代理对(safePrefix)、summary 截断标记尾部多一个换行——均为纯落盘观感改善,dump 文件从不回流线上;
  4. 不变项:默认关闭、文件名与会话 id 净化、GC 调用、信封结构 {status,request,response}、装得下时的完整输出、三个调用点(preflight / loop-core / relay)。

是否有回归问题:逐项清点既有行为——默认关闭提前返回不变;小 body 路径输出逐字节一致;Buffer 输入、精确上限边界、一侧小一侧大、禁用门均有测试钉住;dump 是旁路产物,不进 wire/会话/缓存状态。未发现回归。

是否破坏缓存:不涉及(诊断产物,不进入任何缓存/重试/游标/去重路径)。

是否改了设计方向:不涉及。是否引入新配置:不涉及(schema/默认值/env 零变更)。

其他:diff 干净(2 文件、单模块、纯 fix、Closes #4297);PR base 落后 master 若干提交(mergeable_state=behind),合并前建议 rebase。若新一轮 CI 同样两个测试再红,建议按 Windows-node22 runner 稳定性问题处置(证据如上),不阻塞本 PR。

标签:bug + scope/other + p3(诊断车道缺陷,默认关闭,仅磁盘超限)——已在位,未改动。

判定:可合——rebase 到最新 master 且当前 CI 重跑全绿后即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

审核完成(独立重审,非复读 issue 结论)。结构化八问:

  1. 是什么问题:开了 BILI_DUMP_4XX=1 后,写盘的 4xx dump 文件实际字节数会超过配置的 dump4xxMaxBytes——上限是在「格式化之前的 JS string length(UTF-16 码元)」上量的,截断 marker、JSON 转义、pretty-print 膨胀、summary envelope 全都不在预算内。issue [diagnostics] 4xx dump files exceed dump4xxMaxBytes after UTF-8 and JSON serialization #4297 报告的机制分析是准确的。
  2. 什么原因导致的:预算施加在了错误的表示层——对「输入字符数」设限而非对「最终落盘字节」设限;且 summary 两侧各自独立设限后再叠加 envelope。根因是计量单位与计量时机都错,不是某处截断少算了几字节。
  3. 影响范围与严重程度:仅影响显式开启 dump 的用户(默认关闭);症状是诊断文件超出配置上限(ASCII 场景超 ~30B,多字节/envelope 场景可超数倍,如报告的 2494B vs 1024B)。p3:无可用性影响、无数据丢失、无缓存泄露,纯诊断卫生问题。
  4. 怎么修复的:把预算搬到最终输出上。capText 先预留最长截断 marker、再二分搜索 surrogate 安全前缀(safePrefix,compactEntry summary clamp (slice(0,199)+'…') can strand a lone high surrogate → same deterministic UTF-8 gateway 500 family #816/fix(decompress-shared): surrogate-safe clamp in search_context previews #828/[bug] summaryFingerprintLine 的 head/tail 裸码元切片产生孤立代理项 → 上游 JSON 400、会话永久卡死(#816/#828 同族第三站点;0.1.169 仍未修) #1615 家族纪律);summary 侧用「与最终写盘完全相同的序列化形状」测出 envelope overhead,两侧共享剩余预算,小侧完整保留、大侧截断,envelope 恒为合法 JSON;超大 body 靠 textBytes 的 limit 提前返回 + side() 跳过 parse,临时序列化有界。我手工推演了全部四种大小组合(双小/单大/双大)的预算数学,overhead + escLen(req') + escLen(resp') <= cap 是精确等式不是近似。
  5. 是否有回归问题:逐项过既有行为——①未开启时两函数照旧返回 null(门控测试在案,过);②空 body 返回 null(不变);③小体量合法 JSON 仍被 pretty-print(不变);④summary 小交换(两侧都放得下)输出与旧实现逐字节相同(现有内容等值测试过);⑤文件名方案、目录、gcDumpDirIfConfigured 调用不变;⑥三个调用点(loop/core.ts:1575、preflight.ts:1299、server/relay.ts:1378)签名未动。有意行为变更(披露):超限 body 的 dump 现在把 marker 计入预算,同 cap 下保留的正文字节比旧实现少最多 ~30B——这正是修复目的([diagnostics] 4xx dump files exceed dump4xxMaxBytes after UTF-8 and JSON serialization #4297 的 expected 明确要求 marker 在内)。未发现无意回归。已知边界:cap 被设到 ~70B 以下(小于 marker 自身长度)的退化配置下,输出可超 cap 至多 ~35B——属于荒谬配置角落,不构成缺陷类,不另立项,记录在此。
  6. 是否破坏缓存:不涉及——纯诊断路径,默认关闭,不触碰任何缓存/重试/游标/去重键。
  7. 是否改了设计方向:不涉及——同模块、同 knob、同文件布局,只是把计量搬到了正确的层。
  8. 是否引入了新的配置:无——复用既有 diagnostics.dump4xx* 面,零 schema 变更。

验证证据(本地定向,非全量):

  • 新测试红先绿后成立:换回 master 旧实现跑,恰好 3 个新测试失败(main UTF-8 上限、summary 双侧、一字节越界);恰好边界保留用例在旧实现下本就能过,符合预期。
  • PR 分支上 6 个关联文件(error-dump / text-safe / issue1993-preflight-400 / reasoning-echo-400 / state-gc / knobs-config-precedence)63/63 通过。
  • 分支落后 master 92 个提交,但 master 对 error-dump/text-safe/knobs/state-gc/paths 及该测试文件零后续改动,无语义冲突面,GitHub 报 mergeable,无需 rebase。

CI 状态(合并判定的唯一权威,当前未齐):原推送的 CORE 矩阵里 test (ubuntu-latest, 24, 1)(单腿全量套件,含新测试)与 ubuntu 22 三条分片腿均绿;唯一红:test (windows-latest, 22, 2)。按 ci.yml 的 CORE 矩阵,Windows 走 2 分片,我用运行器同款 LPT 分区算法复算确认:这条红腿恰好包含 error-dump.test.ts 及其余全部关联套件。annotation 只有 exit code 1,日志端点在本环境反复不可达(REST 两种形式 404/超时,不再纠缠)。注意该运行器自带 #3029/#3665 的有界 flake 恢复(吞错重跑 + 整相重试一次),这条红扛过了内部重试,所以要么是该 runner 上的确定性失败、要么是双重 flake——没有日志无法区分。今天 10:11 UTC 同一 head SHA 已重新触发一整批 CI(仍在跑),其结果一锤定音。

判定:代码审核通过——根因修法正确、预算数学经手工推演无懈可击、测试有牙且红先绿后已实证、diff 干净(2 文件 +121/-15,每行都与目的相关)、无无意回归。暂不定「可合」:等重跑的 windows 22/2 腿结果——转绿即可合;若确定性复红则是平台相关的测试/环境问题,需要日志定位后再定。我不会代合(PR 合并只归人)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

补一条 CI 处置记录(接上条八问):今天 10:11 UTC 平台对同一 head SHA 自动重触发的两批 CI 互相顶掉、全部 cancelled,测试腿没跑起来;我尝试用 workflow_dispatch 手动补跑,但 PR head 在 fork 上、base 仓库看不到该 ref(API 422: No ref found),agent 侧无法代发。所以那条红的 test (windows-latest, 22, 2) 目前悬而未决,需要作者或 owner 触发一次干净的 CI(作者往分支推一个空提交即可)。

判定维持不变:代码审核通过,合并绿灯等这条 windows 腿转绿。若它确定性复红,把 job 日志贴出来(本环境拉不到 Actions 日志),我按日志定位——重点会看是不是新测试的平台相关问题(我在 Linux 上已排除逻辑层面问题:63/63 定向通过 + 红先绿后实证)。

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4525(master 6d7c587,合并方式 merge commit,提交保留原作者署名)。本 PR 关单收尾;若列车中对应提交出问题,回滚点为 #4525 单提交 revert。

感谢 @0XCocoa 的贡献——你的提交以原作者署名随列车进入 master(合并方式为 merge commit),仓库贡献者列表可见。

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

Labels

bug Something isn't working p3 scope/other

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[diagnostics] 4xx dump files exceed dump4xxMaxBytes after UTF-8 and JSON serialization

2 participants