Skip to content

[PR] fix(#4227): honest compression diagnostics — cumulative shrink/postCtx over all blocks, internal-lane receipts pinned to the round's own offer - #4229

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-22_4227-compression-observability
Oct 24, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-22_4227-compression-observability

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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

Closes #4227

查重: 无(按 shrink/postCtx/observability、acp-compress-obs、"No compressible ranges remain"/viable ranges 矛盾等关键词独立检索 open+closed issue/PR,无命中;#2383/#4224 管 digest 质量与收敛速度,本 PR 管诊断面准确性)

What

Two observability defects from the #4224 dsh-fork marathon (87 blocks), both verified against production log lines:

  1. shrink%/postCtx were this-fold meters printed as session meters. viewTokens is the raw resend view (includes messages already covered by earlier blocks); postCtx = viewTokens - tokensCompressed subtracted only THIS fold. With 86+ active blocks the line read shrink 0% (~68948/14565283 tok) + postCtx≈14.5M + ceiling ≥0% for a heavily compressed session.
  2. "102 viable ranges" vs "No compressible ranges remain" in the same session. Preflight internal-lane folds built their RewriteCtx WITHOUT lastNudge, so postCompressTail fell back to a live recompute judged on statusInputBaseline — the previous request's usage-grade input tokens (Status readers still trust estimate-grade failure baselines after #1846 #2029's low value for status surfaces). In an overflow marathon that baseline sits far below the window while the actual payload is 19x over → kernel sees no pressure → false stop signal on every fold, while the same round's walk logged 102 viable ranges. The relay lane already pins lastNudge: prepared.nudge (post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404); the internal lanes missed it.

How

  1. src/stream.ts: keep shrinkRatio exactly as-is where gates need one rewrite's worth (degenerate-fold gate, staged-compress note, lastCompress) and label it this-fold; add a cumulative figure over every active block; redefine postCtx as the RENDERED post-fold context (raw view minus the union of all active blocks' covered mass). Single-block sessions are byte-identical to the old values (union == this fold).
  2. src/preflight.ts: commitFold and the tier-recovery distill pass the round's own turn.nudge as lastNudge, pinning the receipt tail to the same offer/scope/moment the walk acted on. Side benefit: removes one full processTurn recompute per successful internal fold.

Behavior changes (old → new)

Tests

New tests/issue4227-compression-observability.test.ts:

  • multi-block fixture (pre-seeded active block + head fold): pins shrink 44% this-fold (~10000/22500) + cumulative 67% (~15000/22500) + postCtx≈7500 + ledger V=22500/Vp=7500 (old code: no cumulative figure, postCtx≈12500, Vp=12500);
  • single-block control: values byte-identical to the historical meter;
  • wiring-level repro through preflightCompress: actual payload ~20x window (emergency digest regime, zero model calls) vs a low usage-grade baseline, one seeded mid-history block splitting the history into two disjoint runs — asserts the first committed fold's receipt advertises the round's remaining offer instead of a false stop signal (old code: every receipt was a stop signal).

Targeted suites green locally (compress-observability, usage-observability, issue1839, compress-success-tail, preflight-emergency-fold, issue3646-tier-recovery-picker, issue2678-batch-fold, preflight-round-budget, issue1841-futility: 58/58) + typecheck + build. Full suite = remote CI on this head.

Note: independent of #4226 (digest quality/convergence) — different hunks in src/preflight.ts; if #4226 lands first, rebase takes the union trivially.

@ranxianglei ranxianglei changed the title fix(#4227): honest compression diagnostics — cumulative shrink/postCtx over all blocks, internal-lane receipts pinned to the round's own offer [PR] fix(#4227): honest compression diagnostics — cumulative shrink/postCtx over all blocks, internal-lane receipts pinned to the round's own offer Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-22_4227-compression-observability (ed4d3d8)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.5234-pr.4229.64ef990

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

Install instructions are refreshed on each push.

awork added 2 commits October 23, 2026 17:46
…rathons

Two observability defects observed live in the #4224 dsh-fork marathon
(87 blocks):

1. The [acp-compress-obs] line metered only the CURRENT fold against the raw
   resend view: with 86+ active blocks it printed "shrink 0%" /
   "postCtx=14.5M" / "ceiling >=0%" for a heavily compressed session.
   postCtx is now the RENDERED post-fold context (raw view minus the union of
   ALL active blocks' covered mass); the this-fold ratio keeps its name and
   semantics where gates need it (degenerate-fold gate, staged-compress note,
   lastCompress) and is explicitly labelled; a cumulative figure covers every
   active block. Single-block sessions stay byte-identical to the old values.
   Cache-ledger Vp follows the same rendered value (fallback clamp in
   decomposeSample when the fold's X anchor is absent).

2. Internal-lane (preflight) receipt tails judged "anything left?" on a live
   recompute fed by statusInputBaseline - the previous request's usage-grade
   input tokens - while the walk acted on THIS request's actual payload. In an
   overflow marathon the baseline sits far below the window while the payload
   is 19x over, so folds claimed "No compressible ranges remain" in the very
   round whose own walk logged "102 viable range(s)". commitFold and the
   tier-recovery distill now pass the round's own nudge decision as lastNudge,
   pinning the tail to the same offer the walk acted on (the #2404 discipline
   the relay lane already followed). Also removes one processTurn recompute per
   successful internal fold.

No wire change: proxy-mode preflight receipts reach operators via bili.log
only (those blocks carry no tool-call carrier); plugin/relay lanes untouched.
No config surface, env var, or kernel change.

Tests: tests/issue4227-compression-observability.test.ts pins both meters on a
pre-seeded multi-block fixture (incl. ledger V/Vp) and reproduces the mixed
scope at the preflightCompress wiring level (actual payload ~20x window vs a
low usage-grade baseline), asserting the first receipt advertises the round's
remaining offer instead of a false stop signal.
@ranxianglei
ranxianglei force-pushed the 2026-10-22_4227-compression-observability branch from 268c9fb to ed4d3d8 Compare October 23, 2026 09:50
@ranxianglei ranxianglei added bug Something isn't working p3 scope/ui labels Oct 23, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复(独立复核:按 shrink/postCtx/observability、"No compressible ranges remain"/viable ranges 两组关键词检索 open+closed issue/PR,均无命中;与 #2383/#4224 的边界一致——它们管 digest 质量与收敛速度,本 PR 管诊断面准确性。)

标签: bug / scope/ui / p3(与源 issue #4227 同缺陷族——压缩诊断面准确性;纯观测误导不阻塞功能)

审核结论:内容通过,新 head CI 绿后可合(人工合并)

独立重读了 diff、调用方与 kernel 侧消费点,不是照抄 PR 描述。关键核验:

方向关 —— 两个缺陷都真实存在且修法打到根因:① obs 计量结构上就是「原始重发视图 − 本次 fold」,看不见已有块的净节省,加 cumulative 视角 + 重定义 postCtx 是对症的;② 内部车道假停报的根因是 RewriteCtx 不带 lastNudge → receipt tail 退回 live recompute 且用 statusInputBaseline(上一请求的低值基线)当判定输入,而同一轮 walk 用的是本请求真实 payload——把本轮自己的 nudge offer 钉进去让两层看同一份数据,矛盾结构性消失,不是措辞补丁。

回归清点(逐项审过既有行为):

  • 全仓只有 3 处构造 RewriteCtx:src/server/relay.ts:1813(post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 早已钉 prepared.nudge)、src/preflight.ts commitFold 与 tier-recovery distill(本 PR 补齐)。没有漏掉的内部车道。
  • 钉住的是 walk 真正行动过的那份 offer:round loop 每轮重跑 processTurn(src/preflight.ts:1880),walk 的候选就取自同一个 turn.nudge.compressibleRanges(:1943),commitFold 闭包捕获当前轮的 turn——同源/同 scope/同时刻成立。tier-recovery 侧 measureEst() 在 distill 循环前必跑一次、每次 distill 后刷新,fold 时 measuredNudge 不会悬空。
  • lastCompress.shrinkRatio、degenerate-fold 门(≥0.8)、staged-compress 注记语义未动(仍是单次 rewrite 语义);postCompressTail 两分支合同未动,只是内部车道的输入源从 live-recompute 换成 pinned offer——与 relay 车道既有行为一致。
  • 出站 wire 零变化:obs 行只走 ctx.log(bili.log);proxy 模式 preflight receipt 本就只进日志(那些块没有 tool-call carrier);plugin/relay 车道不触碰。
  • 既有断言兼容性:tests/compress-observability.test.ts 钉的 "shrink 62%"、"~10000/16250"、"postCtx≈6250"、"postCtx≈0" 子串在新格式下全部命中(本地跑绿验证)。
  • cache-ledger:V 不变;Vp 变渲染值。核到 kernel/src/cache-report.ts:109 x = f.firstFoldStartTokens ?? f.viewAfter ?? 0——Vp 只在 X 锚缺失时作 fallback 分歧点,影响面与 PR 披露一致(另 Web UI fold-economics 的 V′ 展示同值,属同一诊断面)。

测试有效性:三个测试都有牙——多块 fixture 钉死精确计量(shrink 44% this-fold + cumulative 67% + postCtx≈7500 + ledger V=22500/Vp=7500,旧代码产不出这组数);单块对照钉字节级不变;接线级复现走真 preflightCompress(payload ≈20×窗口、usage 基线远低于窗口、端口 9 拒接保证零模型计费、种子块把历史劈成两段不相交 run),断言首个 receipt 广告本轮剩余 offer 而非假停报。若原 bug 复发,第一个和第三个测试都会红。

diff 整洁度 / 代码整洁:3 文件单提交,无无关改动、无 lockfile/version 噪音。发现两处注释已与代码事实不符(本 PR 自身造成的过时):src/stream.ts 的 RewriteCtx.lastNudge 文档「Absent on internal lanes (preflight)」和 postCompressTail else 分支「Internal lanes … capture no prepare-time nudge」——内部车道现在都带 lastNudge 了。已顺手修掉(见下)。

我做的动作(均已工具核实)

  1. rebase 到当前 master:PR 落地时基于 c87185a05,审核时 master 已前进且恰好动过同一对热文件([Bug][anthropic] fold summary rendered as user right after a mid-conversation system message → 400 "role 'system' must precede an 'assistant' message" (0.1.204, since #3992) #4292 kernel emission、[PR] Refused compress exchanges become foldable like failed ones, no longer permanently stuck on the wire | 被拒绝的压缩调用像失败的一样可折叠,不再永久占着上下文 #4310 refused-compress-unprotect 等)——按 §7.2 陈旧基线纪律,把分支 rebase 到 b2ad1b5de,干净无冲突。
  2. 注释修正:独立标注 commit ed4d3d874 docs(stream): refresh lastNudge comments superseded by #4227 internal-lane pinning(仅两处注释,零运行时影响)。
  3. push(force-with-lease,非 master 分支):远端 head 现为 ed4d3d874,API 复核确认,mergeable: true 无冲突。
  4. 本地定向验证(新 head):typecheck 干净;54/54 绿(issue4227 新文件 + compress-observability + usage-observability + issue1839 + compress-success-tail + preflight-emergency-fold + issue3646-tier-recovery-picker + issue2678-batch-fold + preflight-round-budget + issue1841-futility)。
  5. CI:旧 head 268c9fbc0 全绿(test 分片 ubuntu/windows × node 22/24 + static-gates + 各 guard + mysql-contract + lifecycle-ledger-guard + docs-coverage + version-guard + test-import-graph;e2e 系按设计 skip)。rebase+注释修正后 CI 正在新 head 上重跑(mergeable_state: blocked = checks pending)。

结构化八问

  1. 是什么问题:多活跃块溢出马拉松会话里压缩诊断日志自相矛盾——86+ 块时显示「shrink 0%、postCtx≈14.5M、ceiling ≥0%」像压缩没在工作;同会话 preflight 报「102 viable ranges」而 kernel receipt 报「No compressible ranges remain」。
  2. 什么原因导致的:① obs 计量定义就是「原始视图 − 本次 fold 节省」,结构上看不见已有块的净节省;② preflight 两个内部车道构造 ctx 时不带 lastNudge,receipt tail 退回 live recompute,该 recompute 拿上一请求的 usage 级低值基线当判定输入,而同一轮 walk 拿的是本请求真实 payload(19× 窗口)——两层用不同基线回答同一个问题。
  3. 影响范围与严重程度:proxy 模式所有多活跃块会话,溢出马拉松最典型;纯日志面误导、不阻塞功能 → p3;实际代价是延长 # #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 类问题的诊断时间。
  4. 怎么修复的:① this-fold 计量保留并显式标注(门和 lastCompress 需要单次 rewrite 语义),新增 cumulative 视角;postCtx 改为渲染后上下文(原始视图 − 全部活跃块覆盖并集),单块会话字节级不变。② commitFold 与 tier-recovery distill 传入本轮自己的 nudge offer——tail 从此钉住 walk 刚行动过的同一份数据(补齐 post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 纪律到内部车道)。
  5. 是否有回归问题:无。lastCompress/degenerate 门/staged 注记语义未动;tail 两分支合同未动(输入源对齐 relay 车道既有行为);出站 wire 零变化;无配置面/持久化/kernel 变更;既有 obs 断言在新格式下全部保持命中(本地跑绿)。
  6. 是否破坏缓存:否。前缀缓存/重试/去重零改动;cache-ledger Vp 在多块场景变为真实渲染值(更准而非失效),且只在 X 锚缺失时才参与 decomposeSample 的分歧点计算;附带每次内部 fold 省一次 processTurn recompute。
  7. 是否改了设计方向:否。是把内部车道对齐到既有 post-compress tail immediately re-advertises newly-released ranges -> chained folds at zero growth -> upstream prefix-cache misses #2404 纪律,无架构/边界/数据流转向。
  8. 是否引入了新的配置:无。

行为变更披露(旧→新):obs 行新增 this-fold 标签与 · cumulative Y% (~D/B tok) 子句(既有可 grep 子串全部保留);postCtx 旧=原始视图−本次fold → 新=原始视图−全部活跃块覆盖并集(单块相同,多块从 resend 质量降到真实渲染值);cache ceiling % 从恒 ≥0% 变为有意义下界;内部车道 receipt 从假停报变为本轮剩余 offer 枚举(仅 bili.log,合法停报照常);Web UI fold-economics 的 V′ 跟随渲染值。

注意:#4226(emergency digest 质量/收敛)仍在途且碰 src/preflight.ts 相邻 hunk——若它先合入,本 PR 需一次平凡 rebase(不同 hunk,未发现语义交互)。

判定:内容审核通过;等 ed4d3d874 的 CI 全绿即可合(人工合并)。CI 结果出来我再跟一条。

@ranxianglei
ranxianglei merged commit 1f2886d into master Oct 24, 2026
47 of 72 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.803-master.1f2886d (rolling master tag).

npm install -g billion-context@0.0.803-master.1f2886d  # 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

bug Something isn't working p3 scope/ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EN | Compression observability: shrink%/postCtx misleading with many active blocks + "viable ranges" vs "no ranges remain" contradiction

1 participant