Skip to content

[PR] fix: recognize host rewind/undo (tail truncation) in fold reconciliation (#3724) - #3734

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-18_tail-truncation-rewind
Oct 20, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-18_tail-truncation-rewind

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3724

What

Recognizes host rewind/undo (tail truncation) in fold reconciliation — the exact mirror of the head-truncation handling that #3644 shipped for host compaction.

Why this was broken

src/fold-reconcile.ts classifies a benign truncation only when the resent wire is a suffix continuation of the recorded baseline (wireContinuity) — i.e. the client dropped its oldest turns and kept the tail. A user rewind/undo deletes the newest turns, so the surviving ids form a prefix cut that never satisfied that test. For a fold whose covered span got rewound away:

  • fully-wiped span → read as total-loss drift → false fold epoch confirmation required error + folding paused after 3 passes (plugin lane), and a false proxy-mode reap of the snapshot;
  • partial case with any re-anchoring → claims > 0 → went completely silent.

In both cases the fold summary kept rendering over content the user deleted ("undeleted content"), with no honest diagnostic.

The fix

Add tailTruncated, the mirror of wireContinuity: the shared ids are contiguous at the front of both the baseline and the inbound wire, and the baseline extends beyond that prefix (a real tail-cut). It is folded into the verdict classifier so a clean rewind reads as the same benign sanctioned-deletion class:

  • no destroy streak / no false epoch-confirm (folding keeps running);
  • the #2695 reap z-streak is suppressed for it (snapshot retained);
  • one distinct per-episode info line names the rewind (cross-gated so it logs once, not once per stable resend).

Plain appends, mid-history edits, and wholesale replacement all stay out of the signal (verified by the negative branches + regression test).

Deliberately NOT in scope (decision item)

This changes classification, state, and diagnostics only — it does not alter the outbound wire shape, config schema, persistence format, or anything under kernel/. It therefore does not yet actively stop a fully-rewound block's stale summary from rendering; that drop/re-anchor action is the part #3641 floor 9 deferred to a maintainer decision (+ R1 host-message-ids to distinguish intentional-delete from protocol-drop). Flagging it here rather than bundling an unreviewed wire-shape change into this fix.

Verification

  • New regression tests/fold-anchor-doctrine.test.ts › #3724 …: fails on the unfixed tree (AssertionError), passes on this branch.
  • npm run typecheck clean.
  • Targeted suites green (134 tests): fold-drift, fold-reconcile, fold-reconcile-positional, issue2915-order-centric-reconcile, issue2202-coverage-accrual, compaction-archive, fold-anchor-doctrine. Full-suite verdict = remote CI on this head.

#3644 taught the reconciler to read head truncation (host compaction drops the
oldest turns) as sanctioned deletion via wireContinuity: the surviving ids form
a SUFFIX continuation of the recorded baseline. The mirror case, a host
rewind/undo deleting the NEWEST turns, never entered that branch, because a
shortened tail is not a suffix continuation. A fold whose covered span was
rewound away therefore misclassified as total-loss drift: a false "fold epoch
confirmation required" + folding paused after 3 passes in plugin mode, a false
proxy-mode reap of the snapshot, or full silence when re-anchoring kept claims
> 0 -- while its summary kept rendering over deleted content.

Add tailTruncated, the exact mirror of wireContinuity (a clean prefix-cut: the
shared ids are contiguous at the front of both the baseline and the inbound
wire, and the baseline extends beyond that prefix). Fold it into the verdict
classifier so a clean rewind reads as the same benign sanctioned-deletion class
(no destroy streak, no false epoch-confirm), suppress the #2695 reap z-streak
for it, and emit one distinct per-episode info line naming the rewind. Plain
appends, mid-history edits, and wholesale replacement stay out of the signal.

Closes #3724
@ranxianglei ranxianglei changed the title fix: recognize host rewind/undo (tail truncation) in fold reconciliation (#3724) [PR] fix: recognize host rewind/undo (tail truncation) in fold reconciliation (#3724) Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-18_tail-truncation-rewind (ac3df96)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4646-pr.3734.158b485

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-pr3734.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

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 open+closed 全量检索「tail truncation / rewind / undo / fold reconciliation」家族:本 PR 是该症状唯一在途的修复条目,源 issue #3724。相关但不同:#3644(头端截断,已合入,机制是后缀延续判定,与本次前缀切断互补不重叠)、#3545(pi-native /tree rewind 重置工具装载——不同子系统/不同症状)。无并列重复 PR。

标签: bug / opencode / scope/kernel / p2(与源 issue #3724 一致:宿主撤销致 fold 对账误判、渲染已删内容的陈旧摘要;上下文管理核心逻辑;opencode 客户端复现;特定操作下能用但有明显问题)。

开始按 PR 审核规范独立审:①原 issue 方向 → ②回归清点 → ③代码 → ④测试有效性 → ⑤diff 整洁度。分支已拉取(6751d533a,单 commit,+88/-3,仅 src/fold-reconcile.ts + 一个回归测试),完整结论随后贴出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

独立审核完成,结论:可合。 未照搬 PR/issue 表述,以下判断全部基于我自己重读 diff、重推谓词语义、本地重跑验证得出。

结构化八问

  1. 是什么问题:宿主 rewind/undo 删掉的是最新轮次,幸存 id 构成前缀截断;而 fold reconciliation 的良性截断判定(wireContinuity)只认「最旧被丢、尾部续接」的头截断。前缀截断落进 total-loss drift:整段覆盖区被 rewind 掉时假报 fold epoch confirmation required + 3 pass 后暂停折叠(plugin 车道)/ 误 reap 快照(proxy 车道),部分场景无诚实诊断;期间旧摘要持续渲染在用户已删内容上。
  2. 什么原因导致的:连续性判定的左右不对称——只实现了 suffix-continuation 一侧,verdict classifier 在决策点就把前缀截断误分类为全量丢失。修在决策点(classifier 加镜像信号),不是下游过滤症状,符合「疏不堵」。
  3. 影响范围与严重程度:仅当「宿主发生过 rewind 且 rewind 越过已折叠段」时触发;p2——能用但有明显问题(模型继续读到已删内容 + 特定子情形假告警/误 reap),可恢复,非硬故障。
  4. 怎么修复的:新增 wireContinuity 的精确镜像 tailTruncated(共享 id 同时是 baseline 与入站 wire 的连续头部,且 baseline 严格长于该前缀 = 真 tail-cut),接入三处决策:① totalDrift 排除项(不再累积 destroy streak / 假 epoch-confirm);② structurallyAbsent(抑制 [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 的 z-streak reap,快照保留);③ 每 episode 一条独立 info 日志命名 rewind(与头截断行交叉门控,只记一次)。纯追加(k==n 被排除)、中段编辑(破坏头部连续性)、整体替换(k=0)按构造全部落在信号外;头/尾两信号在唯一 id 下数学互斥,交叉门控只会去重同 episode 的重复行,不会吞掉不同 episode 的诊断。
  5. 是否有回归问题:逐项审过触碰路径的既有行为——① 头截断路径([PR] fold anchoring doctrine: order over hash — shape churn, image offload, host truncation stop reading as destruction (#3641) #3644/[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)零改动,唯一交互是交叉门控,现有 foldTruncationNoted latch 测试仍绿;② reap 阈值(3 pass)与 gate(proxy+repair only)未动;③ 升级条件只对 clean prefix-cut 形状放宽——那正是原假警报本身;整段替换仍正常升级(Snapshot as session reconstruction: identity claim order takes priority, message hash demoted to reference signal (root- | 快照即会话重构:身份认领顺序优先,消息哈希降级为参考信号(根治 #3588/#3640 一类误判) #3641 负向测试绿)、低于质量线的真实编辑仍诚实报 drift(honesty-gate 测试绿);④ reset 路径对称清掉新 latch,生命周期与兄弟键一致;⑤ 持久化只加一个 metadata 键(自由 bag,同模式,无格式版本变更);⑥ 两种压缩模式都推过:classifier 与模式无关,reap 臂仍是 proxy-only,plugin 车道经 epoch-confirm 路径修复。行为变更披露(old→new):clean rewind 旧=误分类为 total-loss drift → 假 epoch-confirm/暂停/误 reap/无诚实诊断;新=识别为 sanctioned-deletion 类 → 无 streak、无 reap、一条 info 行。这就是本 PR 修的 bug 本体,PR 描述已披露。已知残留(与头侧既有残留同款):同一 pass 里另一块恰好真被毁时全局信号会被 co-suppress,下一稳定 pass 自纠——PR 注释已写明,我认可。
  6. 是否破坏缓存:不涉及。快照是被保留而非失效;不碰缓存/重试/增量游标/去重键策略。
  7. 是否改了设计方向:没有转向。刻意留出的部分(主动让 fully-rewound 块停止渲染旧摘要 = drop/re-anchor,wire-shape 变更)按 Snapshot as session reconstruction: identity claim order takes priority, message hash demoted to reference signal (root- | 快照即会话重构:身份认领顺序优先,消息哈希降级为参考信号(根治 #3588/#3640 一类误判) #3641 floor 9 留给 maintainer 决策,且需 R1 host-message-ids 区分「有意删除 vs 协议丢弃」——PR 正文已 flag,我认为这个 PR 作为「分类+状态+诊断」是独立闭环,后续动作应另立项,不应捆进来。
  8. 是否引入新配置:无。无 env/config/CLI 变化;内部 metadata 键 foldTailTruncationNoted 一个,无需迁移。

验证证据(均为本人执行)

  • 红→绿钉死:基线树(c398859 的 src/fold-reconcile.ts)+ 新测试 → 恰 1 失败:not ok 4 - #3724 host rewind/undo (tail truncation) retains the snapshot(AssertionError);分支版本 → 全绿。
  • 定向套件 7 个文件(fold-drift / fold-reconcile / fold-reconcile-positional / issue2915-order-centric-reconcile / issue2202-coverage-accrual / compaction-archive / fold-anchor-doctrine)= 134/134 通过;tsc --noEmit 干净。
  • base 落后当前 master 一个 docs-only commit(CONFIGURATION.md 两行,无代码交集):本地 rebase 到 live master 后 typecheck + 134/134 复跑全绿;未 push(BEHIND 非阻塞因素,避免再烧一轮 CI)。
  • CI(head 6751d53):最新一轮 check suite 全 success/skipped(41 success + 26 gated e2e skip,0 fail;更早的 cancelled 组为被取代的重跑)。
  • §7.4 auto-merge gate 8 项全过(单模块 / 回归测试红→绿 / rebased-head 绿 / 无 config-persist-wire-kernel 触碰 / 纯 fix: / 干净 diff(+88/-3,每行服务于目的)/ Closes [Bug] Host-side rewind/undo (tail truncation) is unhandled — user-deleted content survives as fold summaries (#3644 covers head truncation only) #3724 / 非 load-bearing infra)。

收工判定:可合,合并由人执行。

@ranxianglei
ranxianglei merged commit a20bfd5 into master Oct 20, 2026
20 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.644-master.a20bfd5 (rolling master tag).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Host-side rewind/undo (tail truncation) is unhandled — user-deleted content survives as fold summaries (#3644 covers head truncation only)

1 participant