Skip to content

fix: normalize Responses side-request compaction handoffs - #1822

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-09-30_responses-side-compaction
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-09-30_responses-side-compaction

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Supersedes #1765 — its head branch was deleted on the remote, so the old PR froze at stale head 0ad9565 and can no longer receive pushes. This is the same single fix commit rebased onto current master (96137977, after #1814/#1784).

Fixes #1763

Responses side requests can echo a private fc_bili_* compaction handoff and receive HTTP 400 (Expected an ID that begins with 'cmp'). This branch bypassed the summary conversion already used by normal Responses preparation and the native fallback fixed in #770.

Reuse replaceBiliCompactionItems() before the side request is forwarded: retain the summary as a user message at its original position, drop legacy local markers without recoverable summaries, and preserve genuine upstream compaction items. Requests without local handoffs keep their raw buffer. Side requests still bypass kernel mutation and compression/tool injection. The normalization applies in both plugin and proxy modes once the request reaches the side lane; no compression carrier policy changes.

Add the compaction-ID rule to the permanent wire-contract ledger and fake validator (WC-012), scoped to compaction IDs rather than function-call IDs.

Validation:

Only four files change: one server branch and three regression/contract files. Related open #1431 changes side-request classification; this PR only normalizes requests already in that branch.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_responses-side-compaction (0ad9565)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1802-pr.1822.bc8efa1

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-pr1822.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

[bot] 🏷 Reviewing this PR now (not redoing the work — verifying the rebase per #1763's original review).

Initial structural check ✅:

Continuing: code review vs the previously-approved #1765 fix, CI status, and local validation (typecheck + wire-contract + codex-compact-e2e + full suite). Full structured conclusion in my next comment.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 ## Review 结论 — PR #1822(结构化七问)

Rebase 保真度已独立验证(不是只看描述):head 225a2bfe 与原始修复提交 3de2ea8(本地仍有该对象)的 git patch-id --stable 完全相同(2593ffa…)——字节级同一补丁;merge-base == master head 96137977,零漂移;原 base b785c43c 到当前 master 之间的提交(#1814/#1784/release v0.1.178/#1804)未触碰本 PR 的任何一个文件,rebase 无语义风险。四文件、单提交,与 #1765 一致。

七问

  1. 是什么问题:Responses 侧请求(title-gen 等小请求)把 bili 私有的压缩交接项(type:"compaction", id=fc_bili_*, blob=bili:acp:*)原样转发给严格上游,上游按 Responses 契约要求 compaction ID 以 cmp 开头 → HTTP 400 Expected an ID that begins with 'cmp',整个请求失败。
  2. 什么原因导致的:根因是侧请求直通分支绕过了本已存在的摘要转换。buildTriggerForgeBody() 产出的本地摘要载体天生带 fc_bili_* id;仓库里四条 Responses 转发路径中,正常准备(:4002)与 native fallback(:2692,fix: normalize bili compaction markers in Codex native fallback #770 修的)都调用了 replaceBiliCompactionItems(),唯独侧请求分支没有——缺口的生产者就是「该分支从未做归一化」,修在决策点上而非在流里剥标签,方向正确。
  3. 怎么修复的:转发前复用既有归一器 replaceBiliCompactionItems():有可恢复摘要的交接项就地替换为 user message(保持原位),无摘要的遗留标记丢弃,真正的上游 compaction 项原样保留。重建仅当 replaced+dropped>0 且 protocol==="responses" 时发生,否则 sideBody 保持 scrubAnthropicPck 输出(非 anthropic 协议下即原始 buffer)——无交接的请求逐字节不变。同时把 compaction-ID 规则写入永久 wire-contract ledger(WC-012)+ fake 校验器,范围限定 compaction ID,不误伤 function-call 的 fc_* ID(有专门用例钉住)。
  4. 是否有回归问题:无。逐项审过的既有行为:
    • 侧请求仍绕过 kernel mutation / 压缩 / 工具注入(sidePrepared 未动,compressInjected:false, sidePassthrough:true);压缩载体策略(plugin/proxy 两种模式)零变更——归一化发生在路由到侧车道之后,不碰主请求路径;
    • 非 Responses 协议的侧通道:被 protocol 门控,不受影响;
    • 无本地交接的 Responses 侧请求:bodyBuffer 逐字节不变(门控条件保证);
    • 正常主请求路径、native fallback、/responses/compact 三处调用点均未触碰;
    • wire 保真:{...parsed, input: items} 展开原 body 仅替换 input,不加不减字段;tool arguments 路径完全不经过此分支;
    • ledger 校验器里 isPlainObject 早退上提是语义等价重构;WC-012 置于 tools 早退之前与 WC-011 同构;
    • 高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。
      证据:A/B 独立复现——只回退 src/server.ts 一个文件,新回归测试即以 issue 原文错误 Invalid 'input[0].id': 'fc_bili_local'. Expected an ID that begins with 'cmp' 失败,恢复后通过(测试有牙);typecheck ✓;wire-contract + codex-compact-e2e 28/28 ✓;全量套件 3459 pass / 0 fail / 19 skip(计数高于原始 3360 是因 master 前进新增测试,口径一致);CI 13 个 check run 全绿(含 real-client e2e 门、win22/24、hermetic registry)。
  5. 是否破坏缓存:不涉及。不动 session 状态、缓存、重试、游标、去重键;这些请求此前是直接 400 失败的,不存在可失效的历史缓存态。
  6. 是否改了设计方向:不涉及。没有新机制——把一个已在三处使用的归一器补到第四条转发路径上,收敛既有的「四条路径各自处理」缺口;架构、边界、数据流不变。
  7. 是否引入了新的配置:不涉及。无新 env/config/默认值。

合并前唯一协调事项:open 的 #1431(anchor affinity 路由)改的是同一个 side-request 分支的入口条件(:2413)和 413 守卫块(:2415-2441),与本 PR 插入点(:2445-2453)紧邻。两者语义正交(#1431 决定什么进侧车道,本 PR 归一化已进车道的 body;#1431 合入后辅助请求自动获得同样的归一化,方向正确),但先后合并时会有文本冲突,需要 rebase 排序——PR 正文已披露此关系,无需改代码。

判定

可合并(merge 由人执行):#1822 —— 修复打在根因上,diff 干净(每行都在目的内),回归测试有牙且 A/B 验证过,CI 全绿,rebase 保真度可证明。建议合并顺序:本 PR 与 #1431 任选其一先合,另一个 rebase 后跟进。

@ranxianglei
ranxianglei force-pushed the 2026-09-30_responses-side-compaction branch from 225a2bf to 0ad9565 Compare October 1, 2026 04:23
@ranxianglei

Copy link
Copy Markdown
Owner Author

关闭本 PR:撤销替代方案。原 PR #1765(作者 @InCerryGit)仍处于可合并状态(其 head 分支被删导致引用冻结,但 head 本身 mergeable、CI 全绿),应直接合并原 PR。给首次贡献者带来的困扰,抱歉。

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.

Responses side requests forward private compaction handoffs and fail cmp ID validation

2 participants