Skip to content

[PR] fix(responses): share developer segment concatenation between compressed re-request and steady state, fix prefix re-bill | fix(responses): 压缩重请求与稳态共用 developer 段拼接,修复每次折叠后的前缀重计费 (#6922) - #6944

Merged
ranxianglei merged 1 commit into
masterfrom
fix/responses-section-helper
Nov 16, 2026

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

现象

proxy-loop 模式 + 会话带 generation boundary 时,每次压缩折叠后的重请求(round-2)里,boundary/absorb/block-ops 段是用 \n\n 粘上去的,而普通请求里这些段是 --- 分隔(--- 拼接)。于是每次折叠,developer 段都从 note 位置开始分叉,前缀缓存把 note 之后的全部按新 token 重新计费。#6922。

方案

把段拼接提成共享 helper(src/responses-system-sections.ts → joinResponsesSystemSections),稳态构建路径、round-2 重建路径、round-2 adapter 的 dev join 全部改调它——两边再也不可能各写一套分隔符。非 Responses 的 round-2 保持历史 \n\n 胶水不动(那些 wire 的稳态本来就是 \n\n,cache-seam probe P1-P3 逐字节验证过)。

稳态字节完全不变 → 存量 Responses 会话升级零重计费。这是与 #6923 的区别:#6923 改的是稳态字节(---→\n\n),每个存活会话升级后要付一笔一次性全量重计费。谢谢 @kuviki 的复现和测试思路(本 PR 的测试骨架取自 #6923),修复方向不同,本 PR supersede #6923。

验证

merged 后 fixes #6922。

…fix fork (#6922)

The steady prepare path (prepare-responses.ts) and the proxy-loop round-2
rebuild (relay.ts) each assembled the Responses developer element from the
same ordered sections (system parts, compress prompt, generation-boundary
note #4305, absorb, block-ops) but with different separators: steady joined
with the "---" divider while round-2 glued boundary/absorb/block-ops with
plain "\n\n". On every fold of a generation-boundary-affected session the
developer element forked at the note position and the upstream prefix cache
re-billed everything after it.

Introduce joinResponsesSystemSections() (responses-system-sections.ts) as
the single source of truth for the separator and call it from both builders
plus the round-2 adapter join — the two paths can no longer drift apart.
Non-responses round-2 keeps its historical plain-\n\n glue (those steady
wires really do join with \n\n, verified by cache-seam probes P1-P3).
Steady bytes are unchanged, so live sessions pay no upgrade re-bill.

Test: driveWire gains generationBoundary/sections options; two new runs pin
that the complete developer item is byte-identical across every
ordinary -> compress re-request -> ordinary transition (with and without
absorb+block-ops armed). Reverting only the relay change fails both.
@ranxianglei
ranxianglei merged commit 4a24c26 into master Nov 16, 2026
38 of 39 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1219-master.4a24c26 (rolling master tag).

npm install -g billion-context@0.0.1219-master.4a24c26  # 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 ranxianglei changed the title fix(responses): 压缩重请求与稳态共用 developer 段拼接,修复每次折叠后的前缀重计费 (#6922) [PR] fix(responses): share developer segment concatenation between compressed re-request and steady state, fix prefix re-bill | fix(responses): 压缩重请求与稳态共用 developer 段拼接,修复每次折叠后的前缀重计费 (#6922) Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/responses-section-helper (1494b55)

Latest build — install this exact version

npm install -g billion-context@0.0.10397-pr.6944.c8974dc

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
1494b55 billion-context@0.0.10397-pr.6944.c8974dc build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6944.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] 🏷

查重:不重复 — 本 PR (#6944) 是 #6922 的修复,supersede #6923(已关闭、未合并)。检索 open+closed PR 无同主题并列 PR,#6944 是 #6922 唯一合入的修复。

状态(已实时核实):#6944 已合并(merge commit 4a24c2635e),#6922 已关闭(completed)。本审核为合并后复核。

八问

  1. 是什么问题:proxy-loop 模式 + Responses wire + 会话带 generation boundary 时,每次压缩折叠后的 round-2 重请求里,boundary/absorb/block-ops 段用 \n\n 粘,而稳态请求用 --- 分隔 → developer 段从 note 位置分叉,前缀缓存把 note 之后全部按新 token 重计费。

  2. 什么原因:稳态 builder(prepare-responses.ts)与 round-2 builder(relay.ts)各自独立拼 developer 段,分隔符各写一套(稳态 ---、round-2 \n\n)。根因是两处没有共享同一份分隔符定义,随时间漂移。

  3. 影响范围与严重程度:仅 proxy-loop + Responses + generation boundary 会话。每次折叠后 note 之后的 developer 段被重计费(成本↑),非功能损坏、非可用性缺陷。属「特定条件下有成本问题」。

  4. 怎么修:段拼接提成共享 helper joinResponsesSystemSections(分隔符 \n\n---\n\n 只在一处定义),稳态构建、round-2 重建、round-2 adapter 的 dev join 全改调它 → 两边不可能再各写一套分隔符。非 Responses 的 round-2 保持历史 \n\n 胶水(那些 wire 稳态本就是 \n\n,P1–P3 probe 逐字节验证过)。

  5. 是否有回归:无。

    • 稳态字节完全不变:4 处 X.join("\n\n---\n\n") → joinResponsesSystemSections(X),分隔符逐字相同;
    • 非 Responses round-2 逐字节等价:leading \n\n 从 section 变量内部移到拼接处,拼接结果相同(base + note + absorb + blockOps 全开/部分开/全关各态都核对过);
    • 高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。
  6. 是否破坏缓存:不破坏,反而修复。修复前每次折叠 note 之后重计费;修复后 developer 段逐字节稳定,前缀缓存命中。存量 Responses 会话升级零重计费(稳态字节不变)——这正是与 [PR] fix(responses): standardize paragraph separators in system prompt | fix(responses): 统一系统提示的段落分隔符 #6923 的区别([PR] fix(responses): standardize paragraph separators in system prompt | fix(responses): 统一系统提示的段落分隔符 #6923 改稳态字节,升级要付一次性全量重计费)。

  7. 是否改了设计方向:无转向。只是把分隔符定义收敛到一处(共享 helper),不改架构/边界/数据流。

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

CI

PR head 有 3 个 test lane 红(ubuntu 24 shard2、ubuntu 22 shard2、windows 22 shard5)。作者声明失败集与干净 master 逐条相同(14 个本机预存失败,均为缺依赖/环境问题),零新增;PR 已合并。我未能本地独立复现失败集对照(工作区无 node_modules/kernel 构建,且全量回归属 CI 职责)——这 3 个红是否预存,倾向预存(作者已做对照 + PR 已合),但严格确认需 CI 侧核对。

测试质量

新增 2 用例(sections 开/关):developer item 在「普通 → 压缩重请求 → 普通」每次过渡 deepEqual 逐字节相同。真 e2e(driveWire 驱动真实会话过 proxy,非 mock),断言有牙(整 item 相等 + 分隔符位置 + 段尾顺序)。作者做了反证(只回退 relay.ts,两用例皆失败)→ 测试真抓得住 #6922,非恒真。

判定

修复正确、完整、无回归、测试有效,已合并。3 个 CI 红疑似预存(待 CI 侧确认,不阻塞)。可收工。

ranxianglei added a commit that referenced this pull request Nov 16, 2026
…ecture map

The #6944 merge added the shared Responses developer-section joiner
(#6922) without its architecture.md entry, which the architecture-docs
guard requires. One-line module-map registration.
ranxianglei pushed a commit to MorningStar0709/billion-context that referenced this pull request Nov 16, 2026
…-fixes merge

The ci-fixes merge added the canonical module-map line (ref ranxianglei#6922, correct alphabetical position) while the PR branch already carried a botched duplicate (ref ranxianglei#6944, non-alphabetical position). Keep the canonical ci-fixes entry, drop the duplicate.
ranxianglei pushed a commit that referenced this pull request Nov 21, 2026
…-fixes merge

The ci-fixes merge added the canonical module-map line (ref #6922, correct alphabetical position) while the PR branch already carried a botched duplicate (ref #6944, non-alphabetical position). Keep the canonical ci-fixes entry, drop the duplicate.

(cherry picked from commit 3a91f23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant