Skip to content

[PR] fix(preflight): re-land #4288 — stop burning the fold ladder on an already-fitting payload after a model switch - #4771

Closed
ranxianglei wants to merge 13 commits into
masterfrom
2026-10-26_reland-4288-target-aware-fit-exit
Closed

ranxianglei wants to merge 13 commits into
masterfrom
2026-10-26_reland-4288-target-aware-fit-exit

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4288
Supersedes revert f4c10bd (the naive form was commits 621c35a / cherry-pick 041c32b).

What & why

After switching to a smaller-window model, preflight kept burning its multi-round
summarization ladder on a payload that already fit the new window, until the client
timed out — the "switch model → stuck" symptom in #4288. Root cause: the round-top stop
criterion judged on decisionTokens, which is floored by the session usage baseline.
That baseline was measured under the prior, wider-window model and can sit ABOVE the new
window, so the floored exit never tripped.

Fix

Judge the round-top exit on the payload's own floorless estimate
(result.payloadEstimate < textTarget) — the same quantity the forward gate already
trusts (#1839/#1492). Floored implies floorless, so folding never increases versus
pre-#4288 behavior.

Why textTarget and not the hard window limit (the reverted form): callers legitimately
fold window-fitting payloads toward a TIGHTER target — compressionTarget plans (a66353a)
and codex native-compaction headroom (#68f6bfe3). Judging on the raw window would have
stopped those folds early; that is exactly why f4c10bd reverted the naive change.
textTarget = max(0, min(limit, compressionTarget ?? limit) - imageReserve).

Behavior change (old → new)

Round-top stop criterion: decisionTokens < textTarget (floored by a possibly-stale
baseline) → result.payloadEstimate < textTarget (floorless, same target).
Effect: a fitting payload under a stale high baseline now forwards immediately (zero
summarization calls); genuinely-overflowing and tighter-target folds are unchanged.
An info log fires only when the stale-baseline scenario actually occurs
(baselineFloor >= textTarget).

Tests

  • New tests/issue4288-preflight-stale-baseline-fit-exit.test.ts: e2e (fitting payload +
    stale 300k usage baseline forwards with zero summarization calls) plus the
    target-awareness band (a payload above the fold target but below the window still gets
    its 429-retry attempt, then stays forwardable).
  • tests/preflight-fail-fast.test.ts (fix: honor anthropic-beta context-1m to size the context window #301 e2e): now asserts zero summarization calls
    (the previous ≥1 expectation had encoded the old over-fold behavior).
  • tests/preflight-summary-length-budget.test.ts: the single-chunk case now exerts
    target-pressure via an explicit compressionTarget (the old stale-floor trick no longer
    triggers a fold once the trigger is target-aware).
  • Full preflight suite green locally (217/217); full repo suite = CI.

Scope note

Clean, minimal re-land of ONLY the #4288 fit-exit. Deliberately excludes the #4740
fragment-merge work (tracked separately) and is distinct from the mislabeled 50-file PR
#4725 (branch 2026-10-25_empty-pr), which carries the same one-line fix entangled with
~49 unrelated files.

Config surface: none (no config/env/CLI changes).

ci-check and others added 9 commits October 25, 2026 23:02
…ment

#4316 PR3/3 (restampRefsToLedger) re-homes citation numbers once on every
full-mode cold load; goldens pinning exact ref numbers are born-red. Re-pin
the 7 storage-lane tests (engine-proofs x6 + orphan-recovery x1) modulo that
renumbering — zero production code touched.

- golden-storage-drive.ts: per-turn citation-normalized digest (shaCiteNorm)
  and state digest modulo stripOneTimeAlignment (stateDigestAligned); the
  deep-sort helper is hoisted into golden-canonical.ts for sharing.
- corrupt-index-child.ts: new stripOneTimeAlignment normalizer — strips the
  refLedgerAligned stamp and re-homes refs onto canonical raw-id order so a
  clean full-mode read and the legacy fallback load compare equal.
- storage-engine-proofs.test.ts: wire legs assert shaCiteNorm equality vs
  the legacy restart leg and the committed goldens; state legs assert
  stateDigestAligned; rollback leg now spells BILI_STORAGE_UNIFIED=legacy
  explicitly (#3818 flip: absent resolves to full, deleting the env would
  vacate the legacy path).
- storage-orphan-recovery.test.ts: pins the content-addressable
  byRaw->byRef round-trip instead of a counter-era m00003 literal.
- golden/storage-render/*.json regenerated with shaCiteNorm/stateDigestAligned.

Converges the master-red storage-lane family (#4599 plan A, owner directive).
…dger parity masks

The #4316 one-time renumbering restamped messageRefs but left
state.tokenSnapshot keyed by the OLD refs, so post-restart bodies
carried stale per-message token counts (1.3K vs 1.4K) and the
full-mode-restart wire drifted off the legacy baseline (#4599).

persist.ts: two-pass remap (stage moves, delete old keys, then write
new keys) so entries whose new ref collides with another move's old
ref survive; fires only when superseded refs exist.

Aligned normalizer (corrupt-index-child.ts): the cacheLedger's
segment bookkeeping (be/bl/bs, unfinalized tail line), the derived
agg block, and per-line miss-attribution (prov/seam) are restart
experience, not content — no-restart and restart legs legitimately
differ there. Masked in the aligned view only; raw digests keep
full accounting. Goldens regenerated (stateDigest + aligned).

storage-engine-proofs 12/12, golden-storage-render 5/5 locally.
…persisted state (#4599)

The fork-survival test asserted immediately after the compress tool
response, but the fold lands in the live session state asynchronously
(#3573 replay semantics). Slow CI runners persisted the pre-fold state
('0 block(s) (compressions=0)' cold load) and the deepEqual diverged.
Bounded 5s wait on the in-memory fold; fast machines exit on the first
iteration. Product semantics unchanged.
The #4316 cold-load alignment reads the unified sidecar; its ingest of
just-flushed records completes asynchronously. Slow runners compared
the pre-ingest state and saw refLedgerAligned missing while the fold
itself had landed. Poll (bounded 5s) until the loaded state carries
the flag; fast machines exit on the first probe.
Git-for-Windows autocrlf checks the bundled .md posts out with CRLF;
the exact-match '---' fences then failed to parse and every post lost
its title/excerpt/date frontmatter (Windows CI: 'bundled meet-bili post
found' assertion). Normalize CRLF to LF inside parseFrontmatter when
the fence is CRLF-shaped; LF content is byte-identical as before.
Regression test with a CRLF fixture.
… storage mode (#4599)

The #4316 cold-load alignment sets refLedgerAligned only when the
unified store is available; config-clean machines (CI runners) run
legacy mode where it is an honest skip. The test asserted the flag
unconditionally, so every shard carrying this file was born-red on CI
while unified-config machines passed. Expectation now mirrors
store.replicasAvailable(); verified 49/49 in BOTH modes locally.
…t < limit)

Round-top stop judged on decisionTokens, which is floored by the session usage baseline; after a smaller-window model switch that baseline can sit above the new window, so the floored exit never trips and preflight burns the multi-round summarization ladder on an already-fitting payload until the client times out (the model-switch-stuck symptom). Judge on the payload's own floorless estimate instead.

Use the fold target (textTarget = min(limit, compressionTarget) - imageReserve), NOT the hard window limit: callers legitimately fold window-fitting payloads toward a tighter target (compressionTarget plans, codex native-compaction headroom #68f6bfe3). The earlier naive form (621c35a) used 'limit' and broke exactly those, hence its revert f4c10bd. Floored implies floorless, so folding never increases versus pre-#4288 behavior.

Updates affected fixtures (#301 e2e asserts zero summarization calls; summary-length-budget single-chunk case uses an explicit compressionTarget) and adds tests/issue4288-preflight-stale-baseline-fit-exit.test.ts (e2e fit + target-awareness band). Full preflight suite green (217/217).

Supersedes revert f4c10bd. Closes #4288.
@ranxianglei ranxianglei changed the title fix(preflight): re-land #4288 — stop burning the fold ladder on an already-fitting payload after a model switch [PR] fix(preflight): re-land #4288 — stop burning the fold ladder on an already-fitting payload after a model switch Oct 25, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 —— 本 PR 是 #4288 的干净重落地。相关条目已核对:

开始按 PR Review 规范审核:①原 issue(#4288)方向 → ②回归清点 → ③代码 → ④测试有效性 → ⑤diff 整洁度。分支 2026-10-26_reland-4288-target-aware-fit-exit @ 6fc1c9699,结论稍后按八问给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

审查完成(①方向 → ②既有行为清点 → ③代码 → ④测试有效性 → ⑤diff 整洁度)。判定:hold —— 方向对、主切片已修,但退出判据的写法混了通道,PR 里两条核心不变量声明在 imageReserve>0 时不成立;请在本 PR 内做一个小机械修正后再合。

一句话结论:round-top 退出从 decisionTokens(带 floor)换成 payload 自身无 floor 估计——方向正确,用 textTarget 而非 limit(被 revert 的形式)也正确;但写成的 result.payloadEstimate < textTarget 是「左全通道、右文本通道」的混合比较:左边 = 文本+图片的全 payload,右边 = 窗口−图片的文本目标,比任何自洽形式都严格了一个 imageReserve。纯文本会话(R=0)表现与声明完全一致;带图会话(R>0)会多折至多一个 imageReserve,#4288 的「payload 已 fit 但带图」这一片没修到。

八问

  1. 是什么问题:切到更小窗口的模型后,payload 本身已 fit 新窗口,preflight 仍烧多轮摘要梯子直到客户端超时(The symptom is that switching models causes a hang, suspected to be triggered by dsh native compression. | 症状是切模型卡住疑似触发 dsh 原生压缩 #4288)。
  2. 什么原因导致的:round-top 退出判在 decisionTokens 上,它被旧大窗口模型下测得的 usage baseline floor 住;baseline 高于新窗口时退出永不触发。
  3. 影响范围与严重程度:纯文本会话(imageReserve=0,主受影响面)已完全修复——同场景实测 master 7 次摘要调用 → 本分支 0 次。带图会话部分未修:payload 落在 [target−reserve, target)(仍 fit 窗口/目标但超文本目标)时,梯子照烧(实测两分支行为完全相同,均为 exhausted)。可用性不受影响,残留为 p2 级;原 issue p1 的主切片由本 PR 修掉。
  4. 怎么修复的:退出改判 payload 自身无 floor 估计、保留 target-aware 语义。具体写法有上述混通道问题。代数(C=min(limit,compressionTarget), R=imageReserve, T=文本估计, P=T+R, B=floor,C>R 区间):旧退出触发当且仅当 (B<C)∧(T<C−R);新退出触发当且仅当 T<C−2R。即 R>0 时新触发集严格小于旧——PR 正文「floored implies floorless,folding never increases」只在 R=0 成立;同理「tighter-target folds are unchanged」也不成立(带图的 tight-target fold 会越过目标至多 R)。两个等价正确写法(都是旧触发集的真超集,即真正「不多折」):
    • ① if (roundText < textTarget) —— 纯文本通道,与 Bill images and text separately — the image estimate's ±15× error bar poisons every window decision (dual-channel accounting) #1843 双通道记账设计一致(src/preflight.ts:1482 注释明言 "fold decisions run on the TEXT channel"),src/preflight.ts:2061 一词之改(roundText 在 :2026 已定义),直接复用现有可变 textTarget(含 :2157/:2198 两处 relaxation 复位);
    • ② if (result.payloadEstimate < Math.min(limit, deps.compressionTarget ?? limit)) —— 纯全通道,与 forward gate 同量同目标。
      推荐 ①。实证状态如实说明:严格增折带(B<C 且 payload∈[target−2R, target−R))在我的 harness 里无法逼出实际调用差——kernel 在没有 usage-grade baseline 时不 advertise 可折 range——该点依据是代数推导 + 你的 band test 把这个更严语义钉成了预期行为(见第 4 条测试节)。
  5. 是否有回归问题:逐项审过的既有行为——R=0 round-top 退出:新≡旧、stale-baseline 情形严格变好(实测 7→0);compressionTarget plans / codex headroom 的 tight-target fold:R=0 代数等价,不变;fix: honor anthropic-beta context-1m to size the context window #301 fail-fast 转发契约:fitsWindow 计算(:3016)未动,测试断言在位;preflight fail-fast × soft-protection livelock: over-window payload with nothing foldable outside the protected zone 502s forever #330 soft-zone relaxation、模型压缩输出是输入的数倍 #1841 futility gate、[Bug] preflight 把确定性的 end_turn 空摘要判为「瞬时故障」:每个 span 烧尽重试预算、零 fold 落地,且诊断无法区分 thinking-only 与正文被中继吞掉(0.1.188→0.1.193 未修) #2832 probe gating、emergency digest、external-summary batch:全部未触碰。另两处中圈 gate(src/preflight.ts:2526、:2602)仍用带 floor 的 decisionTokens:有界残留(payload 起步高于 target 且 floor 主导时,非紧急轮至多多折 1 次;紧急路径 CPU-only),相对 master 非回归——在此提及,不强求进本 PR。小瑕疵:info log 条件 baselineFloor >= textTarget 拿总视图比文本通道,比真实「floor 主导」条件(B≥C)略宽,会少量多打日志,无害。
  6. 是否破坏缓存:不涉及(缓存/重试/游标/去重策略零改动)。
  7. 是否改了设计方向:不涉及——维持 Bill images and text separately — the image estimate's ±15× error bar poisons every window decision (dual-channel accounting) #1843 双通道记账框架;我的建议正是恢复该设计的通道纯度。
  8. 是否引入新配置:无(diff 确认无 config/env/CLI 变更,与 PR 声明一致)。

测试有效性(④):e2e 主测试有牙——拷到 master 上跑,红,报 "got 2 call(s)"(与本 PR 注释预测一致);band unit test 在 master 上也绿(B≥C 时两分支都折,不构成判别)。两个问题:

diff 整洁度(⑤):干净——单 commit、4 文件、每行都与目的相关,无无关改动。

验证记录:typecheck clean;PR 点名的 3 个测试文件本地 14/14 绿(全量留给 CI——审查时 22 个 check-run 均 queued);最小 preflightCompress 驱动做双分支 A/B(上面 cfg2/cfg3 即其输出)。

修复清单(小、机械、同一机制家族,建议本 PR 内做完):

  1. src/preflight.ts:2061 退出 LHS result.payloadEstimate → roundText(或 RHS 换 Math.min(limit, deps.compressionTarget ?? limit)),同步注释与 PR 正文的两条声明;
  2. 重建 band test fixture(真高于 target)+ 补负向行(fitting+图片→0 调用);
  3. (可选)mid-walk gates(:2526/:2602)对齐同一判据,或显式留待后续。

确认写法 ①(或 ②)后我可以直接把修复 commit 推到这个分支。

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_reland-4288-target-aware-fit-exit (2560eb5)

Latest build — install this exact version

npm install -g billion-context@0.0.5946-pr.4771.0bc96e2

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
2560eb5 billion-context@0.0.5946-pr.4771.0bc96e2 build
6fc1c96 billion-context@0.0.5847-pr.4771.9176e60 build

Download artifact

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

Install instructions are refreshed on each push.

ci-check and others added 4 commits October 26, 2026 09:14
The ci-check lane's expectation change (c496cfb) exposed a real Windows
bug: stripInheritedProxy builds inlineEnv as a spread copy of process.env,
which keeps the original key casing (ComSpec) — Windows env vars are
case-insensitive but plain objects are not. planClientSpawn's exact
env.COMSPEC probe then missed it and silently degraded every wrapped spawn
to the bare-name 'cmd.exe' fallback (verified by repro on a real win32 box:
childEnv.COMSPEC=undefined while process.env.COMSPEC was set).

Fix: probe COMSPEC/ComSpec/comspec in planClientSpawn and planDshSpawn.
Verified on real Windows (Node 22): launcher-opencode-inline + fix-679 +
dsh-refresh 37/37; host tsc clean, 35 pass / 2 win32-skips.
…OMSPEC case-probe

c496cfb re-derived the win32 expectation from ambient process.env, which
still mismatches production: Node's process.env member access is
case-insensitive on Windows while the child env handed to the planner is a
plain object whose key keeps the OS casing (ComSpec), so the exact
env.COMSPEC probe fell through to the bare-name fallback. The assertion now
derives from the child's OWN captured env/options and probes
COMSPEC/ComSpec/comspec exactly like planClientSpawn does post-dfeea8a11 —
self-contained under any concurrent-test env churn in single-process CI
shards — and additionally pins windowsVerbatimArguments=true on the wrap.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策

CI conflict lane (attempt 1/3), bot: ci-engineer-r1. I did NOT rebase/push: no conflict resolution on this PR can produce a mergeable branch, because the fix it carries is already on master in a strictly better form. Details and options below.

What I verified live this run

Why the PR's own form is the inferior one (not just stale)
The PR judges the round-top exit on result.payloadEstimate < textTarget — a total-space quantity (roundText + imageReserve) compared against a text-space target that already subtracts imageReserve. That subtracts the reserve twice and misses the exit on image lanes. Round-2 review (F1) caught exactly this and switched to text-to-text (roundText < textTarget); master's new unit test pins that defect. Re-landing the PR's hunk would regress master.

Options

Default if undecided: treat as superseded — I will not push anything to the branch, and further auto-fix attempts on this PR should stop (they will hit the same wall); owner closes at convenience.

标签: needs-decision(PR 已被 master 上的演进版本完全取代,关不关由 owner 拍板)


八问(中文结构化结论)

  1. 是什么问题:PR [PR] fix(preflight): re-land #4288 — stop burning the fold ladder on an already-fitting payload after a model switch #4771 与 master 冲突(dirty),但本质不是普通冲突——它携带的 The symptom is that switching models causes a hang, suspected to be triggered by dsh native compression. | 症状是切模型卡住疑似触发 dsh 原生压缩 #4288 修复已经通过另一条线(Collapsed preview is rejected once per round: when a large tool-result exceeds the chunk budget, splitChunks first emits | 折叠预览每轮必拒一次:大 tool-result 超过 chunk 预算时 splitChunks 先吐出只有 64 字符的 call 碎片 #4740 rework 谱系)合入 master,且 master 版本是经过两轮评审改进后的严格超集;本 PR 已被完全取代,任何冲突解法都产不出可合并的分支。
  2. 什么原因导致的:同一修复的两条并行工作线:本 PR(2026-10-26 的 The symptom is that switching models causes a hang, suspected to be triggered by dsh native compression. | 症状是切模型卡住疑似触发 dsh 原生压缩 #4288 re-land)与 Collapsed preview is rejected once per round: when a large tool-result exceeds the chunk budget, splitChunks first emits | 折叠预览每轮必拒一次:大 tool-result 超过 chunk 预算时 splitChunks 先吐出只有 64 字符的 call 碎片 #4740 rework 线(041c32b00b → 23310dd → de5e036 → 785af36 → 9384074)先后合入 master,且评审 round-2(F1)发现并修正了本 PR 自身形式的一个缺陷(total-to-text 比较在 image 车道上双重扣减 imageReserve、漏掉 fit exit);PR 分支此后未再更新,master 又前进了 2077 个提交。
  3. 影响范围与严重程度(分选项):
    • A(关闭):零代码影响,master 不动,修复已在 master 生效;严重度:无(纯收尾)。
    • B(rebase 全取 master 侧):零代码影响,但 force-push 重写 PR 分支历史,产出空 PR 仍需 owner 关闭;严重度:无,纯浪费。
    • C(rebase 保留 PR 侧形式):严重——行为回归:image 车道 fit exit 再次漏判(F1 缺陷复活)、使用pi 压缩后就提示prompt is too long #1195 overflow-arm 救援被移除、fitExitForward 终局判决处理被回退;波及 image 会话与 overflow-arm 救援路径。
  4. 怎么修复的:无需代码修复——修复已在 master 上(且是更好的形式)。正确动作是把 PR 以 superseded 关闭(owner 操作),本评论即取代关系的完整记录(含 master 提交链与逐文件包含性核对)。
  5. 是否有回归问题(分选项):A:无——什么都不合入,master 原样。B:无——diff 为空。C:有,3 处回归(F1 image-lane exit、overflow-arm 例外、fitExitForward 判决),见第 3 问。
  6. 是否破坏缓存:不涉及——任何可行选项都不改代码。
  7. 是否改了设计方向:不涉及——master 的设计(text-to-text exit + overflow-arm 例外)保持不变;仅 C 会反向回退它。
  8. 是否引入了新的配置:不涉及。

收工判定:本轮不动分支(不 rebase、不 push),已打 needs-decision 标签;等 owner 在 A/B/C 中拍板,推荐 A(以 superseded 关闭)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] auto-fix stalled: test (windows-latest, 22, 1), test (ubuntu-latest, 22, 2), test (ubuntu-latest, 24, 1), test (windows-latest, 22, 5), test (ubuntu-latest, 22, 1), test (windows-latest, 22, 4), test (windows-latest, 22, 3), test (ubuntu-latest, 24, 3), test (windows-latest, 22, 2), test (ubuntu-latest, 22, 3), test (ubuntu-latest, 24, 2) — stopping for human review

@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing: the #4288 round-top fit exit this PR re-lands is already on master (src/preflight.ts:1801/2257; commits 9384074, 785af36, de5e036 from 2026-10-26, which postdate this branch).

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

Projects

None yet

1 participant