Repository navigation
fix: dispatch preflight folds by payoff, keep the recent zone last-resort (#2682) - #2721
Conversation
…sort (#2682) Preflight walked compressible ranges oldest-first and folded one range per round. A summarization call costs the same wall clock whether it folds 6K or 64K tokens (measured 25-44s/call), and the head range re-grows after each fold (block + newer messages form one bigger range again), so a pass re-folded an almost-exhausted head every round while the largest ranges never got dispatched within the budget (#2682: five head re-folds over a 180s pass; two ranges worth 108K tokens untouched). Two-tier dispatch order: tier 1 (ranges outside the soft-protected recent zone) goes largest-span first with age order breaking ties of equal mass; tier 2 (ranges entering the zone, present only after a #330/#1841 relax) stays oldest-first within it and never outranks old content, preserving #330's stated policy. The boundary comes from a CPU-only processTurn probe under the ORIGINAL protection config (the kernel keeps computeProtectedRefs internal), re-derived each round because a zone fold slides the last-N window forward. Behavior change: preflight fold dispatch changes from oldest-first to payoff-first OUTSIDE the protected zone (old value: ref-number ascending; new value: token mass descending, ties age-ascending); inside a relaxed zone the effective order is unchanged (ref-number ascending). No wire shape, config surface, persistence, or kernel change. New info log line reports the chosen fold order once per pass.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3817-pr.2721.7daa4a7This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2721.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR review 完成 — 可合并。 拉取分支逐行审了 diff( 审原 issue(方向关):#2682 成立——测量证据完整(180s pass 内 5 次 head 重折、savings 递减、108K 大 range 从未派发;summary 调用 25-44s 与大小无关),根因定位准确(ref 号升序派发 + 调用成本与大小无关 + head 折后再生长 = 大 range 预算饥饿)。修法对齐 issue 提案 1(payoff 序)+ 提案 4(日志);提案 2/3 有意不实现的理由成立(既有出口已给 pass 上界,阈值启发式只添调参常数)。 回归审查(逐项既有行为清点):
代码审查要点:sort comparator 三种 tier 组合逐一验证正确(tie-break 显式,不依赖 sort 稳定性);边界探测与 #1841 既有探测惯例完全同构(原始保护配置、CPU-only、state 丢弃不采纳)、每轮重推以跟随 last-N 窗口前移;探测返回空时 boundary=-1 → 全量落入 tier 2 → 纯 oldest-first = legacy 行为,兜底方向安全;每个 relaxed round 多一次 processTurn,CPU 成本与既有探测同量级,可接受。无 测试有效性:3 个测试均为真 kernel core + mock upstream 的行为测试(listen(0) 取端口,确定性达标)。我在本地独立复验了咬合:把 master 版 八问结论:
diff 整洁度:单 commit、2 文件、每一行都与本 PR 目的相关,无空白/锁文件噪音。未发现需要顺手修的小问题。 判定:可合并,请 owner 合并。 |
…t.ts) Only conflict: the #2682 dispatch rework and #2952 tier-distillation recovery both touched the same declaration spot. Kept both sides (union): the fold-order log flag plus the whole #2952 recovery block — they are independent (dispatch ordering vs exhaustion-path recovery). Verified on the merged tree: tsc --noEmit clean after kernel rebuild; preflight family 189/189 green including issue2682 payoff-order (3), issue2952 tier-recovery (5).
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.459-master.44eea7f # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2682
What
Preflight walked compressible ranges oldest-first and folded one range per round. A summarization call costs the same wall clock whether it folds 6K or 64K tokens (measured 25-44s/call), and the head range re-grows after each fold (its block + newer messages form one bigger range again) — so a pass re-folded an almost-exhausted head every round while the largest ranges never got dispatched within the budget. Exactly what was measured on v0.1.191: five head re-folds over a 180s pass; two ranges worth 108K tokens untouched.
Fix (src/preflight.ts only)
Two-tier dispatch order:
tests/preflight-compress-responses.test.ts(Codex 长会话在 macOS 休眠唤醒后 Bili 未触发压缩,导致上下文窗口超限 #280) andtests/preflight-hold.test.ts(Preflight compression holds the request with zero response bytes; client undici headersTimeout (default 300s) kills it -> repeated[preflight] summarization aborted: client disconnected5-minute death loop, payload never forwarded #568).The tier boundary comes from a CPU-only
processTurnprobe under the original protection config (the kernel keepscomputeProtectedRefsinternal to acp-kernel, so no kernel change is needed); it is re-derived each round because a zone fold slides the last-N window forward.Also logs the chosen fold order once per pass (
[preflight] fold order (largest first outside the recent zone, #2682): ..., info level, capped at 8 entries + overflow count) so ordering is diagnosable from logs without reading source (issue proposal 4).Behavior change disclosure (old -> new)
Tests
New
tests/issue2682-preflight-payoff-order.test.ts(hermetic: real kernel core + mock upstream):Targeted family run locally:
tests/preflight-*.test.ts+tests/issue1372-*.test.ts+tests/issue2682-*.test.ts-> 145/145 pass (four of these — #1372 skip diagnostics, #280 responses e2e, covered-ranges, #568 hold — failed under the intermediate pure-mass iteration and are green under the two-tier order). Typecheck clean, build clean. Full suite + e2e lanes delegated to CI.Notes
decisionTokens < textTarget, summary/round budgets, 模型压缩输出是输入的数倍 #1841 futility gates) already bound the pass; threshold heuristics would add tuning constants without fixing a remaining mechanism.