Skip to content

[PR] fix: stale fold ledger after model switch — attribute the failure so the breaker offers acp_status - #4044

Closed
ranxianglei wants to merge 2 commits into
masterfrom
wt-4038-ework-daemon
Closed

ranxianglei wants to merge 2 commits into
masterfrom
wt-4038-ework-daemon

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Closes #4038

Problem

A mid-conversation model/upstream switch reuses the session id and re-sends a rewritten history; every pre-switch fold block deactivates, but nothing rebases or archives the state. The deactivated blocks stay resident, so remembered bN refs keep resolving against them and every compress fails with Requested range(s) already compressed (e.g. b1..b43) next to 0 active block(s) in the SAME receipt — a self-contradicting verdict the model retries forever. After 3 failures the circuit breaker arms with the loop-noise wording ("do not poll acp_status") — forbidding the one recovery step. The session is stuck until /clear.

Root cause (verified at source level; master == v0.1.202 == reporter version)

  • Kernel: when both boundaries of the requested range resolve to INACTIVE blocks (no active ancestor inheriting their content), each boundary classifies as "consumed" (kernel/src/boundaries.ts); block refs never become dangling message refs, so the gate emits "already compressed" with the coverDetail fallback "stale block ref(s) distilled or consumed by higher-tier blocks" — while coveringBlockIds (active-only) finds nothing.
  • Host: compressFailureCause (src/stream.ts) had no branch for this shape → cause "" → the breaker armed with loopNoisePauseParagraph, whose verbatim sentence forbids polling acp_status. The refs snapshot printed "0 active block(s)" without naming the dead ledger.

Fix (host-side, src/stream.ts only)

  1. compressFailureCause: "already compressed" + zero active blocks ⇒ substrate-destruction-family attribution. The compound condition has no benign reading: message-ref consumption always records dangling refs → "cannot be anchored"; only inactive-block resolution reaches this text with an empty active set. Routing through the existing prefix makes the breaker pick up substrateDestructionPauseParagraph automatically (one recovery step: run acp_status once, then compress what it reports compressible — one success clears the breaker), and acp_status gains the FOLD SUBSTRATE INVALID annotation / tailored armed line — zero consumer-side changes.
  2. currentRefsSnapshot: when zero active blocks coexist with resident ones, name it: "All N resident block(s) are inactive — every bN you remember from earlier is STALE and can never compress again; target only live refs."

Recovery semantics: the model runs acp_status once (the live table was already advertised in the same receipt), folds a live range, one success clears the streak; zombie blocks stay inert (decompress/search still serve them).

Behavior changes (disclosed per policy)

  • Old → new: failures of this shape were attributed "" (loop-noise breaker paragraph + generic acp_status STOP order) → now substrate-destruction attribution (single-recovery-step paragraph + FOLD SUBSTRATE INVALID annotation on acp_status + panel banner). WHY: the old wording forbade the only working recovery action for this shape.
  • Failure receipts gain one extra sentence ONLY when zero active + resident blocks.
  • No folding decisions, thresholds, config surface, wire formats, persistence or retry-policy changes. Loop-noise wording stays byte-verbatim for all other causes (pinned by negative-control tests).

Tests

tests/issue4038-stale-fold-ledger.test.ts — gate discipline (#3617), both directions asserted:

  • positive: kernel verdict reproduced + new attribution + snapshot note at n=1; armed breaker offers "run acp_status once" and does NOT contain "do not poll acp_status";
  • negative A: covered-by-active-block WITH an active block present → verbatim loop-noise sentence intact, no substrate attribution;
  • negative B (truth-table cell): "already compressed" via the kernel "active block, none visible" consumed path WITH active blocks present → loop-noise kept;
  • acp_status: pre-arm FOLD SUBSTRATE INVALID section; armed tailored line.

Local targeted run green: issue4038 + issue2146/issue2432/issue2360/issue847/issue3126 (34 tests). Full-suite verdict = CI.


Addendum (commit 16c3378): en-passing fix — verif harness left CI red on solver-less runners

Tracked down while monitoring this PR's CI: a deterministic red UNRELATED to #4038. tests/verif-generic-append-stability.test.ts:50 called t.skip(...) WITHOUT a return, so in solver-less environments the body fell through to the first real solveSmt2() call and threw "no solver available" — TAP printed not ok ... # SKIP ... but node:test still counted it as a code failure, making every test shard containing that file red on solver-less runners (introduced by 74eca4e / #3939; dev machines carry cvc5, which is why every local run stayed green). Fixed with the missing one-line return, verified both directions locally (solver hidden → clean documented skip, fail 0; solver present → real solve passes).

Behavior change: solver-less environments go from deterministic red to the documented auto-skip (the AGENTS.md KDD 14 contract); solver-present environments are untouched. Full root cause + timeline + evidence posted to tracking issue #4049 (sub-defect 3). Shipped as an independent labeled commit per the 几行级小修 policy (fix-in-current-PR).

@ranxianglei ranxianglei changed the title fix: stale fold ledger after model switch — attribute the failure so the breaker offers acp_status [PR] fix: stale fold ledger after model switch — attribute the failure so the breaker offers acp_status Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-4038-ework-daemon (b1c22d3)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4934-pr.4044.78922d8

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-pr4044.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)

查重: 不重复。 本 issue 是 GitHub PR #4044(Closes #4038)的镜像;检索 open PR 无其他条目处理同一缺陷(引用 #4038 的仅本 PR,#4057 为无关的 snapshot-render 工作)。PR 第二个 commit(test(verif): return before t.skip,#4049 子缺陷 3)属几行级 CI 红修复,按「小问题直接修」独立标注提交、归属 #4049 跟踪家族,非范围蔓延。

标签: bug / dsh / scope/wiring / p1(保留既有 pr)。理由:缺陷类;复现环境 DSH desktop;修复在宿主侧请求管道(receipt/breaker/attribution 层,src/stream.ts,不触 kernel → wiring);p1 = 可用性类(触发后压缩整体不可用至 /clear)。

以下是我对该 PR 的独立审核——重新拉取分支,独读 diff、全部消费端与 kernel 源码,未复用 #4038 线程结论:

已核实的证据

行为变更披露(旧→新)

  1. stale 形状("already compressed" + 零 active block)的失败归因:旧 ""(无归因,breaker 出通用 loop-noise 段、禁止 poll acp_status)→ 新 substrate-destruction — …(#4038)(breaker 换单步恢复段,acp_status 出现 FOLD SUBSTRATE INVALID 节/armed 定制行,panel banner 点亮)。原因:该形状无 benign reading(已证),旧措辞恰好封死唯一恢复步骤。
  2. 失败 receipt 在 0-active+resident-blocks 共存时多一句话(refs snapshot 点名死账本);其余情况逐字节不变。请求 wire 字节不变,prefix cache 不受影响。

结构化八问

  1. 是什么问题:会话中途换模型/上游后,历史被带外改写、fold 块全部失活但账本仍在,模型记住的 bN 指向死块,每次 compress 都收到自相矛盾的 "already compressed" + "0 active block(s)",breaker 三败后还禁止 poll acp_status——唯一恢复步骤被封死,卡到 /clear。
  2. 什么原因导致的:两层。kernel 层(既有行为,未动):边界解析命中 inactive block 判 consumed,无 dangling m-ref 时 gate 出 "already compressed",kernel 区分不了「被活块覆盖」与「指向死账本」。宿主层(本 PR 修的缺陷):compressFailureCause 没有这个形状的分支 → cause 为空 → breaker 落到禁止 acp_status 的通用段。
  3. 影响范围与严重程度:任何经历带外历史改写(换模型/上游、客户端批量重写)且保留 resident fold 账本的会话;一旦触发,压缩能力完全不可用直至 /clear——会话本身还能聊天,但长会话核心承诺失灵。p1 可用性类。
  4. 怎么修复的:归因而非重做——把该形状路由进 substrate-destruction 家族(唯一无 benign reading 的读法),复用既有的单步恢复机制(breaker 段落、acp_status 判定节、panel banner)自动点亮,外加失败 receipt 里一句点名死账本。不动折叠、阈值、wire、持久化、重试。
  5. 是否有回归问题:未发现。逐项:新分支触发条件经 kernel 源码证明无 benign 误伤路径;分支顺序无冲突;下游 startsWith 消费端全部稳定前缀匹配;loop-noise 原句对其余 cause 逐字节不变(负向控制钉住);snapshot 句仅进失败 receipt 不进请求 wire;部分成功批次不经过失败路径;verif 改动仅是 t.skip 前补 return(修 solver-less 环境穿透执行),纯测试基建。
  6. 是否破坏缓存:否。请求前缀字节不变,receipt/snapshot 句只出现在 tool-result 里;重试/去重/游标/dead-ref tombstone 均未触碰。
  7. 是否改了设计方向:否。纯宿主侧 attribution 层修复,kernel/ 未动(不触 Kernel Boundary 人审档)。更深的根因(静默 generation 变化的显式 rebase/archive 触发)不在本 PR——[Bug] Model-switch (session-generation change) leaves a stale fold ledger resident: compress reports already compressed (e.g. b1..b43) next to 0 active block(s), and the breaker never offers acp_status #4038 floor 3 已列 A/B/C 选项(默认 A 维持现状),等你拍板,不阻塞本 PR。
  8. 是否引入了新的配置:无。

一个观察(非阻塞):snapshot 句 "can never compress again" 在「切回原上游再次改写历史导致块复活」的极端边缘略绝对,实际影响可忽略,且措辞已被测试钉住——属有意措辞选择,不改。

判定:代码层面可合。 方向正确(可用性修复、归因层、最小爆炸半径),机制经源码验证,测试有牙,未发现回归。4 个红 CI shard 均为已知 flake 家族,需人工点 rerun-failed-jobs(我无 API rerun 权限);转绿后即可合并,合并动作本身留给你。修复随合并后第一个包含此 commit 的版本发布(报告者用的 0.1.202,需 ≥ 下一版本)。

awork added 2 commits October 21, 2026 17:55
…ers acp_status (#4038)

A model/upstream switch that reuses the session id rewrites the history
out-of-band; every pre-switch fold block deactivates but stays resident, so
remembered bN refs keep resolving to inactive blocks and compress fails with
'already compressed' next to '0 active block(s)' forever. The classifier had
no branch for the shape (cause ''), so the breaker armed with the loop-noise
paragraph that forbids polling acp_status — the one recovery step. Zero-active
+ already-compressed now routes into the substrate-destruction family (single
recovery step in the breaker, FOLD SUBSTRATE INVALID on acp_status), and the
refs snapshot names the dead ledger. Loop-noise wording stays verbatim for all
other causes; both directions pinned by tests.
…failing (#4049)

The generic append-only stability harness called t.skip() without return
when no SMT solver is installed. t.skip() alone does not stop the test
body, so execution fell through to the first real solveSmt2 call, which
throws 'no solver available' — every solver-less CI runner reported the
test as 'not ok ... # SKIP' (failureType testCodeFailure), turning its
shard red deterministically. Introduced by 74eca4e (#3939); local dev
machines carry cvc5 under $HOME/tmp/cvc5, which is why only CI went red.

All other verif harnesses already use 'return t.skip(...)'; this restores
the same pattern and the documented 'no-solver environments auto-skip'
contract (AGENTS.md Key Design Decisions 14). Verified both directions:
solver hidden -> ok/SKIP, fail 0; solver present -> real solve passes.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决,分支已 rebase 到当前 master 并 force-push(b1c22d311,mergeable 已转干净,现等新一轮 CI)。

冲突原因:本分支基于旧 base(56a0f5a46)期间,master 合入了约 40 个 PR(含 release v0.1.203)。唯一冲突点在 tests/issue3769-pooled-bare-load.test.ts:master 侧的 PR #4087(9a497802e)与本分支上一个 ci-worker 提交(69dcac950)修的是同一个 Windows EBUSY 问题(删 index.db 前未关 store1 的 sqlite 句柄),两边代码行完全相同、仅注释措辞不同——典型的并发重复修复撞车。

处置(union-of-intent):rebase 时冲突取 master 版本,并把本分支那个重复提交整个丢弃(它的功能已被 #4087 覆盖,保留只会留下无意义的注释差异)。最终分支 = master 之上 2 个干净提交,实质 diff 与之前完全一致(3 文件,+203/-2):

八问:

  1. 是什么问题:PR 分支与 master 产生合并冲突(dirty),阻塞合并。
  2. 什么原因导致的:master 在分支存活期内推进了 ~40 个 PR,[PR] fix(ci): close store1 before dropping index.db in #3769 pooled-bare-load — Windows EBUSY #4087 与本分支的 ci-worker 提交对同一测试文件的同一处做了功能相同的修复,注释措辞不同导致文本冲突。
  3. 影响范围与严重程度:仅 PR 合并状态受阻;产品行为零影响(丢弃的提交与 master 已有代码逐字节等价于同一功能)。
  4. 怎么修复的:rebase 到 origin/master(7790bea91),唯一冲突取 master 版本,重复提交按「意图并集」丢弃,不引入任何新内容。
  5. 是否有回归问题:本地定向验证全绿——typecheck 干净、build 通过、49 项定向测试全过(含 [Bug] Model-switch (session-generation change) leaves a stale fold ledger resident: compress reports already compressed (e.g. b1..b43) next to 0 active block(s), and the breaker never offers acp_status #4038 全部 5 个用例的正反双向断言、[Bug] MCP failed compression record rotation prematurely rewrites the history prefix, triggering expensive cache recompu | [Bug] MCP 失败压缩记录轮换提前改写历史前缀,触发大额缓存重算 #3769 pooled-bare-load 套件、verif 子语言守卫 + solver 实跑)。被丢弃提交的功能已由 master 上的 [PR] fix(ci): close store1 before dropping index.db in #3769 pooled-bare-load — Windows EBUSY #4087 承载,无行为漂移。
  6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标逻辑)。
  7. 是否改了设计方向:不涉及(PR 原始范围原样保留,纯归因层修复)。
  8. 是否引入了新的配置:不涉及。

补充:floor 3 记录的 4 片 CI 红是已知的 #3769/#4049 存储水合 flake,与本 PR diff 零交集;本次 force-push 已触发新 head 上的全新 CI 运行,以那轮结果为准。结论:冲突已清,等 CI 绿后可由人工合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

随 #4038 关闭:PR 的三个修复点建立在 0.1.202 的机制上,现 master 已无对应入口——①'代际切换调用点'不存在(resetSessionCompression 仅 session.ts:1501 一个调用点,原子清);②③的前提(refs 重铸但账本残留)已被 #4316 ledgerSeq + id 键稳定发号取代。

②的思路(把 'already compressed' + 0 active blocks 防御性归类为 substrate-destruction,让断路器切到 substrateDestructionPauseParagraph 那条带 acp_status 指引的文案)本身便宜且合理,如果未来出现复现,欢迎从本 PR 历史里捡回来单独提。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p1 scope/wiring

Projects

None yet

1 participant