Skip to content

[PR] [Pi/Responses] consume announced native-compaction boundary in the /v1/responses lane - #3480

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-17_responses-compaction-archive-consumer
Oct 20, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-17_responses-compaction-archive-consumer

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3477

What was broken

The /v1/responses preparation path was the only one of the four prepare lanes that never consumed an announced native-compaction boundary. When pi's session_compact fires, the plugin posts POST /__bili/plugin/compact, which sets compactionBoundary = { at, pending: true }. The anthropic / openai / google lanes then call applyCompactionArchive on the next turn to archive the deactivated blocks and prune obsolete refs — but the responses lane only reconciled the separate nativeCompactionBoundary rebase marker (reconcileNativeCompactionBoundary) and never touched compactionBoundary.pending.

Result: after a pi compact on a pi/Responses session, the pending flag stayed true forever and pre-compaction fold blocks were neither archived nor ref-pruned — the session carried dead state indefinitely. Reproducible in both plugin mode and proxy mode.

Fix

Wire in applyCompactionArchive exactly as the sibling lanes do (src/server/prepare-responses.ts):

  • snapshot activeBefore before processTurn's syncBlocks deactivates the covered blocks;
  • after processing the post-compaction history, archive against the live ids;
  • gate on compactForm === undefined so a codex compaction-generation request (trigger or recognized local prompt form) cannot eat an unrelated pending marker;
  • reuse the already-computed compactForm at the forge branch instead of re-deriving it (no forge behavior change).

Behavior change (old → new)

  • Old: on /v1/responses, an announced /__bili/plugin/compact boundary was never consumed — compactionBoundary.pending stayed true, pre-compaction blocks were never archived, refs were not pruned.
  • New: the next ordinary /v1/responses turn consumes it exactly once — archives the deactivated blocks, prunes refs to the live ids while pinning the ref high-water mark, clears pending. Compaction-generation turns (trigger / prompt form) deliberately skip it.
  • Why: restores parity with the other three lanes; the missing consumer was an oversight, not a design choice. No wire shape, config, persistence-version, or kernel change.

Config surface

None. No config field, env var, or CLI flag added / renamed / re-semantics'd.

Tests

New regression suite tests/issue3477-responses-compaction-archive.test.ts (route-level, mirrors the #2451 harness):

  1. plugin-mode consumption (fold → announce → resend tail);
  2. proxy-mode consumption (same lifecycle, no plugin channel);
  3. trigger-form request does not consume an unrelated boundary;
  4. recognized codex-prompt-form request does not consume either;
  5. a later upstream HTTP failure does not undo already-committed bookkeeping.

Local: npm run typecheck clean; targeted suite 5/5; adjacent suites (compaction-archive, issue2451-dsh-responses-compaction, native-compact-terminal, codex-compact, codex-local-compaction, compaction-trigger-finality) 38/38. Full regression left to CI.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_responses-compaction-archive-consumer (44db73b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4650-pr.3480.dce3b31

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-pr3480.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)

查重:不重复。 检索 open+closed issue/PR(含近期):本 PR 针对的是「四条 prepare 车道里唯独 /v1/responses 缺 applyCompactionArchive 消费者」这一个具体缺口;#3477 里列的 #395/#421(原始 archive 机制本身)、#2598/#2618(Google 车道接线)、#2483(另一种上游重建机制)都是相关背景,症状与机制均不同,无并列在途 PR。这是 #3477 的唯一修复 PR。

开始独立审查:拉取分支 2026-10-17_responses-compaction-archive-consumer(d89eb55),按「原 issue 方向 → 回归清点 → 代码 → 测试有效性 → diff 整洁度」逐项过,结论用结构化八问回复。

The /v1/responses preparation path was the only one of the four prepare lanes that never consumed an announced native-compaction boundary (pi session_compact -> POST /__bili/plugin/compact -> markCompactionBoundary). It only reconciled the separate nativeCompactionBoundary rebase marker, so compactionBoundary.pending stayed true forever and pre-compaction blocks were neither archived nor ref-pruned; the session carried dead fold state indefinitely after a pi compact.

Wire in applyCompactionArchive exactly as the anthropic/openai/google lanes do: snapshot activeBefore before processTurn's syncBlocks deactivates covered blocks, then archive against the post-turn live ids. Gate on compactForm === undefined so a codex compaction-generation request (trigger or recognized prompt form) cannot eat an unrelated pending marker; reuse the already-computed compactForm at the forge branch instead of re-deriving it.

Regression suite tests/issue3477-responses-compaction-archive.test.ts covers plugin-mode + proxy-mode consumption, trigger/prompt-form non-consumption, and failure-isolation of committed bookkeeping.

Closes #3477
@ranxianglei
ranxianglei force-pushed the 2026-10-17_responses-compaction-archive-consumer branch from d89eb55 to 4aabb3b Compare October 17, 2026 05:32
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review 结论:可合并(等 CI test lanes 绿;合并由人执行)

独立审了 diff、源码语义、测试有效性与 master 现状,结论如下。

1. 是什么问题:/v1/responses 是四条 prepare 路径里唯一从不消费「已宣布的原生压缩边界」的——pi session_compact 经 POST /__bili/plugin/compact 置位后,pending 永远为 true,压缩前的 fold 块既不归档也不剪 ref,会话无限期携带死状态。

2. 什么原因导致的:接线遗漏,不是设计取舍。三条兄弟路径(anthropic/openai/google)都在 processTurn 后调 applyCompactionArchive;responses 路径只 reconcile 了另一个机制的 nativeCompactionBoundary.pendingRebase rebase 标记,对这个 pending 标记没有任何消费者。

3. 影响范围与严重程度:所有走 Responses 线、经过插件渠道宣布 compact 的会话(plugin/proxy 两种模式都中)。无可见报错、请求照常通过,但 ACP 状态持续泄漏(ref 映射累积、pre-compaction 归档缺失、decompress 兜底记录丢失)——内部状态腐化类,运行越久越重。#3477 里附带的缓存命中率下降时间线是另一件在查的事:本 PR 不碰任何 wire 字节与缓存键,与该现象无关(既不修复也不加重)。

4. 怎么修复的:照抄兄弟路径的既有模式——processTurn 前快照活跃块,处理完压缩后历史再调 applyCompactionArchive(归档失活块+剪 ref+清 pending);另加一个 responses 特有的闸:compactForm === undefined,让 codex 压缩生成请求(trigger/prompt 形态)不会误吃无关的 pending 标记。compactForm 计算上移后在 forge 分支复用——我验证过新旧位置之间 parsed.input 只有临时 sysdev 标记(finally 恢复),无永久变更,forge 行为不变。

5. 是否有回归问题:逐项过完触碰路径的既有行为,无意回归未发现:

  • 无已宣布边界的普通轮次 → applyCompactionArchive 在 !pending 时直接返回(src/session.ts:1412-1415),零变化;
  • trigger 形态请求 → 不消费(新测试 3 钉住);
  • codex prompt 形态请求 → 不消费(新测试 4 钉住);
  • forge 分支 → 上移后的表达式与原式语义等价(见第 4 问验证);
  • kernel transform 失败路径 → 不调 archive,标记留在下一个普通轮次重试,无半状态;
  • ref 空间 → 剪枝时用 bili:ref-floor 重新钉住高水位(src/session.ts:1447-1465),「ref 永不复用」契约保持;
  • wire 形态 / 配置面 / 持久化格式 / kernel → 均未触碰;compactionBoundary 元数据形状与其他三路径既写形状一致,无版本漂移。

两个观察(均非本 PR 引入,不拦):① 宣布之后若下一轮仍重发完整历史(截断未落地),该轮会消费掉标记(归档 0 块),真正的截断历史到达时已无标记——anthropic/openai/google 三路径今天就是同样性质,本 PR 是达到对等而非新增风险;② responses 路径没有 detectUnannouncedHistoryRewrite(兄弟路径能对静默重写自置边界),属既有缺口,但当前 responses 线上已知静默压缩流量都有可识别签名(codex trigger/prompt、dsh checkpoint framing),无受影响流量的证据,不单独立项。

6. 是否破坏缓存:不涉及。只动服务端簿记(metadata + ref map),wire 字节、prefix-cache 键、重试策略全部原样。

7. 是否改了设计方向:不涉及。纯补齐第四条路径缺失的消费者,架构/边界/数据流不变。

8. 是否引入了新的配置:无。

测试有效性:route 级真端点(seed/fold 走 POST /__bili/plugin/tool、announce 走真实 POST /__bili/plugin/compact、消费走真实 /v1/responses),port 0 + 隔离 store/registry/session/plugin 状态,确定性良好。断言有牙:测试 1-2 在无修复时必红(pending 恒 true、ref 不剪);测试 3-4 钉住闸门(无脑无条件接线会红);测试 5 钉住「后续上游失败不回滚已提交簿记」。

我做的核验与动作:

调度提示:在途 PR #3490(lane 决策点收尾)与 #3467(preflight 超限出口)也都改 prepare-responses.ts——若它们先合入,合并本 PR 前需再 rebase 一次确认,避免热文件语义冲突。

判定:可合并(CI test lanes 绿后即可;合并操作请人工执行:https://github.com/ranxianglei/billion-context/pull/3480)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 已全绿(补上审查结论里唯一悬着的一项)

rebase 后的 head 4aabb3bb5 的 CI(run 39006646387)现在是 conclusion=success:静态门禁、ubuntu/windows × node 22/24 全部 test 分片、全部 e2e lane(fake codex / pi-codex-ws / real codex / persona / local registry / native opencode+pi+dsh)、PR Build Artifact 全绿。

之前唯一的红是 test (windows-latest, 22, 2),定性为环境抖动、与本 PR 无关,证据:

  1. 零断言失败:该分片 TAP 汇总 pass 3257 / fail 0 / cancelled 1 —— 没有任何一条断言挂掉;
  2. 被取消的那条是无关子系统的 tests/issue2672-preflight-blocked-split.test.ts(「[Bug][preflight] the chunked retry after a summary failure splits on raw message indices — halves land on protected messages, every sub-chunk is rejected as "BLOCKED..mNNNNN", and the whole range is abandoned #2672 halving midpoint…」),挂在 Windows runner 负载下的事件循环排空(Promise resolution is still pending but the event loop has already resolved,hang 5.6s 后被 node:test 级联取消),不是逻辑错误;同一分片序列里其他两次 windows 失败也是同一签名、不同文件(lane-decisions-matrix),断言失败数均为 0;
  3. 该测试文件在本树本地定向单跑通过(exit 0,~4s);同树其余 5 个 test 分片 + 全部 e2e lane 均绿;
  4. 对 run 执行了 rerun-failed-jobs(只重跑那一个 job)→ 绿。

结论维持上一条评论:可合并。 合并仍由人来操作:#3480

提醒一句(与首条一致):若 #3490(lane 决策点收尾)或 #3467(preflight 413)先合入,合并前需把本分支再 rebase 一次——两者与本 PR 改的是同一文件的不同区段,冲突风险低但顺序敏感。

@ranxianglei ranxianglei changed the title [Pi/Responses] consume announced native-compaction boundary in the /v1/responses lane [PR] [Pi/Responses] consume announced native-compaction boundary in the /v1/responses lane Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

这个自带压缩是不是应该默认拒绝?而不是通过?

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

好问题——我按代码把三个客户端的「自带压缩」现状逐一核了一遍,结论:能拒的两个客户端(dsh、codex)现在就已经是默认拒绝/拦截,只有显式 opt-in 才放行;而本 PR 的对象 pi 在物理上没有可拒绝的时机。

1. Dsh —— 已经是默认拒绝。 wire 级守卫(src/server/dsh-compaction-guard.ts,#1729/#2360):dsh 的原生压缩请求在 openai/anthropic/responses 所有 lane 上默认被本地拒掉(422,明确告知「bili owns compression on this lane」),用户要放行必须显式配置 dsh.allowDshCompaction: true / BILI_ALLOW_DSH_COMPACTION=1(#2028)。这正是你说的「默认拒绝而不是通过」的姿态,dsh 早就这么跑了。

2. Codex —— 默认就是拦截。 codexCompactMode() 的默认值是 "intercept"(BILI_CODEX_COMPACT > codexCompact > "intercept",src/knobs.ts:424-428):codex 自带压缩的生成请求(trigger 形式或 #3008 识别出的本地 SUMMARIZATION_PROMPT 形式)默认就被 bili 拦下,改由 bili 做确定性 ACP 交接(forge 分支),不让上游生成外来的压缩 blob。想放行要显式设 pass。本 PR 里 compactForm === undefined 那个 gate 保护的就是这个机制不被误消费。

3. Pi(本 PR 对象)—— 「拒绝」不成立。 pi 的 session_compact 在 pi 客户端内部完成;POST /__bili/plugin/compact 是事后通知,不是授权请求——bili 收到时 pi 的历史已经改写完了,不存在说「不」的时间窗。能选的反应只有一个:收到通知后怎么记账。消费归档(本 PR)= 归档失效块、修剪 ref、清 pending;无视(旧行为)= pending 永远挂着、ref 泄漏、死状态常驻。所以对 pi 这不是「放行 vs 拒绝」的策略开关,而是唯一可行的反应。

为什么「默认拒绝」不能替代这层消费逻辑:即使姿态再严,总有 bili 看不见的落地路径——dsh desktop 的 summarizer 直接调 ctx.llm.stream() 绕过代理、手动 /compact、无 ALS 归因的 idle-session 路径(代码注释里都记着),pi 的客户端侧改写天然不可见。这些只能靠落地后恢复兜底(#2432/#2658 rebase、#1001 unannounced-rewrite 归档、#2695 zombie reap,以及本 PR 补齐的四 lane 统一归档)。「拒可见的」和「收已落地的」是互补的两层,不是二选一——把消费层删掉去「强制拒绝」会严格变差。

结论:本 PR 没有改变任何客户端的默认姿态,它只是补上 responses lane 对「已落地压缩」缺失的记账,让四条 lane 对齐。如果你想进一步收紧,唯一还有空间的方向是给 pi 加 dsh 式的 wire 级默认拒绝守卫——但前提是拿到流量证据:pi 的自带压缩生成请求确实以可识别的形式经过 bili(目前代码库里没有任何 pi 压缩请求的 wire 签名)。有证据了我单独立项做,现在不投机建设。

@ranxianglei
ranxianglei merged commit 33accd1 into master Oct 20, 2026
44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.659-master.33accd1 (rolling master tag).

npm install -g billion-context@0.0.659-master.33accd1  # 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][Pi/Responses] plugin-announced native compaction boundary is never archived/consumed (v0.1.197)

1 participant