From d351a4d3a93ce33cca16820022b36ec8c3c9b0f8 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Sat, 21 Nov 2026 14:36:15 +0800 Subject: [PATCH 1/2] fix: disable the 32 MiB ingest cost band by default for all lanes (#7426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #5794's ingest band proxied 'beyond every model window' by raw decoded bytes, which is invalid on the re-send lanes (opencode/dsh re-send the whole raw ledger every turn and bili folds it) — it 413'd a 33.5 MB opencode turn whose folded context was tiny. Default -> 0 (unlimited, all lanes); the sibling receive (5 GiB) / decode (10 GiB) transport guards still bound pathological bodies. BILI_INGEST_BODY_BYTES re-enables the band. Supersedes #6933. --- docs/configuration.ja.md | 4 ++-- docs/configuration.md | 4 ++-- docs/configuration.zh-CN.md | 4 ++-- docs/lifecycle.md | 2 +- src/knobs.ts | 29 ++++++++++++++++----------- tests/issue5794-ingest-cap.test.ts | 17 ++++++++++++++++ website/config-reference/process.yaml | 8 ++++---- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/docs/configuration.ja.md b/docs/configuration.ja.md index 4ab46538df..860ef825db 100644 --- a/docs/configuration.ja.md +++ b/docs/configuration.ja.md @@ -184,7 +184,7 @@ | `network.outboundBodyBytes` | number | 5368709120 | BILI_OUTBOUND_BODY_BYTES | 上流に転送される再構築リクエストの最大バイト数 (転送ステージ 413)。最終ボディ文字列の UTF-8 バイト数としてカウントされる。fetch 前にチェックされるため、予算超過の再構築は上流のウォッチドッグ割り当てに到達しない。 | | `network.wsOutboundBytes` | number | 10485760 | BILI_WS_OUTBOUND_BYTES | WebSocket レーン専用のソフトバイト予算 (#3701): 最終シリアライズされた Responses WS フレームがこれを超過した場合、まず OUTBOUND COPY から古い画像が除去される (プレースホルダーノートとしてアーカイブ — 元画像はセッションストレージに残り、ツールアームされたレーンでは read_original_image / decompress で復元可能 — 注入ツールを拒否する codex スタイルのレーンはサイズのみ注釈を保持)、その後残ったものは jimp maxDim ラダーを通じて有界にダウンスケールされる。それでもフレームが収まらず、イベント前に上流が 1009 でクローズした場合、同じリクエスト内で厳密に小さい再送信が 1 回試行される。0 に設定すると除去を無効化 (従来のそのまま送信する動作)。HTTP レーンには影響しない — ハード拒否上限は network.outboundBodyBytes のまま。 | | `network.httpOutboundBytes` | number | 10485760 | BILI_HTTP_OUTBOUND_BYTES | プレーン/プロキシ/pi ネイティブ HTTP リレーレーン専用のソフトバイト予算 (#3909): 最終シリアライズされたリクエストがこれを超過した場合、まず OUTBOUND COPY から古い画像が除去される (プレースホルダーノートとしてアーカイブ — 元画像はセッションストレージに残り、ツールアームされたレーンでは read_original_image / decompress で復元可能 — 注入ツールを拒否する codex スタイルのレーンはサイズのみ注釈を保持)、その後残ったものは jimp maxDim ラダーを通じて有界にダウンスケールされる。画像密集セッションが空けられるギャップを閉じる: トークンスペースの折りたたみはトークンで決定するが、上流はバイト/ピクセルデコード CPU (Cloudflare Worker 503) で拒否するため、約 48 MiB のリクエストは同じピクセルを再送信するたびに永遠に 503 になる。マネージドトランスポートがインストールされていない場合 (spawned リレー) のみ適用される; WS レーンは network.wsOutboundBytes を使用し、マネージド HTTP トランスポート (inline-engine / dsh-inline) はここでは決して除去されない (#3701 Finding 1)。0 に設定すると無効化 (従来のそのまま送信する動作); ハード拒否上限は network.outboundBodyBytes のまま。 | -| `network.ingestBodyBytes` | number | 33554432 | BILI_INGEST_BODY_BYTES | デコード後 (#5794 item 2) の JSON.parse + 正規化スイープのためのコストバンド (デコードバイト数)。これを超過するテキスト主体のボディは、スイープ前に実行可能な 413 (ステージ ingest) で拒否される。なぜなら、32 MiB を超えるパース可能なテキストボディはすでに約 800 万トークンであり、すべての実際のモデルウィンドウを超えており、それをパースするためにイベントループの時間を数秒消費する (51.2 MiB / 29,619 メッセージのインシデント: 1 ラウンドあたり 5.5–7.2 秒、ローカル CPU の 54.6%、FATAL 747 秒) ことは成功に終わらないためである。画像を含むボディはすべてのレーンで免除される: base64 ピクセルは設計上トークンメーターから除外される (画像は別途請求され、生バイト数では決して失格にならない — #496/#1800/#857) ため、バンド超過の画像量は、アドミッションスロット、受信上限、および各レーン独自の shed / 送信前バイト予算 (#3909 約 48 MiB の画像密集セッション、#3701 WS スクリーンショット; Responses レーンは完全に免除) によって管理される。アドミッション SLOTS (network.receiveBodyBytes 閾値) とは異なる: スロットは大型デコードの並行性を制限するが、この上限は単一のボディを制限する。0 に設定すると無効化 (従来のすべてパースする動作)。 | +| `network.ingestBodyBytes` | number | 0 | BILI_INGEST_BODY_BYTES | デコード後 (#5794 item 2) の JSON.parse + 正規化スイープのためのコストバンド (デコードバイト数)。これを超過するテキスト主体のボディは、スイープ前に実行可能な 413 (ステージ ingest) で拒否される。なぜなら、32 MiB を超えるパース可能なテキストボディはすでに約 800 万トークンであり、すべての実際のモデルウィンドウを超えており、それをパースするためにイベントループの時間を数秒消費する (51.2 MiB / 29,619 メッセージのインシデント: 1 ラウンドあたり 5.5–7.2 秒、ローカル CPU の 54.6%、FATAL 747 秒) ことは成功に終わらないためである。画像を含むボディはすべてのレーンで免除される: base64 ピクセルは設計上トークンメーターから除外される (画像は別途請求され、生バイト数では決して失格にならない — #496/#1800/#857) ため、バンド超過の画像量は、アドミッションスロット、受信上限、および各レーン独自の shed / 送信前バイト予算 (#3909 約 48 MiB の画像密集セッション、#3701 WS スクリーンショット; Responses レーンは完全に免除) によって管理される。アドミッション SLOTS (network.receiveBodyBytes 閾値) とは異なる: スロットは大型デコードの並行性を制限するが、この上限は単一のボディを制限する。#7426 以降デフォルト無効 (デフォルト 0, 全レーン): 再送信レーン (opencode / dsh) は毎ターン生台帳全体を再送信し bili が折りたたむため、受信の生バイト数は折りたたみ後コンテキストの代理にならない — バイト数を設定すると再有効化できる。 | | `network.maxMessages` | number | 0 | BILI_MAX_MESSAGES | 上流ごとの messages[] 配列長のハード上限 (#5000 item 2) — COUNT 次元: バイト/トークン推定では表現できないワイヤー制約 (#5000 セッションの 26,903 メッセージ / 55.2 MiB はすべてのサイズゲートを通過したが、カウントエラーで上流で死んだ)。意図的に上流ごと: 普遍的な値が存在しないため、デフォルトは 0 = 無効; 上流の既知の制限に設定し、カウント超過のボディには保証された上流 400 の代わりに実行可能な 413 (セッションの再起動または巻き戻し) を返す。カウントのみ — 決して折りたたまない。プリフライト (トークントリガーの前) および no-model レーンのエグレスフュージで強制される。 | | `network.caFile` | string | unset | BILI_CA_FILE | bili の独自のアップストリームフェッチが信頼する追加ルート CA を含む PEM ファイルへのパス (#3776)。Node の組み込みルートおよび NODE_EXTRA_CA_CERTS エントリとマージされる — 決して置き換えない。HTTPS/暗号化接続スキャンを行うセキュリティソフトウェア (Kaspersky、エンタープライズ DLP) またはアップストリームを再署名する企業 MITM プロキシに対して: そのルート CA を PEM にエクスポートし、これを指すように設定する。未設定 = デフォルトの信頼、バイト単位で同一の動作。 | | `guardrails` | object | {} (all defaults) | — | ガードレール: pi/omp プラグインバンドル用のツール出力ガードレール (#3066) およびプロキシ側のテキストランストリームガード (#3406)。 | @@ -1978,7 +1978,7 @@ ACP ネイティブエージェント(現在は `pi` 拡張機能)は、プ | `BILI_IMAGE_BILLING` | `imageBilling` | auto (resolves to pixels) | | `BILI_IMAGE_RESCALE` | `imageRescale` | true | | `BILI_IMAGE_TOKEN_CAP` | `imageTokenCap` | unset (uncapped) | -| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 33554432 | +| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 0 | | `BILI_INVARIANT_JUDGE` | `diagnostics.invariantJudge` | true | | `BILI_KEEP_ALIVE_TIMEOUT_MS` | `network.keepAliveTimeoutMs` | 5000 | | `BILI_LOG_BUDGET_BYTES` | `diagnostics.logBudgetBytes` | 268435456 (256 MiB, floor 1 MiB) | diff --git a/docs/configuration.md b/docs/configuration.md index da988fbe55..e515ad9374 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -187,7 +187,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `network.outboundBodyBytes` | number | 5368709120 | BILI_OUTBOUND_BODY_BYTES | Max rebuilt request bytes forwarded upstream (forward-stage 413), counted as UTF-8 bytes of the final body string. Checked before the fetch so an over-budget rebuild never reaches the upstream watchdog allocation. | | `network.wsOutboundBytes` | number | 10485760 | BILI_WS_OUTBOUND_BYTES | Soft byte budget for the WebSocket lane only (#3701): when the final serialized Responses WS frame exceeds it, older images are shed from the OUTBOUND COPY first (archived as placeholder notes — originals stay in session storage, recoverable via read_original_image / decompress on tool-armed lanes — codex-style lanes that reject injected tools keep the size-only annotation), then whatever remains is boundedly downscaled through the jimp maxDim ladder. If the frame still does not fit and the upstream closes with 1009 before any event, one strictly smaller resend is attempted within the same request. Set 0 to disable shedding (previous send-as-is behavior). HTTP lanes are unaffected — the hard refusal cap stays network.outboundBodyBytes. | | `network.httpOutboundBytes` | number | 10485760 | BILI_HTTP_OUTBOUND_BYTES | Soft byte budget for the plain/proxy/pi-native HTTP relay lane (#3909): when the final serialized request exceeds it, older images are shed from the OUTBOUND COPY first (archived as placeholder notes — originals stay in session storage, recoverable via read_original_image / decompress on tool-armed lanes — codex-style lanes that reject injected tools keep the size-only annotation), then whatever remains is boundedly downscaled through the jimp maxDim ladder. Closes the gap image-dense sessions leave open: token-space folding decides in tokens while the upstream rejects in bytes / pixel-decode CPU (Cloudflare Worker 503), so a ~48 MiB request 503s forever with every retry resending the same pixels. Applies only when no managed transport is installed (the spawned relay); the WS lane uses network.wsOutboundBytes and managed HTTP transports (inline-engine / dsh-inline) are never shed here (#3701 Finding 1). Set 0 to disable (previous send-as-is); the hard refusal cap stays network.outboundBodyBytes. | -| `network.ingestBodyBytes` | number | 33554432 | BILI_INGEST_BODY_BYTES | Cost band (decoded bytes) for the JSON.parse + normalization sweep AFTER decode (#5794 item 2). A TEXT-DOMINATED body above it is refused with an actionable 413 (stage ingest) before the sweep, because any parseable text body over 32 MiB is already ~8M tokens — beyond every real model window — and burning seconds of event-loop time to parse it (the 51.2 MiB / 29,619-message incident: 5.5–7.2 s per round, 54.6% of local CPU, 747 s FATAL) cannot end in success. Image-bearing bodies are exempt on every lane: base64 pixels are excluded from the token meter by design (images billed separately, never doomed on raw bytes — #496/#1800/#857), so over-band image mass stays governed by the admission slots, the receive cap and each lane's own shed / pre-send byte budget (#3909 ~48 MiB image-dense sessions, #3701 WS screenshots; the Responses lane is exempt outright regardless). Distinct from the admission SLOTS (network.receiveBodyBytes threshold): the slots cap CONCURRENCY of large decodes, this cap bounds a single body. Set 0 to disable (legacy parse-everything). | +| `network.ingestBodyBytes` | number | 0 | BILI_INGEST_BODY_BYTES | Cost band (decoded bytes) for the JSON.parse + normalization sweep AFTER decode (#5794 item 2). A TEXT-DOMINATED body above it is refused with an actionable 413 (stage ingest) before the sweep, because any parseable text body over 32 MiB is already ~8M tokens — beyond every real model window — and burning seconds of event-loop time to parse it (the 51.2 MiB / 29,619-message incident: 5.5–7.2 s per round, 54.6% of local CPU, 747 s FATAL) cannot end in success. Image-bearing bodies are exempt on every lane: base64 pixels are excluded from the token meter by design (images billed separately, never doomed on raw bytes — #496/#1800/#857), so over-band image mass stays governed by the admission slots, the receive cap and each lane's own shed / pre-send byte budget (#3909 ~48 MiB image-dense sessions, #3701 WS screenshots; the Responses lane is exempt outright regardless). Distinct from the admission SLOTS (network.receiveBodyBytes threshold): the slots cap CONCURRENCY of large decodes, this cap bounds a single body. **Disabled by default since #7426** (default 0, all lanes): on the re-send lanes (opencode / dsh) the host re-sends the whole raw ledger every turn and bili folds it, so raw inbound bytes are not a proxy for the folded context — set a byte count to re-arm the band. | | `network.maxMessages` | number | 0 | BILI_MAX_MESSAGES | Per-upstream hard cap on the messages[] array length (#5000 item 2) — the COUNT dimension: a wire constraint no byte/token estimate expresses (the 26,903-message / 55.2 MiB #5000 session cleared every size gate and died at the upstream with the count error). Per-UPSTREAM on purpose: there is no universal value, so the default is 0 = disabled; set it to your upstream's known limit and over-count bodies get an actionable 413 (restart the session or rewind) instead of a guaranteed upstream 400. Count only — it never folds. Enforced in preflight (before the token trigger) and at the egress fuse for the no-model lane. | | `network.caFile` | string | unset | BILI_CA_FILE | Path to a PEM file with extra root CAs trusted by bili's OWN upstream fetches (#3776). Merged with Node's built-in roots and any NODE_EXTRA_CA_CERTS entries — never replaces them. For security software doing HTTPS/encrypted-connection scanning (Kaspersky, enterprise DLP) or a corporate MITM proxy that re-signs the upstream: export that root CA to PEM and point this at it. Unset = default trust, byte-identical behavior. | | `guardrails` | object | {} (all defaults) | — | Guardrails: tool-output guardrails for the pi/omp plugin bundles (#3066) plus the proxy-side text-run stream guard (#3406). | @@ -1992,7 +1992,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | `BILI_IMAGE_BILLING` | `imageBilling` | auto (resolves to pixels) | | `BILI_IMAGE_RESCALE` | `imageRescale` | true | | `BILI_IMAGE_TOKEN_CAP` | `imageTokenCap` | unset (uncapped) | -| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 33554432 | +| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 0 | | `BILI_INVARIANT_JUDGE` | `diagnostics.invariantJudge` | true | | `BILI_KEEP_ALIVE_TIMEOUT_MS` | `network.keepAliveTimeoutMs` | 5000 | | `BILI_LOG_BUDGET_BYTES` | `diagnostics.logBudgetBytes` | 268435456 (256 MiB, floor 1 MiB) | diff --git a/docs/configuration.zh-CN.md b/docs/configuration.zh-CN.md index 43ab578e7f..e4b89a8440 100644 --- a/docs/configuration.zh-CN.md +++ b/docs/configuration.zh-CN.md @@ -187,7 +187,7 @@ | `network.outboundBodyBytes` | number | 5368709120 | BILI_OUTBOUND_BODY_BYTES | 转发到上游的重建请求字节上限(forward 阶段 413),按最终 body 字符串的 UTF-8 字节计。在 fetch 之前检查,超预算的重建不会触发上游看门狗分配。 | | `network.wsOutboundBytes` | number | 10485760 | BILI_WS_OUTBOUND_BYTES | 仅针对 WebSocket 通道的软字节预算(#3701):当最终序列化的 Responses WS 帧超出该预算时,优先从出站副本中裁减较早的图片(归档为占位符备注——原始文件仍保留在会话存储中,可通过 read_original_image / decompress 恢复——仅限注册了 bili 工具的通道;拒绝注入工具的 codex 类通道只有尺寸备注),随后对剩余内容通过 jimp maxDim 阶梯进行有界降采样。若帧仍超出限制且上游在任何事件发出前即以 1009 关闭连接,则在同一请求内尝试一次严格更小的重发。设为 0 可禁用裁减(即恢复此前的原样发送行为)。HTTP 通道不受影响——硬性拒绝上限仍为 network.outboundBodyBytes。 | | `network.httpOutboundBytes` | number | 10485760 | BILI_HTTP_OUTBOUND_BYTES | 面向普通/代理/pi 原生 HTTP 中继通道的软字节预算(#3909):当最终序列化的请求超出该预算时,优先从出站副本中裁减较早的图片(归档为占位符备注——原始文件仍保留在会话存储中,可通过 read_original_image / decompress 恢复——仅限注册了 bili 工具的通道;拒绝注入工具的 codex 类通道只有尺寸备注),随后对剩余内容通过 jimp maxDim 阶梯进行有界降采样。它补上图片密集会话留下的缺口:token 空间折叠按 token 决策,而上游按字节/像素解码 CPU 拒收(Cloudflare Worker 503),于是 ~48 MiB 的请求会永远 503、每次重试都重发同样的像素。仅在未安装受管传输(即 spawn 出来的中继)时生效;WebSocket 通道用 network.wsOutboundBytes,受管 HTTP 传输(inline-engine / dsh-inline)在此从不裁减(#3701 Finding 1)。设为 0 可禁用(恢复此前的原样发送);硬性拒绝上限仍为 network.outboundBodyBytes。 | -| `network.ingestBodyBytes` | number | 33554432 | BILI_INGEST_BODY_BYTES | 解码之后进入 JSON.parse+归一化清扫的成本带(解码后字节,#5794 第 2 项)。超限的**文本为主**的体在清扫之前以可操作的 413(stage ingest)拒收:任何可解析的 32 MiB+ 文本体都 ≥ ~8M token、超过一切真实模型窗口,为它烧掉数秒事件循环时间没有意义(51.2 MiB / 29,619 条消息现场:每轮 5.5–7.2s、占本机 CPU 54.6%、747s FATAL)。带图片的体在所有车道豁免:base64 像素按设计不进 token 计量(图片单独计费、绝不在原始字节上判死——#496/#1800/#857),超带的图片体量仍由准入槽位、收件上限与各车道自身的裁减/预发送字节预算治理(#3909 ~48 MiB 图片密集会话、#3701 WS 截图;Responses 车道无论如何整体豁免)。与大解码准入槽位(network.receiveBodyBytes 阈值)不同:槽位限的是大解码的并发数,本上限限的是单个体的成本。设为 0 可禁用(恢复此前的全解析)。 | +| `network.ingestBodyBytes` | number | 0 | BILI_INGEST_BODY_BYTES | 解码之后进入 JSON.parse+归一化清扫的成本带(解码后字节,#5794 第 2 项)。超限的**文本为主**的体在清扫之前以可操作的 413(stage ingest)拒收:任何可解析的 32 MiB+ 文本体都 ≥ ~8M token、超过一切真实模型窗口,为它烧掉数秒事件循环时间没有意义(51.2 MiB / 29,619 条消息现场:每轮 5.5–7.2s、占本机 CPU 54.6%、747s FATAL)。带图片的体在所有车道豁免:base64 像素按设计不进 token 计量(图片单独计费、绝不在原始字节上判死——#496/#1800/#857),超带的图片体量仍由准入槽位、收件上限与各车道自身的裁减/预发送字节预算治理(#3909 ~48 MiB 图片密集会话、#3701 WS 截图;Responses 车道无论如何整体豁免)。与大解码准入槽位(network.receiveBodyBytes 阈值)不同:槽位限的是大解码的并发数,本上限限的是单个体的成本。**#7426 起默认关闭**(默认 0,所有车道):重发车道(opencode / dsh)每轮重发整段原始台账、bili 折叠它,原始入站字节数并非折叠后上下文的代理——设成具体字节数可重新启用该带。 | | `network.maxMessages` | number | 0 | BILI_MAX_MESSAGES | 单上游 messages[] 数组长度硬限(#5000 第 2 项)——COUNT 维度:任何字节/token 估算都表达不了的线路约束(#5000 的 26,903 条消息 / 55.2 MiB 会话清掉所有尺寸闸后仍在上游以条数错误死掉)。刻意按上游设置:没有通用值,默认 0 = 关闭;把它设为你所连上游的已知上限后,超条数的体会得到可操作的 413(重启会话或 rewind)而不是一次必然的上游 400。只判条数、从不折叠。在 preflight(token 触发器之前)与无模型车道的出站熔断处强制执行。 | | `network.caFile` | string | unset | BILI_CA_FILE | PEM 文件路径,包含要额外信任的根 CA(#3776),仅作用于 bili 自己的上游 fetch。与 Node 内置根证书及 NODE_EXTRA_CA_CERTS 中的条目合并——从不替换。安全软件做 HTTPS/加密连接扫描(卡巴斯基、企业 DLP)或企业 MITM 代理重签上游时使用:把该厂商根证书导出为 PEM 并指向此键。未设置 = 默认信任,行为逐字节不变。 | | `guardrails` | object | {} (all defaults) | — | 守卫集合:pi/omp 插件的工具输出守卫(#3066)及代理侧流式 text-run 守卫(#3406)。 | @@ -1969,7 +1969,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | `BILI_IMAGE_BILLING` | `imageBilling` | auto (resolves to pixels) | | `BILI_IMAGE_RESCALE` | `imageRescale` | true | | `BILI_IMAGE_TOKEN_CAP` | `imageTokenCap` | unset (uncapped) | -| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 33554432 | +| `BILI_INGEST_BODY_BYTES` | `network.ingestBodyBytes` | 0 | | `BILI_INVARIANT_JUDGE` | `diagnostics.invariantJudge` | true | | `BILI_KEEP_ALIVE_TIMEOUT_MS` | `network.keepAliveTimeoutMs` | 5000 | | `BILI_LOG_BUDGET_BYTES` | `diagnostics.logBudgetBytes` | 268435456 (256 MiB, floor 1 MiB) | diff --git a/docs/lifecycle.md b/docs/lifecycle.md index fa839b7f5c..48a3122fd8 100644 --- a/docs/lifecycle.md +++ b/docs/lifecycle.md @@ -111,7 +111,7 @@ | `BILI_OUTBOUND_BODY_BYTES` | network.outboundBodyBytes,5 GiB——重建后转发上游的硬上限(#3128) | | `BILI_WS_OUTBOUND_BYTES` | network.wsOutboundBytes,10 MiB——WS 车道出站软预算:超限先把旧的非保护图归档/降采样再发送(#3701:网关对大帧 close 1009;0 关闭预发送削减;HTTP 车道不受影响) | | `BILI_HTTP_OUTBOUND_BYTES` | network.httpOutboundBytes,10 MiB——普通/代理/pi 原生 HTTP 中继车道出站软预算:超限先把旧的非保护图归档/降采样再发送(#3909:图片密集会话按字节/像素解码 CPU 被上游拒收、token 折叠不触发;仅在无受管传输时生效,受管 HTTP/dsh-inline 从不裁减 #3701 Finding 1;0 关闭) | -| `BILI_INGEST_BODY_BYTES` | network.ingestBodyBytes,32 MiB——解码后进入 JSON.parse+归一化清扫的成本带(#5794:51.2 MiB 体每轮吞 5.5–7.2s 事件循环 → 747s FATAL;超带的**文本为主**体即 413,因为任何可解析的 32 MiB+ 文本体 ≥ ~8M token、超过一切真实窗口;带图片的体豁免——像素按设计不进 token 计量,由槽位预算/收件上限/车道 shed 治理(#496/#3909/#3701);0 关闭) | +| `BILI_INGEST_BODY_BYTES` | network.ingestBodyBytes,0(#7426 起默认对所有车道关闭;重发车道原始入站字节≠上下文)——解码后进入 JSON.parse+归一化清扫的成本带(#5794:51.2 MiB 体每轮吞 5.5–7.2s 事件循环 → 747s FATAL;超带的**文本为主**体即 413,因为任何可解析的 32 MiB+ 文本体 ≥ ~8M token、超过一切真实窗口;带图片的体豁免——像素按设计不进 token 计量,由槽位预算/收件上限/车道 shed 治理(#496/#3909/#3701);0 关闭) | | `BILI_MAX_MESSAGES` | network.maxMessages,默认 0(关闭)——单上游 messages[] 数组长度硬限(COUNT 维度,任何字节/token 估算都表达不了;#5000:26,903 条消息体清掉所有尺寸闸仍在上游死掉;超限 413 提示 restart/rewind,不做折叠;按上游各自设置) | | `BILI_CACHE_KEEPALIVE`(#3376) | unset(false;同 `cacheKeepalive.enabled` 层级 env 覆盖) | | `BILI_CACHE_KEEPALIVE_ASSUME_TTL` | unset(从 body cache_control 断点探测) | diff --git a/src/knobs.ts b/src/knobs.ts index 9fe5ee2e2c..54869f278a 100644 --- a/src/knobs.ts +++ b/src/knobs.ts @@ -284,12 +284,16 @@ const DEFAULT_LIMITS_DECODED_BYTES = 10 * 1024 * 1024 * 1024; const DEFAULT_LIMITS_OUTBOUND_BYTES = 5 * 1024 * 1024 * 1024; const DEFAULT_WS_OUTBOUND_BYTES = 10 * 1024 * 1024; const DEFAULT_HTTP_OUTBOUND_BYTES = 10 * 1024 * 1024; -// #5794: the ingest cost band (decoded bytes) that may run the JSON.parse / -// normalization sweep. 32 MiB ≈ the observed 51.2 MiB/29,619-msg incident -// (5.5–7.2 s per round, 54.6% of local CPU, 747 s event-loop FATAL); any -// parseable body ABOVE it is already ≥ ~8M tokens = 5–10× the largest model -// window, so it can never succeed. 0 = no ingest cap (legacy). -const DEFAULT_INGEST_BODY_BYTES = 32 * 1024 * 1024; +// #5794 → #7426: disabled by default (0 = no ingest cap, all lanes). The original +// 32 MiB cost band was a proxy for "beyond every model window", but on the re-send +// lanes (opencode/dsh re-send the ENTIRE raw ledger every turn and bili folds it) +// the RAW inbound byte count says nothing about the real (folded) context — it 413'd +// a 33.5 MB opencode turn whose folded context was tiny. So the band is OFF for all +// lanes by default (#7426, user decision). Set BILI_INGEST_BODY_BYTES / +// network.ingestBodyBytes to re-enable the #5794 cost band if a specific deployment +// hits the pre-fold parse CPU (51.2 MiB incident: 5.5–7.2 s/round, 54.6% CPU, +// 747 s event-loop FATAL). +const DEFAULT_INGEST_BODY_BYTES = 0; /** BILI_RECEIVE_BODY_BYTES > network.receiveBodyBytes > 5 GiB. Max inbound wire bytes * read into memory per request. #3128: these were hardcoded 100 MiB constants; the @@ -343,12 +347,13 @@ export function limitsHttpOutboundBytes(): number { return Number.isFinite(v) && v >= 0 ? Math.floor(v) : DEFAULT_HTTP_OUTBOUND_BYTES; } -/** BILI_INGEST_BODY_BYTES > network.ingestBodyBytes > 32 MiB. Cost band for the - * JSON.parse + normalization sweep AFTER decode (the 51.2 MiB #5794 body spent - * seconds there per round). Bodies above it are refused before the sweep with - * an actionable 413; any parseable body over 32 MiB is ≥ ~8M tokens, i.e. - * beyond every real model window, so nothing valid is blocked. 0 disables the - * ingest cap (legacy parse-everything). */ +/** BILI_INGEST_BODY_BYTES > network.ingestBodyBytes > 0 (disabled). Cost band for + * the JSON.parse + normalization sweep AFTER decode (#5794). DISABLED by default for + * all lanes (#7426): on the re-send lanes (opencode/dsh) the raw inbound byte count is + * not a valid "beyond model window" proxy — it 413'd a 33.5 MB opencode turn whose + * folded context was tiny. Set BILI_INGEST_BODY_BYTES to re-enable the #5794 cost band + * (any parseable body over 32 MiB is ≥ ~8M tokens, beyond every real model window). + * 0 = no ingest cap (parse-everything). */ export function limitsIngestBytes(): number { const v = tInt("BILI_INGEST_BODY_BYTES", loadConfigFile().network?.ingestBodyBytes); return Number.isFinite(v) && v >= 0 ? Math.floor(v) : DEFAULT_INGEST_BODY_BYTES; diff --git a/tests/issue5794-ingest-cap.test.ts b/tests/issue5794-ingest-cap.test.ts index e9a5c6c266..13bede2e3a 100644 --- a/tests/issue5794-ingest-cap.test.ts +++ b/tests/issue5794-ingest-cap.test.ts @@ -33,6 +33,7 @@ import { startServer } from "../src/server.ts"; import type { ProxyOptions } from "../src/config.ts"; import { SessionStore, _setStoreForTest } from "../src/persist.ts"; import { _setForTest as setRegistryForTest } from "../src/registry.ts"; +import { limitsIngestBytes } from "../src/knobs.ts"; import { rmrf } from "./tmp-rm.ts"; const WINDOW = 20_000; @@ -116,6 +117,22 @@ async function setup(window = WINDOW): Promise<{ ctx: Ctx; calls: Call[]; close: }; } +// #7426: the band is DISABLED by default (0 = no ingest cap) for ALL lanes. The e2e tests +// below arm it explicitly (1 MiB via BILI_INGEST_BODY_BYTES), so this pins the new default +// they would otherwise hide, plus the opt-in re-arm path (operator still has the escape hatch). +test("#7426: ingest band defaults to 0 (unlimited, all lanes); BILI_INGEST_BODY_BYTES re-arms it", () => { + const prev = process.env.BILI_INGEST_BODY_BYTES; + try { + delete process.env.BILI_INGEST_BODY_BYTES; + assert.equal(limitsIngestBytes(), 0, `default must be 0 = no ingest cap (#7426), got ${limitsIngestBytes()}`); + process.env.BILI_INGEST_BODY_BYTES = "33554432"; + assert.equal(limitsIngestBytes(), 33554432, "BILI_INGEST_BODY_BYTES re-arms the #5794 cost band"); + } finally { + if (prev === undefined) delete process.env.BILI_INGEST_BODY_BYTES; + else process.env.BILI_INGEST_BODY_BYTES = prev; + } +}); + const postMessages = (ctx: Ctx, content: string) => fetch(ctx.url, { method: "POST", diff --git a/website/config-reference/process.yaml b/website/config-reference/process.yaml index 6a0632a4e6..6d152d5023 100644 --- a/website/config-reference/process.yaml +++ b/website/config-reference/process.yaml @@ -215,12 +215,12 @@ entries: desc_ja: "プレーン/プロキシ/pi ネイティブ HTTP リレーレーン専用のソフトバイト予算 (#3909): 最終シリアライズされたリクエストがこれを超過した場合、まず OUTBOUND COPY から古い画像が除去される (プレースホルダーノートとしてアーカイブ — 元画像はセッションストレージに残り、ツールアームされたレーンでは read_original_image / decompress で復元可能 — 注入ツールを拒否する codex スタイルのレーンはサイズのみ注釈を保持)、その後残ったものは jimp maxDim ラダーを通じて有界にダウンスケールされる。画像密集セッションが空けられるギャップを閉じる: トークンスペースの折りたたみはトークンで決定するが、上流はバイト/ピクセルデコード CPU (Cloudflare Worker 503) で拒否するため、約 48 MiB のリクエストは同じピクセルを再送信するたびに永遠に 503 になる。マネージドトランスポートがインストールされていない場合 (spawned リレー) のみ適用される; WS レーンは network.wsOutboundBytes を使用し、マネージド HTTP トランスポート (inline-engine / dsh-inline) はここでは決して除去されない (#3701 Finding 1)。0 に設定すると無効化 (従来のそのまま送信する動作); ハード拒否上限は network.outboundBodyBytes のまま。" - key: network.ingestBodyBytes type: number - default: "33554432" + default: "0" env: BILI_INGEST_BODY_BYTES group: process - desc_en: "Cost band (decoded bytes) for the JSON.parse + normalization sweep AFTER decode (#5794 item 2). A TEXT-DOMINATED body above it is refused with an actionable 413 (stage ingest) before the sweep, because any parseable text body over 32 MiB is already ~8M tokens — beyond every real model window — and burning seconds of event-loop time to parse it (the 51.2 MiB / 29,619-message incident: 5.5–7.2 s per round, 54.6% of local CPU, 747 s FATAL) cannot end in success. Image-bearing bodies are exempt on every lane: base64 pixels are excluded from the token meter by design (images billed separately, never doomed on raw bytes — #496/#1800/#857), so over-band image mass stays governed by the admission slots, the receive cap and each lane's own shed / pre-send byte budget (#3909 ~48 MiB image-dense sessions, #3701 WS screenshots; the Responses lane is exempt outright regardless). Distinct from the admission SLOTS (network.receiveBodyBytes threshold): the slots cap CONCURRENCY of large decodes, this cap bounds a single body. Set 0 to disable (legacy parse-everything)." - desc_zh: "解码之后进入 JSON.parse+归一化清扫的成本带(解码后字节,#5794 第 2 项)。超限的**文本为主**的体在清扫之前以可操作的 413(stage ingest)拒收:任何可解析的 32 MiB+ 文本体都 ≥ ~8M token、超过一切真实模型窗口,为它烧掉数秒事件循环时间没有意义(51.2 MiB / 29,619 条消息现场:每轮 5.5–7.2s、占本机 CPU 54.6%、747s FATAL)。带图片的体在所有车道豁免:base64 像素按设计不进 token 计量(图片单独计费、绝不在原始字节上判死——#496/#1800/#857),超带的图片体量仍由准入槽位、收件上限与各车道自身的裁减/预发送字节预算治理(#3909 ~48 MiB 图片密集会话、#3701 WS 截图;Responses 车道无论如何整体豁免)。与大解码准入槽位(network.receiveBodyBytes 阈值)不同:槽位限的是大解码的并发数,本上限限的是单个体的成本。设为 0 可禁用(恢复此前的全解析)。" - desc_ja: "デコード後 (#5794 item 2) の JSON.parse + 正規化スイープのためのコストバンド (デコードバイト数)。これを超過するテキスト主体のボディは、スイープ前に実行可能な 413 (ステージ ingest) で拒否される。なぜなら、32 MiB を超えるパース可能なテキストボディはすでに約 800 万トークンであり、すべての実際のモデルウィンドウを超えており、それをパースするためにイベントループの時間を数秒消費する (51.2 MiB / 29,619 メッセージのインシデント: 1 ラウンドあたり 5.5–7.2 秒、ローカル CPU の 54.6%、FATAL 747 秒) ことは成功に終わらないためである。画像を含むボディはすべてのレーンで免除される: base64 ピクセルは設計上トークンメーターから除外される (画像は別途請求され、生バイト数では決して失格にならない — #496/#1800/#857) ため、バンド超過の画像量は、アドミッションスロット、受信上限、および各レーン独自の shed / 送信前バイト予算 (#3909 約 48 MiB の画像密集セッション、#3701 WS スクリーンショット; Responses レーンは完全に免除) によって管理される。アドミッション SLOTS (network.receiveBodyBytes 閾値) とは異なる: スロットは大型デコードの並行性を制限するが、この上限は単一のボディを制限する。0 に設定すると無効化 (従来のすべてパースする動作)。" + desc_en: "Cost band (decoded bytes) for the JSON.parse + normalization sweep AFTER decode (#5794 item 2). A TEXT-DOMINATED body above it is refused with an actionable 413 (stage ingest) before the sweep, because any parseable text body over 32 MiB is already ~8M tokens — beyond every real model window — and burning seconds of event-loop time to parse it (the 51.2 MiB / 29,619-message incident: 5.5–7.2 s per round, 54.6% of local CPU, 747 s FATAL) cannot end in success. Image-bearing bodies are exempt on every lane: base64 pixels are excluded from the token meter by design (images billed separately, never doomed on raw bytes — #496/#1800/#857), so over-band image mass stays governed by the admission slots, the receive cap and each lane's own shed / pre-send byte budget (#3909 ~48 MiB image-dense sessions, #3701 WS screenshots; the Responses lane is exempt outright regardless). Distinct from the admission SLOTS (network.receiveBodyBytes threshold): the slots cap CONCURRENCY of large decodes, this cap bounds a single body. **Disabled by default since #7426** (default 0, all lanes): on the re-send lanes (opencode / dsh) the host re-sends the whole raw ledger every turn and bili folds it, so raw inbound bytes are not a proxy for the folded context — set a byte count to re-arm the band." + desc_zh: "解码之后进入 JSON.parse+归一化清扫的成本带(解码后字节,#5794 第 2 项)。超限的**文本为主**的体在清扫之前以可操作的 413(stage ingest)拒收:任何可解析的 32 MiB+ 文本体都 ≥ ~8M token、超过一切真实模型窗口,为它烧掉数秒事件循环时间没有意义(51.2 MiB / 29,619 条消息现场:每轮 5.5–7.2s、占本机 CPU 54.6%、747s FATAL)。带图片的体在所有车道豁免:base64 像素按设计不进 token 计量(图片单独计费、绝不在原始字节上判死——#496/#1800/#857),超带的图片体量仍由准入槽位、收件上限与各车道自身的裁减/预发送字节预算治理(#3909 ~48 MiB 图片密集会话、#3701 WS 截图;Responses 车道无论如何整体豁免)。与大解码准入槽位(network.receiveBodyBytes 阈值)不同:槽位限的是大解码的并发数,本上限限的是单个体的成本。**#7426 起默认关闭**(默认 0,所有车道):重发车道(opencode / dsh)每轮重发整段原始台账、bili 折叠它,原始入站字节数并非折叠后上下文的代理——设成具体字节数可重新启用该带。" + desc_ja: "デコード後 (#5794 item 2) の JSON.parse + 正規化スイープのためのコストバンド (デコードバイト数)。これを超過するテキスト主体のボディは、スイープ前に実行可能な 413 (ステージ ingest) で拒否される。なぜなら、32 MiB を超えるパース可能なテキストボディはすでに約 800 万トークンであり、すべての実際のモデルウィンドウを超えており、それをパースするためにイベントループの時間を数秒消費する (51.2 MiB / 29,619 メッセージのインシデント: 1 ラウンドあたり 5.5–7.2 秒、ローカル CPU の 54.6%、FATAL 747 秒) ことは成功に終わらないためである。画像を含むボディはすべてのレーンで免除される: base64 ピクセルは設計上トークンメーターから除外される (画像は別途請求され、生バイト数では決して失格にならない — #496/#1800/#857) ため、バンド超過の画像量は、アドミッションスロット、受信上限、および各レーン独自の shed / 送信前バイト予算 (#3909 約 48 MiB の画像密集セッション、#3701 WS スクリーンショット; Responses レーンは完全に免除) によって管理される。アドミッション SLOTS (network.receiveBodyBytes 閾値) とは異なる: スロットは大型デコードの並行性を制限するが、この上限は単一のボディを制限する。#7426 以降デフォルト無効 (デフォルト 0, 全レーン): 再送信レーン (opencode / dsh) は毎ターン生台帳全体を再送信し bili が折りたたむため、受信の生バイト数は折りたたみ後コンテキストの代理にならない — バイト数を設定すると再有効化できる。" - key: network.maxMessages type: number default: "0" From 6f4f05002e5afcb4a3ca806373d0eb2d303d9388 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 21 Nov 2026 14:58:13 +0800 Subject: [PATCH 2/2] docs: align stale ingest-band comments with the disabled default + CHANGELOG entry (#7426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drive-by: three code comments still described the 32 MiB band as the active default (content-encoding.ts, config.ts, handle.ts) — comments that disagree with the code are defects; reworded to 'disabled by default since #7426, set a byte value to re-enable'. Added the [Unreleased] Changed entry for the default flip (32 MiB -> 0, all lanes) per the per-PR CHANGELOG convention. --- CHANGELOG.md | 1 + src/config.ts | 9 ++++++--- src/content-encoding.ts | 3 ++- src/server/handle.ts | 6 ++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c7bd7a61..c7ddc385a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag - **compress-at-fold-point 整功能移除(owner 指令 2026-11-10,#6132;v1 #5471 + 未发布的 v2 #5949)**:删除 `compress.compressAtFoldPoint` / `compress.compressAtFoldPointClearThinking` 配置键、`BILI_COMPRESS_AT_FOLD_POINT` / `BILI_COMPRESS_AT_FOLD_POINT_CLEAR_THINKING` env、kernel 的 `relocate-compress-carriers` 管线节点与 `relocateCompressCarriers` / `planRelocateCompressCarriers` 导出、`Config.reasoningDroppable`、v2 的 `already-folded-echo` 解析 kind、web 配置行与 i18n 文案、config-reference/站点文档与博客文章(owner 指令直接删除)。移除原因:9 天内在其目标模型家族(qwen3-27b 系)出现两次不同的真实事故——2026-11-08 v1 引发的自发重复压缩循环(#5949 现场报告,v2 的设计动机)与 2026-11-10 生产会话(v0.1.213,v1 语义)中的作者误认:同轮「回答 + compress」被重放时,压缩对挪位后该轮回答文本裸挂在 transcript 尾部(无 pending 工具调用、无工具结果、无用户输入),27B 模型把自己的最后一条发言当成用户消息(m00376 链),重复回答了自己的答案且错误认知被固化进折叠块主题。v2 从未发布(最新 tag v0.1.213 仍为 v1,`git tag --contains` 为空),移除零迁移成本:开关关闭时布局就是移除后的布局(字节级一致)。旧配置残留的键:一次性 INERT 警告(`warnInertRemovedCompressKeys`,含 top-level 残留)并忽略值。kernel 0.0.192 → 0.0.193。回归面:`tests/removed-compress-keys-inert.test.ts`(新增移除键用例)、`tests/compress-reject-reasons.test.ts`(删除 echo 用例)、`kernel/tests/parse-compress-input.test.ts`(删除两个 pointer-echo 用例)、`kernel/tests/pipeline.test.ts`(节点清单)。 ### Changed +- **ingest 32 MiB 成本带默认对所有车道关闭(owner 拍板,#7426)**:`network.ingestBodyBytes` / `BILI_INGEST_BODY_BYTES` 默认 **33554432(32 MiB)→ 0(关闭)**。#5794 成本带的前提是「入站字节数 ≈ 模型输入 token 数」,这对出站/增量车道成立,对重发车道不成立(opencode/dsh 每轮把整段原始台账重发、bili 折叠后才发上游)——#7426 的 opencode 会话折叠后上下文仅 ~39 万 token,原始重发体 33.5 MB,每轮在 `stage: ingest` 被 413、永远发不出去(且自锁:越需要折叠的会话越先撞闸)。关闭后两段传输层兜底仍在:`receive` 收件默认 5 GiB、`decode` 解码后默认 10 GiB(内存/DoS 保护,不是 token 窗口保护)。重新启用:把 `BILI_INGEST_BODY_BYTES`(或 `network.ingestBodyBytes`)设成具体字节数。回归:tests/issue5794-ingest-cap 新增默认值单测(默认 0 + env 重新启用),既有 3 个 e2e(显式 1 MiB 测试带)不受影响。 - **存储缺省翻纯 SQLite:JSON 信封写出默认关闭,新增 `storage.unified=sqlite` 拼写(owner 指令 2026-11-13)**:此前缺省 = `unified=full` + `jsonWriter=on`(索引+legacy JSON 信封双写);现在 `storage.unified` 留空或 `sqlite` = **纯 SQLite**(索引 index.db 是唯一持久副本,不再写 `.json`/`.md` 信封)。已有数据不受影响——索引始终是读权威,旧信封照常可读可恢复;但纯索引会话对 ≤v0.1.196 的二进制不可见,请把 index.db 纳入备份(面板一次性提示 storage-sqlite-default 可关闭)。**显式 `storage.unified=full` 的用户保持历史双写缺省(零变化)**;恢复双写 = `storage.jsonWriter=on`(或 `BILI_STORAGE_JSON_WRITER=1`),`storage.jsonWriter` 现在也接受显式 `on`。`sqlite` 是拼写不是新内核模式(内核机器类型仍 `legacy|shadow|full`,未来 mysql/json 等后端拼写同形)。注意:纯 sqlite 缺省下**新会话没有信封可重建**——索引损坏的恢复来源是备份与双写期所写信封(quick_check 语义不变,响亮报警+降级只读)。process.yaml / env-only.yaml / README×3 同步,web 详情标签 `det.storage_mode_full` 文案去「双写」字样。 - **会话详情「交接文档」(handoff) web 渲染升级:Markdown 正文 + 语法高亮 + 角色卡片(eWork 风格)**:此前 handoff 页把每条消息正文按纯文本转义直出——assistant 回复里的粗体/行内代码/链接全是字面量,代码块原样显示 ``` 围栏,工具输入输出是一大块无语言、无高亮、无复制按钮的 pre。现在:① 消息正文(含思维链)按 Markdown 渲染,服务端 `markdownToHtml`(博客文章、handoff 兜底)与浏览器 IIFE 共用同一实现——新共享核心 `src/web/mdrender.ts`(转义优先、零运行时依赖,dist 零依赖守卫不变,`.toString()` 内联进 IIFE,附自包含契约测试防转译破坏);② 代码块按语言高亮(json/diff/js/ts/py/sh 等手写词法器,GitHub 明/暗双配色,未知语言退化为纯文本转义,注入面全转义);③ 消息改角色卡片布局(user/assistant/tool 左边框 + 徽章,思维链默认收起,工具卡输入/输出标签 + 语言标注 + 复制按钮 + JSON 美化,≤20 行默认展开);④ 文档头元信息(标题/session id/token 数/压缩块)不再被客户端跳过,渲染为灰底 key-value 盒;新增 GFM task list 复选框。回归:tests/mdrender.test.ts(18 用例,含 esbuild-minify 复刻 tsup 产线的内联契约)、tests/web-handoff-roles.test.ts 适配新 markup(#2065 语义不变量保留:正文 `### N.N` 标题不成为角色分隔线)、tests/web-sessions.test.ts(XSS/unsafe-link/handoffHtml 断言原样穿过新实现),全部 web 沙箱测试套件绿。 - **AGENTS.md 瘦身(owner 指令 2026-11-08):76 KB → 50.6 KB(−34%),规则零丢失,编号不变**。KDD 分两级:Tier A(#2/#4/#6/#7/#8/#10,每会话操作规则)留 AGENTS.md 全文;Tier B(#1/#3/#5/#9/#11–#18)全文逐字搬入新文件 `reference/design-decisions.md`(append-only 台账,**KDD 编号 = 稳定公共 API,原样保留**),AGENTS.md 每条留 1–3 行操作性后果 + 指针。Issue 分类与标签规则整节搬入 `reference/triage.md`(p1 口径与总账讨论链接留在正文)。E2E/Release 细则收敛为指向既有 `reference/testing.md` / `reference/release.md` 的硬规则。被反向引用的 heading 锚点(`#4-git-safety-rules-mandatory` 等 6 处)文本原样不动。 diff --git a/src/config.ts b/src/config.ts index 31c4c0cd00..520b9c8e66 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2400,9 +2400,12 @@ type FileConfig = { * guaranteed upstream 400. Count only — it never folds. Env BILI_MAX_MESSAGES wins. */ maxMessages?: number; /** #5794 item 2: cost band (decoded bytes) for the JSON.parse + normalization sweep AFTER - * decode; a body above it is refused with an actionable 413 before the sweep, because any - * parseable body over 32 MiB is ≥ ~8M tokens — beyond every real model window. 0 disables - * the ingest cap (legacy parse-everything). Env BILI_INGEST_BODY_BYTES wins. */ + * decode; when re-enabled, a body above it is refused with an actionable 413 before the + * sweep, because any parseable body over 32 MiB is ≥ ~8M tokens — beyond every real model + * window. DISABLED by default for all lanes (#7426): on the re-send lanes (opencode/dsh + * re-send the entire raw ledger every turn and bili folds it) the raw inbound byte count + * is not a valid "beyond model window" proxy. 0 = no ingest cap (the default); set a byte + * value to re-enable. Env BILI_INGEST_BODY_BYTES wins. */ ingestBodyBytes?: number; }; /** Session persistence knobs (#2030) — was BILI_PERSIST_* env-only. */ diff --git a/src/content-encoding.ts b/src/content-encoding.ts index bccd5d2fd1..a2fd25f7b4 100644 --- a/src/content-encoding.ts +++ b/src/content-encoding.ts @@ -15,7 +15,8 @@ export class DecompressedTooLargeError extends Error { } /** #5794 item 2: raised for a decoded body above the INGEST cost band - * (network.ingestBodyBytes / BILI_INGEST_BODY_BYTES, default 32 MiB). Distinct + * (network.ingestBodyBytes / BILI_INGEST_BODY_BYTES; disabled by default since + * #7426 — 0 = no cap, set a byte value to re-enable). Distinct * from DecompressedTooLargeError (a decode-cap bomb guard): this one bounds the * JSON.parse + normalization sweep itself — a 51.2 MiB / 29,619-message body * spent 5.5–7.2 s per round there (54.6% of local CPU → 747 s event-loop diff --git a/src/server/handle.ts b/src/server/handle.ts index a3d4e59067..e2e4afb07a 100644 --- a/src/server/handle.ts +++ b/src/server/handle.ts @@ -522,8 +522,10 @@ async function handleRequest( // session). Any TEXT-dominated parseable body above the ingest // cost band is already ≥ ~8M tokens — beyond every real model // window — so refuse it HERE, after decode (which can balloon - // 10:1) but before the sweep that costs the seconds. 0 disables - // the cap (legacy parse-everything). + // 10:1) but before the sweep that costs the seconds. DISABLED + // by default for all lanes (#7426: on the re-send lanes the raw + // inbound byte count is not a valid "beyond model window" + // proxy); set a byte value to re-enable. // // Image-bearing bodies are exempt on EVERY lane: base64 pixels // are excluded from the token meter by design ("images billed