Skip to content

fix(#2598): wire #1001 unannounced-history-rewrite detection into the google lane - #2618

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-10_google-rewrite-detect
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-10_google-rewrite-detect

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2598

What

The google lane consumed the archive+prune channel (applyCompactionArchive, src/server/prepare-google.ts) but no path ever set metadata.compactionBoundary for google-lane sessions — the channel was a permanent no-op there. A silent client history rewrite (sid unchanged) would leave partially-alive blocks citing vanished ids → nudge broadcasts dead refs → compress fails → breaker (the #2432/#2592 failure domain).

This wires the producer trio exactly as prepare-openai.ts / prepare-anthropic.ts carry it:

  1. pre-turn knownRefsBefore snapshot (before processTurn assigns fresh refs — timing invariant; detection would otherwise read ratio 1.0);
  2. the shared protocol-agnostic detectUnannouncedHistoryRewrite gate (detectUnannouncedHistoryRewrite 误判 1 条消息的侧边辅助请求(如 WebSearch),导致 Ref 映射表被洗空、编号雪崩耗尽(m99999)及 363 万 Token 溢出 #1075-hardened: ≥10 incoming, overlap required, known/incoming < 0.5, ≥20 known refs, non-empty blocks);
  3. on detection: log warn + recordConflict("unannounced-rewrite") + markCompactionBoundary. The consumer side (applyCompactionArchive) was already in place.

Behavior change (disclosed)

  • Google lane only: sessions now get a compaction boundary marked when the 模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001 detector fires (silent client rewrite). Previously this path was unreachable on the google lane — behavior there changes from "permanently no-op" to "archive+prune on detected rewrite". No other lane is touched.
  • Conflict-watch gains unannounced-rewrite entries for google-lane sessions when (and only when) the detector fires.
  • False-positive risk is bounded by the same conservative gates already proven on two live lanes (openai/anthropic); the gate's design comment states "a false positive is fatal", which is why the thresholds are high (ratio < 0.5 AND overlap AND volume floors).

Config surface

None. No new config fields, env vars, or CLI flags.

Tests

  • New google-wire e2e variant of the 模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001 openai e2e in tests/fix-1001-history-rewrite.test.ts: preflight block on turn 1 → silent rewrite (keep 8 of 24, append 16) on turn 2 → asserts boundary marked + consumed, block archived with reason, byRaw pruned without ref re-issue, folded view forwarded without dead refs; turn 3 proves continued operation with unique refs.
  • Targeted local runs: tests/fix-1001-history-rewrite.test.ts + tests/e2e-google-compress.test.ts → 11/11 pass; typecheck clean. Full suite + codex e2e left to CI (ci.yml all-PR matrix + ci-e2e-fake.yml).

Second commit (labeled minor fix, found during #2598 verification)

chore: drops five unused session.js imports left in src/server.ts by the #1440 split (applyCompactionArchive, detectUnannouncedHistoryRewrite, markCompactionBoundary, reconcileNativeCompactionBoundary, REWRITE_MIN_INCOMING_TOTAL) — each verified to appear exactly once (its own import line). No behavior change.

Out of scope (tracked in the #2598 thread)

The responses lane lacks both the detector and the applyCompactionArchive consumer — possibly intentional under its previous_response_id identity model; owner judgment, kept as a checklist item in the issue.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_google-rewrite-detect (5cf23f2)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2965-pr.2618.04132a4

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-pr2618.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] 🏷 Review 完成——可合并(CI 全绿前我按「已审完、无拦截项」判定;当前 CI 无失败,部分 job 仍在排队)。

审查过程(证据):

结构化八问:

  1. 是什么问题:google 车道的 archive+prune 通道只有消费端(applyCompactionArchive),生产端(置 compactionBoundary)从未接线,通道在该车道恒为 no-op;宿主静默改写历史(sid 不变)时死 ref 滞留 → nudge 广播死引用 → compress 持续失败 → 熔断([bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432/[Bug] #2436 的宿主本地压缩检测只接在 OpenAI 车道,Anthropic 车道缺失——未宣告宿主压缩后 nudge 广播的 compress ref 永久不可解析 #2592 同款失败域)。
  2. 什么原因导致的:模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001 实现时检测器只接了 openai/anthropic 两条 prepare 路径,google 路径历史遗漏(git -S 证实含 audit: 全仓冗余审计与重构计划——server.ts 解体、客户端矩阵去重、死代码、AGENTS.md 模块图腐化 #1440 拆分前亦然);消费端在拆分时进了 google 车道,生产端三件套没跟上。
  3. 影响范围与严重程度:仅「走 Google wire 且会话中途静默重写历史」的宿主(gemini-cli 家族等),触发面窄;可达日志取证为零事件,属潜在覆盖缺口而非已发生事故;若触发则后果与 [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 同级(compress 熔断)。
  4. 怎么修复的:纯接线——把活车道已证明的生产端三件套(pre-turn 快照 + 共享协议无关检测器 + markCompactionBoundary)逐字移植进 google 车道,消费端原样复用;ref 剪枝由 REF_FLOOR_RAW_ID 钉住高水位,保证剪枝后 ref 号永不重发(kernel id-never-reused 契约)。
  5. 是否有回归问题:逐项过——happy path(append-only)ratio≈1.0 不触发,零变化;title-gen/side-request/大追加 resume 三类误报源被门控挡住;其他车道零触碰(openai 变体测试未回归);chore commit 五个符号 grep 均 0 引用;无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化。唯一行为变更即修复目的本身,已在 PR 正文按旧值→新值披露。
  6. 是否破坏缓存:不涉及——prefix cache/指纹路径零触碰;ref map 剪枝仅在检测命中后发生且有 REF_FLOOR 保护,e2e 断言剪枝后 byRef 无重复。
  7. 是否改了设计方向:不涉及——补齐既有机制的车道覆盖,无新机制。
  8. 是否引入了新的配置:不涉及——无新 config/env/CLI flag。

测试有效性:新 e2e 是真测试——修复前 metadata.compactionBoundary 不存在,assert.ok(bound) 必红,回归有牙;断言链完整(boundary 置位+消费、归档带 reason、byRaw 精确回 24 无 additive leak、byRef 唯一、折叠视图含摘要去死 ref、第三轮持续工作)。responses 车道两端皆缺的问题按粒度纪律留在 #2598 线程做 checklist,未另立项,处理正确。

diff 整洁度:3 文件 +140/-2,每行都服务于 PR 目的;chore commit 独立标注,符合顺手小修规则。

结论:可合并(待你手动 merge;CI 剩余 job 若转红我再跟进)。

ework-agent added 2 commits October 11, 2026 11:35
… google lane

prepare-google.ts already consumed the archive+prune channel
(applyCompactionArchive) but no path ever set
metadata.compactionBoundary for google-lane sessions, so the channel
was a permanent no-op there: a silent client history rewrite (sid
unchanged) left partially-alive blocks citing vanished ids → nudge
broadcasts dead refs → compress fails → breaker (#2432/#2592 failure
domain).

Wire the producer trio exactly as prepare-openai.ts /
prepare-anthropic.ts carry it: pre-turn knownRefsBefore snapshot
(before processTurn assigns fresh refs — timing invariant, detection
would otherwise read ratio 1.0), the shared protocol-agnostic
detectUnannouncedHistoryRewrite gate (#1075-hardened: min incoming,
overlap required, ratio < 0.5, >= 20 known refs, non-empty blocks),
and markCompactionBoundary + recordConflict on detection. The consumer
side (applyCompactionArchive) was already in place.

Regression test: google-wire e2e variant of the #1001 openai e2e in
tests/fix-1001-history-rewrite.test.ts — turn-1 preflight block,
silent rewrite (keep 8 / append 16), boundary marked + consumed,
blocks archived with reason, byRaw pruned without ref re-issue,
folded view forwarded.
…erver split

Leftovers verified unused on current master (each symbol appears exactly
once in src/server.ts — its own import line): applyCompactionArchive,
detectUnannouncedHistoryRewrite, markCompactionBoundary (#1001 family,
now home in the lane modules), reconcileNativeCompactionBoundary
(#2373/#2432 family) and REWRITE_MIN_INCOMING_TOTAL (#1001 constant).
No behavior change; root tsconfig has no noUnusedLocals so CI never
flagged them.
@ranxianglei
ranxianglei force-pushed the 2026-10-10_google-rewrite-detect branch from 8fe5bb8 to 5cf23f2 Compare October 11, 2026 03:39
@ranxianglei
ranxianglei merged commit f12e259 into master Oct 11, 2026
30 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.270-master.f12e259 (rolling master tag).

npm install -g billion-context@0.0.270-master.f12e259  # 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] Google 车道从未接线 #1001 unannounced-history-rewrite 检测——applyCompactionArchive 在该车道恒为 no-op

1 participant