Skip to content

[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 仍在外) #7426

Open

Description

@whoishuai

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 的重复

一句话:#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 正常折叠)。这是解卡,不是治本:会话继续变长仍会撞上更高的线,真正的修法是按上面的方向把折叠感知接进这道闸。

复现步骤

  1. opencode 里把单个会话用到原始历史约 32 MiB(bili.log 该会话 request: 行的 inbound 爬到 ~32 MiB),保持 ingestBodyBytes 默认;
  2. 再发一条消息;
  3. 观察:413: request body exceeds 33554432 bytes + 响应体 error.stage="ingest";
  4. 对照 index.db:该会话 contextTokens 远小于窗口、blocks 数量可观(折叠本来是好的),证明被误杀。

附带

Activity

  1. changed the title [-][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 仍在外)[/+] on Nov 21, 2026
  2. ranxianglei commented on Nov 21, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [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…);
    • 增量车道(incremental lane)的 turn 是小 delta,永远到不了 32 MiB band,所以放宽豁免对它们无害;
    • 比 dsh+opencode 白名单更有原则(不用维护白名单),比"检查 session 折叠块"更简单(后者需要在 session-resolve 前读存储)。

    修复

    在 src/server/handle.ts 把豁免条件从 x-bili-plugin === "dsh" 泛化为 x-bili-plugin !== undefined,并更新注释说明泛化理由。新增 2 个 e2e 测试(tests/issue5794-ingest-cap.test.ts):

    • 正向:opencode 车道(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 为准。

    结构化八问

    1. 是什么问题:opencode 车道的长会话被 32 MiB ingest 硬闸永久 413——一个仅超 band 0.06% 的健康会话被锁死,folding 没机会跑。
    2. 什么原因导致的:ingest 闸的前提("inbound bytes ≈ model input")对全量重发插件车道不成立——body 是宿主的 ledger(折叠基质),不是模型输入。[PR] fix: exempt the dsh plugin lane and compaction calls from the 32 MiB ingest band (#6908) #6933 已为 dsh 修了这个前提,但只豁免 dsh(=== "dsh"),opencode 有同样的全量重发结构却被漏在外面。
    3. 影响范围与严重程度:所有 opencode(及其他非 dsh 插件车道)会话,只要 raw ledger 超过 32 MiB 就被永久 413 锁死——不能用。p1。
    4. 怎么修复的:把豁免条件从 x-bili-plugin === "dsh" 泛化为 x-bili-plugin !== undefined(任意插件车道)。该头本身就是"我的 body 是我的 ledger,折叠它"的宣告,对全量重发车道在维度上成立;增量车道 turn 小、到不了 band,放宽无害。
    5. 是否有回归问题:无。band 仍拒绝非插件车道的超 band body(反向测试钉住);dsh 豁免与 compaction-marker 豁免不变;image doctrine 不变。唯一变化是其他插件车道(omp/pi/kimi/zcode)也被豁免——这是有意的泛化,它们有同样的全量重发结构。
    6. 是否破坏缓存:否。闸在 ingest(JSON.parse 之前),修复只放宽哪些 body 过闸,不触碰缓存/重试/去重。
    7. 是否改了设计方向:否。把 [PR] fix: exempt the dsh plugin lane and compaction calls from the 32 MiB ingest band (#6908) #6933 的既有豁免泛化到更有原则的判据,无架构变更。
    8. 是否引入了新的配置:否。无新 env/config/默认值。

    收工判定:修复已并入 PR #6933 并推送,待 CI 绿 + owner 合并。

  3. ranxianglei commented on Nov 21, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    CI 对新 head(aa2ba04fc99)已全绿:16 success + 14 skipped,0 failure。PR #6933 现在同时覆盖 #6908(dsh)与 #7426(opencode/任意插件车道),待 owner 合并。

    🔗 #6933

  4. added a commit that references this issue on Nov 21, 2026
  5. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions