Skip to content

fix: wire the #2621 novelty gate on the anthropic and google dsh lanes - #2775

Closed
ranxianglei wants to merge 1 commit into
masterfrom
fix-dsh-novelty-gate
Closed

ranxianglei wants to merge 1 commit into
masterfrom
fix-dsh-novelty-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#2621 added a novelty gate to carriesDshLocalCompactionSummary (a freshly-landed checkpoint is a NEW id; a quoted/replayed mention hits an OLD id) and wired it on the openai and responses lanes. #2658 then shipped the detector on the anthropic (src/server/prepare-anthropic.ts) and google (src/server/prepare-google.ts) lanes — but called it without the second argument, although knownRefsBefore is already computed at both call sites:

if (dshGap && carriesDshLocalCompactionSummary(msgs)) {   // ← no knownRefsBefore

Why it matters

Without the ref map, only the carrier gate ① runs: any user-role plain-text message that merely quotes the checkpoint framing (DSH_CHECKPOINT_OPEN_TAG anywhere in the text, or the preamble prefix) satisfies it. A user pasting checkpoint text in an earlier turn, replayed with identical raw bytes → an OLD id in messageRefs.byRaw. Combined with ordinary edit/truncate/resume drift decimating fold coverage (missing ≥ 8 and missing*2 ≥ expected), the lane false-recorded a native-compaction conflict, ran markNativeCompactionBoundary + reconcileNativeCompactionBoundary, and resetSessionCompression silently wiped all live ACP state (folds, refs, content store) — exactly the false-rebase profile #2621 fixed on openai in v0.1.190, reborn on the two new wires.

Refs are high-water pinned (reserveRefsThrough), so this is recoverable — but it silently restarts compression from scratch plus a false "another compressor ran" attribution.

Change

  • prepare-anthropic.ts / prepare-google.ts: pass knownRefsBefore (one line each, same wiring + comment shape as the openai lane).
  • Tests: port the #2621 negative to both new wires — a seeded user message quoting the framing, replayed byte-identical (old id) + a real fold gap (8/9 covered ids missing) must NOT rebase, must NOT record a native-compaction conflict, and the live fold must survive.
  • The contract comment in dsh-compaction-guard.ts ("every in-repo caller passes it") is true again.

Verification

  • New tests red without the wiring (6/8 pass, both new negatives fail with a false rebase) and green with it (8/8).
  • tests/issue2432-dsh-local-compaction 11/11, tests/issue2451-dsh-responses-compaction 4/4, tests/issue2709-dsh-native-compaction-attribution 5/5, tests/e2e-anthropic 6/6 — all green.
  • Found during the v0.1.193 (PR release v0.1.193 #2767) regression review; no default-behavior change, no config-surface change.

carriesDshLocalCompactionSummary(msgs) was called without the pre-turn ref
map on prepare-anthropic.ts and prepare-google.ts, although knownRefsBefore
is already computed there — the openai (#2621) and responses lanes pass it.
Without the second argument a USER-role message that merely QUOTES the
checkpoint framing and is replayed (identical raw bytes → an OLD id in
messageRefs.byRaw) passed the carrier gate alone; combined with ordinary
drift decimating fold coverage (missing ≥ DSH_LOCAL_COMPACTION_MIN_MISSING)
the lanes false-fired the native-compaction rebase and resetSessionCompression
wiped live ACP state — the v0.1.190 incident class shipped on the two lanes
#2658 added.

Also ports the #2621 negative (old-id framing quote + real gap → no rebase)
to /v1/messages and generateContent; red without the wiring, green with it.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix-dsh-novelty-gate (533459c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3052-pr.2775.7885d2e

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-pr2775.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] 🏷 Working on it now. Bug confirmed in-tree: src/server/prepare-anthropic.ts:208 and src/server/prepare-google.ts:137 call carriesDshLocalCompactionSummary(msgs) without the pre-turn ref map, although knownRefsBefore is already computed at both sites (lines 154 / 113) — so the #2621 novelty gate is dead on these two wires and the carrier gate alone decides.

Plan:

  1. One-line wiring fix in both lanes (same comment shape as the openai lane).
  2. Port the [Bug] dsh 原生压缩检测误报:历史里引用过 <compacted-summary> 即判为宿主压缩落地并 rebase ACP 状态(0.1.190) #2621 negative to both wires in tests/issue2658-dsh-anthropic-google-compaction.test.ts (seeded user quote of the framing, replayed byte-identical → old id, + real fold gap 8/9 missing): must not rebase, must not record a native-compaction conflict, live fold must survive. Verifying red-without / green-with.
  3. While auditing I also spotted a sibling gap on the google lane: no dshRebased capture/skip around detectUnannouncedHistoryRewrite (openai/anthropic/responses all skip the double-record there). If it checks out I'll land it as a separate clearly-labeled commit and flag it explicitly.

Full report with the structured conclusion follows once CI-visible evidence is in.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Done — PR #2783 (Closes #2775): #2783

Two commits: (1) the one-line knownRefsBefore wiring on both lanes + the ported #2621 negatives; (2) a separately-labeled parity fix found while auditing — the google wire shipped without the dshRebased skip that openai/anthropic/responses carry around detectUnannouncedHistoryRewrite, so a genuine landing could have double-recorded unannounced-rewrite beside native-compaction (mature sessions only, ≥20 known refs). Now captured + skipped, matching the siblings, with the no-double-record assertion pinned on the google e2e positive.

1. 是什么问题: #2658 把 dsh native-compaction 检测器移植到 anthropic/google 两条线时漏传了 pre-turn ref map,#2621 的 novelty gate 在这两条线上完全失效——用户消息里引用的 checkpoint framing 被字节一致地重放、叠加普通 fold 漂移时,会误判 native compaction 并静默清空全部 ACP 状态。
2. 什么原因导致的: #2621 的修法是要求 framing 匹配必须是 NEW id(新落地的 checkpoint),但 #2658 在 prepare-anthropic.ts:208 / prepare-google.ts:137 调用时丢了第二个参数——尽管两个调用点的 knownRefsBefore 都已算好(line 154 / 113)。机制存在、接线缺失:只剩 carrier gate ① 在跑。
3. 影响范围与严重程度: 仅 dsh 绑定、走 /v1/messages 或 :generateContent、有活跃 fold、且历史中存在 user-role 纯文本引用了 framing(tag 任意位置或 preamble 前缀)并被字节一致重放、fold 覆盖同时被漂移削到 missing≥8 且 missing*2≥expected 的会话。后果:静默丢失全部 ACP 压缩状态(folds/refs/content store 被 resetSessionCompression 清空)+ 错误的「另一个压缩器在跑」归因;refs 高水位钉死可恢复,但压缩从零重启。非 dsh 会话与其他 lane 不受影响。
4. 怎么修复的: 两处调用点传入已算好的 knownRefsBefore(各一行,与 openai lane 相同的接线+注释形态),framing 匹配重新要求 novelty;把 #2621 的 negative 移植到两条线(seeded user quote、字节一致重放=old id + 真实 8/9 gap → 不 rebase、不记 conflict、live fold 存活)。不带接线时 6/8 红(两条新 negative 以 false rebase 失败),带上后 8/8 绿。google 的 double-record 缺口作为独立标注 commit 补齐。
5. 是否有回归问题: 逐 lane 审过既有行为:真实新落地仍正常 rebase(两条线的 positive e2e 绿——新 checkpoint id ∉ pre-turn map,匹配不变);paste-while-intact、gap-without-framing、non-dsh 绑定、non-user carrier 引用等既有 negative 全绿;issue2432 11/11、issue2451 4/4、issue2709 5/5、guard 18/18、e2e-anthropic 6/6;typecheck 干净。行为变更已按政策披露(PR 描述内):google lane 不再在刚记录的 native-compaction rebase 旁重复记录 unannounced-rewrite(旧值:成熟会话下可能双归因 → 新值:单归因,与三条兄弟 lane 一致);commit 1 纯去假阳,无阈值/默认值/时序/输出格式变化。
6. 是否破坏缓存: 否。refs 高水位钉死未动;修复只是在 processTurn 之前对 pre-turn 快照做一次成员检查(与 rewrite detection 同一个 TIMING INVARIANT)。前缀缓存锚点不受影响——反而避免了误 rebase 引发的缓存重置。
7. 是否改了设计方向: 否。同一双信号检测器、同一 rebase 机制;dsh-compaction-guard.ts 的契约注释(「every in-repo caller passes it」)在四条线上重新为真。
8. 是否引入了新的配置: 无。

判定:可合并——diff 收敛为两行接线 + 一处 parity guard + 测试,定向证据本地全绿,全量回归交给 CI。

@ranxianglei ranxianglei added the duplicate This issue or pull request already exists label Oct 11, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing as superseded by #2783.

Both PRs fix the same defect: #2658's anthropic/google port called carriesDshLocalCompactionSummary without the knownRefsBefore argument, leaving only carrier gate ① armed on those wires. #2783's commit 1 is this PR's single commit rebased onto current master (verified hunk-for-hunk: identical wiring, only comment/test-naming differences) plus an extra commit 2 found while auditing for it (google lane double-record skip around detectUnannouncedHistoryRewrite). One mechanism, one PR — #2783 carries the full scope; its thread has the complete review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant