Skip to content

[PR] Hard-block session history over-limit along real dimensions: message-count gate + 32MiB ingestion cost band + fatal erro | 会话历史超限按真实维度拦死:条数闸 + 32MiB 摄入成本带 + 判死信息点名超重字段 (#5000 #5794 #5885) - #5973

Merged
ranxianglei merged 3 commits into
masterfrom
2026-11-09_gate-count-ingest
Nov 9, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

打包修复 #5932 合并后四个 issue 里剩余可构建的部分(#5932 修的是「按真实出站体计量」;本 PR 修的是计量之外的三个独立维度/路径)。每个机制 → 文件 → 现场:

A. 条数闸 — #5000 item 2(消息条数:计量器永远看不见的维度)

#5000 的 55.2MiB 会话有 26,903 条消息。它穿过了所有既有闸门——核心文本 1.44MiB(2MiB 绝对线以下)、出站字节(1M 窗口 × 7.5 B/tok 线以下)、#5932 的新计量档(文本 token 达标)——然后在上游死于消息条数上限。条数无法被任何字节/token 估算表达(且每条消息还各带 ~69B 的 m-ref 标记,26,903 条 ≈ 1.8MB 纯标记),所以这道闸必须是独立的。

B. 判死信息点名超重字段 — #5000 item 3(「unknown vs doomed」+ 维度诊断)

#5932 的三道计量闸给的是一个总数(~N TEXT tokens)。#5000 的 55.2MiB 出站体里 1.44MiB 是消息、大头是 tools[]——运维拿到一个总数不知道删什么。现在 estimateRawBodyBreakdown(src/preflight.ts,与 #554 计量器同一遍历、同一排除集)把计量按顶层字段分桶(messages / tools[] / system / other),三道判死信息全部改带分桶明细:tools[] ~X(#5000 形状)或 messages ~X(巨大粘贴/工具结果形状)。

C. 32MiB 解码摄入成本带 — #5794 item 2(单条大请求的解析扫掠)

#5794 每轮 51.2MiB/29,619 条:#5932 的 32MiB 槽位预算限的是并发(2 槽),单条请求照样独占事件循环 5.5–7.2s(JSON 解析+归一化扫掠,本机 CPU 54.6% → 747s FATAL 自重启、全员缓存冷)。成本带在解析之前按解码后字节 413(stage=ingest):network.ingestBodyBytes / BILI_INGEST_BODY_BYTES,默认 32MiB,0=关闭。32MiB+ 的可解析体已是 ≥~8M token,超出所有真实模型窗口——放行必然先烧事件循环再死。

本 PR 不修的(已单独立项/另有归属)

验证

本地全绿(sanitized env):23 个回归套件 332 用例(#4079/#4185/#2490/#857/#3701/#496/#3013/#2847/#3384/#3071/#5278/preflight-round-budget/#3918/#4894/fix-arm-headroom-clamp/#3846/#1839-ghost/#4205/fix-1001/#767/side-request-isolation/request-body-budget/dsh-native/native-intercept/web-diagnostics/issue5719/proxy-session-id)+ 本 PR 新增 5 e2e + 1 单测;tsc 干净;config-surface-guard 与 lifecycle-ledger-guard 通过(两个新键已注册)。

@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

自评(自查已修 2 项,均已在本分支内修正):

  1. 32MiB 成本带误杀 [Bug] Jimp is active, but image accumulation still triggers Responses WS 1009; duplicate request size not reduced (v0.1. | [Bug] Jimp 已生效,图片累积仍触发 Responses WS 1009;重复请求未缩小(v0.1.200) #3701:初版对全部协议生效,Responses 车道的 16 张截图体(≈38.5MiB base64,受支持工作负载)被 413 拦截,WS shed→1009→重发回归红。修复:protocol === "responses" 豁免(该车道有 wsOutboundBytes 预发送预算+丢弃逻辑兜底),chat 车道照拦。tests/issue3701-ws-byte-budget.test.ts 11/11 恢复绿。
  2. 新 e2e 的 env 泄漏:条数闸/成本带测试初版在模块作用域钉 BILI_MAX_MESSAGES=500 / BILI_INGEST_BODY_BYTES=1MiB,CI 测试车道多文件同进程运行时会泄漏进兄弟套件([Bug] Jimp is active, but image accumulation still triggers Responses WS 1009; duplicate request size not reduced (v0.1. | [Bug] Jimp 已生效,图片累积仍触发 Responses WS 1009;重复请求未缩小(v0.1.200) #3701 的 413 即此路径的早期信号)。修复:改为 per-test arm/disarm(finally 恢复原值)。

自查未修、说明原因:

  • 条数闸是纯判死、不做条数折叠——折叠在一轮 preflight 的轮次预算内关不掉 ~20K 条缺口,且规划器按 token 收益驱动(auto-fold sharp edges: a sub-floor autoFoldTargetTokens causes a fold storm, and externalSummary.* file edits do not take effect until a PUT /__bili/config #3444)。缺口大时的可执行动作是「重启/回退会话」,已写进 413 文案。
  • 成本带是常数 32MiB、非 env 可配——32MiB 可解析体已是 ≥~8M token(超所有真实窗口),不存在「合法的大于 32MiB 的 chat 文本体」,无需调参面;0 可经 env 关闭。
  • Responses 豁免是车道级而非内容级(内容级需要解析后才能判断,与「解析前拦截」的目的矛盾);该车道仍受槽位预算 + 5GiB 收件上限约束。

回归面:332 用例全绿(23 套件,含 #5932 的全部既有钉与 #3701/#857/#496 图片/WS 面),tsc 干净,config-surface / lifecycle-ledger 双 guard 通过。

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-09_gate-count-ingest (fa447f9)

Latest build — install this exact version

npm install -g billion-context@0.0.8695-pr.5973.ba9fe86

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
fa447f9 billion-context@0.0.8695-pr.5973.ba9fe86 build
108b1fd billion-context@0.0.8686-pr.5973.e019584 build
d1b2d8f billion-context@0.0.8684-pr.5973.814cfef build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5973.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title 会话历史超限按真实维度拦死:条数闸 + 32MiB 摄入成本带 + 判死信息点名超重字段 (#5000 #5794 #5885) [PR] Hard-block session history over-limit along real dimensions: message-count gate + 32MiB ingestion cost band + fatal erro | 会话历史超限按真实维度拦死:条数闸 + 32MiB 摄入成本带 + 判死信息点名超重字段 (#5000 #5794 #5885) Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 修复 commit 108b1fd(两个 guard 红,均非逻辑问题):

  1. unused-exports:MeasuredOutbound 接口被导出但无外部消费者 → 改回模块私有(measuredOutbound 函数的返回类型随之内部化)。
  2. docs-sync([docs][website] 配置文档单一事实源:从声明式 schema 生成 CONFIGURATION.md 与网站 /docs/(一步到位) #2107 drift guard):新增的 network.maxMessages / network.ingestBodyBytes 种子条目需要重新生成配置文档 → 已跑 tools/gen-config-docs.mjs generate 并提交再生成的 docs/configuration.md(EN/ZH)。
    (hermetic registry e2e 的 0s fail 是队列取消——"higher priority waiting request",非代码问题,新 push 会重跑。)

…trine #496/#3909)

The band's premise "any parseable body over 32 MiB is >=~8M tokens" holds
only for TEXT-dominated bodies: base64 pixels are excluded from the token
meter by design (#496/#1800/#857), so an over-band IMAGE body is not
automatically over-window. #3909's ~48 MiB image-dense chat requests would
have been refused 413 stage=ingest on every turn by the default-on band —
breaking a supported workload the outbound shed exists precisely for.

- handle.ts: over-band refusal now requires countImagesInRawBody(...) === 0
  (probe-gated, so text-dump rejection stays parse-free). The Responses-lane
  exemption is unchanged.
- tests/issue5794-ingest-cap.test.ts: +1 e2e — an over-band body carrying
  two ~800 KB images must NOT be refused at ingest (200 + forwarded), on a
  1M window where the pixels stay token-fit.
- yaml/lifecycle/CHANGELOG: wording corrected to "text-dominated"; docs
  regenerated (gen-config-docs).
@ranxianglei ranxianglei added bug Something isn't working p2 scope/wiring labels Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复 —— 本 PR 是 #5000/#5794/#5885 的实施,未发现其他同机制(会话历史按真实维度拦死)的在途条目。

标签:bug p2 scope/wiring(缺陷类:超限会话在上游不透明地死掉、超大文本体每轮烧事件循环至进程 FATAL;整体可用、特定条件严重;范围在请求管线/协议边界层,未触碰 kernel)。

审核结论:方向正确、实现质量达标;审出 1 处默认行为回归风险,已直接修进你的分支(fa447f9ce5),等该 head 上 CI 转绿即可合并。

验证过程(不止读 diff):

审出并已修复的回归(旧→新披露):32MiB 摄入成本带的前提「任何可解析的 32MiB+ 体 = ≥~8M token」对图片为主的体不成立——base64 像素按设计不进 token 计量(#496/#1800/#857「图片单独计费、绝不在原始字节上判死」),且 #3909 明确支持 ~48MiB 图片密集 chat 会话(出站 shed 就是为它存在的)。初版默认开的成本带会让这类会话每轮 413 stage=ingest——默认行为破坏受支持工作负载。修复:判死条件追加 countImagesInRawBody(...) === 0(先走廉价子串探针,文本 dump 的拒绝仍是零解析零 CPU;Responses 车道豁免保持不变)。旧行为(本 PR 初版):chat 车道一切超 32MiB 体一律 413 → 新行为:仅「超带且无图」才 413,带图体回落槽位预算/收件上限/车道 shed 治理,并补了反向 e2e(超带带图体必须放行到上游)。若你认为应保留严格字节带,回退这一个 commit 即可——但我不建议。

CI 状态:两个 guard 红(unused-exports / docs-sync)经 108b1fd 修复已绿;全量 test matrix 分片在我审核时仍在队列等待(fleet 拥塞,非红)。我的 push 会触发 fa447f9 上的全套重跑——以那一轮为准。

八问:

  1. 是什么问题:会话历史超限的三个真实维度——条数、解码后字节、哪个字段超重——此前要么没有闸(条数),要么判死信息只给总数不点名,超限会话在上游不透明地死掉,51MiB 文本体每轮独占事件循环数秒直至整进程 FATAL。
  2. 什么原因导致的:既有闸全部按字节/token 估算,而条数是任何尺寸估算都表达不了的维度(每条还各带 ~69B m-ref 标记);成本带最初不区分内容类型,而计量器体系里图片从来单算;判死信息没有字段级分桶。
  3. 影响范围与严重程度:p2——仅特定条件会话受影响(历史上限超上游条数上限、或解码后体 >32MiB 且文本为主);普通用户无感(条数闸默认关、成本带只在 32MiB 以上触发)。修复前症状:上游不透明死亡、或 [perf][dsh] 51.2 MiB / 29.6k-msg inbound has no cost admission - DecodedRequestAdmission only sees compressed bodies | 51.2 MiB 入站没有成本准入:admission 只覆盖压缩体 #5794 式整进程 FATAL + 全员缓存冷。
  4. 怎么修复的:三道闸各归其位——条数闸(按上游 opt-in,token 触发器之前 + 出站熔断双点执行)、维度点名判死信息(与计量器同源分桶 messages/tools[]/system/other)、解析前 32MiB 成本带(带图体豁免,回落到图片车道治理)。条数闸纯判死不折叠:一轮 preflight 预算关不掉 ~20K 条缺口,可执行动作是重启/回退,已写进 413 文案。
  5. 是否有回归问题:逐项清点过——[Bug] Jimp is active, but image accumulation still triggers Responses WS 1009; duplicate request size not reduced (v0.1. | [Bug] Jimp 已生效,图片累积仍触发 Responses WS 1009;重复请求未缩小(v0.1.200) #3701 WS 截图车道(豁免 + 自有预发送字节预算,本地 11/11 绿)、[PR] Over-window requests no longer sent raw upstream: three forwarding gates metered by actual outbound body size + 32 MiB c | 超窗请求不再裸发上游:三道转发闸按真实出站体计量 + 大请求 32MiB 成本带准入 (#5000 #4543 #5885 #5794) #5932 计量/doom 钉组(15/15 绿)、[Question] 非白名单上游(如 DeepSeek)图片按 b64/4 估算,实测高估约 100×;且该估算被写回 lastInputTokens 并自愈成 confirmed 窗口,使 #496 逃生门永久失效 #857/PR #489 后续: 默认图片计费 b64/4 在像素 tile 计费上游(官方 Anthropic/OpenAI)会硬 502 误杀多模态会话 #496 图片计费面(d1b2d8f 时 CI e2e 车道全绿;本次改动只放宽不收紧)、身份/解码路径未动。发现 1 处真回归风险并已修:成本带误杀带图体(见上「旧→新」),这是超出 PR 自述设计的唯一语义变更,特此披露。
  6. 是否破坏缓存:否。拒绝发生在会话状态写入之前,413 响应带 retryable=false;正常轮的缓存路径字节级不变。
  7. 是否改了设计方向:否。三道闸都挂在既有闸栈上(槽位预算→收件上限→成本带→计量判死→出站熔断),无新数据流。
  8. 是否引入了新的配置:2 个新键,均落在既有 network 段、均有 env 覆盖——network.maxMessages / BILI_MAX_MESSAGES(默认 0=关闭,按上游设置)、network.ingestBodyBytes / BILI_INGEST_BODY_BYTES(默认 32MiB,0=关闭)。无迁移;yaml/docs en+zh/lifecycle 台账齐备,config-surface 与 lifecycle-ledger 两 guard 绿。

判定:代码与测试达标,唯一审核发现已在分支内修复(fa447f9ce5)。fa447f9 上 CI 转绿后即可合并。

@ranxianglei
ranxianglei merged commit de7bbc9 into master Nov 9, 2026
108 of 152 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1100-master.de7bbc9 (rolling master tag).

npm install -g billion-context@0.0.1100-master.de7bbc9  # 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

bug Something isn't working ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant