Skip to content

[PR] fix(preflight): converge view-vs-rebuild fit judgment at the window edge (#5974) - #5983

Merged
ranxianglei merged 3 commits into
masterfrom
2026-11-09_preflight-view-reconstruction-divergence
Nov 10, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-11-09_preflight-view-reconstruction-divergence

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#4543 residual ① (carved out of the PR #5932/#5973 scope ruling — fold-reconcile domain, not gate metering): at the window edge the preflight walk judged fit on its own BLIND view (processTurn on the client re-send, the same array every round) while the OUTBOUND reconstruction measured over the window. Fold-reconcile switch-pass id churn re-enters unfolded mass the two pipelines disagree about, so each turn under-folded by exactly the divergence — the ~5k-tokens/round crawl from the issue title ("view meets target but outbound reconstruction exceeds window").

How

Issue expectation clause ②: force the fit judgment through the post-reconstruction single source of truth.

  • When pass 1 folds something, exits early-fit (no failure verdict) and leaves foldable ranges behind, preflightCompressIfNeeded now runs the full-pipeline rebuild ONCE and measures it with the same meter family the system already trusts (estimateCoreMessages + wire overhead + image reserve + the session's k̂ calibration).
  • If the rebuild measures ≥ the window AND exceeds the pass-1 view by ≥ max(10K tok, 2% of window) (noise floor — estimator jitter must not trigger a corrective pass), ONE bounded corrective second pass runs with that measured divergence as its exit bar (viewDeltaCorrection on PreflightDeps). Every fit judgment inside that pass — exit comparator, futility deficit, both relax triggers/resets, tier-distillation funnel, final fitsWindow — runs on the corrected scale, so the walk keeps folding until the RECONSTRUCTION is predicted to fit, or says honestly that it cannot.
  • Safety rails: unknown-baseline sessions keep their legacy upper-bound regime (fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553); absent/zero correction stays byte-identical to the legacy walk (pinned field-for-field); when the corrective pass folds nothing, the probe rebuild IS the final rebuild — zero extra prepare passes in the common case; the client hold spans both passes so the client sees one continuous "compressing".

Behavior change (old → new)

NEW capability: a bounded corrective second preflight pass can run after an early-fit exit when the fresh rebuild measures over the window by ≥ max(10K tok, 2% window). Previously such a turn forwarded once for upstream arbitration (#1839 arm) regardless of how far over the rebuild was — the crawl. Outcome contracts unchanged: the #1839 forward-once arm, the #3146/#4185 post-compress recheck gate and the relay egress fuse (measured tiers from #5932) all keep their existing behavior. No config surface change: viewDeltaCorrection is an internal PreflightDeps field set only by the corrective orchestration — no new config key, env var, or CLI flag.

Tests

New tests/issue5974-preflight-view-divergence.test.ts, both directions per #3617:

  1. legacy baseline — no correction: early-fit exit on the blind view, pool left behind;
  2. positive — divergence larger than the blind-fit residual: walk keeps folding until the CORRECTED scale fits (strictly more ranges than case 1, corrected total under the window);
  3. negative bound — divergence no folding can absorb: never yields a declared fit (the 模型压缩输出是输入的数倍 #1841 futility discipline runs on the corrected scale too and may bail early);
  4. safe default — explicit viewDeltaCorrection: 0 reproduces case 1 field-for-field;
  5. full-server common path — a one-pass fold-to-fit still forwards EXACTLY ONCE with the probe/corrective plumbing in place (divergence below noise floor → no corrective pass, probe reused).

Targeted local runs green: the new file plus issue1841 (futility), issue1933 (calibration), issue4185 (forward arms), issue3918 (progress verdict), issue2952 (tier recovery), issue4079 (egress fuse) — 28/28 adjacent tests pass; typecheck clean. Full suite rides CI.

Closes #5974

@ranxianglei ranxianglei added bug Something isn't working p1 labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-09_preflight-view-reconstruction-divergence (691ab4a)

Latest build — install this exact version

npm install -g billion-context@0.0.8769-pr.5983.1152e13

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
691ab4a billion-context@0.0.8769-pr.5983.1152e13 build
0372399 billion-context@0.0.8758-pr.5983.ba4edca build
76d0de1 billion-context@0.0.8703-pr.5983.7fcb443 build
f41de29 billion-context@0.0.8700-pr.5983.ce951ec build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5983.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(preflight): converge view-vs-rebuild fit judgment at the window edge (#5974) [PR] fix(preflight): converge view-vs-rebuild fit judgment at the window edge (#5974) Nov 8, 2026
@ranxianglei

ranxianglei commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重 (dedup): not a duplicate. Checked all open [PR] rows on the mirror plus GitHub preflight/reconstruction searches — no other open PR targets view-vs-rebuild fit convergence. Same-symptom relatives with DIFFERENT mechanisms (linked, not merged): #5899 (overflow-arm evidence-floor disarm + anthropic-lane egress clamp; disjoint files), #4294/#4938/#4771 (opposite direction — preventing over-folding when already fitting).

标签: bug + dsh + scope/kernel + p1 — defect fix in the compression engine core, dsh evidence lane per source issue #5974, p1 because window-edge sessions become unusable. The upstream PR already carries bug+p1; the mirror's label endpoint returned "not implemented" in this environment, so mirror-side labels could not be applied — flagging for ops.

Review scope. Full diff read (3 files, +425/−51), every downstream outcome arm traced, targeted suites run locally, CI checked on head f41de297adbf.

Mechanism (as implemented). After pass 1 folds and exits early-fit with ranges left behind, preflightCompressIfNeeded runs the full-pipeline rebuild ONCE as a probe and measures it with the SAME meter family as the final gate (estimateCoreMessages + wire overhead + image reserve + k̂ calibration — the probe formula is byte-identical to the final-gate rebuiltCalibrated, so the probe predicts exactly what the gate computes). If the probe measures ≥ window AND exceeds the pass-1 blind view by ≥ max(10K tok, 2% of window) (noise floor — estimator jitter must not trigger a corrective pass), ONE bounded corrective pass runs with the measured divergence as its exit bar via viewDeltaCorrection. Every fit judgment inside that pass — exit comparator, futility deficit, both relax triggers/resets, tier-distillation funnel, final fitsWindow — runs on the corrected scale, so the walk keeps folding until the RECONSTRUCTION is predicted to fit, or says honestly that it cannot.

Regression audit (existing behaviors touched, item by item):

Test quality. Both directions present per #3617; assertions sharp except one flaw: case 3's second assertion was tautological (mathematically guaranteed by the preceding fitsWindow === false pin — zero teeth). Fixed directly on the PR branch: replaced with a failure-kind pin (failure === undefined || kind === "exhausted" — in that fixture any failure MUST be honest exhaustion, so a future misclassification as relay failure would be caught), commit 76d0de19e6, locally re-run 5/5 green.

Local verification. Targeted runs: new file + #1841 (futility) + #1933 (calibration) + #4185 (forward arms) + #3918 (progress verdict) + #2952 (tier recovery) + #4079 (egress fuse) = 33/33 pass; typecheck clean. Full suite rides CI.

CI (head f41de297adbf, checked 2026-11-09 03:17 UTC). No failing checks: full test matrix (ubuntu/windows × node 22/24, all shards), static-gates, mysql-contract, and every guard lane (kernel-guard, config-surface-guard, architecture-docs, docs-sync/docs-coverage, lock-sync, version-guard, pi-subagents-guard, lane-guard, lifecycle-ledger-guard, unused-exports, test-import-graph, plan, e2e gate) report success; the cancelled rows belong to a superseded workflow invocation. The updated head 76d0de19e6 (test-only pin) awaits its run — expected identical.

Behavior change disclosure (old → new). NEW bounded capability: after an early-fit exit, one corrective preflight pass can run when the fresh rebuild measures over the window by ≥ max(10K tok, 2% of window). Previously such a turn forwarded once for upstream arbitration (#1839 arm) regardless of how far over the rebuild was — the ~5k-tokens/round crawl. Outcome contracts (#1839 arm, #3146/#4185 gate, egress fuse) all keep their existing behavior. No config surface change: viewDeltaCorrection is an internal PreflightDeps field set only by the corrective orchestration — no new config key, env var, or CLI flag.


结构化八问(中文)

  1. 是什么问题:窗口边缘的会话每轮压缩都"视图达标、出站重建仍超窗"——preflight 行走用盲视图判 fit,出站却按重建后的真实体量计量,两条流水线对同一批未折叠质量各执一词,每轮恰好少折那个差值(~5k token/轮的爬升)。
  2. 什么原因导致的:根本原因是 fit 判定与出站计量走了不同流水线、不同米制:行走的退出条件读的是客户端重发数组(每轮同一个),而实际出站走重建产物;fold-reconcile 切换通道时 id 抖动不断把未折叠质量重新送进两条流水线的分歧区,行走每轮都"以为达标"提前退出。
  3. 影响范围与严重程度:受影响面 = 体量贴近/达到窗口边的长会话(源 issue 的 dsh 大会话即此场景);触发条件 = 会话处于窗口边缘且视图/重建分歧超过噪声底。严重度 p1:特定条件下不可用——每轮只推进 ~5k,最终整轮被拒。
  4. 怎么修复的:pass 1 折叠后若早退且池子有剩余,先跑一次全流水线重建当探针,用与终局门同一米制族计量(公式与终局门逐字一致);探针 ≥ 窗口且分歧 ≥ max(10K, 2%×窗口) 时跑一次有界纠正 pass,以实测分歧为退出基准——该 pass 内所有 fit 判定改在纠正尺度上运行,折到"预测重建能装下"或诚实声明装不下为止。安全栏:unknown-baseline 会话保持旧上限制;缺省/零纠正与旧行走字节等价(字段级钉死);纠正 pass 没折到东西时探针就是终局重建,常见路径零额外 prepare;客户端 hold 跨两个 pass。
  5. 是否有回归问题:逐项审过——旧无纠正路径(字节等价,case 4 字段级钉死);fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 上限制(整体排除出探针);任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839 forward-once 臂(条件逐字未动,仅其前折叠量变化);[Bug] 新会话(无 usage 基线)preflight 把字符数当 token——折叠其实成功(2263796→1111212)却 fail-fast 502,上游实际只计费 540828 #3146/413 Deadlock: When an authenticated session exceeds the reservation window with zero collapsibles, the #3146 forwarding | 413 死锁:带身份会话超预留窗口且零可折叠时,#3146 转发门因 anonymous 条件不触发,会话从首条消息起永久不可用 #4185 复检门 + measured doom 分层 + 出口熔断(路径未触碰);stats.requests 记账(四分支全部验证);growth 模式(探针只在重建 ≥ 真实窗口时触发,不会朝 lean 目标多折);两层 limit 教义 [Bug][dsh native] preflight fold target sits ABOVE the engine's own denominator (1048576 vs 1000000) and the upstream-stated window from a 400 never feeds it — 'deficit 0' forwards an over-window payload → context_length_exceeded kills the turn #3450/fix: overflow-arm stored above the headroom-reserved judging limit → unbounded CONTEXT_WINDOW_EXCEEDED loop #3738(既有架构,未变)。未发现回归。
  6. 是否破坏缓存:不涉及——前缀缓存锚点、prefix-affinity、session-order 均未触碰;唯一新增成本是纠正 pass 的 summary 调用(有界至一个 pass),属修复本身的必要开销。
  7. 是否改了设计方向:没有转向——正是落地源 issue 期望条款②(fit 判定强制过重建后单一事实源)。机制边界留在 preflight 编排层(PreflightDeps 内部字段),不跨模块边界,不新增配置面。
  8. 是否引入了新的配置:无。viewDeltaCorrection 为内部字段,仅由纠正编排赋值;无新 config key / env var / CLI flag。

判定:review 通过,无阻塞项。代码与行为均符合预期条款②;CI 在旧头 f41de297adbf 全绿,新头 76d0de19e6(仅测试断言钉紧)等 CI 复跑确认后由人工合并即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

ci-check added 2 commits November 9, 2026 13:20
… view and rebuild diverge (#5974)

blind processTurn view while the outbound reconstruction measured over the
window (fold-reconcile switch-pass id churn re-enters unfolded mass the two
pipelines disagree about) — every turn under-folded by exactly the
divergence, the ~5k tokens/round crawl in the issue title.

When a fresh full-pipeline rebuild measures over the window by at least
max(10K tok, 2% of window), run ONE bounded corrective second pass seeded
with the measured divergence (viewDeltaCorrection): every fit judgment in
that pass — exit bar, futility deficit, relax triggers, tier-distillation
funnel, final fitsWindow — runs on the corrected scale. Absent/zero
correction stays byte-identical to the legacy walk; when no corrective fold
happens the probe rebuild is reused as the final rebuild (no extra prepare).
The #1839 forward-once arm, the #3146/#4185 post-compress gate and the relay
egress fuse keep their contracts unchanged.
@ranxianglei
ranxianglei force-pushed the 2026-11-09_preflight-view-reconstruction-divergence branch from 76d0de1 to 0372399 Compare November 9, 2026 05:42
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决,已 rebase 到当前 master 并推送。

冲突点(仅一处文本冲突):master 自本 PR base(848f59b)前进了 78 个提交到 5c3c268。唯一冲突在 src/server.ts 的 import 行——master 的 #5000 给 preflight.js import 加了 estimateRawBodyBreakdown / type RawBodyBreakdown,本 PR 加了 type PreflightDeps;按双方意图取并集解决,无其他冲突区。

与 master 新变更的语义交互核查(两边都动了同一个函数,逐一确认过):

rebase 后验证:typecheck 干净;定向 7 套(issue5974 + issue1841/1933/4185/3918/2952/4079)33/33 通过。全量回归交给远端 CI。

当前状态(实时核对):新 head = 0372399(rebase 重写了原 f41de29 + 76d0de1 两个提交,内容不变);PR mergeable=true,mergeable_state=blocked —— 即冲突已清,仅剩新 head 的 CI 在跑。看到已加「马上合并」标签:CI 绿后即可合。


中文八问

  1. 是什么问题:PR [PR] fix(preflight): converge view-vs-rebuild fit judgment at the window edge (#5974) #5983 分支落后 master 78 个提交导致与目标分支产生合并冲突(owner 报「冲突」)。
  2. 什么原因导致的:PR 创建后 master 持续合入([Bug][dsh][0.1.208] Kill switch / egress fuse only measures message.text: a session with 26,903 messages and only 1.44 M | [Bug][dsh][0.1.208] 判死/egress fuse 只量 message.text:26,903 条消息、core text 仅 1.44 MiB 的会话绕过 fuse 发出 55.2 MiB 请求体,被上游 413 拒收(ModelArts.… #5000、[PR] Put each compression summary at its fold point; the old slot keeps a pointer instead of a full compress command (compressAtFoldPoint v2) #5949、bili-native (dsh): empty intercept slot sends a 6.7 MiB / 2.1M-token body direct — the 8 MiB byte cap does not catch it, provider answers 400 CONTEXT_WINDOW_EXCEEDED #5996、[PR] fix(#5951): replay a stream cut that lands after reasoning-only output #5956 等),其中 [Bug][dsh][0.1.208] Kill switch / egress fuse only measures message.text: a session with 26,903 messages and only 1.44 M | [Bug][dsh][0.1.208] 判死/egress fuse 只量 message.text:26,903 条消息、core text 仅 1.44 MiB 的会话绕过 fuse 发出 55.2 MiB 请求体,被上游 413 拒收(ModelArts.… #5000 恰好改了本 PR 同一 import 行,产生文本冲突。
  3. 影响范围与严重程度:仅本 PR 分支不可合并;不影响任何线上行为。严重度:流程阻塞级(不修则无法合并)。
  4. 怎么修复的:rebase 到当前 master(5c3c268),唯一冲突(import 行)按双方意图取并集解决;force-with-lease 推送 PR 分支。
  5. 是否有回归问题:无。逐项核对了 master 侧同函数变更与本 PR 的交互:COUNT gate 在更早阶段早退、互不相交;函数改名不涉及本 PR 引用路径;kernel v2 变更下定向测试全绿。既有行为契约(任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839 单次转发臂、[Bug] 新会话(无 usage 基线)preflight 把字符数当 token——折叠其实成功(2263796→1111212)却 fail-fast 502,上游实际只计费 540828 #3146/413 Deadlock: When an authenticated session exceeds the reservation window with zero collapsibles, the #3146 forwarding | 413 死锁:带身份会话超预留窗口且零可折叠时,#3146 转发门因 anonymous 条件不触发,会话从首条消息起永久不可用 #4185 复核门、fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 上界制式)均不受 rebase 影响。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及(本 PR 本就无配置面变更;master 侧新增的 BILI_MAX_MESSAGES 属 [Bug][dsh][0.1.208] Kill switch / egress fuse only measures message.text: a session with 26,903 messages and only 1.44 M | [Bug][dsh][0.1.208] 判死/egress fuse 只量 message.text:26,903 条消息、core text 仅 1.44 MiB 的会话绕过 fuse 发出 55.2 MiB 请求体,被上游 413 拒收(ModelArts.… #5000,非本 PR)。

收工判定:冲突已解、验证完成,无需我侧进一步动作——等新 head 0372399 的 CI 转绿即可由你合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复——本任务是既有 PR 的冲突修复车道,无平行立项;但发现一次并发同款 rebase(见下)。

结论先行:冲突已解决并验证通过,本次未再 push——远程分支上已存在一个与我的解法逐字节相同的 rebase(并发运行先推),按 push 纪律不抢分支、不覆盖正在跑的 CI。

本轮做了什么:

  1. 定位冲突:PR 分支 2026-11-09_preflight-view-reconstruction-divergence(旧头 76d0de19e6)对 master 为 dirty。rebase 到当前 master(5c3c2688f8)时仅一处文本冲突:src/server.ts 的 ./preflight.js import 行——master 侧([PR] Hard-block session history over-limit along real dimensions: message-count gate + 32MiB ingestion cost band + fatal erro | 会话历史超限按真实维度拦死:条数闸 + 32MiB 摄入成本带 + 判死信息点名超重字段 (#5000 #5794 #5885) #5973 等)新增了 estimateRawBodyBreakdown + type RawBodyBreakdown,PR 侧新增 type PreflightDeps,两边改了同一行。src/preflight.ts 自动合并干净(+27/−13,与 PR 自身 hunk 数一致),测试文件无冲突。
  2. 解决方式:import 行取两侧并集;逐一验证三个符号在合并后的 src/preflight.ts 均有导出(PreflightDeps :231、RawBodyBreakdown :481、estimateRawBodyBreakdown :489),且 estimateRawBodyBreakdown 被 master 代码真实使用于 src/server.ts:3788 和 :4492——不是死导入。
  3. 本地验证(rebase 后):npm run typecheck 干净;定向测试 33/33 全绿(issue5974 新文件 5 cases + issue1841 futility + issue1933 calibration + issue4185 forward arms + issue3918 progress verdict + issue2952 tier recovery + issue4079 egress fuse);净 diff 与原 PR 逐字节同范围(+430/−51,3 files)——零额外语义改动。
  4. push 前复查(fetch origin)发现远程头已从 76d0de19e6 移到 0372399e:另一并发运行已把同样的两个 commit rebase 到同一 master 头上推上去了。git diff 我的 rebase 树 vs 远程头 = 空(逐字节相同)。此时 force-push 只会把 ref 换成等价 SHA、孤儿化正在跑的 CI run,纯消耗——故停手不推。

实时状态(镜像缓存,05:45Z 抓取,非记忆):head 0372399e,mergeable_state = blocked(= 等必过检查,不再是 dirty → 冲突已消);30 项检查 0 failed / 12 pending(test 矩阵分片 + windows static-gates 在跑)/ 其余全绿或 skip(mysql-contract、static-gates ubuntu-24、全部 e2e 车道)。


结构化八问(中文)

  1. 是什么问题:上游 PR [PR] fix(preflight): converge view-vs-rebuild fit judgment at the window edge (#5974) #5983(preflight view-vs-rebuild fit 收敛修复)与 master 合并冲突(dirty),无法进入合并流程。
  2. 什么原因导致的:PR 自 merge-base 848f59b996 拉出后,master 陆续合入 [PR] Hard-block session history over-limit along real dimensions: message-count gate + 32MiB ingestion cost band + fatal erro | 会话历史超限按真实维度拦死:条数闸 + 32MiB 摄入成本带 + 判死信息点名超重字段 (#5000 #5794 #5885) #5973 等变更,在同一 preflight.js import 行新增了导出引用;PR 也改了这一行加 PreflightDeps——双方编辑同一行的文本级冲突,无语义分歧。
  3. 影响范围与严重程度:只挡本 PR 自身的可合并性,不影响任何运行时行为或用户;属流程阻塞,严重度低(修完即通)。
  4. 怎么修复的:两 commit rebase 到最新 master,唯一冲突按「两侧并集」解 import(验证三符号均存在且新符号有真实使用点);随后发现并发运行已推送逐字节相同的 rebase 结果,按 push 纪律(不抢分支、fetch 后先集成远程头)不再覆盖推送,改为独立复核该头。
  5. 是否有回归问题:无。净 diff 与原 PR 完全同范围(typecheck 干净 + 33/33 定向测试绿);未引入任何超出原 PR 的改动;高危模式逐项过——无阈值/时序/输出格式漂移,无 fail-fast 变吞错。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

判定:冲突解决完成且经独立验证(类型检查 + 定向测试 + 树同构比对),CI 在 0372399e 上 0 红、矩阵跑完即可由人工合并;本轮无需任何决策项。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

状态补充(实时核对,不重复前两条已说过的修复细节):

  • 冲突修复已完成且唯一:本会话 rebase 到 master 5c3c2688f8、解掉唯一 import 行冲突并推送新 head 0372399e;并发唤醒的 ci-engineer-r1 车道独立走到同一结论,确认远程分支上已有逐字节相同的 rebase,未二次 push,无分支争抢、无覆盖正在跑的 CI。
  • 当前 PR 状态(GitHub 实时):mergeable=true(冲突已清),mergeable_state=blocked —— 仅剩新 head 0372399e 的 CI 在跑,目前 0 失败。
  • 收工判定:我侧无待办。CI 转绿后由你合并即可(合并权在你)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

…e too

The pre-walk #1841 gate measures its deficit as payloadEstimate +
viewDeltaCorrection - limit, but the mid-walk bail kept the uncorrected
payloadEstimate - limit while its comment claimed parity with the
pre-walk gate. In a corrective pass (non-zero viewDeltaCorrection) the
bail therefore understated the gap and could burn summarization calls
on ranges that cannot close the true window gap. Pass 1 (correction 0)
is byte-identical; pass 2 now matches the declared invariant that every
fit judgment in that pass runs on the corrected scale.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Verdict: APPROVE — independent end-to-end review of head 0372399e00, rebased onto master 5c3c2688f8 (= current master tip, no base drift). The fix does what source issue #5974 expectation clause ② asks: fit judgment is forced through the post-reconstruction single source of truth. One non-blocking finding was fixed on the spot (below). No kernel/ change, no kernel-change declaration → outside the human-only tier.

Direction (issue audit). #5974: at the window edge the preflight walk judges fit on the blind client view while egress is metered on the rebuilt body — two pipelines, systematic positive delta, ~5k tokens/round crawl. The PR implements clause ② as a bounded probe → at most one corrective pass, without touching either pipeline's own accounting. It fixes the judgment at the decision point — not by filtering payloads or fudging meters. Correct layer.

Mechanism verified (independent re-read at src/server.ts:4296–4335 / 4355–4400 and every preflight.ts correction site):

  • Probe fires only when compressedRanges>0 && !unknownBaseline && failure===undefined && rangesRemaining>0 — pass 1 exited early-fit with live foldable mass left (rangesRemaining = viable foldable ranges at walk end, src/preflight.ts:2312). Unknown-baseline sessions (#553 upper-bound regime) stay fully excluded.
  • Probe formula ≡ final-gate formula, byte-identical structure (estimateCoreMessages(msgs)+overheadEstimate → applyEstimateCalibration(…, kFactor, kOrigin, currentOrigin) + imageTokens) — the probe predicts exactly what the measured gate computes. Inner gate adds a noise floor divergence >= max(10_000, round(limit*0.02)): estimator jitter cannot trigger a corrective pass.
  • Exactly ONE corrective pass; viewDeltaCorrection clamped ≥ 0; every fit site inside the pass runs on the corrected scale (textTarget init + both relax resets, tier-distill funnel/fit-break/cap/recovered/overBy, pre-walk futility deficit, both relax triggers, futility-bail escape, final fitsWindow). result.payloadEstimate itself stays the honest raw blind-view measure — downstream arms read an un-inflated number.
  • Egress still goes through the normal rebuild + measured gate (rebuiltCalibrated < limit for known-baseline sessions, src/server.ts:4395): the corrective pass works by folding MORE until the reconstruction actually fits — the gate itself is never loosened.
  • Client hold spans both passes (probe + corrective sit inside the existing try/finally hold, src/server.ts:4298–4336) — one continuous "compressing", no new deadline exposure.
  • Stats accounting balances in all four branches: every prepare entry does ++session.stats.requests (src/server/prepare-openai.ts:80, prepare-responses.ts:71/744, prepare-google.ts:88, prepare-anthropic.ts:79); the probe decrements immediately (src/server.ts:4303), a fresh rebuild decrements at its own site (src/server.ts:4362), probe-reuse adds zero. Net +1 per client request, identical to legacy. The common case (folded, no divergence over the noise floor) adds ZERO extra prepares — the probe replaces the rebuild the legacy path always did after a folding pass.

Regression audit (existing behaviors touched, item by item):

  • Legacy zero-correction walk — byte-identical (every site reduces to the old expression at correction=0); pinned field-for-field by test case 4.
  • #1839 forward-once arm (src/server.ts:4505) — condition byte-unchanged; the corrective pass only changes how much folds before the arm evaluates, and its payloadEstimate operand is ≤ pass-1's — strictly less-over views reach the arm. Safe direction.
  • #3146/#4185 post-compress recheck gate + measured doom tiers — untouched; the lastInputTokens write still happens before the arms evaluate in both old and new code, so the #4185 noUpstreamEvidence population is unchanged.
  • Relay egress fuse (#5932 measured tiers, relay.ts) — not touched.
  • Two-tier limit doctrine (#3450/#3738) and growth mode — unchanged; the probe triggers against the same server-side wall the final gate uses, and only when the rebuild measures ≥ that wall — no lean-target over-folding.
  • lastInputTokens after a corrective fold — retains the PROBE measurement (max-only bump) instead of the final rebuild size; intended conservative direction, self-corrects at the next upstream usage report. Disclosed below.

Tests. New suite tests/issue5974-preflight-view-divergence.test.ts (5 cases): legacy baseline / positive corrected-fit (strictly more folds than uncorrected) / negative exhaustion (failure-kind pin ∈ {undefined, "exhausted"}) / zero-correction field-for-field identity / full-server common path asserting EXACTLY ONE forward. Both directions present per #3617; assertions have teeth (fixture self-checks overflow; the full-server case distinguishes summary calls from forwards by their task prefix). Local: 41/41 across the nine preflight-related suites + typecheck clean, at the original head AND after my fix commit. Full-suite verdict rides CI (green at 0372399e00; re-running at 691ab4a72f).

Finding fixed on the spot (non-blocking). The mid-walk #1841 futility bail (src/preflight.ts:2793) computed its deficit as payloadEstimate - limit while its comment claimed parity with the pre-walk gate — which this PR had moved to the corrected scale (payloadEstimate + viewDeltaCorrection - limit, src/preflight.ts:2353). In a corrective pass the bail therefore understated the gap and could burn summarization calls on ranges that cannot close the true gap. Safe direction (availability preserved, final fitsWindow unaffected), but it broke the PR's own stated invariant that every fit judgment in the corrective pass runs on the corrected scale. Fix: one line onto the corrected scale + marker comment; pass 1 (correction=0) byte-identical; 41/41 + typecheck green after the fix.
已顺手修:mid-walk futility bail 的 deficit 未走修正尺度(与其注释声称的 pre-walk gate parity 不一致,纠正 pass 里会低估缺口多烧 summary 调用)→ 已对齐修正尺度,pass-1 字节不变 + commit 691ab4a

Behavior change disclosure (old → new):

  1. NEW bounded capability: after an early-fit exit with live foldable mass left, one throwaway probe rebuild plus at most one corrective pass may run when the probe measures ≥ window AND divergence ≥ max(10k tok, 2%×window). Old: such turns forwarded once for upstream arbitration regardless of how far over the rebuild was — the ~5k/round crawl. Bounded: one pass, gated, unknown-baseline excluded.
  2. session.stats.lastInputTokens: old = the single post-pass rebuild size, written once; new = max(old, probe measurement) written before the corrective pass — when the corrective pass folds further, the probe measurement (slightly larger than what ships) is retained. Conservative direction (earlier compression trigger, leaner context); self-corrects at the next upstream usage report.
  3. No config surface change: viewDeltaCorrection is an internal PreflightDeps field set only by the corrective orchestration — no new config key, env var, or CLI flag.

结构化八问(中文)

  1. 是什么问题:窗口边缘会话每轮压缩都「视图达标、出站重建仍超窗」——preflight 行走用盲视图判 fit,出站按重建后的真实体量计量,两者系统性差 ~5k token,每轮只推进 ~5k,长会话反复压缩直至整轮被拒。
  2. 什么原因导致的:fit 判定与出站计量走两条不同流水线、不同米制:行走读客户端重发数组(每轮同一份),出站走重建产物;id 抖动把未折叠质量反复送进分歧区,行走每轮「以为达标」提前退出。修法落在判定层(决策点校准),不是载荷过滤或米制造假——层次正确。
  3. 影响范围与严重程度:触发条件 = 已知基线会话 + 首轮折过且池子有剩余 + 探针实测 ≥ 窗口且分歧 ≥ max(10K tok, 2%×窗口)。修复前该场景 p1(特定条件下不可用:~5k/轮爬升直至整轮拒绝);修复后一轮收敛。无数据丢失、无 wire 破坏。
  4. 怎么修复的:首轮早退且池子有剩余时,跑一次全流水线重建当探针(公式与终局门逐字一致),超噪声底则跑一次有界纠正 pass,该 pass 内所有 fit 判定改在修正尺度上运行,折到「预测重建能装下」或诚实声明装不下为止;终局出站仍走正常重建 + 实测门(measured < limit),门本身从未放松。
  5. 是否有回归问题:逐项审过——零纠正旧路径(字节等价,case 4 字段级钉死);#553 unknown-baseline(整体排除出探针);#1839 forward-once 臂(条件逐字未动,operand ≤ 首轮值,方向安全);#3146/#4185 复检门 + doom 分层(路径未触碰,lastInputTokens 写入时序不变);relay 出口熔断(未触碰);stats.requests 四分支记账平衡(净 +1/请求);growth 模式与两层 limit 教义(未变)。有意变更两处已按 old→new 披露(见上)。未发现无意回归。
  6. 是否破坏缓存:不涉及——前缀缓存锚点/affinity/session-order 均未触碰;唯一新增开销是纠正 pass 的 summary 调用(有界至一个 pass),属修复必要成本。
  7. 是否改了设计方向:没有转向——正是落地源 issue 期望条款②(视图读取强制走重建后单一事实源);机制留在 preflight 编排层的内部字段,不跨模块边界。
  8. 是否引入了新的配置:无。viewDeltaCorrection 为内部字段,仅由纠正编排赋值;无新 config key / env var / CLI flag。

判定:APPROVE。PR 不触碰 kernel/、无 kernel-change 声明,不属人工评审档;一处非阻塞发现已当场修掉(commit 691ab4a,CI 在新头复跑中,当前 0 failed)。CI 全绿后由 owner 合并即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review posted (GitHub API rejected the APPROVE event with "Can not approve your own pull request" — this account IS the PR author, so the verdict rides as a review comment on the PR thread): #5983 (review)

Verdict: APPROVE — independent end-to-end review of head 0372399e00, rebased onto master 5c3c2688f8 (= current master tip, no base drift). The fix does what source issue #5974 expectation clause ② asks: fit judgment is forced through the post-reconstruction single source of truth. One non-blocking finding was fixed on the spot (below). No kernel/ change, no kernel-change declaration → outside the human-only tier.

Direction (issue audit). #5974: at the window edge the preflight walk judges fit on the blind client view while egress is metered on the rebuilt body — two pipelines, systematic positive delta, ~5k tokens/round crawl. The PR implements clause ② as a bounded probe → at most one corrective pass, without touching either pipeline's own accounting. It fixes the judgment at the decision point — not by filtering payloads or fudging meters. Correct layer.

Mechanism verified (independent re-read at src/server.ts:4296–4335 / 4355–4400 and every preflight.ts correction site):

  • Probe fires only when compressedRanges>0 && !unknownBaseline && failure===undefined && rangesRemaining>0 — pass 1 exited early-fit with live foldable mass left (rangesRemaining = viable foldable ranges at walk end, src/preflight.ts:2312). Unknown-baseline sessions (fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 upper-bound regime) stay fully excluded.
  • Probe formula ≡ final-gate formula, byte-identical structure (estimateCoreMessages(msgs)+overheadEstimate → applyEstimateCalibration(…, kFactor, kOrigin, currentOrigin) + imageTokens) — the probe predicts exactly what the measured gate computes. Inner gate adds a noise floor divergence >= max(10_000, round(limit*0.02)): estimator jitter cannot trigger a corrective pass.
  • Exactly ONE corrective pass; viewDeltaCorrection clamped ≥ 0; every fit site inside the pass runs on the corrected scale (textTarget init + both relax resets, tier-distill funnel/fit-break/cap/recovered/overBy, pre-walk futility deficit, both relax triggers, futility-bail escape, final fitsWindow). result.payloadEstimate itself stays the honest raw blind-view measure — downstream arms read an un-inflated number.
  • Egress still goes through the normal rebuild + measured gate (rebuiltCalibrated < limit for known-baseline sessions, src/server.ts:4395): the corrective pass works by folding MORE until the reconstruction actually fits — the gate itself is never loosened.
  • Client hold spans both passes (probe + corrective sit inside the existing try/finally hold, src/server.ts:4298–4336) — one continuous "compressing", no new deadline exposure.
  • Stats accounting balances in all four branches: every prepare entry does ++session.stats.requests (src/server/prepare-openai.ts:80, prepare-responses.ts:71/744, prepare-google.ts:88, prepare-anthropic.ts:79); the probe decrements immediately (src/server.ts:4303), a fresh rebuild decrements at its own site (src/server.ts:4362), probe-reuse adds zero. Net +1 per client request, identical to legacy. The common case (folded, no divergence over the noise floor) adds ZERO extra prepares — the probe replaces the rebuild the legacy path always did after a folding pass.

Regression audit (existing behaviors touched, item by item):

Tests. New suite tests/issue5974-preflight-view-divergence.test.ts (5 cases): legacy baseline / positive corrected-fit (strictly more folds than uncorrected) / negative exhaustion (failure-kind pin ∈ {undefined, "exhausted"}) / zero-correction field-for-field identity / full-server common path asserting EXACTLY ONE forward. Both directions present per #3617; assertions have teeth (fixture self-checks overflow; the full-server case distinguishes summary calls from forwards by their task prefix). Local: 41/41 across the nine preflight-related suites + typecheck clean, at the original head AND after my fix commit. Full-suite verdict rides CI (green at 0372399e00; re-running at 691ab4a72f).

Finding fixed on the spot (non-blocking). The mid-walk #1841 futility bail (src/preflight.ts:2793) computed its deficit as payloadEstimate - limit while its comment claimed parity with the pre-walk gate — which this PR had moved to the corrected scale (payloadEstimate + viewDeltaCorrection - limit, src/preflight.ts:2353). In a corrective pass the bail therefore understated the gap and could burn summarization calls on ranges that cannot close the true gap. Safe direction (availability preserved, final fitsWindow unaffected), but it broke the PR's own stated invariant that every fit judgment in the corrective pass runs on the corrected scale. Fix: one line onto the corrected scale + marker comment; pass 1 (correction=0) byte-identical; 41/41 + typecheck green after the fix.
已顺手修:mid-walk futility bail 的 deficit 未走修正尺度(与其注释声称的 pre-walk gate parity 不一致,纠正 pass 里会低估缺口多烧 summary 调用)→ 已对齐修正尺度,pass-1 字节不变 + commit 691ab4a

Behavior change disclosure (old → new):

  1. NEW bounded capability: after an early-fit exit with live foldable mass left, one throwaway probe rebuild plus at most one corrective pass may run when the probe measures ≥ window AND divergence ≥ max(10k tok, 2%×window). Old: such turns forwarded once for upstream arbitration regardless of how far over the rebuild was — the ~5k/round crawl. Bounded: one pass, gated, unknown-baseline excluded.
  2. session.stats.lastInputTokens: old = the single post-pass rebuild size, written once; new = max(old, probe measurement) written before the corrective pass — when the corrective pass folds further, the probe measurement (slightly larger than what ships) is retained. Conservative direction (earlier compression trigger, leaner context); self-corrects at the next upstream usage report.
  3. No config surface change: viewDeltaCorrection is an internal PreflightDeps field set only by the corrective orchestration — no new config key, env var, or CLI flag.

结构化八问(中文)

  1. 是什么问题:窗口边缘会话每轮压缩都「视图达标、出站重建仍超窗」——preflight 行走用盲视图判 fit,出站按重建后的真实体量计量,两者系统性差 ~5k token,每轮只推进 ~5k,长会话反复压缩直至整轮被拒。
  2. 什么原因导致的:fit 判定与出站计量走两条不同流水线、不同米制:行走读客户端重发数组(每轮同一份),出站走重建产物;id 抖动把未折叠质量反复送进分歧区,行走每轮「以为达标」提前退出。修法落在判定层(决策点校准),不是载荷过滤或米制造假——层次正确。
  3. 影响范围与严重程度:触发条件 = 已知基线会话 + 首轮折过且池子有剩余 + 探针实测 ≥ 窗口且分歧 ≥ max(10K tok, 2%×窗口)。修复前该场景 p1(特定条件下不可用:~5k/轮爬升直至整轮拒绝);修复后一轮收敛。无数据丢失、无 wire 破坏。
  4. 怎么修复的:首轮早退且池子有剩余时,跑一次全流水线重建当探针(公式与终局门逐字一致),超噪声底则跑一次有界纠正 pass,该 pass 内所有 fit 判定改在修正尺度上运行,折到「预测重建能装下」或诚实声明装不下为止;终局出站仍走正常重建 + 实测门(measured < limit),门本身从未放松。
  5. 是否有回归问题:逐项审过——零纠正旧路径(字节等价,case 4 字段级钉死);fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 unknown-baseline(整体排除出探针);任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839 forward-once 臂(条件逐字未动,operand ≤ 首轮值,方向安全);[Bug] 新会话(无 usage 基线)preflight 把字符数当 token——折叠其实成功(2263796→1111212)却 fail-fast 502,上游实际只计费 540828 #3146/413 Deadlock: When an authenticated session exceeds the reservation window with zero collapsibles, the #3146 forwarding | 413 死锁:带身份会话超预留窗口且零可折叠时,#3146 转发门因 anonymous 条件不触发,会话从首条消息起永久不可用 #4185 复检门 + doom 分层(路径未触碰,lastInputTokens 写入时序不变);relay 出口熔断(未触碰);stats.requests 四分支记账平衡(净 +1/请求);growth 模式与两层 limit 教义(未变)。有意变更两处已按 old→new 披露(见上)。未发现无意回归。
  6. 是否破坏缓存:不涉及——前缀缓存锚点/affinity/session-order 均未触碰;唯一新增开销是纠正 pass 的 summary 调用(有界至一个 pass),属修复必要成本。
  7. 是否改了设计方向:没有转向——正是落地源 issue 期望条款②(视图读取强制走重建后单一事实源);机制留在 preflight 编排层的内部字段,不跨模块边界。
  8. 是否引入了新的配置:无。viewDeltaCorrection 为内部字段,仅由纠正编排赋值;无新 config key / env var / CLI flag。

判定:APPROVE。PR 不触碰 kernel/、无 kernel-change 声明,不属人工评审档;一处非阻塞发现已当场修掉(commit 691ab4a,CI 在新头复跑中,当前 0 failed)。CI 全绿后由 owner 合并即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in a fresh clone (head 691ab4a7 against 5c3c2688).

What I verified

  • New suite tests/issue5974-preflight-view-divergence.test.ts: 5/5 pass.
  • Pinned neighbors (#1841 futility, #1933 calibration, #4185 forward arms, #3918 progress verdicts, #2952 tier recovery, #4079 egress fuse, #1839 ghost denominator): 31/31 pass.
  • tsc --noEmit clean (after building kernel + pi-subagents, the two pretypecheck subprojects), check:test-import-graph and test-suite-lock gate both ok. CI is green on head.

Correctness walk-through

  • Pass 1 (correction = 0) is byte-identical to the legacy walk: every touched site in src/preflight.ts is gated on + viewDeltaCorrection (textTarget :1784, tier-distill loop/fit/cap :2025–2151, both relax resets :2376/:2419, pre-walk + mid-walk futility deficits :2353/:2794, futile-bail escape :3164, final fitsWindow :3255).
  • The probe gate (src/server.ts:4299) fires only when pass 1 exited early-fit with foldable mass left AND the session has a known baseline — unknown-baseline sessions keep the #553 upper-bound regime, and failed / no-fold passes fall through to the legacy arms untouched.
  • stats.requests accounting balances on all three paths: initial prepare +1; probe +1/−1; fresh rebuild +1/−1 (the probe-reuse path decrements zero times). Net +1 per client request in every case.
  • The probe's lastInputTokens anchor (src/server.ts:4307–4310) mirrors the #1987 block exactly (same processedMessages fallback, same "estimate" source). The "estimate" source does NOT floor the corrective walk's baseline (src/preflight.ts:2207–2209 floors only "usage"/"overflow-arm"), so the probe can't accidentally pin the second pass.
  • Worst case = one extra bounded pass (fresh per-call budgets), capped by the #1841 futility gate on the corrected scale. The final forward/fail-fast still judges on the measured rebuild (fits = rebuiltCalibrated < limit), so the corrective pass can never make a forward decision the measured body contradicts — at worst it lands on the #1839 forward-once / measured-413 arms, i.e. the legacy outcome plus one bounded attempt.
  • A probe whose kernel transform failed (empty processedMessages → originalMessages fallback) measures the same raw messages pass 1 saw, so the divergence ≈ 0 and the gate stays silent — no spurious corrective pass on that path.

Minor observations (non-blocking)

  1. The e2e case pins only the NEGATIVE side of the server gate (divergence below the noise floor → no corrective pass, probe rebuild reused). The positive firing path — gate arithmetic, verdict merge, probe-reuse vs fresh-rebuild, the requests decrement — is not directly pinned by a test. Synthesizing a deterministic view/rebuild divergence through the full server is hard, so pinning the preflight side at unit level (as done here) is reasonable; noting the gap for the record.
  2. The corrective pass assumes the view/rebuild divergence stays constant across its folds. If the true divergence shrinks as the pass folds (the re-entering mass stops re-entering), the pass folds a little more than strictly needed — conservative and bounded. If it grows, the final gate re-measures and falls back to the #1839 arm. Both directions safe by construction; noting the assumption is doing real work.
  3. When the divergence comes from mass the blind view cannot see (exactly the fold-reconcile re-entry case), the corrected-scale futility gate compares the blind view's foldable mass against the TRUE deficit and may bail "exhausted" even though folding would have helped the rebuild. The request then rides the #1839 forward-once / measured-413 — same as legacy — after one bounded attempt. That's the inherent limit of the approach (you can't fold what the view can't see) and the fallback is correct; noting it so the behavior is expected, not surprising, when it happens.

LGTM — the design keeps every legacy arm reachable and makes the post-reconstruction measurement the source of truth for the fit judgment.

@Nxida2419

Copy link
Copy Markdown

Live sample: 29.5% view-vs-rebuild divergence, and pass 1 finished with deficit 0

This is a production capture of exactly the asymmetry described here, with the largest gap I have measured so far (199,521 tok / 29.5%). Sharing the raw log because the "churn producer" still needs live evidence.

Environment: bili 0.1.213 · DSH 0.2.1-rc.2 (web bundle) · Windows 11 · deepseek-flash · maxTokens 256000 · session with 166 turns / 3,238 messages.

Timeline (~/.local/state/billion-context/bili.log)

01:53:25.523 [persist] ledger-aligned refs: kept=0 restamped=2155 rehomed=733 blocked=129 superseded=2888 (#4316 PR3/3)
01:53:25.524 [persist] cold-loaded session-…: 3102 ref(s), 51 block(s) (50 active), baseline 245405 tok, savedAt ~69 min ago
01:53:25.701 [warn]    dsh native compaction detected (924/2414 covered id(s) retained) — rebasing ACP state
01:53:25.862 processTurn: 3238 msgs, renderTags=text-only
01:53:25.862 nudge idle: usage=33% (245405/750000)
01:53:26.167 [warn]    I1 violation: mid-history-rewrite @205 — inbound[205] assistant/tool-call:compress#…
01:53:29.076 [error]   unified shadow DIGEST DRIFT [diverged: state; state: messageRefs] — dropped the ingest watermark
01:53:33.701 [warn]    upstream context overflow — window 1048576 stated upstream, rejected payload ~919133 tokens stated
01:53:33.894 nudge INJECT T1: usage=100% (750000/750000), growth=504595/22500
01:53:34.104 [preflight] round 1/16: payload ~676385 tok vs window 750000 (deficit 0), 75 viable range(s)
01:53:54.820 [preflight] compressed 1 range(s), ~18937 tokens saved (750000 → 657414) in 20850ms
01:53:54.824 request: 2085 msgs, inbound=3.1MiB, outbound=2.9MiB
01:53:59.742 [warn]    context overflow — refold retry still rejected (HTTP 400)
01:53:59.743 [warn]    ← upstream 400: … (875906 in the messages, 256000 in the completion)

The three numbers

Source Tokens
cold-load baseline 245,405
preflight view (deficit 0) 676,385
bili overflow estimate after 400 919,133
upstream actual 875,906

875,906 − 676,385 = 199,521 → 29.5% under-estimate, and because it came as deficit 0 pass 1 declared fit and never folded the remaining 75 viable ranges. It only folded one T1 range (20,790 tok) for the nudge, then sent. Note the internal spread too: preflight 676,385 vs the post-400 overflow estimate 919,133 — 36% apart, two estimates of the same body.

Useful contrast (same session, later restart)

cold-load blocks baseline preflight outcome
01:53 51 245,405 676,385 vs 750,000 → deficit 0 400, session dead
13:05 8 635,557 748,880 vs 744,000 → deficit 4,880 folded, request succeeded

The 13:05 restart behaved, so this is not "old block count" — it is specifically the case where the view never computes a positive deficit.

Relation to the current fix

PR #5983 triggers the bounded corrective pass when pass 1 folded something and exited on an early fit while foldable budget remains. Here pass 1 did fold one range (m14732–m14814, 20,790 tok) and exited with deficit 0, then the rebuilt body measured 875,906 ≥ 750,000 — well past the max(10K, 2% window) noise floor. Two questions:

  1. Does the deficit 0 exit path count as "early fit" for the corrective-pass trigger? In this capture deficit 0 came from the view before the T1 injection was reflected; the injection then moved the reported number to 750000 → 657414 while the real body stayed at 875,906.
  2. Where does the 676,385 view come from when the same request is later estimated at 919,133? If the 242,748 spread is in estimateCoreMessages input rather than the estimator, it may be the same root as #5914 (cold-load drops lastUsagePayloadUpper / contextEstimateTokens), which this session also exhibits (kept=0, 2155 restamped refs).

Reproduce

Any session with 40–50 bili blocks, 160+ turns and a 20–30 万-token steady state: kill DSH after a restart-free stretch, wait ≥1 h, reopen the session. Watch for kept=0 / DIGEST DRIFT, then a preflight line with deficit 0 followed by a 400 whose message count is 25–30% above the view. Full session capture: session-572ee904-e897-4c5d-b647-f9584ca35af0 (166 turns, 21,021 events).

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)

Thanks — that's the largest measured view-vs-rebuild gap on record (29.5%), and it exercises exactly the path this PR changes. Both questions answered from the code at the current branch head; related existing thread for Q2: #5914 (open).

Q1 — does the deficit 0 exit count as "early fit" for the corrective-pass trigger? Yes.

The probe gate is src/server.ts:4301: result.compressedRanges > 0 && !unknownBaseline && result.failure === undefined && result.rangesRemaining > 0. A deficit-0 exit is precisely a fit exit carrying no failure verdict (failure === undefined) — that is the early-fit case the gate targets (the other walk exits are failure verdicts: upstream/exhausted/aborted). Walking your capture through the four conditions:

Then the probe rebuilds the actual outbound once and measures it with the trusted meter family; your numbers give probe ≈ 875,906 ≥ window 750,000, divergence ≈ 875,906 − 657,414 ≈ 218K ≫ noise floor max(10K, 2%·750K = 15K) → the bounded corrective pass fires with that divergence as its exit bar, and every fit judgment inside it (exit comparator, futility deficit, relax triggers, final fitsWindow) runs on the corrected scale.

Your specific worry — "the injection moved the reported number while the real body stayed at 875,906" — is exactly what the design neutralizes: the trigger never trusts any reported or view-side number. The probe measures the reconstructed bytes themselves, and the divergence is built from that fresh measurement. Bookkeeping drift in the view cannot mask the trigger.

Two honest boundaries:

  1. Whether the walk can close a ~218K gap depends on the foldable mass inside those 75 viable ranges. If it can't, the turn ends in an honest local refusal (measured doom 413 with the per-dimension breakdown) instead of forwarding into the fatal 400 loop — strictly better than the silent session death you captured, but not a rescue.
  2. If a deployment ran that session anonymously (prefix-affinity resolution, no stamped client id), the fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553 upper-bound regime deliberately excludes the corrective pass (k̂ calibration needs a billed baseline). That's a known scope boundary of this PR, flagged here for visibility — whether to extend coverage to that regime is an owner call, not something I'll self-file.

Q2 — where does 676,385 come from when the same body is later estimated at 919,133?

I can't attribute the 242,748 spread from here without the session files, but your hypothesis maps cleanly onto an existing open issue: #5914 — "buildSession loses persisted context estimation and usage-payload anchor after reload" (bug/p2/scope/storage). Its signature — kept=0, thousands of restamped refs, DIGEST DRIFT dropping the ingest watermark, two bili meters disagreeing on the same body after a cold load — matches your capture. The root-cause fix for the dropped anchors (contextEstimateTokens / contextEstimateCalibrated / lastUsagePayloadUpper) belongs in that thread.

One deliberate design note: #5983 is not supposed to depend on knowing why the view undershoots. Id-churn re-entry (#4543 family), anchor loss (#5914 family), estimator drift — whichever degrades the blind view, the corrective design absorbs it by forcing the fit judgment through the post-reconstruction measurement. Also worth separating: 676,385 (preflight core-messages meter) and 919,133 (overflow-path estimate after the 400) are two different meters with different inclusion rules — that internal spread is a metering-consistency question best pursued in the #5914 analysis rather than asserted in either direction here.

Live state (just verified): branch head is now 691ab4a7 — the review round landed one follow-up after my rebase (mid-walk futility deficit now also judged on the corrected scale, src/preflight.ts; pass 1 byte-identical, pass 2 matches the declared invariant). All 30 checks are green on that head; the branch shows "behind" master again (normal churn in this repo — sync at merge time). Not merged as of this writing.

Nothing further needed from me on this thread; the merge call is yours.

@ranxianglei
ranxianglei merged commit a61c55c into master Nov 10, 2026
100 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1162-master.a61c55c (rolling master tag).

npm install -g billion-context@0.0.1162-master.a61c55c  # 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

Projects

None yet

2 participants