Skip to content

[PR] fix(agent/dsh): decode content-encoded request bodies in fork-adoption and recall body gates - #4832

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-26_4829-zstd-fork-gate
Oct 26, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-26_4829-zstd-fork-gate

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #4829

What & why

The Codex SSE transport (pi-ai) ships request bodies as zstd-compressed Uint8Array with a content-encoding: zstd header. bodyJsonOf() in src/agent/dsh-native.ts parsed byte bodies as plain UTF-8 text only, so every such body failed the fork-adoption body-parse gate: seeded fork children of long compressed conversations could never adopt the parent's compression state (resume-inheritance miss → multi-million-token preflight compression → client disconnect before the model request was forwarded). The same blind parse also made the #4082 negotiated recall silently skip encoded retries.

Fix

  • bodyJsonOf now reads content-encoding from init.headers (Headers instance / [name, value] pairs / record shapes) and decodes through the server-side codec table (src/content-encoding.ts: gzip/x-gzip/br/zstd-via-fzstd/deflate) before JSON.parse. Decoding is inspection-only — outgoing bytes are never touched.
  • Every failure mode (undecodable bytes, unsupported coding, decoded-size cap via the existing limitsDecodedBytes() knob) still yields undefined = today's behavior; string bodies parse as-is (a JS string cannot be compressed).
  • maybeNegotiatedClaim becomes async; the takeover gate's none arm settles via .then() preserving today's control flow exactly (streak reset only on non-claim). The gate contract already tolerates Promise verdicts (threw arm). Review refinement (61f31b9): the no-init shape fast-paths SYNCHRONOUSLY — no init means nothing to decode and the claim can never succeed — so the WS-lane consumer that compares its gate result with === false WITHOUT awaiting (src/agent/native-ws-intercept.ts) keeps receiving exactly today's synchronous verdict for that shape; dsh-native.test.ts pins the raw (non-awaited) verdict.

Behavior changes (intended, disclosed)

Config surface

No new config. Reuses the server-side codec table and the existing network.decodedBodyBytes / BILI_DECODED_BODY_BYTES cap (default 10 GiB), so lane and proxy share one understanding of which codings are understood.

Tests

kernel-change declaration — superseded by rebase (2026-10-26)

An earlier revision of this branch (fcdb843) merged origin/ci-fixes into the PR, which carried two kernel/package-lock.json lines (recorded versions synced with acp-kernel 0.0.165) into the diff and tripped the coarse kernel-guard Rule 1; a kernel-change: declaration was then added to the body to unblock the gates. That branch form has been REPLACED by a rebase onto master (341e76c), whose lockfiles are already in step with acp-kernel 0.0.166 — the PR diff now contains ZERO kernel/ files, so the guard cannot fire and the declaration is no longer needed (left noted here for provenance). Branch history is now linear: fix (308c009) + review refinement (61f31b9) + whitespace nit (06964c6).

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_4829-zstd-fork-gate (06964c6)

Latest build — install this exact version

npm install -g billion-context@0.0.6248-pr.4832.1daa378

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
06964c6 billion-context@0.0.6248-pr.4832.1daa378 build
fcdb843 billion-context@0.0.6242-pr.4832.b56587e build
14ba754 billion-context@0.0.6238-pr.4832.a6ad614 build
72cd66a billion-context@0.0.6231-pr.4832.7408de1 build
6efdffe billion-context@0.0.6230-pr.4832.4f5bd90 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(agent/dsh): decode content-encoded request bodies in fork-adoption and recall body gates [PR] fix(agent/dsh): decode content-encoded request bodies in fork-adoption and recall body gates Oct 26, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 本 PR 是 #4829 的唯一实现入口(检索 open+closed issues/PRs:没有其它在途 PR 修同一机制——bodyJsonOf 不识别 content-encoding;相邻的 #4589/#3011 是「adoption 已启动后 snapshot 409」的不同失败域,triage 时已分开)。

标签:bug / dsh / scope/wiring / p1(理由:seeded fork 子会话继承被永久放弃 = p1 ①类,与 #4829 一致;镜像 web 面当前未实现标签 API,在此如实申报,原 issue 标签已就位)。

正在复审本 PR(代码 + 既有行为回归清单 + CI 状态),结构化结论随后评论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

lock-sync 红 → 已修复并推送,新 head 14ba754b0,全量 CI 已绿。 此红为继承性失败(master 侧问题),不是本 PR 代码问题。

  1. 是什么问题:lock-sync 门禁红——根 package-lock.json 记录的 acp-kernel 版本落后于 master(首红时 0.0.163 vs 0.0.165,即 CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 登记的继承红;分支经 ci-fixes 扫到 0.0.165 后,master 又前进到 0.0.166)。门禁命令 npm install --package-lock-only && git diff --exit-code 出现版本行漂移。纯 lockfile 记录漂移,零代码逻辑涉及。
  2. 什么原因导致的:master 通过 [PR] fix(#4797): root-cause fix for superseded live-key collision — restamp pruning + semantics-preserving guard translation | fix(#4797): superseded 活键碰撞根治——restamp 剪枝 + 守卫保义翻译 + 一次性标志修复 (kernel 0.0.166) #4807 车系把 acp-kernel 同步到 0.0.166(lockfile + kernel/package.json 一起动),而分支的 lockfile 记录停在上一次 ci-fixes 扫描的 0.0.165——ci-fixes 哨兵已把修复收敛在 ci-fixes/[PR] ci: converge master-CI fixes (persist restamp guard + lockfile version sync) (#4599) #4814,[PR] ci: converge master-CI fixes (persist restamp guard + lockfile version sync) (#4599) #4814 未合入期间,先合 ci-fixes 的分支仍会落后 master 一步。
  3. 影响范围与严重程度:仅 CI 门禁层面,影响本 PR 的 mergeable 状态;对用户行为、产物内容无影响。
  4. 怎么修复的:不在分支上单独补版本行(那等于在自己分支重复修 master 级失败),直接 merge origin/master(e290b4fda)进分支。冲突仅在两个 lockfile 的版本行,取 master 侧解决,单个 merge commit 14ba754b0。附带效果:分支对 master 的 diff 收敛回本 PR 原有的 3 个文件(src/agent/dsh-native.ts + 两个测试文件),不再触碰任何 kernel/** 文件 → kernel-guard 声明问题随之消失(我未自行添加/移除任何声明,PR 正文一字未动)。
  5. 是否有回归问题:无。merge 带入的全部是 master 既有变更(已合入、门禁绿);冲突解决逐字节取 master 侧(已验证两个 lockfile 与 master 字节一致)。此前登记的 born-red 签名(issue847/issue1492 措辞钉、storage-render golden、Plugin history render drops an entire fold (covered rows suppressed AND no summary anchor) when the fold reaches the transcript tail — ok:true, no error #4732 teardown EBUSY)随 master 修复一并带入转绿。本地验证:lock-sync 门禁命令原样重跑零 diff(root 与 kernel/ 两处)、typecheck 干净、定向套件 issue4829+dsh-native 73/73 绿。远程 CI 判定:全绿——主 CI(lock-sync、kernel-guard、全部 guard、static-gates、16 个测试分片)+ 11 个 e2e 工作流在 14ba754b0 上全部 success。
  6. 是否破坏缓存:不涉及(只改 lockfile 记录行,不触运行时/缓存路径)。
  7. 是否改了设计方向:无。
  8. 是否引入新配置:无。

备注:上一车道在历史里留了一个空提交 49d287193(retrigger,消息称已往 PR 正文补 kernel-change 声明)——空树、内容无影响;现在 diff 不再触碰 kernel/,该声明也无实际作用。按 owner policy 2026-10-26 我未自行编辑 PR 正文,留待 owner 处置。

判定:新 head 全部门禁绿,可进入 owner 审查/合并。

…call body gates (#4829)

The Codex SSE transport (pi-ai) ships zstd-compressed Uint8Array request
bodies with a content-encoding header. bodyJsonOf() parsed byte bodies as
plain UTF-8 text only, so every such body failed the fork-adoption
body-parse gate: seeded fork children of long compressed conversations
could never adopt the parent's compression state (resume-inheritance
miss -> multi-million-token preflight compression -> client disconnects
before the model request was forwarded). The same blind parse also made
the #4082 negotiated recall silently skip encoded retries.

- bodyJsonOf now reads content-encoding from init.headers (Headers /
  pairs / record shapes) and decodes through the server-side codec table
  (src/content-encoding.ts: gzip/x-gzip/br/zstd via fzstd/deflate) before
  JSON.parse; decoding is INSPECTION ONLY — outgoing bytes are untouched.
- Every failure mode (undecodable bytes, unsupported coding, decoded-size
  cap via limitsDecodedBytes) still yields undefined = today's behavior;
  string bodies parse as-is (a JS string cannot be compressed).
- maybeNegotiatedClaim becomes async; the takeover gate's none arm settles
  via .then() preserving today's control flow exactly (streak reset only
  on non-claim). The gate contract already tolerates Promise verdicts
  (threw arm); the WS lane never passes init, so its sync call path is
  unchanged.
- Behavior change (intended): gzip/x-gzip/br/zstd/deflate request bodies
  are now decoded for inspection in the dsh lane (fork-adoption gate,
  recall claim/learn); previously ANY non-plain-text byte body failed the
  gates. Outgoing request bytes are unchanged in all cases.
- Gate warn line now says 'after content-encoding decode' (#4215 wording
  preserved for log consumers).
- Tests: new suite tests/issue4829-zstd-fork-gate.test.ts pins both
  directions (#3617) — zstd/gzip bodies reach the adopter protocol,
  undecodable/unsupported encodings hit the gate once, plain-text
  behavior unchanged; three dsh-native gate assertions updated to await
  the now-async none arm (same idiom the threw arm already used).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 本条是系统转发的本 PR 冲突处置任务(conflict-worker 车道),非新立项;查重结论已在 floor 8 给出。标签维持:bug / dsh / scope/wiring / p1(floor 8 已申报,未变更)。

冲突处理完成:分支已与 master 同步,GitHub 报告 mergeable=true(当前状态 blocked = 等 CI 检查,开放 PR 的正常态)。

八问:

  1. 是什么问题:PR 分支落后于 master,平台在 10:12Z 检测到冲突(dirty)状态并唤醒本次处置。
  2. 什么原因导致的:master 持续前进(10:07Z 合入 [PR] fix(#4797): root-cause fix for superseded live-key collision — restamp pruning + semantics-preserving guard translation | fix(#4797): superseded 活键碰撞根治——restamp 剪枝 + 守卫保义翻译 + 一次性标志修复 (kernel 0.0.166) #4807;其后又合入 [PR] fix(wiring): degenerate-turn continuation retry joins the 429 governor (#4743) #4802 的 429-governor 工作)而 PR 分支停在旧基线上。我接手前分支已于 10:18Z 合过一次 master(提交 14ba754),原始 dirty 状态随之清除;核验期间 master 又前进 3 个提交,分支处于「落后但无文本冲突」状态。
  3. 影响范围与严重程度:仅影响本 PR 的可合并性,无代码行为变化、无外部用户影响。流程性问题,已解决。
  4. 怎么修复的:把最新 master(tip 341e76c)直接 merge 进 PR 分支后推送——fast-forward 推送、无 rebase、无历史重写(与本分支此前的同步方式一致)。两侧改动文件零重叠:master 侧纯新增 src/degenerate-retry.ts 及其测试,PR 侧只动 src/agent/dsh-native.ts 与两个测试文件,git 自动合并完成,零手工冲突解决。新 head:fcdb843e1。因无任何手工解冲突且文件零重叠,本地未跑套件(工作区未装依赖),回归判定交给推送 head 上的 CI(§7.2)。
  5. 是否有回归问题:无。merge 只带入 master 的纯新增(2 个新文件,113 行插入、0 删除),未触碰本 PR 的任何代码路径;不涉及 kernel/、配置面、wire 协议。高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

未出现需要设计决策的冲突,故未开 decision-request issue(auto-fix 车道规则)。等待 fcdb843e1 上的 CI 结果;若红,按 #4599 流程处理。收工判定:冲突闭环,可继续走正常评审/合并流程。

ci-check added 2 commits October 26, 2026 19:01
…r the WS-lane consumer (#4829 review)

The #4829 change made the none arm settle via maybeNegotiatedClaim(...).then(...),
which returns a Promise in every case. native-ws-intercept.ts compares its gate
result with === false WITHOUT awaiting — a Promise never equals false, so an
unattributed no-init (WS-shaped) call would stop being refused and be rewritten
onto the proxy instead of going direct. Without init there is no body to decode
and the claim can never succeed (maybeNegotiatedClaim returns undefined
immediately), so fast-path that shape synchronously: exact pre-change verdict
class restored, async decode kept for HTTP shapes only. dsh-native.test.ts now
pins the sync verdict class (raw === false before the await).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

复审完成。结论先行:本 PR 可合并(最终 head 06964c651 CI 全绿)。复审中发现一处潜在契约缺口,已在 PR 内直接修掉(独立 commit),残留的既有同类缺口另立 issue #4841。

结构化八问

  1. 是什么问题:DSH 车道的 fork-adoption / recall 门把请求体当裸 UTF-8 字节解析,完全不看 content-encoding 头——而 Codex 的 SSE 传输(pi-ai)发的是 zstd 压缩字节体,于是这类请求永远卡在 body-parse 门:长压缩会话的 fork 子会话无法继承父会话压缩状态,触发百万级 token 的预检重压缩,客户端常在转发前就断开。
  2. 什么原因导致的:src/agent/dsh-native.ts 的 bodyJsonOf 对字节体只有一条解析路径(TextDecoder 逐字 → JSON.parse),编码声明被整体忽略——缺陷在「解析层」而非压缩引擎层;解码后 JSON 本身完好(报告者离线复现已双向证明)。
  3. 影响范围与严重程度:受影响面 = DSH 宿主 + 传输发编码体的用户(当前主要即 pi-ai Codex SSE 的 zstd);fork 继承是永久错过而非偶发,属 p1 可用性类(resume-inheritance 放弃 → 巨大重复压缩成本 → 断连)。proxy 模式与其他车道不受影响;任何情况下出站请求字节不变。
  4. 怎么修复的:解码后再检查——从 init.headers(Headers / pairs / record 三种形状)读 coding,走服务端共享 codec 表(src/content-encoding.ts:gzip/x-gzip/br/zstd/deflate)展开后 JSON.parse;一切失败模式(不可解码、不支持的 coding、超 decoded 上限)仍返回 undefined = 今天的行为。复审补强(commit 61f31b921):无 init 的形状同步快速路径返回(无 init 即无可解码物、claim 不可能成功),保住这类调用的原同步判决形状——动机见第 5 问。
  5. 是否有回归问题:逐项清点过——ok/threw 臂控制流未动;none 臂 .then() 与原代码控制流等价(streak reset 仅在 non-claim、刻意不 noteAttrRecovery,健康信号保持诚实);字符串体行为不变;warn 日志措辞变更已披露。复审发现一处真实缺口:原实现让 none 臂恒返回 Promise,而 WS 车道消费方(native-ws-intercept.ts:412)用同步 === false 比较、不 await——Promise 永不等价于 false,该假设组合下「拒绝接管、直连上游」会静默失效。生产上仅 pi 安装 WS 拦截器且宿主各自独立进程,当前不可达;但 PR 描述里「WS 车道同步路径不变」在原实现中并未被代码保证。已在本 PR 内修掉(同步快速路径 + dsh-native.test.ts 新增 raw 非 await 断言钉死同步判决形状);threw 臂的同类缺口早于本 PR 存在,已单立 WS-lane takeover gate consumer misses Promise verdicts (sync === false comparison) | WS 车道 takeover gate 同步 === false 比较漏掉 Promise 判决(拒绝直连静默失效) #4841(p3,A/B 选项在正文等你拍板)。
  6. 是否破坏缓存:不涉及——纯 inspection-only,不触碰缓存/重试/增量游标/去重键;claim/recall 语义不变。
  7. 是否改了设计方向:没有——lane 与 proxy 共用同一 codec 表与同一 decoded 上限(limitsDecodedBytes()),是强化「单一理解」契约而非转向。
  8. 是否引入新配置:没有——复用既有 network.decodedBodyBytes / BILI_DECODED_BODY_BYTES(默认 10 GiB)。

披露的行为变更(旧 → 新)

验证与 CI

判定

可合并。合并后 #4829 自动关闭(Closes #4829)。后续跟进见 #4841(p3,WS 车道契约缺口,A/B 修法待拍板)。

@ranxianglei
ranxianglei merged commit 9d59116 into master Oct 26, 2026
51 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.854-master.9d59116 (rolling master tag).

npm install -g billion-context@0.0.854-master.9d59116  # 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DSH native fork adoption skips zstd-compressed Codex SSE request bodies at body-parse gate

1 participant