Skip to content

fix(#2709): attribute framing-absent dsh native compaction via refusal ledger (inferred tier) - #2715

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-11_dsh-native-compaction-attribution
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-11_dsh-native-compaction-attribution

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follows #2709 (core attribution gap; P3 bili-side switch + CONFIGURATION.md doc note deferred to owner decision — see issue thread)

Problem

When a client-native (dsh) compaction lands without its <compacted-summary> checkpoint marker in the resent history, the existing detectors classify it as a generic unannounced rewrite:

  • #1001 (detectUnannouncedHistoryRewrite, prepare-openai/prepare-anthropic) → records unannounced-rewrite;
  • #2193 total-loss drift escalation (fold-reconcile) → logs only, no ledger action.

The banner then tells the user there is an "unconfirmed signal / reason unknown" and points them at disabling auto-compaction or hunting a second compressor — but bili already witnessed the real cause: it refused the client's own compaction calls this session (metadata.dshCompactionRefusals, #1729/#2028) and never used that witness for attribution.

Fix (attribution only — no rebase)

Add a native-compaction-inferred conflict tier. When a dsh-bound session has a non-zero dshCompactionRefusals AND a bulk rewrite is detected, attribute the event to client-native compaction [inferred] instead of leaving it unconfirmed.

Key design decision: attribution ≠ rebase. Without the checkpoint marker bili cannot identify the new baseline/checkpoint, so it must NOT reconcileNativeCompactionBoundary onto a guessed view. Recovery stays exactly markCompactionBoundary (archive+prune) — byte-identical to before. Only the classification label and user-facing wording change.

Wired at:

The server classification ladder treats inferred as confirmed-native (isConfirmedConflictEvent), and the web banner mirrors it (src/web/client.ts) so the two surfaces agree.

Behavior changes (old → new) — flagged per policy

  1. Ledger kind: a previously-witnessed framing-absent dsh landing recorded unannounced-rewrite → now records native-compaction-inferred. Non-dsh sessions and dsh sessions with zero refusals are unchanged (still unannounced-rewrite).
  2. Banner/advice text: a lone framing-absent dsh landing previously rendered as "UNCONFIRMED signal … disable client auto-compaction or a second compressor" → now renders under the confirmed-native tier: do not go hunting for a second plugin … bili attributed this from its own witness (it refused the client's compaction calls this session) but did NOT see the checkpoint marker, so it could not rebuild the fold base …. Marker-detected landings keep their existing wording verbatim.
  3. Log line (#1001): when witnessed, the warn line reads "client-native compaction landing (framing absent; attributed from refusal ledger)" instead of "unannounced client history rewrite".
  4. acp_status / web stats: summarizeConflicts.kinds now surfaces a native-compaction-inferred count (serves [Bug] #1001 归因缺口:客户端原生压缩落地后只剩「未确认档」——bili 已记录的 17 次拒绝(dshCompactionRefusals)与 10 次 DIRECT 旁路未被用于归因 #2709 P2 quantification); no new field added.

No wire/message-shape change, no config-schema change, no kernel change, no rebase path touched.

Tests

  • NEW tests/issue2709-dsh-native-compaction-attribution.test.ts: witness predicate (dsh / non-dsh / zero / string), inferred-only → confirmed-native advice ("did NOT see the checkpoint marker", not "rebuilds the fold state"), confirmed keeps old wording, unannounced stays UNCONFIRMED, mixed → rebuild wording wins.
  • tests/web-conflict-banner.test.ts: inferred counts as CONFIRMED on the client-side severity mirror (not an unconfirmed signal).
  • Typecheck clean; targeted suite (conflict-watch / fold-reconcile / prepare lanes / web banner, 12 files) 168 pass / 0 fail. Full regression left to CI.

Out of scope (owner decision, tracked in #2709)

  • P3: bili-side switch (allow client compaction but rebase on landing) = new config surface → owner-gated, not built.
  • P2 docs half: CONFIGURATION.md note on "refusal ≠ prevention" → follow-up commit.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始按 PR Review 规范审查本 PR(方向关→回归关→代码关→测试关→diff 整洁度)。先核对分支代码与 CI 状态,结论稍后按结构化八问给出。

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_dsh-native-compaction-attribution (aa1bde8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2957-pr.2715.ad670ed

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-pr2715.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 现已 mergeable(与 master 无冲突),CI 在新 head 上运行中。 按结构化八问给出结论。

冲突处理(本次唤醒的直接任务)

八问

  1. 是什么问题:dsh 客户端原生压缩以「无 checkpoint 定界符」形态落地后,bili 的冲突账本只能记成笼统的 unannounced-rewrite(未确认档),横幅把用户引向「禁用自动压缩 / 排查第二个压缩器」——尽管 bili 自己早已在本会话拒绝过该客户端的压缩调用(事故现场 dshCompactionRefusals=17)且这些事实都在服务端账本里。
  2. 什么原因导致的:根因是归因链断裂,不是文案问题(文案只是症状)。确认档检测器依赖 <compacted-summary> 定界符仍在重发历史里;定界符缺席时,模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001/[dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 检测器只能落回通用 unannounced-rewrite,而 bili 已有的间接见证(拒绝账本)从未被接进分类层——「归因」和「rebase」被绑死在同一个定界符信号上。
  3. 影响范围与严重程度:所有走 dsh 插件、原生压缩以 framing-absent 形态落地的会话(客户端重序列化丢框架 / 检查点不在重发窗口 / 模板漂移)。严重度 = 判读/体验瑕疵:无数据丢失、wire 转发不受影响,但会误导用户做无效操作(去找不存在的第二压缩器)并长期掩盖真实故障模式。
  4. 怎么修复的:新增 native-compaction-inferred 账本档。核心取舍:只做归因、不做 rebase——没有定界符就无法定位新基线/检查点,贸然 reconcile 到猜测视图比不 rebase 更糟;恢复动作保持原样 markCompactionBoundary(archive+prune,字节级不变),只改分类标签与文案。误报控制:witness 为严格合取(dsh 绑定 ∧ dshCompactionRefusals>0 ∧ number 类型),且只在既有严格门之上叠加(模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001 双比值 <0.5,openai/anthropic 两车道的 !dshRebased 分支;[dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 连续 ≥3 pass 全丢且 unmatched≥10,由 ESCALATED latch 保证每 episode 一次)。服务端分级与 web banner 同步识别该档(inferred 视同 confirmed-native 处置层级),inferred-only 时用精确措辞(「未看到检查点 marker → 无法重建折叠基 → 开新会话」),marker 检测档的 rebuild 措辞逐字保留。
  5. 是否有回归问题:无意外回归。逐项过过的既有行为:带定界符的确认档(rebuild 措辞逐字保留,测试钉住)、纯 unannounced-rewrite(仍 UNCONFIRMED,测试钉住)、非 dsh 会话 / 零拒绝 dsh 会话(不变,测试钉住)、[Bug][proxy] unframed host-side history deletion leaves zombie fold blocks rendering carriers forever — one carrier flaps in/out every turn (persistent prefix-cache churn) #2695 zombie reap(master 新代码,proxy-only,与 dsh witness 互斥,见上)、[dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 升级错误行/latch 语义(不变)、恢复路径 markCompactionBoundary(字节一致)。高危模式逐项:fal-fast 变吞错——无;阈值/时序漂移——无(所有既有门原样,witness 纯叠加);输出格式变化——有意变更已披露(旧→新):①被见证的 framing-absent dsh 落地账本 kind unannounced-rewrite→native-compaction-inferred;②banner advice 对 inferred-only 场景换精确措辞;③模型切换后压缩块跨模型失配,新模型收到 61.3 万 token 全量上下文 #1001 warn 日志措辞;④stats 多一个 native-compaction-inferred 计数(服务 [Bug] #1001 归因缺口:客户端原生压缩落地后只剩「未确认档」——bili 已记录的 17 次拒绝(dshCompactionRefusals)与 10 次 DIRECT 旁路未被用于归因 #2709 P2 量化,非新增字段)。无线协议/消息形状变化、无配置 schema 变化、无 kernel 改动。
  6. 是否破坏缓存:不涉及。head-system anchor、prefix cache、重试策略、增量游标均在改动面之外;恢复动作与改动前字节一致。
  7. 是否改了设计方向:没有转向,是补齐既有方向的最后一公里——把「归因」从「rebase」解耦(归因可用弱证据,rebase 必须强证据),使无定界符落地也能被正确点名而非退回笼统未确认档。
  8. 是否引入新的配置:无。(P3「允许客户端压缩+落地时 rebase」开关属新配置面,按 owner-gate 纪律未实现。)

审查发现与处置(小问题直接修)

判定

可合并——冲突已解、方向关/回归关/代码关/测试关/diff 关全过,CI 转绿后即可由你合并(合并权限在你)。遗留待裁决项维持 #2709 线程原状:P3 bili 侧开关(owner-gated 新配置面)、P2 CONFIGURATION.md 文档半(refusal≠prevention + DIRECT 旁路说明,follow-up commit)、#2709↔#2592 归并与 F2 方向统一(归因 only vs rebase 升级,需你定调)。

ework-agent and others added 2 commits October 11, 2026 10:50
…l ledger (inferred tier)

When a client-native (dsh) compaction lands WITHOUT its checkpoint marker in the resent history, the #1001/#2193 detectors classify it as a generic unannounced rewrite and the banner sends the user hunting for a phantom second compressor. bili already witnesses such landings indirectly: it refuses the client's own compaction calls (#1729/#2028) and counts them in metadata.dshCompactionRefusals.

Add a native-compaction-inferred conflict tier: when a dsh-bound session has a non-zero refusal count AND a bulk rewrite is detected, attribute it to client-native compaction instead of leaving it unconfirmed. Attribution ONLY - without the marker bili cannot identify the checkpoint, so no rebase (recovery stays markCompactionBoundary, byte-identical to before).

Wired at both #1001 sites (prepare-openai/prepare-anthropic) and the #2193 destruction escalation (fold-reconcile); classified as confirmed-native on the server ladder and mirrored in the web banner so the two surfaces agree. Regression test tests/issue2709-dsh-native-compaction-attribution.test.ts.
…uction point

The original PR pinned the witness predicate and banner tiering but left the
two decision-point wirings untested at call-site level: removing the
dshNativeCompactionWitness branch in fold-reconcile.ts would have stayed green.
Adds two regression tests to the existing #2193 escalation scaffolding:
witnessed dsh total-loss drift records exactly ONE native-compaction-inferred
event (ESCALATED latch), unwitnessed variants (no binding / zero refusals /
non-dsh) record none.
@ranxianglei
ranxianglei force-pushed the 2026-10-11_dsh-native-compaction-attribution branch from e39f3cb to aa1bde8 Compare October 11, 2026 02:53
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

冲突已解,已重推。

根因:PR 分支停在旧基线 c0c9593(master 期间推进了约 25 个合并),其中 refactor(fold-reconcile) (#2627) 改到了我动过的同一处 import,导致 mergeable=dirty、CI 无法在干净基线上构建——这就是「冲突 + ci 失败」的来源。

处理:把 PR 分支 rebase 到当前 master(aac8bc3fe)。唯一冲突是 src/fold-reconcile.ts 的 import 行——master(#2627) 新增了 coveredRealHistoryIds, isResponsesTurnSeparatorId 且已引入 recordConflict,我这边加了 dshNativeCompactionWitness,合并为:

import { coveredRealHistoryIds, isResponsesTurnSeparatorId } from "./session.js";
import { dshNativeCompactionWitness, recordConflict } from "./conflict-watch.js";

无任何其它语义改动;两个提交(fix + test)原样保留在新基线上。

重推后本地已验:typecheck 干净;定向套件 170/170 通过(fold-reconcile 家族 + #2658/#2451/#2432/#2709)。mergeable 已转 True(blocked=等 CI 出结果)。

CI:新 head aa1bde8f9 已触发全套 lane,build-artifact / e2e / version-guard / OpenCode-V2-WS / real-opencode-native 已绿;unused-exports、config-surface-guard、lane/kernel/pi-subagents-guard、hermetic registry 等在跑。跑完我再给最终结论;哪一关红了我就定向排查。

@ranxianglei
ranxianglei merged commit 76143a8 into master Oct 11, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.251-master.76143a8 (rolling master tag).

npm install -g billion-context@0.0.251-master.76143a8  # 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.

1 participant