Skip to content

[PR] incremental: pull-receipt ack reconciliation + drift fallback serves the richer side (#4352, #4323) - #4337

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-22_incremental-cjk-estimator
Oct 23, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-22_incremental-cjk-estimator

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes the two root causes behind the 2026-10-22 incremental dogfood incident (full timeline in the issue comments of #4323).

Root cause 1 — ack channel depended on the response-header transport (#4352)

pi's after_provider_response exposes response headers only for some provider transports. When the x-bili-applied-seq header never reaches the extension, noteIncrementalAck never runs — and every subsequent turn re-seeds the full history (sinceSeq=0, 21K messages resent as a "delta").

  • GET /__bili/plugin/turn?conversation=<id> now returns the warm canonical's {appliedSeq, boundary}. boundary = wire hash of the last applied message (byte-identical to the client's incrementalWireHash); a cold canonical reports null — it cannot vouch and is never adopted.
  • pi.ts maybeIncrementalTurn reconciles any still-pending un-acked plan by pulling the receipt before planning the next turn, adopting only when boundary proves the canonical absorbed OUR last message. Never on mere seq progress — a foreign full-resend also advances the canonical.

Root cause 2 — drift fallback served the stale side (#4323)

With multiple writers sharing one sessions directory, the loadSync drift fallback unconditionally served the legacy envelope — resurrecting an older fold generation (11,849 refs / 12 active) over the newer index generation (26,971 refs / 16 active). Coverage stopped matching the canonical rows → the raw history replayed unfolded (0 compressible ranges) → preflight dead-ended at a phantom 8.29M tokens (502, not forwarded).

  • The drift fallback now compares both sides' mapped-ref counts and serves the richer one; the envelope still wins ties (its bytes are whole-file atomic — the index's superiority must be visible).

Tests

  • tests/incremental-ack-pull.test.ts (3): response-header ack regression pin / pull adoption without any response observation / cold boundary: null refuses adoption (honest re-seed).
  • tests/storage-full-flip.test.ts 4b: a stale envelope loses to a newer index generation.
  • Families green: incremental-lane 24/24, inc-canonical-pointers 3/3, storage-full-flip 10/10, issue3343 ×2 (9/9), fix-1117 3/3, issue1158 5/5; tsc clean; unused-exports gate clean.

Out of scope (tracked)

…the richer side (#4352, #4323)

- GET /__bili/plugin/turn?conversation=<id> now returns the warm canonical's
  {appliedSeq, boundary}; the boundary is the wire hash of the last applied
  message (byte-identical to the client formula), null when cold.
- pi's maybeIncrementalTurn reconciles any un-acked pending plan by pulling
  the receipt BEFORE planning the next turn, adopting it only when the
  boundary proves the canonical absorbed OUR last message — a missed
  response-header ack (transport-dependent after_provider_response) no
  longer turns every turn into a full re-seed.
- persist loadSync drift fallback now compares both sides' mapped-ref
  counts and serves the richer one: a stale envelope (older multi-writer
  generation) can no longer resurrect an outdated fold state over a newer
  index generation, which dead-ended preflight at a phantom 8.29M tokens
  with 0 compressible ranges.
@ranxianglei ranxianglei changed the title incremental: pull-receipt ack reconciliation + drift fallback serves the richer side (#4352, #4323) [PR] incremental: pull-receipt ack reconciliation + drift fallback serves the richer side (#4352, #4323) Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-22_incremental-cjk-estimator (2d6e092)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5179-pr.4337.712705e

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重结论(先答)

查重: 本单是 PR,不与既有 issue 重复;但发现与在途 PR #4332 存在同一机制的重叠实现,需要你拍板合并方式。

标签

标签:bug · pi · scope/wiring · p1(缺陷类;客户端车道为 pi;主新面是协议接线层的 ack 拉取接缝;严重度按缓存泄露类口径判 p1——ack 丢失导致每轮整包重发历史,成本爆炸+preflight 假性死局 502,会话不可用)。

当前状态

CI 取证已完成(上述结论)。正在本地做定向验证(增量车道家族 + storage-full-flip + 新增 3 例),并逐行核对 pull-receipt 采纳条件与 hash 公式两侧一致性。全量回归以 CI 为准(master 红修好前拿不到全量绿,见 #4334/#4330)。最终八问审核结论随后回帖。

@ranxianglei ranxianglei added bug Something isn't working p1 pi scope/wiring labels Oct 22, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

审核结论(八问)

一句话:代码本身质量过关、双根因修法正确、定向验证全绿;CI 的 8 个红 lane 全部是 master 既有红(与本 PR 无关,已核实);合并前需要你拍板一件事——与 #4332 在同一代码行的重叠实现怎么合成一个闭环。

  1. 是什么问题:2026-10-22 增量车道 dogfood 事故的双根因——①ack 回执只走响应头一条道,pi 的部分 provider 传输不暴露响应头 → ack 永远到不了 → 之后每一轮都把全量历史当「delta」重发;②多实例共写一个 sessions 目录时,冷加载的漂移回退无条件吃旧信封 → 旧折叠世代复活 → 已折叠内容整包回上下文 / preflight 假性死局 502。
  2. 什么原因导致的:①结构性传输盲区,不是偶发——after_provider_response 只在部分传输下带响应头,ack 通道单点依赖它;②loadSync 漂移回退的旧假设「最后一次文件写更新」在多写者乒乓下失效(无单实例守卫:多个 bili 代理进程并存共写 sessions 目录,伴随孤儿 ref、有注册表无 transcript、计数自相矛盾的污染簇 #394 反模式,事发机 6 实例)。
  3. 影响范围与严重程度:①所有跑在隐藏响应头传输上的 pi 插件会话——每轮整包重发(事故现场 21K 条历史),成本爆炸+前缀缓存每轮作废;p1(缓存泄露类口径)。②仅当 storage.unified=full ∧ 漂移 latch 命中 ∧ 存在多写者分歧时触发——重启/驱逐后 +240K token 回灌或 502 不可用;p1。非多写者单机部署不受 ② 影响。
  4. 怎么修复的:①双通道 ack:响应头保留不动,新增拉取回执——GET /__bili/plugin/turn?conversation=<id> 返回热 canonical 的 {appliedSeq, boundary},boundary = 末条已吸收 wire 消息的哈希(客户端/服务端公式逐字节一致,已核对);pi 扩展在规划下一轮前拉取,只有 boundary 证明 canonical 吸收的是我方末条消息才采纳,绝不按 seq 前进盲目采纳(外来全量重发也会推进 seq);冷 canonical 诚实报 null → 客户端保持诚实 re-seed,下一轮自愈。②漂移回退取富侧:比较两侧 mapped-ref 数(byRef key 计数),严格更富的一侧赢;平局仍归信封(整文件原子写,索引的优越性必须可见)。
  5. 是否有回归问题(逐项过既有行为):响应头 ack 路径——未动,且新增回归钉测试 ✓;无 ?conversation 参数的探针响应形状——一字未变(字段条件展开)✓;非漂移冷加载(unified-first 默认路径)——未动 ✓;漂移命中但信封侧更富/平局——仍走原信封路径(含负 token 钳制),Storage wrap-up: 6 fixes + switch default mode to full (single PR) | 存储收尾六修 + 缺省模式翻 full(一个 PR 统一处理) #3818④ 既有用例全绿 ✓;canonical/applyTurn 语义——boundary 纯附加字段,resync/空 delta 边界处理已核 ✓;探针路由安全面——沿用既有 adminGateDenial 门控,无新暴露面 ✓。有意变更两处(即修复本身):待采纳计划可经拉取转 delta(不再 re-seed);索引严格更富时漂移回退改道索引。未发现无意回归。
  6. 是否破坏缓存:否。拉取回执只读热 canonical(不触发 touchCache/重建);前缀缓存接缝、重试、水位线、去重键均不受影响;修复方向反而减少整包重发,缓存稳定性变好。
  7. 是否改了设计方向:无转向。在既有增量车道上增加第二条 ack 传输(拉取与响应头并存,服务端 seq 权威不变);漂移回退仍在 loadSync 既有判定结构内对称化。
  8. 是否引入新配置:无。无新 env/config/CLI 面(config-surface-guard 绿);?conversation= 是既有端点的可选附加参数。

验证证据

需要你拍板:与 #4332 的重叠处置

两个 PR 都改 src/persist.ts loadSync 同一块 drift fallback,不能按现状都合。差异:本 PR 用 mapped-ref 数取富侧(纯读侧);#4332 用 active-block 数取索引更富侧(你在 #4323 点名的口径),另带本 PR 没有的写侧遏制(连续 3 次不收敛→响亮告警+本进程冻结信封写入)。指标说明:ref 数是累计单调量(内核约定 id 永不复用,世代越新 ref 越多),active-block 数会随 mega-refold 把低层块折进高层而回落(块的 active 标志翻 false、条目不删,persist.ts:1420 的计数口径)——「块多=更新」在重度折叠场景可能失真;事故现场两组数字(11,850 refs/12 act vs 26,971 refs/16 act)两种口径都指向索引,所以本次事故两种修法都能救,差别在未来边缘场景。

选项 做法 影响面/风险
A(推荐) 两半各取所长合成一个闭环:写侧遏制(冻结+告警)从 #4332 移植过来,读侧指标二选一(refs 或 active-blocks,我倾向 refs,理由如上但尊重你 #4323 的原话口径),合成后关掉冗余一侧 改动最小地得到完整机制闭环;符合「一个机制一个 PR」政策;风险:需要一次合并整理 commit(我来做)
B 先合本 PR(refs 口径),#4332 摘掉冲突的读侧 hunk 只留冻结+告警再合 两次合并、中间态短暂存在两套回退逻辑之一;refs 口径成为事实标准(偏离你原话「取块多一侧」,需你确认)
C 以 #4332 为准(active-blocks 口径+冻结),本 PR 只留 ack-pull 半(#4352),persist.ts hunk 和 4b 测试摘除 最省改动、完全贴合你 #4323 的原话;代价:读侧指标用波动量,重度折叠世代下判新能力弱于 refs

另两件小事(不阻塞):①本 PR 正文缺字面 Closes #4352,合并不会自动关 #4352,#4323 则由 #4332 的 Closes 关闭——合成方案 A 时我会补上关键词;②分支名 2026-10-22_incremental-cjk-estimator 与内容不符(疑似复用旧分支名),纯外观,不强求改。

收工判定:代码可合(定向验证+静态门禁全绿);前置两件事——你拍板 A/B/C,以及 #4334/#4330 把 master 修绿拿到全量套件判决。拍板后我立即执行对应整理并回帖确认。

@ranxianglei

Copy link
Copy Markdown
Owner Author

拍板:方案 A,读侧指标用 refs 数。请 @ework 执行合成。

归并决定

  1. 读侧取富:保留本 PR 的 refs 口径(Object.keys(state.messageRefs.byRef).length),不用 active-blocks。技术理由:
  2. 写侧遏制:把 [PR] fix: escalate structural digest drift to alarm + envelope freeze, load the fuller side (#4323) #4332 的冻结+告警机制(连续 3 次不收敛→响亮告警+本进程冻结信封写入)移植进本 PR——从源头止住多写者乒乓,与本 PR 的读侧取富互补成完整闭环。
  3. 收尾:合成后 [PR] fix: escalate structural digest drift to alarm + envelope freeze, load the fuller side (#4323) #4332 关闭(或改造成纯写侧 follow-up);本 PR 正文补 Closes #4352 关键词;分支名不符内容纯外观,不改。

后续(不阻塞)

@ework:合成整理 commit + 回帖确认后本 PR 可合。

@ranxianglei
ranxianglei merged commit fba2d13 into master Oct 23, 2026
23 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.747-master.fba2d13 (rolling master tag).

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

ranxianglei pushed a commit to Mako-L/billion-context that referenced this pull request Oct 28, 2026
…ane (ranxianglei#4352)

Claude Code builds that stamp no agent-id headers (VS Code extension) send
subagent model requests under the parent session id. Their short, unrelated
histories ride the parent session and destroy its fold substrate: fold-reconcile
sees covered ids missing, confirms epoch destruction, and the model's compress
calls die as substrate-destruction with refs recorded DEAD.

The ranxianglei#975 two-signal gate cannot see these subagents: VS Code builds share the
parent's first system block verbatim, so the main-prefix negative check fails
even when the agent-id headers are present.

Route claude anthropic-wire traffic (x-claude-code-session-id source, evidence
allowlist in the lane-decisions registry) through the continuity-aware order
resolver when the ranxianglei#975 gate misses: a continuing main conversation keeps the raw
id on order+content evidence; a history-disjoint ride forks onto its own |sub:<fp>
lane (own lock chain, own compression state); a byte-drifted system on continuing
history still keeps the raw id (ranxianglei#1106). Gated by the existing subagentSplit knob
(no new config surface); side calls and empty-system requests stay verbatim.

Re-applies the fix from unmerged PR ranxianglei#4409 (closed by a stale-ticket bot that
misattributed the closure to ranxianglei#4337, which does not touch this path) onto current
master. Closes ranxianglei#4769 (re-report of ranxianglei#4352).

Tests: tests/issue4352-claude-anthropic-subagent-split.test.ts — both gate
directions plus the live VS Code field shape captured in the issue comment.
Docs: CONFIGURATION.md/.zh-CN.md subagentSplit rows describe both paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant