Skip to content

[PR] kernel: all-or-nothing summary-length pre-check for multi-range compress (#3003) - #3670

Closed
ranxianglei wants to merge 5 commits into
masterfrom
wt-3003-ework-daemon
Closed

ranxianglei wants to merge 5 commits into
masterfrom
wt-3003-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

Multi-range compress committed per-range: when one range's summary failed length validation (over/under cap) while sibling ranges were valid, the valid siblings landed first — opening a seam (the next request re-pays everything after the fold point) — and the model's retry of the bad range paid a second seam. This is the PARTIAL-fold double-seam cost tracked in #3003 (production instance #2997 fold #12: S=34.1K saved vs T=237.9K re-paid, ledger verdict NOT PAID BACK). It is a cost issue, not a stability bug — probe PR #3002 confirmed seams are head-stable.

Summary length is a pure function of (spec.summary, spec.summaryMaxChars, cfg) — no session state, no cross-range coverage — so it can be screened before any block commits. This makes applyCompression reject the WHOLE batch all-or-nothing when any fold candidate fails length validation: zero commits, zero seams, so the model's single retry pays once instead of twice.

Content-class failures stay per-range. Protected-zone-all-empty, turn-integrity split, and no-new-messages errors depend on state + cross-range coverage and cannot be pre-screened against the original state; they keep their existing per-range behavior.

Scope of the gate (deliberate)

The pre-check runs over exactly the fold-candidate set that mutates state (status === "ok" non-skipped, plus status === "consumed" refolds whose decision kind is "refold"). It does NOT run over every requested range: a consumed non-refold range or an unknown/invalid ref whose summary merely happens to be out of range must not kill a batch whose real candidates all validate.

Behavior change (old -> new)

Case Old New
Batch where >=1 candidate summary fails length, others valid PARTIAL: valid ranges commit (1 seam), bad one errors; retry -> 2nd seam FULL-reject: nothing commits (0 seams); retry all -> 1 seam
Batch with zero length failures unchanged unchanged (byte-identical path)
Single-range batch whose summary fails length blocksCreated 0, per-range error blocksCreated 0, same detail now embedded in the batch-reject message

Intentional and approved (#3003 floor 13): trade one extra model round-trip (re-writing the good summaries once more) to save one prefix-cache seam — a seam (tens-hundreds of K tokens re-paid) dwarfs the rewrite (output tokens). Escape hatch: the rejection message offers two exits — shorten/split the offending summary and resend the whole batch, OR drop the offending range(s) and resend only the rest.

The existing nudge guidance (src/compress-tool.ts SUMMARY_BUDGET_NOTE: "a single oversized summary fails the WHOLE compress call — nothing gets folded") now matches actual behavior — previously it described the intended contract while the kernel did partial commits.

Rejection message

Names each offending range + overflow amount and gives both exits:

Batch rejected before folding any range — N of M requested range(s) failed summary-length validation: range mX..mY: Summary too long (A chars, max B)… Nothing was folded, so no prefix was rewritten. Fix it one way or the other and resend: shorten or split each offending range's summary to fit its cap, then resend the whole batch; or drop the offending range(s) and resend only the rest that validate.

Host-side companion (separate commit)

src/loop/core.ts: count fold-rounds per turn and log when a turn carries >=2 folds — the residual multi-seam cost that survives after the length gate (multiple independent compress calls across rounds still pay multiple seams). Purely additive logging; feeds the deferred decision on delayed materialization (not implemented here — needs instrumentation data first).

kernel-change

kernel-change: the per-range commit lives inside the kernel's applyCompression; only the kernel can reorder length-validation ahead of the commit loop. No host-side change can make a partial commit atomic, because the host receives an already-partially-applied result.

Config surface

None. No new fields/env vars/flags. The existing compress.maxSummaryLength / minSummaryLength / per-spec summaryMaxChars are reused unchanged.

Tests

New kernel/tests/issue3003-all-or-nothing-length.test.ts pins both directions of the gate (#3617): too-long rejects the batch, too-short rejects the batch, all-valid commits every range (control), and a non-candidate range with an out-of-range summary does NOT reject a valid fresh fold (scoping). Three existing tests that asserted the old partial behavior were updated to the new contract (compress.test.ts batch test + empty-summary assertion; validation.test.ts empty-summary batch test). Kernel suite green locally (1304/1304); full bili suite/e2e gated on CI.

Closes #3003.

@ranxianglei ranxianglei changed the title kernel: all-or-nothing summary-length pre-check for multi-range compress (#3003) [PR] kernel: all-or-nothing summary-length pre-check for multi-range compress (#3003) Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-3003-ework-daemon (eed105e)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4372-pr.3670.2f2ac9e

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

查重: 不重复 —— 按失败签名(多 range compress 部分落地双缝 / all-or-nothing 长度预检)检索 open+closed issue/PR,无同机制在途条目。最近的邻居都不同域:#3634/#3635 是 external-summary 模式下超长摘要被静默丢弃(不同路径、不同症状),PR #3002 是已关闭的缝稳定性探针,#2997 是已关闭的 prefix-excess 稳定性 bug。本 PR 即 #3003 拍板后((floor 9「接单」))的唯一实现。

标签: pr + bug + dsh + scope/kernel + p2(缺陷类成本问题;#2997 现场为 dsh-lane;修复主体在内核压缩引擎;特定条件下多 range 折叠有实际成本损失、非致命)。

开工审核。这是 kernel 改动(human-only review tier),我按 PR Review 规范走:先核对 #3003 方向与批准链 → 全量读 diff → 回归清点(重点:external-summary 路径与新门的交互、consumed/refold 作用域、零失败时字节不变性、单 range 错误面、plugin/proxy 两模式)→ 测试有效性 → CI。结论用八问给出,稍后回帖。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #3670 review complete. Bottom line up front: 方向正确、实现与 #3003 批准的设计一致、未发现无意回归 —— 可合入(kernel 变更 → 人工审核层,等你合并)。审查中我按「小问题直接修」向 PR 分支补了 3 个标注 commit(见下)。

结构化八问

  1. 是什么问题:多 range 的 compress 批次逐 range 提交——一个 summary 长度校验失败、其余合格时,合格的先落地开出 prefix-cache 缝(下个请求把折叠点之后的内容全部重付一遍),模型重试坏 range 再付第二条缝。生产实例 [cache] 0.1.196 (d64139f9) 仍复现 post-fold follow-up excess —— #2741/#2755 修复后 2/2 大折叠复发 #2997 fold refactor: reapOrphanBlocks should live in acp-kernel, not the proxy #12:省了 S=34.1K、重付 T=237.9K,ledger 判定 NOT PAID BACK。是成本问题不是稳定性问题(探针 test(dsh-lane): post-fold prefix-stability backstop for the uncovered plugin/openai lane (#2997) #3002 已确认缝头稳定)。
  2. 什么原因导致的:长度校验与提交循环交织——fresh fold 在 applySingleRange 推块前才校验、refold 在 applyRefolds 原地更新前才校验——所以靠前的 range 可以在靠后 range 的长度失败被发现之前先提交。而 summary 长度是 (summary, summaryMaxChars, cfg) 的纯函数(无会话状态、无跨 range 覆盖依赖),本可以整体前置筛查,只是提交循环没有做。
  3. 影响范围与严重程度:p2。触发条件 = 模型一次提交多 range 批次且至少一个 summary 超/欠上限(实际以超长为主)。后果 = 每次事故多付一条缝的重计费(数万到数十万 token),无数据丢失、会话不坏。其余所有批次形状与 master 字节级一致。
  4. 怎么修复的:把长度校验移到提交前的整批筛查,候选集恰好等于循环真正会提交的集合(fresh ok range ∪ consumed 且 refold 决策为 refold 的 range——我逐行核对了与循环提交路径一致)。任一长度失败 → 整批拒绝、零提交、零缝。内容类失败(protected-zone / turn-integrity / no-new-messages / unknown refs)保持逐 range——它们依赖状态+跨 range 覆盖,无法前置。拒绝信息点名每个违规 range + 超出量 + 两条出路(缩短/拆分后重发整批,或剔除违规 range 只重发其余)。host 侧伴随 commit:按 turn 统计 fold-round 数并日志(≥2 才打),纯计量,喂给延后的「延迟物化」决策,未实现该机制本身。
  5. 是否有回归问题:未发现无意回归。逐项审过的既有行为:
  6. 是否破坏缓存:否——这个修复本身就是反缝修复。零失败路径字节级一致,未触碰任何缓存/重试/游标/失效策略。
  7. 是否改了设计方向:否。压缩仍是模型驱动;只有长度类的提交原子性变了(逐 range → 整批 all-or-nothing),owner 已在 [design] Parallel compression saves cache; both failure and success strategies account for PARTIAL fold double-seam cost | [design] 并行压缩节省缓存,失败和成功策略都考虑 PARTIAL fold double-seam cost — per-range commit makes rejected-range retry pay twice (#2997 §5) #3003 拍板(floor 7「都做吧」、floor 9「接单」)。批准计划里的 nudge/prompt 项无需改码:master 的 SUMMARY_BUDGET_NOTE(src/compress-tool.ts:637)早已写明「一个超长 summary 会让整个 compress 调用失败」——在 master 上是愿景,在本 PR 之后变成事实。
  8. 是否引入新配置:无。复用 compress.maxSummaryLength / minSummaryLength / 每 spec 的 summaryMaxChars。

高危域逐项点名核查

  • 自动更新/自更新路径:未触碰。
  • dsh 相关功能:未触碰。
  • lockfile:diff 恰好是 acp-kernel 版本记录 0.0.131→0.0.132(kernel/package.json + kernel/package-lock.json + root 的 file-link 记录),无连带变更。
  • Kernel Boundary:kernel-change: 已声明 ✓;版本同步 ✓;零新增依赖 ✓;golden pin 面(config/prompts/tool-names/wire markers)未触碰,由 CI kernel-guard + wire-contract 车道最终确认。

审查时补进 PR 分支的 3 个小修(additive commits,作者署名不动)

  1. fd6569372 fix:host 侧 compress failure is self-amplifying: failed calls are hidden as orphan refs, making the same range permanently un-compressible #2362 分类器不认识新的失败类——「Batch rejected before folding any range」落进 gate:other 兜底,操作员看不出批次死于何因。补了专用 gate:summary-length 分支(src/stream.ts)。
  2. cfd5926ae test:too-short 批量测试里的「合格 sibling」其实自己也欠长(2 字符 vs min 50),断言「valid sibling must NOT land」是空转。sibling 改为真合格(60 字符,max 检查置 0 关闭),测试这才真的证明「合格 range 被他人 range 的长度失败拖住」。
  3. 645898050 test:门禁的 refold 方向(consumed + refold 候选)原本零覆盖——这是最绕的分支,与 fix: isolate side requests (title-gen) from main session kernel state #398/decompress 被下一轮静默撤销:syncBlocks 无条件复活已失活块 + bili 同时删除内容缓存 + loop 路径把折叠视图喂给回退检索(还原原文再被重折,二次解压永久退化) #400 原地 refold 交互。新测试:fold → inline 恢复 → 超长 refold summary + fresh 合格 sibling 同批 → 零提交、已恢复块保留旧 summary。在门禁前的代码上会失败(fresh sibling 会落地),有牙。

验证证据(定向本地)

  • kernel:issue3003-all-or-nothing-length.test.ts(现 5 个测试含 refold 方向)+ compress.test.ts + validation.test.ts → 47/47 通过。
  • host:typecheck 干净(tsc --noEmit,kernel + pi-subagents 重建);compress-reject-reasons.test.ts + loop-compress.test.ts → 19/19 通过。
  • 全量回归归 CI:pushed head 645898050 的 check-runs 运行中(gates 已绿,kernel-guard/test 车道排队中)。

判定:可合入——方向、机制、候选集边界、测试双向咬合都经独立复核成立,3 个审查小修已就位。kernel 变更为人工审核层,请自行合并:#3670

@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/kernel labels Oct 18, 2026
awork added 5 commits October 18, 2026 20:50
…idation (#3003)

A multi-range compress batch committed per-range, so one length-class failure
(summary over/under cap) among otherwise-valid folds let the valid siblings land
FIRST (opening a seam), and the model's retry of the bad range paid a second
seam. Summary length is a pure function of (spec.summary, cfg) — no state, no
cross-range coverage — so screen it all-or-nothing BEFORE any block commits: any
length-class failure now rejects the WHOLE batch (0 commits, 0 seams). The scope
is exactly the fold-candidate set that mutates state; content-class failures
(protected-zone / turn-integrity / no-new-messages) stay per-range.

Behavior change: a length-class mixed batch goes from PARTIAL (valid ranges land,
bad one errors) to FULL-reject (nothing lands, actionable error names each
offending range + overflow and offers two exits: shorten/split-and-resend, or
drop-the-offender-and-resend-rest). Batches with zero length failures are
byte-identical. The existing nudge guidance ("a single oversized summary fails
the WHOLE compress call") now matches actual behavior.

Bumps acp-kernel 0.0.131 -> 0.0.132.
Each landed fold re-bills the remaining suffix to the prefix cache (one seam).
Count fold-rounds per turn and log when a turn carries >=2 — the residual
multi-seam cost that survives after #3003's all-or-nothing length gate. Purely
additive logging; feeds the deferred decision on delayed materialization.
…view)

The new all-or-nothing length pre-check adds a failure class the #2362
classifier did not know: 'Batch rejected before folding any range' fell
into the 'gate:other' catch-all, losing operator visibility into WHY the
batch died. Add a dedicated gate:summary-length branch.
…review)

The assertion 'the valid sibling must NOT land either' was vacuous: with
minSummaryLength=50 the 2-char sibling summary failed its OWN length check,
so no valid sibling existed in the batch. Make it 60 chars (max check
disabled at 0) so the test actually proves a valid range is held back by a
foreign range's length failure.
… review)

The pre-check screens consumed+refold candidates alongside fresh folds, but
the new suite only covered fresh folds. Add the missing direction: fold
m00001..m00002, restore the block inline (refold candidate), then request an
oversized refold summary plus a fresh valid sibling in one batch — nothing
may commit and the restored block must keep its old summary (no partial
in-place refold may precede the batch rejection). Fails on the pre-gate
per-range commit (the fresh sibling would land).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决 —— PR #3670 分支已 rebase 到当前 master(65d60cbea,含 release v0.1.201 及后续合并),冲突解决后 force-push(eed105e96)。GitHub 侧 merge 状态已转干净(mergeable=true,现 blocked 仅因新 head 的 CI 在跑)。查重: 同一 PR 的冲突唤醒,非新条目,内容基线即 floor 5 已审版本。

结构化八问

  1. 是什么问题:不是代码缺陷,是调度事件——PR 等合并期间 master 前进了(v0.1.201 发版、[PR] fix: v0.1.200 review follow-ups — self-heal guard, cold-load counter, JSONC audit + web editor #3689 等多个合并),PR 分支与目标分支产生文本冲突,系统转发唤醒处理。
  2. 什么原因导致的:master 期间内核版本已从 0.0.130 推进到 0.0.133([compress] Still present after #156: the LLM also gets stuck on an invalid end ref; #370's same-parameter short-circuit fails to prevent it. | [compress] #156 之后仍存在:大模型同样卡在无效 end ref,#370 的同参数短路挡不住 #3302 等其他 kernel 变更),与本 PR 的版本 bump 行(原 0.0.130→0.0.132)相撞——kernel/package.json、kernel/package-lock.json、根 package-lock.json 三个文件各一处版本行冲突;其余文件(含主战场 kernel/src/compress.ts)全部自动合并干净。
  3. 影响范围与严重程度:仅本 PR 分支状态,无用户面影响;rebase 后代码内容与 floor 5 审核过的基线一致,除版本号外零差异。
  4. 怎么修复的:rebase 5 个原 commit 到当前 master(保持线性历史);三处版本行冲突统一解为 acp-kernel 0.0.134(master 现行 0.0.133 + 本次 kernel 变更的 +1,lockfile 记录同步),未动任何逻辑行;bili 根版本保持 0.1.201 不变。
  5. 是否有回归问题:rebase 本身未引入回归。逐项核对:all-or-nothing 长度预检完整在位(kernel/src/compress.ts:646);host 侧 gate:summary-length 分类(src/stream.ts:916)与 fold-round 日志(src/loop/core.ts:649-652)完整;master 侧 [compress] Still present after #156: the LLM also gets stuck on an invalid end ref; #370's same-parameter short-circuit fails to prevent it. | [compress] #156 之后仍存在:大模型同样卡在无效 end ref,#370 的同参数短路挡不住 #3302 sparse-ref tombstone 变更与新门在同一文件共存、自动合并无语义干扰。定向验证(本地):kernel issue3003-all-or-nothing-length + compress + validation = 47/47 通过;host typecheck 干净,compress-reject-reasons + loop-compress = 19/19 通过。全量回归归 pushed head eed105e96 的 CI test 车道。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:无。

行为变更披露:acp-kernel 版本记录 0.0.132(原 PR)→ 0.0.134——纯因等待期间 master 内核版本前进的机械同步,无行为差异。

判定:冲突已清、分支就绪,仍待人工合并(kernel 变更 = 人工审核层):#3670

ranxianglei added a commit that referenced this pull request Oct 19, 2026
…one seam per burst (#3003)

Consecutive compress rounds currently pay one cache seam each: every
committed fold rewrites the outbound prefix immediately, so the next
re-request inside the burst re-pays the whole cache. #3670 already made
the commit itself all-or-nothing for length-class failures; this closes
the success-path seam.

Design (fold-hold):
- The fold still commits to session state immediately (ledger, refs,
  consumed classification, block contents persisted — restart-safe).
- The outbound VIEW defers while the burst continues: any request that
  carries a NEW successful compress result renders held blocks raw
  (prefix byte-identical → full cache hit on the raw tail), the first
  request WITHOUT a new fold result materializes all held blocks —
  exactly one seam for the whole burst.
- Window pressure (tokenCount >= 90% of the effective window, below the
  95% emergency band) materializes immediately; preflight/emergency
  folds pass holdFold:false and render folded on the rescue view.
- Loop lane: refresh condition now skips the settle re-request refresh
  while folds are held (raw re-request view is prefix-stable with the
  request that triggered it — better than today, where the settle round
  itself pays a seam); relay refreshFolded callback materializes.
- Hold view is a clone with held blocks {active:false, expanded:true}
  (the kernel's sanctioned render-raw channel, sync.ts deliberately
  leaves expanded blocks inactive; fork-adoption precedent). Active
  flags are restored before state adoption; a genuine user decompress
  mid-burst is never resurrected (keyed on pre-clone activity).
- Nudge ranges fully covered by held blocks are filtered from the
  injected nudge during hold legs (the view cannot fold them; kernel
  already-covered refusals would spin #156).
- Knob: BILI_DEFER_MATERIALIZATION / compress.deferMaterialization,
  default on; =0 restores the eager contract everywhere.

Worst case (gap-separated folds) is byte-identical to today's behavior.
Eager-vs-hold full-state dump: persisted state identical, only the
settle-round and next-request bodies stay raw; goldens regenerated with
the semantic assert updated (carrier by materialization body, foldAt+2).

Tests: unit fold-hold (10), loop raw-hold + pressure materialize
(#3003a/b), proxy seam e2e (K consecutive folds → exactly ONE
raw→folded transition; escape hatch pins eager), storage goldens regen,
29-file regression batch green.
Zhishulo pushed a commit to Zhishulo/billion-context that referenced this pull request Oct 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

#3670 已被 PR #3956 吸收(item ④ 全有或全无:cherry-pick 了本 PR 的 summary-length 预检两 commit,并扩展到 content-class 全批拒绝,clone-and-simulate 语义)。#3003 已随 #3956 关闭。本 PR 分支长期冲突未再推进,作为被吸收方关闭。

This was referenced Oct 20, 2026
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 p2 scope/kernel

Projects

None yet

1 participant