Skip to content

[PR] fix: #4224 emergency digest quality + convergence (multi-fold, dynamic trim, structural conclusion) - #4226

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-10-22_emergency-digest-quality-convergence
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-10-22_emergency-digest-quality-convergence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Three defects in the #2387 deterministic-digest emergency path, confirmed against v0.1.201/0.1.202 production evidence (dsh fork, deepseek-flash v4.1, 87 blocks at 22.9% window):

# Defect Root cause Fix
1 87 requests to converge (one fold per round) Serial walk inherited LLM-path appliedThisRound===0 cap; wasteful for CPU-only digests maxFoldsPerRound = Infinity when emergencyFold; full walk drains in one round
2 ≥132-entry spans lose ALL excerpts fits() tries [120→0→header-only] all-or-nothing Dynamic per-line head budget: (maxSummary - baseLen - 4N)/N, floor 24 chars
3 Digest is a pure index (zero conclusion) By design as "placeholder" but never upgraded after #2387 made it the primary view One-line structural conclusion: Structure: 89×bash, 45×read, 22×write, ...

Behavior changes

  • Emergency path only (entryOvershoot > 19.2x): folds multiple ranges per round instead of one. Non-emergency path unchanged.
  • Digest format: adds a Structure: line between header and per-entry lines. Degrades gracefully (dropped before header at extreme bounds).
  • Digest excerpts: large spans that previously got zero excerpts now get short ones (≥24 chars/line) when space allows.

Known remaining issues (follow-up)

  • shrink%/postCtx log values misleading with many active blocks (only subtracts current fold's savings)
  • "102 viable ranges" vs "No compressible ranges remain" messaging contradiction between preflight and compress tool layers

Tests

  • Updated existing fallback test for new structure line
  • New: dynamic head trimming regression (150 entries keep excerpts < 120 chars)
  • New: extreme bounds still fall back to header-only
  • All preflight-emergency-fold tests pass (6/6)
  • No new regressions (verified against master: same 3 pre-existing failures in unrelated tests)

Closes #4224

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-22_emergency-digest-quality-convergence (91b2da9)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5020-pr.4226.235f0b4

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: #4224 emergency digest quality + convergence (multi-fold, dynamic trim, structural conclusion) [PR] fix: #4224 emergency digest quality + convergence (multi-fold, dynamic trim, structural conclusion) Oct 21, 2026
awork added 2 commits October 22, 2026 05:55
…c trim, structural conclusion)

Three defects in the #2387 deterministic-digest emergency path, all confirmed
against v0.1.201/0.1.202 production evidence (dsh fork, deepseek-flash, 87
blocks at 22.9% window):

1. One fold per round → 87 requests to converge. The serial walk inherited
   the LLM-path 'one fold per round' cap, but emergency digests are CPU-only
   (zero upstream calls). Now the full walk drains in a single round when
   emergencyFold is active. Non-emergency path unchanged (maxFoldsPerRound=1).

2. fits() all-or-nothing head trimming → ≥132-entry spans lose ALL excerpts.
   Instead of [120→0→header-only], compute the per-line head budget from
   remaining space so large spans keep short excerpts (floor 24 chars).

3. Zero-conclusion digest → model sees an index, not a summary. Added a
   one-line structural conclusion (counts by message category: bash×89,
   read×45, etc.) so even when per-entry excerpts are trimmed, the digest
   conveys WHAT happened in the span.

Tests: updated existing fallback test for the new structure line; added
dynamic-trim regression test (150 entries keep excerpts below 120 chars);
added extreme-bounds header-only fallback test.
…one verb

Review finding on the original commit: digestLabelCategory matched
label.startsWith("tool-result"), but the digest entry builders emit
'tool result <verb>' (space-separated), so that branch was dead code and
tool-heavy spans (the #4224 corpus is ~100% tool traffic) got one category
per 'tool result bash' instead of merging with its call. Both forms now
collapse to the verb: Structure: 178×bash for 89 calls + 89 results.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 本 PR 是 #4224 的实现 PR;#4224 与 #2383 不重复(#2383 = 极端溢出时根本没有快速路径,新增 deterministic digest 路径;#4224/#4226 = 该快速路径自身的三个质量/收敛缺陷)。按失败签名检索 open+closed,无其他触及同一机制的在途 issue/PR。

标签: bug dsh scope/kernel p1(缺陷类;生产证据来自 dsh 车道;领域 = src 侧压缩决策面;严重程度沿用原 issue triage —— 排空前会话不可用 + 块只增不减失控类)。

审核结论:可合并(待新 head 的主 CI 转绿)。 我在 PR 分支上推了 2 个 commit:

  1. 7ce9fc1b2 —— 原 commit rebase 到当前 master(c87185a05 / v0.1.204),干净 rebase(base 之后 master 的变更不触碰 preflight);
  2. 91b2da97d —— review 发现、顺手修掉(独立标注 commit):digestLabelCategory 检查 label.startsWith("tool-result"),但 entry builder 实际产出的是 tool result <verb>(空格分隔),该分支是死代码——工具流量为主的 span(# #2383 Structured digest produces "zero-conclusion" compression blocks under extreme overflow: one block = one messag | # #2383 结构化 digest 在极端溢出下产出「零结论」压缩块:一块 = 一条消息一行、每请求只折一块,87 块常驻 22.9% 窗口(DSH · deepseek-flash · v0.1.201/0.1.202) #4224 语料 ~100% tool traffic)里每个 "tool result bash" 都单独计一类,Structure 行类别翻倍、信息密度减半。现 call/result 合并到同一动词(89 calls + 89 results → 178×bash),并加了钉死该行为的测试。

本地定向验证(rebase 后 head):typecheck clean、build OK、tests/preflight-emergency-fold.test.ts + tests/issue1987-preflight-baseline-anchor.test.ts + tests/context-overflow.test.ts 共 42/42 通过。全量回归以推送 head 上的远程 CI 为准——当前 11 个 workflow 中 10 个已绿(全部 e2e 套件、Build Artifact、Windows codex overlay、ci-image),主 CI test lane 仍在跑。

结构化八问

  1. 是什么问题:fix(#2383): deterministic emergency digest fold for unconvergent preflight overflow #2387 紧急 digest 快速路径(payload > 19.2×窗口时触发)的三个缺陷——每请求只折一个 range(现场 87 个请求才收敛)、≥132 条目的 span 丢失全部摘录(全有或全无)、digest 是纯索引零结论。
  2. 什么原因导致的:①串行 walk 继承了 LLM 路径的「一轮一 fold」上限——对付费摘要合理,对 CPU-only digest 纯属浪费;②fits() 按 [120→0→header-only] 三档全有或全无;③digest 当初按「占位符」设计,成为主视图后从未升级。
  3. 影响范围与严重程度:仅紧急路径(entryOvershoot > 19.2×)。受影响用户:payload 超窗口约 19 倍以上的会话(如 dsh fork deepseek-flash v4.1、87 块驻留 22.9% 窗口现场)——排空前基本不可用,且留下驻留的零结论块。非紧急用户零影响。p1 级。
  4. 怎么修复的:①emergencyFold 时 maxFoldsPerRound = Infinity,整轮 walk 一次排空(EMERGENCY_ROUND_CAP=512 仍封顶轮数);②动态逐行 head 预算 (maxSummary − baseLen − 4N)/N、下限 24 字符——代数验证过公式精确(实际长度 ≤ maxSummary−1,不会越界);③一行结构性结论 Structure: N×verb…,极端边界下优雅降级(先于 header 被丢弃)。外加我的 review 修复(call+result 合并计类)。
  5. 是否有回归问题:未发现。逐项审过的既有行为:
    • 非紧急 walk:字节等价(cap=1 ≡ 旧 ===0/>0 条件;mid-walk futility bail 有 !emergencyFold 守卫,未动);
    • 轮级 模型压缩输出是输入的数倍 #1841 futility gate:完整保留——真正无望的 payload 仍诚实 fail-fast(该 gate 判断「全部折完也补不上缺口」,跳过的只是 mid-walk bail,而每个紧急 fold 免费,跳过正确);
    • recent-zone 保护:未动(tier-2 ranges 仍只在 relax 后出现,protectedTools 硬排除不变);
    • 降级阶梯:单调超集——旧形态(120-head / header-only / padded marker)全部仍可到达;
    • digest 格式消费方:无任何代码解析 [deterministic digest…] 文本(仅测试用 startsWith/includes),既有已折叠块的 summary 不受影响;
    • 状态变更面:commitFold 走与单 fold 相同的 applyRanges(kernel 返回新 state 对象,入站 messages 数组不被改动),currentTokens/compressedRanges/failure 清除逻辑逐 fold 核对无误;
    • 新测试有牙:动态 trim 测试钉住 computed≈83 的实际路径(回退成全有或全无会挂);极端边界测试钉住含 Structure 行的完整降级链;我新增的测试钉住 result 合并。
  6. 是否破坏缓存:否。前缀缓存锚点未动;digest 字节只进入新块;system 头部字节稳定性不受影响;无重试/游标/去重键变化。
  7. 是否改了设计方向:无转向——DSH 分叉会话后触发大量 preflight overflow compress #2383 CPU-only deterministic digest 的设计保持,本 PR 是其质量补完。一个被接受的行为扩展(见下表披露):紧急轮会排空全部 viable ranges 而非达到目标即停(walk 中途不刷新 decisionTokens)——受 recent-zone 保护 + 全部可 decompress 兜底。
  8. 是否引入新配置:否。无 env、无 config 字段、无 CLI flag。

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

变更 旧 新 原因
单轮 fold 数(仅紧急路径) 1 全部 viable ranges CPU-only digest 零成本;87 请求才收敛就是被报告的缺陷
digest 格式 header + 逐条行 中间加 Structure: 行 零结论纯索引是被报告的缺陷;极端边界优雅降级
大 span 摘录 0(全有或全无) 空间允许时 ≥24 字符/行 ≥132 条目 span 丢光摘录是被报告的缺陷
Structure 计类(review 修复) result 单独计类(死代码分支) call+result 合并到同一动词 review 发现的死代码

非紧急路径:零行为变化。

遗留问题(不阻塞合并)

PR 正文已列的两个 known remaining issues 已转为可跟踪工作项 #4228(单一 issue 汇总两个同失败面子缺陷,带来源标记,标签 bug/scope/wiring/p3):①多活跃块下 shrink%/postCtx 日志记账少算节省量;②preflight 与 compress 工具层耗尽消息互相矛盾。两者均为既有缺陷(先于本 PR),多折叠使其更易暴露,修复不阻塞本 PR。

判定

可合并(等 91b2da97d 的主 CI 转绿即齐)。单模块范围(src/preflight.ts + 一个测试文件)、回归测试齐全、无 kernel/config/wire/持久化变更、diff 干净。合并动作归你:#4226

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 全绿确认:head 91b2da97d(rebase 到 v0.1.204 + review 修复 commit)上全部 11 个 workflow 通过,含主 CI 全量 test lane。审核结论维持:可合并,合并动作归你:#4226

ranxianglei pushed a commit that referenced this pull request Oct 23, 2026
Two diagnostic sub-defects from the #4226 multi-fold world, one failure domain
(the observation layer still assumed "one fold per round"):

SD1 — [acp-compress-obs] shrink%/postCtx undercounted savings. Preflight's
commitFold calls applyRanges once per range against the SAME stale ctx.messages,
so each line subtracted only its own fold from the full request view (#4224:
"shrink 0% ... postCtx≈14.5M"). Preflight now hands applyRanges its running
currentTokens as roundBefore; the obs nets this fold against it so each line
reports the live remainder. The model-tool lane (no roundBefore) keeps the #1911
same-space gross-over-view formula byte-identical. Token scale only — unknown-
baseline (char) sessions skip the baseline to avoid mixing scales. The corrected
V/Vp also feed the cache ledger (reporting surface only).

SD2 — the drained-offer stop signal asserted "the context is already at its
minimum", a global claim backed only by the prepare-time offer being exhausted
(#2404 pins it to the pre-fold offer, never a live recompute), so it contradicted
preflight's fresh viable-range count. Narrowed the wording to the local fact it
actually verifies; preflight still auto-compresses overflow.

Behavior changes (disclosed):
- preflight multi-fold [acp-compress-obs] lines now report running-baseline
  values tagged "(round)" instead of the stale full view (denominator was the
  full request view, now the running payload; postCtx now nets the re-entering
  summary). Single-call lanes unchanged.
- cache-ledger fold geometry V/Vp now use the running baseline in multi-fold
  rounds (was the stale full view) — reporting-only, no cache decision impact.
- model-facing stop-signal text changed (SD2); all lanes share stream.ts, so
  proxy/plugin stay consistent.

Regression tests: tests/compress-success-tail.test.ts (+3).
ranxianglei pushed a commit that referenced this pull request Oct 23, 2026
Two diagnostic sub-defects from the #4226 multi-fold world, one failure domain
(the observation layer still assumed "one fold per round"):

SD1 — [acp-compress-obs] shrink%/postCtx undercounted savings. Preflight's
commitFold calls applyRanges once per range against the SAME stale ctx.messages,
so each line subtracted only its own fold from the full request view (#4224:
"shrink 0% ... postCtx≈14.5M"). Preflight now hands applyRanges its running
currentTokens as roundBefore; the obs nets this fold against it so each line
reports the live remainder. The model-tool lane (no roundBefore) keeps the #1911
same-space gross-over-view formula byte-identical. Token scale only — unknown-
baseline (char) sessions skip the baseline to avoid mixing scales. The corrected
V/Vp also feed the cache ledger (reporting surface only).

SD2 — the drained-offer stop signal asserted "the context is already at its
minimum", a global claim backed only by the prepare-time offer being exhausted
(#2404 pins it to the pre-fold offer, never a live recompute), so it contradicted
preflight's fresh viable-range count. Narrowed the wording to the local fact it
actually verifies; preflight still auto-compresses overflow.

Behavior changes (disclosed):
- preflight multi-fold [acp-compress-obs] lines now report running-baseline
  values tagged "(round)" instead of the stale full view (denominator was the
  full request view, now the running payload; postCtx now nets the re-entering
  summary). Single-call lanes unchanged.
- cache-ledger fold geometry V/Vp now use the running baseline in multi-fold
  rounds (was the stale full view) — reporting-only, no cache decision impact.
- model-facing stop-signal text changed (SD2); all lanes share stream.ts, so
  proxy/plugin stay consistent.

Regression tests: tests/compress-success-tail.test.ts (+3).
@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

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

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

Labels

None yet

Projects

None yet

1 participant