Skip to content

[PR] fix(preflight): discard summaries when their fold targets change - #4487

Closed
ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-10-24_preflight-target-stability
Closed

ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-10-24_preflight-target-stability

Conversation

@ReineLan

Copy link
Copy Markdown
Contributor

While preflight awaits a summary, persistence convergence can replace the session state and make the same refs identify a different span. The old summary could then hide unrelated history. Validate the planned membership and consumed source-block content immediately before committing a result, and discard obsolete results in the serial, external-batch, and tier-distillation paths. Equivalent state replacement and unaffected batch entries remain eligible.

Closes #4486. Category C; host-side compression guard only.

Validation on current master 02f544da:

  • Nine new synthetic regression cases; unchanged code passes three controls and fails all six stale-target cases. Includes the real SessionStore.writeNow convergence path, concurrent coverage changes, batch remapping, equivalent state replacement, and source-summary/topic changes during tier distillation.
  • 70 tests across 14 related suites pass, with no skips: summary target stability, batch/tier recovery, dead ranges, aborts, 400 recovery, budgets, multi-range/hold behavior, and frozen-state recovery.
  • npm run typecheck, npm run build, and git diff --check pass. Two manual review passes covered the asynchronous mutation boundary, normal-path preservation, accounting, and cleanup.
  • Separately verified newer-envelope recovery on a local historical state copy, including a subsequent SQLite-only cold load. No private fixture is committed.

Full-suite CI and real-provider Codex E2E are not yet verified. This change prevents misapplication of a returned summary; it does not claim to resolve every high-context or cache-hit incident.

@ranxianglei ranxianglei changed the title fix(preflight): discard summaries when their fold targets change [PR] fix(preflight): discard summaries when their fold targets change Oct 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。检索 open+closed issue/PR 后,与「in-flight summary 在 session-state 收敛后指向错误 span」同症状同机制的只有源 issue #4486 与本 PR;#4370/#4373(cold-load recovery)机制不同(恢复发生在首次使用之前,本竞态发生在 summary 请求已发出之后),PR 描述里也做了区分,成立。其余 preflight 相关在途 PR(#4445、#4455、#4294 等)均不触碰 summary 提交前的 target 校验路径。

标签:bug, scope/kernel, p1(preflight 提交路径属 src 侧压缩决策面;后果是旧摘要挂到错误 span 上遮蔽无关历史——静默上下文数据损坏类,按 owner 2026-10-19 修订归 p1)。

开始正式审核:拉取分支核对代码 + 回归审查 + CI 状态确认,结论稍后按八问体例回复。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

PR Review(#4487)

① 方向关(审原 issue #4486):方向正确。根因是「plan 时快照目标成员、commit 时拿同一批 mNNNNN 字符串对当前 state 重新解析」,本 PR 把校验闸口放在决策点(commit 前一刻)而不是在 payload 上过滤——疏不是堵。serial / external-batch / tier-distillation 三车道全覆盖,与 issue 提案一致;host-side only,kernel/config/wire/persistence 零改动。等价 state 替换(同身份同内容、计数器漂移)仍允许 commit——比较基于内容指纹而非对象身份,这一点实现正确。

② 回归审查(diff 触碰路径的既有行为逐项清点):

  • serial walk 正常路径:每次成功 summary 多一次 preview applyCompression + 键比较,键一致时行为与原先完全相同。✅ 保持
  • batch 路径:捕获复用 nomination 时已有的 planned 块(零额外 kernel 调用);每个 nomination 独立校验,sibling 不受牵连。✅ 保持
  • tier distillation:LLM 调用前新增一次预检——b-range fold 被内核结构性拒绝时直接跳过,不再「先花一次调用再被拒」。终局判定复用既有 "unavailable" stopReason,无新措辞。⚠️ 有意变更(正向方向):该 corner case 下原本会计费后被拒的调用变为未计费即跳过,externalDispatch.calls 会略降。
  • 内核 fatal(zone/split/已全覆盖/摘要长度)不会从 applyCompression 抛出——外层对 applySingleRange 有 try/catch,整批拒绝并返回结构化 result(kernel/src/compress.ts:735-747)。已对照内核源码核实:re-preview 遇到这类情况退化为「无新块 → discard」,不会打崩请求。✅
  • discard 时新增 skipSet.add(ref pair):与既有 kernel-refusal 纪律一致;skipSet 是 per-invocation(src/preflight.ts:1573),不跨请求污染。⚠️ 新行为,范围有界,语义自洽。
  • wire 形状、config 面、持久化格式、kernel、src/update.ts:均未触碰。✅

③ 代码审查:foldTargetKey 捕获了 LLM 实际看到的全部输入(direct messages + 一级 source 块全字节;孙代内容只经子块 summary 文本流入,一级足够);source 块缺失时键中落 false(保守方向);「按 id diff 找新块」的 preview 模式与主 walk 既有 load-bearing 模式(:2531)逐字同源;commitFold 用真实 summary 做最终 preview(资格判定除长度门槛外与 summary 内容无关,长度超限最坏也只是走 discard,安全方向)。命名、注释、风格符合仓库惯例;无死代码、无魔法数字。

④ 测试有效性(本地独立验证,非转述 PR 描述):

⑤/⑤b diff 整洁度与代码整洁:2 文件 +203/−4,每一行都服务于本修复;commit 规范、分支命名合规;外部提交质量达标,无需对齐重构。

⑥ CI 状态(合并阻塞项):

结论八问:

  1. 是什么问题:preflight 等待异步 summary 期间,persistence 收敛可换掉会话 state,同一批 ref 号指向不同消息,旧 summary 会挂到新 span 上掩盖无关历史。
  2. 什么原因导致的:plan 侧快照目标成员、commit 侧对当时当前 state 重新解析同一批 ref 串;两者之间隔着 await 窗口,窗口内 SessionStore 的 stale-write guard 把内存态收敛到磁盘新态。
  3. 影响范围与严重程度:任何 summary 在途期间发生 state 收敛/替换的会话(多实例同会话、冷加载竞态);后果 = 无关历史被错误 summary 掩盖,数据丢失类,p1;触发条件窄(须命中 LLM 延迟窗口内恰好收敛),但命中即严重。
  4. 怎么修复的:commit 前一刻对当前 state 重跑同一个 preview,比较 fold 目标指纹(direct/effective 消息集 + 一级 source 块全字节);不一致 → 丢弃结果并记 skip;三车道共用同一闸口;等价替换照常 commit。
  5. 是否有回归问题:未发现。三车道正常路径逐项核对不变;两处有意微变更已披露(第 ② 条 ⚠️ 两项);无阈值/时序/输出格式漂移,fail-fast 未变吞错(discard 有 warn 日志 + skipReasons 进 verdict)。
  6. 是否破坏缓存:不涉及——不碰前缀缓存接缝、重试策略、去重键;discard 只减少 fold,不产生新的 wire 字节。
  7. 是否改了设计方向:不涉及——纯 host-side 守卫,架构/边界/数据流未转向。
  8. 是否引入了新的配置:不涉及。

合并判定:代码就绪,review 无拦项;合并被既有 master 红阻塞。建议顺序:① 先解/重跑 #4490 跟踪的 master 红;② 本 PR rebase 到绿 master 后重跑 CI;③ 若 windows-22-1 仍红,拉其 job log 确认与本 PR 无关。三步干净即可合。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI verdict: the red lanes are inherited from a red master, not caused by this PR — not fixing on this branch.

What was verified:

  • This PR's diff only touches src/preflight.ts plus the new tests/preflight-target-stability.test.ts — neither failing test's code path is touched. The PR's own new test passes on all 6 shards.
  • The 6 failing shards fail on exactly two tests, both storage tests:
    1. tests/media-cas.test.ts — "stale-row sweep releases media refs and mappings": expects refcount 0, gets 1
    2. tests/issue3250-wal-checkpoint.test.ts — "[bug] index.db-wal 在长驻进程内永不 checkpoint —— STORAGE_PRAGMAS 无 journal_size_limit、master 无 wal_checkpoint 调用,WAL 单调增长到 55 MiB 不回收 #3250 configured cap flows open() → journal_size_limit": WAL left 1095952 bytes vs cap 1048576 + 4KiB slack
  • Bare master tip 02f544da fails the same two tests on 5 shards (jobs 120795516026 / 120795515964 / 120795515956 / 120795515953 / 120795515906) with identical failure signatures — so every PR based on current master inherits this red.
  • Local repro on master tip (node --import tsx --test <file>): both tests fail deterministically; the WAL one reproduces the exact byte count (1095952) — not a flake.

Root cause (details in the linked issue): today's three storage merges (#4346 seq-ledger, #4395 row-identity-historian, #4335 layer3-seq-bounds) outpaced two older tests:

  • media-cas: the completeLog stale-row sweep intentionally changed from DELETE to retire-tombstone ("CAS refs are NOT released: retired rows still own their bytes" — src/storage/store.ts:720-722), but the test still asserts the old delete semantics (refcount→0, mappings dropped).
  • WAL cap: the cap itself is honored (WAL truncated to exactly 1MiB at autocheckpoint); ~47KiB written after the last truncation now exceeds the test's fixed 4KiB slack assumption because schema-v8 page-count drift moved where the checkpoint boundary lands.

Both are test staleness, not production regressions. Fixing them belongs on master, not on this branch (scope discipline). Tracked in #4492 with repro, root cause, and suggested test-side fixes. Once master is unred, a CI re-run (or rebase) on this PR should go green — its own changes show no related failures.

八问

  1. 是什么问题: 这个 PR 的 CI 红不是它自己引起的——它继承了 master tip 上两个确定性的存储测试红。
  2. 什么原因导致的: 今天合入的三个存储 PR 改变了 sweep 语义(DELETE→退休 tombstone)和每条消息占用的页数;两个早于这些合并写成的测试仍在断言旧行为。
  3. 影响范围与严重程度: 仅开发流程——所有以当前 master 为 base 的 PR 都过不了 test gate;用户侧零影响(已发布版本不受影响,两处底层机制本身都按设计工作)。
  4. 怎么修复的: 不在本分支修(超范围)。已立 master CI red: two storage tests stale after the historian/seq-ledger merges (media-cas sweep, WAL cap) — every PR inherits the red #4492 汇总两个子缺陷(同症状同触发面),含复现、根因与建议修法;其中唯一的设计取舍(退休行的 CAS 引用是否应由后续 GC/archive 释放)留 owner 拍板。
  5. 是否有回归问题: 无——本判定未推送任何代码改动。
  6. 是否破坏缓存: 不涉及——无改动。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入新配置: 不涉及。

判定: 停止在本分支修复(auto-fix 第 1/2 次尝试用于诊断)。作者侧无需动作,等 master 转绿后重跑 CI 即可。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

PR 审核结论:#4487 preflight 目标稳定性守卫

独立审核完成(未照抄 issue 侧结论;diff、行为、回归均按本 PR 重新过了一遍)。

① 原 issue 方向(#4486)

机制核实成立:preflight 的摘要请求在途期间,SessionStore.writeNow 的 stale-write 护栏会把内存态收敛到更新的盘上态;ref 是内容指纹,收敛后同一 ref 串指向不同消息,旧摘要就会压到错误跨度上(隐藏无关历史)。修复打在决策点(提交前校验归属)而不是持久化层或 ref 体系——生产者就是「拿快照 X 算出的结果提交到状态 Y」,本 PR 让过期结果根本无法落盘。换一种失步形态来(原地改 vs 整体替换)同样被抓住,因为 plan 时与 commit 时的 key 都从当时的活状态重算。方向正确,打到了根因。

② 回归审查(触碰路径的既有行为逐项清点)

  • 串行 walk 提交路径:状态未变 → key 相等 → 照常提交(「unchanged/equivalent」对照用例钉住);仅当归属真的变了才丢弃并 warn+skip 记录。无静默行为漂移。
  • 批量路径:逐条独立校验,未受影响的条目照常提交(batch-unchanged 断言 2 块全落;batch-remapped 断言 0 块)。
  • tier 蒸馏:新增两个中止点——plan 期预览找不到目标块时直接 unavailable(旧代码会白烧一次 LLM 调用再在 apply 处被拒,终态相同、只是更省);await 后 key 不符则丢弃(旧代码会把过期蒸馏压下去,即本 bug)。
  • skip 记账:丢弃走既有的 noteSkip+skipSet 通道,与其他拒因同型,观测面不新增分支。
  • 成本:每次提交多一次 applyCompression 干跑(O(n)),相对 LLM 调用延迟可忽略;preflight 每轮本就有多个干跑。
  • 高危模式逐项过:无 fail-fast 变吞错(丢弃有 warn 日志+skip 记录)、无阈值/时序/输出格式漂移、无缓存/重试策略变化、wire 与两种压缩模式均不受影响(preflight 是共享兜底,守卫模式中立)、kernel 未触碰、配置面零变化。
  • 潜在抛错面核查:commitFold 里新增的裸 applyCompression 在 ref 失效时不会抛——同文件 plan/batch 两处干跑均按 result.errors 优雅处理该情形,且旧路径同样的输入也会在后续 applyRanges 处以相同方式处理。无新增崩溃面。

③ 代码审查

命名达意(foldTargetKey/previewFoldTargetKey/targetKey)、注释讲为什么(竞态背景)、错误信息带上下文、风格与仓库一致、无死代码、无新依赖。「等价替换仍合格」由 key 字段集保证(含子块 summary/topic/tier 全文,恰好覆盖 tier 蒸馏的源块替换场景)。commitFold 内预览逻辑与 previewFoldTargetKey 有约 6 行结构重复,但 dummy/real summary 的差异是刻意的,不值得抽。通过。

④ 测试有效性

真测试,不是假测试:SessionStore.writeNow 真实收敛路径(persistence 模式,且断言日志里出现 "converging in-memory state" 证明竞态真的发生了)、remap 有硬证据(byRef[first] === "raw-9" 断言)、确定性 mock upstream + listen(0) + env 还原 + 隔离 tmpdir。双向断言齐全:对照组断言「提交且落在正确跨度」,过期组断言「摘要不存在于最终状态」+丢弃日志。我本地做了负控制验证:父提交代码跑这套测试 = 3 过 / 6 失败,PR head = 9/9 过——原始 bug 被精确复现并被修复钉住。CI 上全部 shard 中该套件均为 ok。

⑤ diff 整洁度

2 文件、每行都与目的相关,干净。

CI 状态与合并判定

PR head 上 6 个 test shard 红,逐一核对日志后确认全部来自 master 既有问题,与本 PR 无关:

判定:代码本身可合(质量达标、回归干净、测试有牙);合并需等 #4490/#4489 清掉 master 红之后门禁转绿,或由 owner 知情放行。 行为变更披露(见下第 2 条)已按规范列出。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

结构化八问(接上条审核结论)

  1. 是什么问题:preflight 等摘要返回期间,会话状态被持久化收敛替换后,同一组 ref 指向了不同的消息跨度;返回的旧摘要被原样提交,把无关历史折叠掉(静默上下文数据损坏)。
  2. 什么原因导致的:摘要结果是在快照 X 上算出的,提交时却落到了状态 Y——plan 与 commit 之间没有一致性校验。根因是「跨 await 的结果未经验证即应用」,不是持久化层或 ref 体系本身的错。
  3. 影响范围与严重程度:任何在 preflight 摘要在途时发生状态收敛的会话(长会话 + 活跃持久化,正是高负载场景);后果是错误跨度被摘要覆盖、decompress 也救不回被错误折叠的内容——完全符合 p1 数据损坏类。触发条件较窄(需在途窗口内恰好发生收敛),但一旦发生就是静默损坏。
  4. 怎么修复的:为每个计划中的折叠捕获目标指纹(直接/有效消息 id + 所消费子块的 tier/topic/summary 全文),在提交前一刻用同样的 ref 对当前活状态干跑一次 applyCompression,指纹不一致就丢弃该结果(warn 日志 + skip 记录);串行、外部批量、tier 蒸馏三条路径全覆盖;等价的状态替换指纹相同、照常提交。校验与应用之间无任何 await,事件循环内原子。
  5. 是否有回归问题:无。既有行为逐项清点过(见上条②):状态未变时三条路径行为逐字节不变(对照用例钉住);唯一新增的中止点是 tier plan 期预览失败提前 unavailable,与旧代码白烧一次 LLM 调用后被拒的终态相同;丢弃走既有 skip 通道;无 fail-fast 变吞错、无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:不涉及。不改出站字节构成、不改前缀、不动缓存/重试/去重策略;丢弃只会让本轮少折一个跨度,payload 偏大走原有 fail-fast/下轮重试路径。
  7. 是否改了设计方向:不涉及架构转向。属于「资格判定与执行共用单一投影」([Bug] recommend/apply 对同一区间的 turn-integrity 判定永久不一致:acp_status 反复推荐的区间被 apply 侧整段拒绝(0.1.196,Range would split N turn(s) at the protected-zone boundary) #3236)同族的纪律延伸:判定必须跑在执行将跑的那个状态上——本 PR 把这条纪律补到了「await 之后」的时间维度。
  8. 是否引入了新的配置:无。零新 env/config/默认值。

行为变更披露(旧值→新值+原因):

  • 过期摘要:旧=提交到错误跨度(损坏);新=丢弃+warn+skip 记录(本修复目的)。
  • tier 蒸馏 plan 期:旧=先调 LLM 再在 apply 处被拒(浪费一次外部调用);新=干跑预览找不到目标块时直接 unavailable 中止,不调 LLM;终态不变。
  • skip 观测面:被丢弃的折叠现在出现在 skipSet/noteSkip 里(与其他拒因同型)。

收工判定:代码可合,等 master 红(#4490/#4489)清掉后门禁转绿即可合并;或 owner 知情放行。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

收工摘要

审核全部完成,结论已在本帖上方两条(主审核 + 结构化八问)。这里给一句话版:

做了什么:独立通读 diff(未照抄 issue 侧结论);逐路径核对了串行/批量/tier 蒸馏三条提交链的校验机制(指纹在提交前一刻对活状态重算、校验到落盘之间无 await、等价替换仍合格、dummy 预览与真实摘要不会造成误杀);本地搭了 PR head 工作区跑了新测试套件 9/9 过,并对父提交做了负控制复跑 = 3 过/6 失败(与 PR 声明逐条吻合,原始 bug 被精确复现再钉住);CI 六个红 shard 逐一核对日志,确认全部来自 master 存量存储回归 #4490/#4489(master 同 base SHA 的 run 同样红),与本 PR 无关——已在 #4490 留了交叉引用。

结果:代码可合。质量达标(命名/错误处理/双向断言全过外部提交硬标准)、回归干净(触碰路径既有行为逐项清点,状态未变时逐字节不变)、测试有牙。合并条件:等 #4490/#4489 清掉 master 红后门禁转绿,或 owner 知情放行。标签已打齐(bug/p1/pr/scope/kernel)。

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4525(master 6d7c587,合并方式 merge commit,提交保留原作者署名)。本 PR 关单收尾;若列车中对应提交出问题,回滚点为 #4525 单提交 revert。

感谢 @0XCocoa 的贡献——你的提交以原作者署名随列车进入 master(合并方式为 merge commit),仓库贡献者列表可见。

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

Labels

bug Something isn't working p1 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[preflight] In-flight summary can fold a different span after session-state convergence

2 participants