Skip to content

fix: exclude legacy no-class fold anchors from non-reasoning drift evidence (#2903) - #2909

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-12_fix-legacy-anchor-drift
Oct 12, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-12_fix-legacy-anchor-drift

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2903

What

Old builds (≤0.1.191) persisted foldAnchors without the c (content-type class) field. Those legacy anchors belong to an old id space: once their id leaves the wire they can never re-match and can never be backfilled (the #2732 backfill needs live bytes), so the reconciler reports them "missing" every pass, forever.

The destroy-drift classifier counted them as non-reasoning loss — anchors[id]?.c !== "reasoning" treats c === undefined as non-reasoning — so a healthy long session carrying that permanent bili self-debt latched foldDriftEscalated: true after 3 consecutive passes, and every later diagnosis blamed "host destroyed the history".

Why this fix

Only a known non-reasoning class counts toward the destroy threshold now:

const cls = anchors[id]?.c;
return cls !== undefined && cls !== "reasoning";

A genuine client-side rewrite/deletion still carries a concrete c, so real loss still escalates; pure-legacy debt alone never does. This matches the accounting correction proposed in the issue (suggestion #1) and the reporter's local patch.

Behavior change (old → new)

Drift-escalation evidence: previously c === undefined (a legacy anchor) was classified as non-reasoning and could push the session over the >= 10 unmatched destroy threshold → permanent foldDriftEscalated. Now unknown-class anchors are excluded from that count. Net effect: sessions whose only permanently-missing ids are pre-0.1.192 legacy anchors stop being misdiagnosed as substrate-destruction; sessions with genuinely-missing known-class ids escalate exactly as before.

Scope notes

Tests

tests/fold-drift.test.ts drives reconcileFoldCoverage over a synthetic pre-0.1.192 ledger:

  • pure-legacy debt (20 no-class anchors) → does not latch foldDriftEscalated; asserts the total-loss streak reached the escalate pass first so the negative isn't vacuous. This case fails on the unfixed code (verified by temporarily reverting the filter).
  • 40 legacy + 10 real known-class missing → still escalates (issue requirement Use kernel renderTags:"text-only" + forbid tag echoing in prompt #3: no wholesale silencing).
  • 10 real known-class missing alone → still escalates (genuine detection intact).

Verified locally: npm run typecheck clean; all 93 tests in tests/fold-{drift,reconcile,reconcile-positional}.test.ts green. Full suite to CI.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-12_fix-legacy-anchor-drift (36870e4)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3239-pr.2909.0d0e9c1

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-pr2909.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-12_fix-legacy-anchor-drift branch from 339d53e to 36870e4 Compare October 12, 2026 10:02
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

已 review PR #2909(Closes #2903)。结论:方向正确、修法打到根因、回归测试有牙、diff 干净,可合并。另发现并修复了一个 stale-base 导致的 CI 红灯(与本 PR 改动无关,详见末尾)。按八问作答:

1. 是什么问题
≤0.1.191 写进 foldAnchors 的遗留锚缺 c(contentType 分类)字段。它们属于旧 id 空间,id 一旦离开线路就永远匹配不到、也永远回填不了(#2732 回填需要在线字节),于是每轮都被判 "missing"。升级判定把这份永久的 bili 自身债务当成"客户端改写历史"的证据,把健康长会话永久置成 foldDriftEscalated,之后所有诊断都归因宿主销毁历史。

2. 什么原因导致的
根因在分类器口径,不在数据:src/fold-reconcile.ts 用 anchors[id]?.c !== "reasoning" 统计非推理失配,c === undefined(遗留锚)满足该式被误判为"非推理",而它按构造永远不可能匹配。因果链:遗留锚缺 c → 每轮 missing → 计入非推理漂移 → 连续 3 轮 ≥10 → 永久升级。这是证据分类错,不是客户端 churn(reporter 的账本算术 2450+487=2937、换模型不重写历史的受控实验我都核过,方向成立)。

3. 影响范围与严重程度
所有从 ≤0.1.191 升级上来、账本里仍带缺 c 覆盖锚且这些 id 已离线的长会话(reporter 普查 77 账本 / 30,944 条)。触发条件:遗留 id 累计 ≥10 个离线。后果是误诊——健康会话被永久标记"折叠基底打穿";折叠本身仍能工作,但债务每轮以原文重回线路(~301K tok)。属"特定条件下有问题 + 误导性诊断",非完全不可用。

4. 怎么修复的
只改那一个口径:只有已知的非推理类才计入破坏阈值(cls !== undefined && cls !== "reasoning")。真实客户端改写/删除仍带具体 c,照样升级;纯遗留债不再升级。等价于 issue 建议修法 1。正确性关键:活锚的 c 每轮都在(id 在场就刷新),所以 c === undefined 只可能是遗留锚;一次真实的宿主销毁删的是"离场前已有具体 c"的消息,仍会被计数——因此不会掩盖真破坏,只剔除 bili 自己的旧债。

5. 是否有回归问题
逐项审了这条路径承担的既有行为:① 纯推理丢弃容忍(#2193 follow-up)reasoningOnlyDrop 独立计算、未动,纯推理丢弃仍不升级;② 真实已知类缺失(≥10、3 轮)仍照常升级,无一刀静音;③ #2732 回填测试照旧绿;④ src/fold-reconcile.ts:1146 的同款 c !== "reasoning"(#2695 僵尸块回收判定)有意不动——那里把"缺席"算作 gone 是对的(它确实缺席,喂给孤儿块清理),与"破坏证据"路径语义不同,这个区分判断正确。行为变更披露(旧→新):c === undefined 的锚旧口径计入非推理、可推过 ≥10 阈值触发永久升级;新口径将其排除出该计数——这是有意的修复方向,非漂移。一个次要 nuance:纯遗留债务会话的 totalDrift 仍为真、streak 仍累积但不再 latch,副作用是该会话每轮会打一条 benign 的 "mutation or client-side deletion/truncation" warn(而非旧的"2 warn + 1 error 后静默")——这是既有的 benign 分支日志,非回归;重要变化是不再误报 ERROR + 永久 latch。

6. 是否破坏缓存
不涉及。只改漂移升级的分类判定,不动前缀缓存、重试、增量游标或去重键;不改任何出站字节。

7. 是否改了设计方向
没有。仍是"已知类才算破坏证据"的既有原则,只是把"未知类(遗留债)"从证据里剔除,未转向架构/边界/数据流。issue 建议 #2(停发不可重锚的覆盖 id、让债务不再无限重发)属另一套清理机制、牵涉 proxy-only 孤儿块回收门控,本 PR 不含,如需另立跟踪。

8. 是否引入新的配置
无。无新 env/config/默认值,foldAnchors 持久化格式不变。

测试有效性:新增 3 个用例直接驱动 reconcileFoldCoverage 跑合成 pre-0.1.192 账本:(a) 纯遗留 20 条不 latch,且先断言 streak 已到升级轮次(保证负例不空洞);(b) 40 遗留 + 10 真实仍升;(c) 纯真实 10 条仍升。我实测 (a) 在回退修复后确实红(not ok,断言消息精确命中),证明有牙;另两条修复前后都绿(防一刀静音的护栏)。fixture 镜像受害车道(dsh plugin 模式)关掉 proxy-only 孤儿回收以隔离升级路径,设计合理。

diff 整洁度:单提交、2 文件(src +14/-1,test +66),每行都服务于目的,无无关改动 / 空白 churn / 锁文件变更。干净。

⚠️ CI 红灯(已修,与本 PR 改动无关):原 PR head(339d53e83)上 test job 全平台失败,根因是 stale-base——PR 分叉时早于 master 的 #2896/#2816(把 tests/issue2752-forward-partial-outcome.test.ts 登记进 LIVE_FILES)。PR 树里有这个会 spawn 的测试文件却没登记,scripts/run-ci-tests.mjs 的 tripwire 在跑任何测试之前就 die 了;所有 static-gate / guard / build-artifact 均 success。我已把 PR rebase 到当前 master(master 那 8 个新提交不碰本 PR 的两个文件,rebase 零冲突),新 head 36870e464;本地验证 gate tripwire PASS + 93/93 fold 测试绿 + typecheck 干净,已 force-with-lease 推回(feature 分支,非 master),CI 正在新 commit 上重跑中,转绿后我确认一下。

收工判定:单行口径修正 + 有牙回归钉死,方向正确、无回归、无配置面变更;stale-base 红灯已 rebase 解决。等 CI 新 commit 转绿即可人工合并(合并留给人工)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

✅ rebase 后的新 head 36870e464 上 CI 全绿(18 项检查全部 success:build-artifact / 全部 static-gates / 全部 guard / docs / lock-sync / 以及 ubuntu+windows × node22/24 的 test job)。之前那个 stale-base 红灯已彻底解决。

现在状态:代码方向正确、无回归、回归测试有牙、diff 干净、CI 全绿——可以人工合并了(合并留给人工):#2909

@ranxianglei
ranxianglei merged commit f59cd01 into master Oct 12, 2026
18 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.334-master.f59cd01 (rolling master tag).

npm install -g billion-context@0.0.334-master.f59cd01  # 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
ranxianglei deleted the 2026-10-12_fix-legacy-anchor-drift 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] 旧版账本里的遗留锚被当作漂移证据,长会话被永久判为「折叠基底打穿」(0.1.194 / 0.1.195)

1 participant