Skip to content

feat: surface identity-loss takeovers with an identity-orphan conflict event (#2791) - #2802

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-11_identity-orphan-detection
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-11_identity-orphan-detection

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes the SILENT half of #2791 (the layer that a headless proof CAN cover).

What #2791 exposed

When a host loses its client identity mid-conversation (observed case: dsh's anthropic-messages lane bypasses the native-intercept fetch patch — every request arrives with ZERO bili headers), the anonymous resolver mints a fresh pfa-* session and the identified conversation's fold ledger is orphaned with no observable signal anywhere: the next request pays a full silent re-fold (#2733/#2741 measured a 263%-of-window replay).

The root cause (host fetch-capture timing) is out of bili's reach. The silence is not: the resolver already held every signal needed to NOTICE the takeover — an identified chain whose depth the incoming anonymous history reaches, plus the #2601 normalized tail fingerprint that survives cross-wire re-serialization of the same turn. It just never reported it.

Change (detection-only, resolution untouched)

  1. src/prefix-affinity.ts — resolve() grows an orphan-suspect scan on the new-mint path: for every IDENTified chain within the append window (entry.depth <= incomingDepth <= entry.depth + ALIGN_TAIL_APPEND_MAX), fingerprint the incoming list AT THE POSITION where the chain ended (normalizedTailHashOf(messages, entry.depth) — handles a replay with appended turns). Match => the chain id lands in AnonymousAffinity.orphanSuspect (diagnostics only; Claude 上 resume 导致消息错乱 #1486 stands — the anonymous world never adopts an identified session).
  2. src/server/handle.ts — the mint consumes the flag: a warn log line ([prefix-affinity] anonymous <proto> replay carries the conversation tail of identified session(s) …) plus a recordConflict(suspect, "identity-orphan", …) event on the ORPHANED session, naming the fresh pfa-* fork so the sessions UI shows why compression continuity broke.
  3. src/conflict-watch.ts — new identity-orphan ConflictKind (renders through the existing non-plugin generic path).

Design notes:

Proof (tests/prefix-affinity-orphan.test.ts)

  • resolver: cross-shaped anonymous replay (string content -> content-arrays — exactly the openai-vs-anthropic shape churn that blinds every byte ladder) flags the identified chain WITHOUT adopting it (via === "new", fresh pfa-* mint);
  • negatives: different content under the same shape churn, an anonymous (non-identified) chain, and a replay 80 turns past the append bound do NOT flag;
  • server: full takeover scenario through startServer — plugin-identified chat turns, then a headerless cross-shaped replay => exactly one identity-orphan event on the orphaned session naming the pfa-* fork, session state untouched, fresh mint still served normally.
  • A/B: on master (pre-fix worktree) the two positive tests fail (3/5 — detection absent), negatives pass; on this branch 5/5.
  • Adjacency: affinity-persist + issue2601×2 + dsh-persona-continuity = 31/31; typecheck clean; build OK.

Config surface

No changes: no new config keys, env vars, or CLI flags — the detection is always-on diagnostics with a bounded conflict ring, consistent with the existing conflict-watch kinds.

Kernel boundary

No changes under kernel/ — the scan consumes the host-side resolver's own fingerprint infrastructure (src/prefix-affinity.ts), no kernel touch.

The remaining unreachable layer (host fetch timing itself) needs the native-intercept module-level regression + e2e cross-protocol-switch phase noted in the issue; the detection added here is what makes any future instance VISIBLE instead of silent.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_identity-orphan-detection (40c1a20)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3087-pr.2802.e7802df

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-pr2802.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 started on PR #2802 (detection-only identity-orphan conflict event, closes the silent half of #2791). Pulling branch 2026-10-11_identity-orphan-detection (181f53c) now — will audit direction vs #2791, regression surface on prefix-affinity.ts / server/handle.ts / conflict-watch.ts, test teeth, and diff cleanliness, then post the structured eight-question verdict.

…#2802 review)

The new identity-orphan kind rendered through the generic non-plugin path of formatConflictSection, which is wrong for it: an orphan-only ledger got the [suspected]-plugin advice ('confirm each named plugin really compresses before removing anything') plus the per-client auto-compaction remediation footer and the #1206 third-party-plugin docs pointer — actively misleading guidance on exactly the session that lost fold continuity, since bili's own resolver produced the event and there is no second compressor to hunt for (honest-output guardrail, #155; #2545 tiering discipline).

- new advice tier between nativePresent and pure-[suspected]: identity-loss framing (host lane stopped stamping identity, headerless replay minted the anonymous fork, restore the lane or start fresh), active + historical variants
- Fix footer + docs pointer skipped for orphan-only ledgers (same precedent as the neutral-only skip)
- gated strictly to orphan-only ledgers: mixed ledgers keep their existing tier verbatim
- regression tests pin the orphan-only framing and the mixed-ledger non-change
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — recommend merge (human merge; feat-tier per §7.4). One review finding found and fixed directly on the branch: new commit 40c1a20e5 (details in Q5).

结构化八问

1. 是什么问题
#2791 暴露的 identity-loss takeover 完全无信号:host lane 中途丢失客户端身份(dsh anthropic-messages lane 绕过 native-intercept patch,请求零 bili header)时,匿名解析器铸造新 pfa-* 会话,已识别会话的 fold ledger 被孤儿化且任何地方都观察不到,下一次请求静默全量重折(#2733/#2741 实测 263%-of-window 重放)。本 PR 补上检测层:resolver 孤儿嫌疑扫描 + 在被孤儿化的已识别会话上记录 identity-orphan 冲突事件(点名新 pfa-* fork)。

2. 什么原因导致的
根因在 host 侧(fetch-capture 时序,bili 够不到——PR 正确地标为边界外)。bili 侧的沉默是独立的缺陷层:resolver 手里已经握着全部信号(append 窗口内的已识别链 + #2601 归一化尾部指纹,能扛跨 wire 重序列化),只是从未上报。本 PR 修的是「上报」这一层,层次划分正确,没有去堵 host 侧根因。

3. 影响范围与严重程度
仅影响中途丢身份的会话(罕见:dsh profile wire-protocol 切换这类场景)。修复前:完全静默 → 用户遭遇意外全量重折(实测 ~50k tok / 182s 级重放);修复后:一条 warn 日志 + 冲突事件,continuity 断裂可见。纯检测:不改变任何解析结果(#1486 匿名永不收养已识别会话,保持)、无修复副作用(孤儿会话 refs/blocks 字节不动,集成测试断言)。

4. 怎么修复的
只在 new-mint 路径(罕见路径)追加扫描:对每条 depth 落在 [entry.depth, entry.depth + ALIGN_TAIL_APPEND_MAX=64] 窗口内的已识别链,在链结束的位置指纹化来料列表(normalizedTailHashOf(messages, entry.depth)——与 #2601 chainContinues() 同一证据标准:≥32 字符内容叶、churn key 剔除、跨 shape churn 可匹配)。命中 ⇒ orphanSuspect;server 端 mint 消费该标志:recordConflict(suspect, "identity-orphan", …) 记在被孤儿化的会话上并点名新 fork。每个新 fork 恰好一个事件(后续匿名请求走 prefix ladder 解析到自己的 pfa 链,不会重复标记)。

5. 是否回归问题
逐项审过既有行为:解析语义不变(orphanSuspect 是 mint 结果的附加可选字段,sessionId/via 逐字节相同);mint 路径成本有界(depth 窗口预过滤 + 每候选单消息指纹,罕见路径);无持久化格式变化(orphanSuspect 是瞬态 per-request,snapshot 序列化只写 tracked entries);无配置/线形/kernel 变化;冲突环已有 20 上限;无重复标记回路。发现并已直接修复一处:新 kind 经 formatConflictSection 的 generic non-plugin 路径渲染时落入 [suspected]-plugin 档——orphan-only ledger 会收到「confirm each named plugin really compresses」+ 每客户端 auto-compaction 处置页脚 + #1206 第三方插件文档指针,而该事件是 bili 自己的确认诊断、根本没有第二个压缩器可找(违反 honest-output 护栏 #155 与 #2545 分层纪律;PR 声称的「renders through the existing generic path」只对事件行成立,不对建议行成立)。已在分支上补 commit 40c1a20e5:新增专属建议档(identity-loss 框架:恢复 stamp 身份的 lane 或开新会话,active/historical 两态),严格 gate 到 orphan-only ledger(混合 ledger 逐字节保持旧档位),Fix 页脚+文档指针对 orphan-only 跳过(同 neutral-only 先例),附回归测试。行为变更披露(旧→新):orphan-only 冲突段从「[suspected]-plugin 建议 + auto-compaction 页脚 + #1206 指针」变为「identity-loss 建议、无通用页脚」——有意变更,即所修缺陷本身。

6. 是否破坏缓存
不涉及:不触碰 prefix-cache、重试、增量游标、去重键;检测只读,fold 状态零改动。

7. 是否改了设计方向
未改:留在既有 prefix-affinity resolver + conflict-watch 诊断面内;明确不收养已识别会话(#1486 保持);host fetch 时序这个不可达层按 issue 要求留了边界注记(native-intercept 模块级回归 + 跨协议切换 e2e 阶段),本检测是让未来实例可见而非静默。

8. 是否引入了新的配置
无:always-on 诊断、有界冲突环,无新 env/config/CLI(声明属实,已核实)。

测试有效性(质量关)

正例在 master 上失败(A/B 3/5 → 5/5,真断言有牙);三个负例钉住误报边界(异内容同 shape churn / 匿名链 / 超出 64-append 界 80 转不标记);集成测试钉住 diagnostics-only(状态快照相等、恰好一个事件、detail 正则点名 pfa-[0-9a-f]{16})。原 PR 缺口:新 kind 的渲染面没有测试——已由我的 commit 补上(orphan-only active/historical 两态 + 混合 ledger 不变守卫)。

本地定向验证(全量交 CI)

conflict-remediation/lifecycle/web-conflict-banner/acp-status 43/43;prefix-affinity-orphan 5/5;prefix-affinity/simhash/issue2601×2/dsh-persona-fingerprint 邻接 69/69;typecheck clean。分支落后 master 2 个提交(#2795 merge、#2784 cache-ledger fix),均只碰 cache-ledger 测试文件,与本 PR 无热点冲突,rebase 干净,BEHIND 不构成阻塞。新 commit 推送后 CI 将全量把关。

判定:可合(merge 由人执行:https://github.com/ranxianglei/billion-context/pull/2802)。

@ranxianglei
ranxianglei merged commit e013660 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.286-master.e013660 (rolling master tag).

npm install -g billion-context@0.0.286-master.e013660  # 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.

YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 13, 2026
…ranxianglei#2969)

- add the dsh ACP protocol adapter to the verified non-compressor list
  (its 'acp' suffix names Agent Client Protocol, not acp-kernel); exact
  token match, lookalikes still flagged; stock [suspected] records are
  neutralized at display time, no data migration
- widen the path-segment matcher so scoped names match Windows paths too
- pure [suspected] ledgers drop the imperative per-client fix footer /
  web hint block (acp_status + banner); confirmed and unconfirmed-signal
  tiers keep remediation, mixed ledgers stay verbatim (ranxianglei#2802 gate)
- CONFIGURATION.md scanner section updated to match
@ranxianglei
ranxianglei deleted the 2026-10-11_identity-orphan-detection branch October 15, 2026 05:33
ranxianglei pushed a commit that referenced this pull request Oct 21, 2026
…n events (#4141 review)

Review of #4141 found that a session whose conflict ledger contains ONLY the new id-churn-adoption events (the exact shape this PR produces on a clean cross-build restart) fell through formatConflictSection into the [suspected]-plugin tier: header claimed 'something outside bili touched this conversation' and the advice told readers to 'confirm each named plugin really compresses' — both false, since the event is bili's own fully-handled re-mint adoption (#3642 D1). Same misframing class as #2802 (orphan-only) and #2912 (handled-native-only).

Fix: dedicated adoptionOnly tier in the branch ladder (gated to pure ledgers so mixed ledgers keep their existing wording verbatim) with accurate header + active/historical advice; regression test pins the framing and the absence of plugin-hunt/remediation output. No behavior change beyond the panel/advice text.
ranxianglei pushed a commit that referenced this pull request Oct 24, 2026
A session whose stored folds expose no anchorable covered surface (the host
resent history matching none of the folded originals — mass representation
drift, #2431/#2847 family) hit the covered-empty early exit of
reconcileFoldCoverage, which reset drift state and returned silently. The
terminal state therefore showed healthy book values and ZERO log lines:
the v0.1.195 retest in #2438 (floor 18) produced no drifted/destroyed/
tolerated line at all, leaving operators blind while the wire stayed fully
unfolded/doomed.

Now, when stored blocks exist but none exposes an anchorable covered id:
- one ERROR line per session lifetime (persisted free-form metadata latch,
  deliberately outside resetFoldDriftState so it cannot re-fire on every
  request of the episode);
- one 'fold-vacuum' entry in the per-session conflict ledger (recordConflict
  already marks dirty, so the latch rides the existing save);
- a dedicated pure-case tier in formatConflictSection so a vacuum-only
  ledger is framed as bili's own terminal diagnostic (no second compressor,
  recovery = host resends matching bytes or fresh conversation) instead of
  falling into the [suspected]-plugin advice or the generic remediation
  footer. Mixed ledgers keep their existing tiers verbatim (.every() gating,
  same pattern as the #2802/#2912 pure-case tiers).

Report-only by design: zero behaviour change beyond the report — no wire,
config, persistence-format, or fold-state change. The behavioural response
layer (bound/regime/retire facets) stays pending #3978 coordination.
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