Skip to content

fix(#2658): dsh native-compaction rebase fallback on anthropic/google lanes - #2664

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-10_dsh-anthropic-google-rebase
Oct 10, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-10_dsh-anthropic-google-rebase

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2658

What

#2432/PR #2436's dual-signal detection (dsh checkpoint framing in resent history + decimated fold coverage → immediate ACP rebase) only landed on two wires — openai chat (prepare-openai.ts) and responses (prepare-responses.ts). The anthropic and google lanes had the server-side REFUSAL gate (dshCompactionRefusal("anthropic") exists; the gate covers that wire) but not the post-landing recovery. So any dsh checkpoint landing there — direct-bypass (agentless/background/idle contexts have no ALS attribution), allowDshCompaction: true, or a future gate mismatch — left ACP state permanently unrebased: the cannot-be-anchored death spiral (#2432 defect 1 in full form) plus persistent prefix-cache loss (the #2596 main complaint). This PR ports the identical signature + rebase to both remaining lanes.

Changes

  • src/server/prepare-anthropic.ts: dual-signal block after loopConfig, before reconcileFoldCoverage/processTurn, mirroring prepare-openai.ts:142-155 — gate pluginAgent === "dsh" + active blocks + title-gen skip (same ≤200 max_tokens heuristic as the openai/google lanes); on hit → recordConflict("native-compaction") + warn log + markNativeCompactionBoundary + reconcileNativeCompactionBoundary. The later detectUnannouncedHistoryRewrite is wrapped in if (!dshRebased) so a just-classified dsh compaction is not double-recorded as a second "unannounced rewrite" (same pattern as the openai lane).
  • src/server/prepare-google.ts: same dual-signal block (this lane has no detectUnannouncedHistoryRewrite call, so no flag needed); adds the recordConflict + guard-helper imports.
  • tests/issue2658-dsh-anthropic-google-compaction.test.ts: 6 hermetic e2e tests through a real proxy instance per lane — positive (fold 9 of 14 msgs via plugin compress, replay [checkpoint framing, retained tail] → boundary set, fold destroyed, refs reissued at 3, conflict event recorded, next turn works) plus two negatives per lane (framing paste with INTACT history → no rebase, fold stays alive; decimated history WITHOUT framing → existing paths unchanged, no false rebase).

Behavior change disclosure

  • anthropic + google lanes: when the dual signal hits (checkpoint framing present AND ≥8 missing AND majority of covered ids gone), the request now rebases ACP state onto the compacted history immediately. Old behavior: silent permanent loss of compression for that session (session restart required) + ongoing prefix-cache invalidation. Non-hitting paths are byte-identical — single-signal cases follow exactly the pre-existing paths (framing paste with intact history has no gap; a gap without framing still falls through to detectUnannouncedHistoryRewrite / fold-reconcile as before).
  • No config surface change, no new env vars, no wire-shape change, no kernel change, no version bump off a release branch.

Verification

  • New + sibling suites (issue2658 / issue2432 / issue2451): 17/17 pass
  • Adjacent lanes (anthropic-cache-control, e2e-google-compress, dsh-compaction-guard, compaction-archive): 36/36 pass
  • npm run typecheck clean; npm run build clean
  • codex e2e could not run in this sandbox (the loopback e2e upstream documented in reference/testing.md was unreachable — ECONNREFUSED, environmental; this diff does not touch the responses lane). CI runs it automatically since src/server/** changed.

… lanes

The #2432 dual-signal detection (checkpoint framing in resent history +
decimated fold coverage -> immediate ACP rebase) only landed on the
openai/responses wires. Anthropic and google lanes had the server-side
refusal gate but not the post-landing recovery, so any dsh checkpoint
landing there (direct bypass, allowDshCompaction, future gate mismatch)
left ACP state permanently unrebased: cannot-be-anchored death spiral
plus persistent prefix-cache loss (#2596). Port the identical signature
and rebase to both lanes, with hermetic e2e positive/negative tests.
@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_dsh-anthropic-google-rebase (497242d)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2889-pr.2664.9127093

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-pr2664.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:拉取 PR 分支核对代码、对照原 issue #2658 的方向与修法、审四线一致性(openai/responses 参照实现)、跑定向测试、查 CI。结论按结构化八问给出,稍后回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(CI 全绿 + 本地定向验证)。结论:可合并(合并动作留给人工),但有一个必须处理的关联项(#2599 重复)和两个后续协调项。

结构化八问

1. 是什么问题:#2432 的「dsh 本地压缩落地 → ACP 状态立即 rebase」双信号检测只落在 openai/responses 两条 wire 上;anthropic/google 两条 lane 只有服务端拒绝门(dshCompactionRefusal("anthropic") 存在且覆盖该 wire),没有落地后的恢复路径。凡是有 checkpoint 落到这两条 lane(direct-bypass 无 ALS 归因、allowDshCompaction: true、或未来门禁失配),该会话的 ACP 状态就永久停在压缩前视图上。

2. 什么原因导致的:lane 覆盖不对称——#2432/#2436 修复时只把检测器移植到了当时有流量的两条 wire,拒绝门却按 wire 全覆盖写了。anthropic 是已知真实受害面(dsh 宿主 + Anthropic 兼容上游,如 DeepSeek 官方 API 的 /anthropic/v1/messages),google 为同机制的第二缺口。这是机制覆盖缺口,不是某条路径的实现错误——所以修法是补齐对称性,不是打补丁。

3. 影响范围与严重程度:触发条件 = dsh 绑定会话 × anthropic/google wire × dsh 本地压缩实际落地。命中后:该会话压缩功能完全失效直到重启(cannot-be-anchored 死亡螺旋,#2432 defect 1 完整形态)+ 持续的 prefix-cache 失效(#2596 主诉)。未命中路径零影响。google 面暂无已知流量,属防御性补齐。

4. 怎么修复的:把 openai reference(prepare-openai.ts:142-155)的同一签名+rebase 逐字移植到两条 lane——gate(pluginAgent === "dsh" + active blocks + title-gen ≤200 max_tokens 跳过)、阈值(missing ≥ DSH_LOCAL_COMPACTION_MIN_MISSING(=8) 且 missing*2 ≥ expected)、动作(recordConflict("native-compaction") + warn + markNativeCompactionBoundary + reconcileNativeCompactionBoundary)全部与 reference 字节级一致;插入位置(loopConfig 之后、reconcileFoldCoverage/processTurn 之前)三 lane 对齐。anthropic lane 里既有的 detectUnannouncedHistoryRewrite 包了 if (!dshRebased),防止刚分类的 dsh 压缩被二次记录成 "unannounced-rewrite"(与 openai lane 同模式);google lane 没有该调用,无需 flag。

5. 是否有回归问题:无。逐项过:

  • 非命中路径字节级不变(gate 四个条件全不满足时走原路径;单信号情形——framing 粘贴但历史完整 / 有 gap 无 framing——分别落回原有无操作路径和 detectUnannouncedHistoryRewrite/fold-reconcile,测试负例钉死)。
  • 命中路径是有意行为变更,PR 已按规范披露(旧:静默永久失去压缩 + 持续 cache 失效 → 新:立即 rebase),披露准确。
  • 重点核查项——stale base:PR 基于 e1cd9e1(v0.1.190),而 master 在其后走了 48 个提交,其中 f9d3a0f([Bug] dsh 原生压缩检测误报:历史里引用过 <compacted-summary> 即判为宿主压缩落地并 rebase ACP 状态(0.1.190) #2621)修改了本 PR 依赖的共享检测器 carriesDshLocalCompactionSummary(加了 role=user + contentType=text 生产者门)。PR 自身验证跑在旧版检测器上,合并后语义不同。我做了实证:本地把 PR merge 进当前 master(干净合入,零冲突)→ 构建 kernel/pi-subagents → 跑 8 个定向套件(issue2658/issue2432×2/issue2451/dsh-compaction-guard/anthropic-cache-control/e2e-google-compress/compaction-archive)= 63/63 通过;并核对了 kernel 两条 adapter(kernel/src/wire/anthropic.ts:107、kernel/src/wire/google.ts:165-166)确认 user 文本消息在 core 空间保留 role:"user" + contentType:"text",新 lane 的检测在 [Bug] dsh 原生压缩检测误报:历史里引用过 <compacted-summary> 即判为宿主压缩落地并 rebase ACP 状态(0.1.190) #2621 门控下仍然会触发(不是死代码)。
  • CI:26/26 check runs 全绿(含 ubuntu/windows 双矩阵全量 test、real-client 各 lane、kernel-guard)。

6. 是否破坏缓存:否。cache key 机制零触碰;命中路径反而改善了 checkpoint 落地后的 cache 稳定性(rebase 让头部重新稳定)。非命中路径无变化。

7. 是否改了设计方向:否。是把既有 #2432 机制补到剩余 lane,恢复 lane 对称性;数据流、边界不变。

8. 是否引入了新的配置:无 config/env/默认值变更;无 wire-shape 变更;无 kernel 变更;无版本号改动。

关联项(合并前请处理)

判定

代码与 reference 字节级对齐、测试有牙(正例断言 boundary 置位+同请求消费、refs 精确重发、conflict ledger、无双重记录、下一 turn 可用;负例钉死两条单信号路径)、非命中路径字节级不变、stale-base 风险已实证排除、CI 全绿。可合并;建议顺序:先关 #2599 → 人工合并本 PR。

Drive-by (review of #2684): master's lockfile lags the in-repo component
versions — acp-kernel recorded 0.0.110 while kernel/package.json is 0.0.112
(d16c341), and billion-context-pi-subagents recorded 0.1.3 while
pi-subagents/package.json is 0.1.4. Align both entries to what npm install
writes against current master. No dependency or content change.
@ranxianglei
ranxianglei merged commit 4e6bd5f into master Oct 10, 2026
27 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.227-master.4e6bd5f (rolling master tag).

npm install -g billion-context@0.0.227-master.4e6bd5f  # 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 added a commit that referenced this pull request Oct 10, 2026
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 11, 2026
Follow-up to the v0.1.192 carve-out (ranxianglei#2664): the bugfix channel shipped
with only its embedded pre-flight (typecheck+test+build) — no e2e lane
ever ran on the publish sha, because no PR existed and no e2e workflow
triggers on bugfix-release/** pushes.

Policy (2026-10-10): no matter the release channel, the COMPLETE CI lane
set must be green at the exact publish sha before npm publish.

- new scripts/release-ci-gate.mjs:
  --dispatch: idempotently workflow_dispatch every required lane that has
    no run at the publish sha (or a green run at an EXTRA_MATCH_SHAS,
    e.g. the PR head — same semantics as branch-protection required
    checks, so routine PR-based releases pay zero extra CI);
  --wait: block until every lane's latest run at the publish sha is
    success; any red lane / timeout / un-dispatchable lane ⇒ exit 1,
    publish step never runs (fail-safe).
- release.yml / release-kernel.yml: dispatch early + gate before Create
  tag, gated on is_release; EXTRA_MATCH_SHAS=HEAD^2 reuses PR-head runs.
- release-bugfix.yml: dispatch before the pre-flight (lanes run in
  parallel with it) + gate after it; +actions:write.
- release-manual.yml: direct path (GITHUB_TOKEN push fires no events,
  nothing runs CI on the release commit) gets dispatch+gate before
  Create tag; fallback path is already gated via release.yml after merge.
- required set (override with REQUIRED_CI_WORKFLOWS): ci.yml, ci-e2e.yml,
  ci-e2e-fake.yml, ci-e2e-dsh.yml, ci-e2e-dsh-native.yml,
  ci-e2e-codex-persona.yml, ci-e2e-native.yml, ci-e2e-native-opencode.yml,
  ci-e2e-pi-ws.yml
- tests/release-ci-gate.test.ts: 8 regression tests against an inline
  mock of the GitHub Actions API (no network, no token).
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 11, 2026
…anxianglei#2695)

Host-side deletion of history without a compaction frame (Claude Code
context editing, dsh native checkpoints on lanes without the rebase fix)
orphans fold blocks. syncBlocks keeps them alive forever via arrival-
order cluster ids re-derived by identical later messages, and the remint
feedback loop flaps one carrier in and out every turn - permanent
mid-list churn, i.e. prefix-cache misses on every request (ranxianglei#2596).

Host-only fix (no kernel changes): foldCoverageByBlock records a zombie
streak (z) - consecutive passes with a majority of a block's covered ids
absent from the inbound. After FOLD_DRIFT_ESCALATE_PASSES such passes in
proxy mode, reapDestroyedSubstrate removes the block from state.blocks
(removal is sticky; active=false would be resurrected by syncBlocks),
archives it via the ranxianglei#395 preCompactionArchive path (blockContents stay
for derived decompress), prunes refs, strips anchors/order/coverage, and
records an orphan-reap conflict event. Plugin mode is exempt (covered
ids are legitimately absent after the agent's own compress).

Proofs added (user request: cache proofs covering host compaction):
- cache-proof HOSTCOMPACT (chat wire): decimated replay drops orphan
  carriers, re-arms cleanly; zombie flap bounded (regression pin - red
  on master: zombie rides every later fold round-2, green with reap).
- cache-friendly-plugin P6 (dsh native-compaction rebase, 4 wires):
  checkpointed replay rebases blocks cleanly, era-stable tags, prefix
  append-stable after the rebase turn; red on pre-ranxianglei#2664 masters for
  anthropic/google.

Refs ranxianglei#2596 ranxianglei#2658. Kernel root-fix proposal (remint coveredBases should
scan inactive blocks; instance identity for duplicate clusters) filed in
ranxianglei#2695.
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 11, 2026
v0.1.192 was a carve-out release (78df4ea, ranxianglei#2664 only) and its version
bump never flowed back to master, so master still declares 0.1.191 while
npm latest is 0.1.192. That trips the Release one-click Drift guard:

  ::error::master package.json (0.1.191) != npm latest (0.1.192)

ranxianglei#2664's changes themselves are already in master (f0b3f5d), so this is
metadata-only: bump package.json + package-lock.json (root and
packages."" entries) to 0.1.192 so the next one-click release (0.1.193,
carrying the ranxianglei#2755 fold-summary head-stability fix) can proceed.
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 12, 2026
… cap

Publish Release Notes has been red since 2026-10-10: the 0.1.191 backfill
entry landed at 401 chars, and the 0.1.192 backfill (f24e3e8) added a
520-char bilingual summary. The validator exits on the first offender, so
both must be trimmed in the same push.

- 0.1.192: 520 -> 399 (condense the bilingual pair, keep ranxianglei#2658/ranxianglei#2596/ranxianglei#2664 refs)
- 0.1.191: 401 -> 392 (drop the 'ordinary ' qualifier on fold drift)

Verified locally with the exact validation script from release-notes.yml
(schema:1, 1..20 entries, semver, dedup, tier, <=400 summary, date) — all
14 entries pass.

Fixes the failed runs:
- https://github.com/ranxianglei/billion-context/actions/runs/38152721758
- https://github.com/ranxianglei/billion-context/actions/runs/38040163381
@ranxianglei
ranxianglei deleted the 2026-10-10_dsh-anthropic-google-rebase branch October 15, 2026 05:33
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] dsh 原生压缩单轮 rebase 兜底缺失于 anthropic 线路(#2432 修复未覆盖):checkpoint 落地后 ACP 状态永久失效

1 participant