Repository navigation
Description
TL;DR
opencode(x-bili-plugin: "opencode")车道每轮把整份原始历史重发给代理(LLM 无状态),bili 负责折叠后再发上游。会话攒到约 32 MiB 时,IngestBodyTooLargeError 在 JSON.parse 之前、也就是在 preflight 折叠之前就把请求 413 掉。结果是一个折叠状态完全健康、实际上下文只有约 39 万 token 的老会话,被永久锁死。
关键点:#6908 已经描述了同一"量的是折叠前入站体"的缺陷,而 #6933 的修复只豁免 x-bili-plugin: dsh 车道,其正文并明确写着"the band still refuses non-dsh over-band bodies exactly as before"。opencode 是非 dsh 车道,所以即便 #6933 合并,opencode 长会话依旧会被这道闸打死——这是 #6908/#6933 都没覆盖到的残留缺口。
环境
- billion-context 0.1.216(commit
6a641f378,npm latest,本地无其它补丁) - 客户端:opencode(V2 lane,
session_v2);插件注册头x-bili-plugin: "opencode" - 上游 relay:本机
http://127.0.0.1:3425/v1;upstreamProxyMode=direct - 模型窗口 1,000,000(reserved 936,000),
ingestBodyBytes= 默认 32 MiB
现象(真实会话)
报错会话 ses_e13469e1cffetZm7XKVjFJ5QpX(title "flyrouter WS余额门路径差异 PoC",parent_id=null、fork_session_id=null,不是 fork 会话)。用户 UI 明确显示"上下文 39万 · US$8.73",随后每轮 413:
request body 33,574,033 B (after decode) exceeds the ingestion cost band 33,554,432 B
(#5794: bodies this large are ≥ ~8M tokens — beyond every model window — and burn the
event loop for seconds in the parse sweep). Reduce the session history — restart the
session or rewind to an earlier point — and retry.
bili.log 里该会话同一错误反复出现(跨进程归档 12 次 413: request body exceeds 33554432 bytes)。超线幅度极小:33,574,033 vs 33,554,432 = 只超 19,601 字节(0.06%)。
会话真实状态(index.db)证明它其实很该被折叠、且已经折叠得很好:
| 指标 | 值 | 说明 |
|---|---|---|
contextTokens / lastInputTokens |
391,803 | 上次实际发给模型的量(UI 显示"39万"的来源) |
bili blocks |
390 | 已有 390 个压缩块,折叠状态健康 |
rawInputTokens |
8,015,403 | opencode 这一轮重发的整份原文 |
session_message 行数 |
6224 |
即:入站原始体 8.0M token / 33.5 MB,但其中约 95% 是 bili 已折叠、本可再压掉的废料。32 MiB 硬闸不看这个事实,只按原始字节数判死。
根因(源码逐行,0.1.216 dist/index.js)
抛出点 @4666754:
var IngestBodyTooLargeError = class extends Error {
constructor(limit, bytes){
super(`request body ${bytes.toLocaleString("en-US")} B (after decode) exceeds the ingestion cost band ${limit.toLocaleString("en-US")} B (#5794: ...)`);
...
}
}判定 @5804976,位置在 decodeRequestBody 之后、session 解析与 preflight 折叠之前:
const decoded = await decodeRequestBody(...);
admission.observe(decoded.body.byteLength);
const ingestCap = protocol==="responses" ? 0 : limitsIngestBytes();
if (ingestCap>0 && decoded.body.byteLength>ingestCap && countImagesInRawBody(protocol, decoded.body)===0){
throw new IngestBodyTooLargeError(ingestCap, decoded.body.byteLength) // -> 413 stage:"ingest"
}阈值本身是配置项 @1154223:
function limitsIngestBytes(){
const v2 = tInt("BILI_INGEST_BODY_BYTES", loadConfigFile().network?.ingestBodyBytes);
return Number.isFinite(v2) && v2>=0 ? Math.floor(v2) : DEFAULT_INGEST_BODY_BYTES; // 32*1024*1024
}设计缺陷的本质:这道闸的前提是"入站字节数 ≈ 模型输入 token 数"。这个前提对出站/增量车道成立,但对 opencode 插件车道不成立——opencode 和 dsh 一样每轮全量重发历史,入站体是"宿主账本"而非"模型输入",bili 的职责恰恰就是把它折叠掉。在折叠发生之前用折叠之后才不会超的阈值判死,等于取消了 bili 唯一能救这个会话的机会,并且是自锁的:越是需要压缩的长会话越先撞这道闸。
为什么不是 #6908 / #6933 的重复
- [Bug][dsh][ingest] The 32 MiB ingest cost is measured against the pre-folding inbound body: a normal session folded down | [Bug][dsh][ingest] 32 MiB 摄入成本带量的是折叠前入站体:折叠到 446 KiB 的正常会话被永久 413 #6908(open):描述的正是"32 MiB 量的是折叠前入站体、折叠到 446 KiB 的正常会话被永久 413"——机制同源。但其会话、复现、判定分支(
isDshCompactionCall)全部限定在 dsh 插件车道。 - [PR] fix: exempt the dsh plugin lane and compaction calls from the 32 MiB ingest band (#6908) #6933(open PR,[Bug][dsh][ingest] The 32 MiB ingest cost is measured against the pre-folding inbound body: a normal session folded down | [Bug][dsh][ingest] 32 MiB 摄入成本带量的是折叠前入站体:折叠到 446 KiB 的正常会话被永久 413 #6908 的修复):豁免条件是 (A)
x-bili-plugin: dsh与 (B) dsh 压缩标记 48 字节嗅探,并在 What-this-fix 里明确保留"non-dsh over-band bodies 照旧拒绝(有 negative test 钉住)"。 - 本票:opencode 车道(
x-bili-plugin: "opencode")有同样的全量重发结构,却既不满足 [PR] fix: exempt the dsh plugin lane and compaction calls from the 32 MiB ingest band (#6908) #6933 的 (A) 也不满足 (B),因此 [PR] fix: exempt the dsh plugin lane and compaction calls from the 32 MiB ingest band (#6908) #6933 合并后 opencode 长会话仍被 413 打死。opencode 侧也没有 dsh 那样的"压缩调用能被豁免"的自愈入口——它只能靠 preflight,而 preflight 永远等不到(parse 之前就抛了)。
一句话:#6908/#6933 修了 dsh,opencode 是同一类"宿主全量重发"车道里没被豁免的那一个。建议把豁免判据从"是不是 dsh"改成"是不是插件车道全量重发形状 / 该会话是否已有可用折叠块",覆盖 opencode。
本地解封(配置层,供其它 opencode 用户先用)
network.ingestBodyBytes 是合法配置项,抬高即可让 body 进到 preflight(不改 bundle、可回滚):
{ "autoRestartOnUpdate": false, "network": { "ingestBodyBytes": 134217728 } }(PUT /__bili/config + POST /__bili/config/reload 后即时生效;loadConfigFile() 按 raw 比较缓存。)验证:对 body=33,574,033 B、images=0 复算判定表达式——默认 32 MiB 时 wouldThrow=true,128 MiB 时 wouldThrow=false(进 preflight 正常折叠)。这是解卡,不是治本:会话继续变长仍会撞上更高的线,真正的修法是按上面的方向把折叠感知接进这道闸。
复现步骤
- opencode 里把单个会话用到原始历史约 32 MiB(
bili.log该会话request:行的 inbound 爬到 ~32 MiB),保持ingestBodyBytes默认; - 再发一条消息;
- 观察:
413: request body exceeds 33554432 bytes+ 响应体error.stage="ingest"; - 对照
index.db:该会话contextTokens远小于窗口、blocks数量可观(折叠本来是好的),证明被误杀。
附带
- opencode 车道的插件注册头证据:
dist/agent/opencode-native.jsheaders.set("x-bili-plugin","opencode")(@3804378 附近)。 - 同机
slow-ingest ... starving the event loop (#5744)也在这些大会话上高频出现(单轮 16–20 MiB WAL、1.6–2.2 s),与 [perf][dsh] 51.2 MiB / 29.6k-msg inbound has no cost admission - DecodedRequestAdmission only sees compressed bodies | 51.2 MiB 入站没有成本准入:admission 只覆盖压缩体 #5794 担心的 parse 卡顿一致——但那是性能问题,不该由"直接 413 掉折叠前的 body"来解决。
Activity
[-][Bug][opencode][ingest/0.1.216] opencode 车道的长会话被 32 MiB ingest 硬闸永久 413(且 #6908/#6933 的修复只豁免 dsh 车道,opencode 仍在外)[/-][+][Bug][opencode][ingest/0.1.216] Long sessions on the opencode lane are permanently 413'd by the 32 MiB ingest hard limit | [Bug][opencode][ingest/0.1.216] opencode 车道的长会话被 32 MiB ingest 硬闸永久 413(且 #6908/#6933 的修复只豁免 dsh 车道,opencode 仍在外)[/+]fix: generalize the ingest-band exemption from dsh to all plugin lanes (
ranxianglei commentedon Nov 21, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
查重:不重复 —— 这是 #6908/#6933 的残余缺口(dsh-only 豁免把 opencode 车道漏在外面)。核对过相关 issue,机制均不同:7423(fork 串扰 lineage)、7409(dsh 全量重发 perf 数据点)、6877(dsh nudge/egress 熔断)、7236(orphan ref)、7383(preflight fail-fast)、6175(slow-ingest perf)。本 issue 的失败签名(opencode 车道 + 32 MiB ingest 硬闸 + 413 永久锁死)与上述均不同。
标签:
bug+opencode+scope/wiring+p1(413 锁死的会话 = 不能用,按 owner 2026-10-19 口径 ①会话无法恢复/数据丢失类 = p1,不许降 p2)。审核(三步)
1. 复现/查证(问题真实存在):本地 master = 0.1.216(与 field 一致)。ingest 硬闸在
src/server/handle.ts:537-541:ingestCap = protocol==="responses" ? 0 : knobLimitsIngestBytes(),body 超 cap 且无图即抛IngestBodyTooLargeError。该闸在 preflight folding 之前 触发——所以一个健康会话(391,803 context tokens、390 blocks、8.0M rawInputTokens、33,574,033 B body、仅超 band 0.06%)会被永久 413 锁死,folding 根本没机会跑。已确认。2. 定位层次(根因 vs 表面):根因是闸的前提("inbound bytes ≈ model input")对全量重发插件车道不成立——body 是宿主的 ledger(折叠基质),不是模型输入。#6933 已经为 dsh 车道修了这个前提(
x-bili-plugin === "dsh"豁免),但只豁免了 dsh,opencode 车道有同样的全量重发结构(宿主每轮重发整个 raw ledger,bili 的职责是折叠它)却被漏在外面。所以本 issue 是 #6933 的残余缺口,不是新机制。3. 方案评估:用户建议的方向("是不是插件车道全量重发形状")是对的。我把豁免从
=== "dsh"泛化到x-bili-plugin !== undefined(任意插件车道)。理由:x-bili-plugin头本身就是"我的 body 是我的 ledger,折叠它"的宣告——这个前提对所有全量重发插件车道都成立(dsh、opencode、omp、pi…);修复
在
src/server/handle.ts把豁免条件从x-bili-plugin === "dsh"泛化为x-bili-plugin !== undefined,并更新注释说明泛化理由。新增 2 个 e2e 测试(tests/issue5794-ingest-cap.test.ts):x-bili-plugin: opencode)的超 band 全量重发 body 被折叠并转发(200 + 1 次上游调用),不在 ingest 413;x-bili-plugin头)的超 band body 仍被 413 拒绝(泛化豁免不泄漏到普通客户端)。全部 8 个 case 通过;typecheck 干净。
PR
按「一个 thread 一个修复 PR」规则,本修复并入现有 PR #6933(同一机制:ingest 闸豁免),未另开并行 PR。已推到 #6933 分支(
2026-11-16_ingest-dsh-exemption),并更新 PR 正文覆盖 #7426。🔗 #6933
CI 对新 head(aa2ba04fc99)正在跑,全量回归以 CI 为准。
结构化八问
=== "dsh"),opencode 有同样的全量重发结构却被漏在外面。x-bili-plugin === "dsh"泛化为x-bili-plugin !== undefined(任意插件车道)。该头本身就是"我的 body 是我的 ledger,折叠它"的宣告,对全量重发车道在维度上成立;增量车道 turn 小、到不了 band,放宽无害。收工判定:修复已并入 PR #6933 并推送,待 CI 绿 + owner 合并。
ranxianglei commentedon Nov 21, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
CI 对新 head(aa2ba04fc99)已全绿:16 success + 14 skipped,0 failure。PR #6933 现在同时覆盖 #6908(dsh)与 #7426(opencode/任意插件车道),待 owner 合并。
🔗 #6933
fix: disable the 32 MiB ingest cost band by default for all lanes (#7426
docs: align stale ingest-band comments with the disabled default + CH…
Merge pull request #7443 from ranxianglei/fix/7426-ingest-cap-unlimited
Merge master 98fa957 into 2026-10-30_drifted-name-leak
merge: sync master 98fa957 into PR #6142; resolve kernel version conf…