Skip to content

fix(#1841): preflight futility gate — skip doomed rounds, bail mid-walk - #1851

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-01_preflight-futile-round-skip
Oct 6, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-01_preflight-futile-round-skip

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1841

What

#1841 is item 3 of #1819's suggested-fix list — the one left unimplemented: "Consider skipping the whole preflight round (or bailing early) when cumulative accepted folds cannot bring the payload under the target." The motivating incident (session 08cc0df7, weak local summarizer): preflight spent ~9 summary calls over ~5 minutes for a net −5.5%, because nothing ever asked "can this round possibly succeed?" before spending calls. The admission gate (#1819/A) only rejects an individual expanding fold after its summary call was already spent; this adds the missing round-level feasibility check.

How

Two gates inside preflightCompress, both computed from local estimates only (zero network overhead, re-evaluated per request — no cross-request state, no new config):

  1. Pre-walk skip. A fold removes its span's mass at best (its summary re-enters the payload), so the sum of all resolvable foldable range masses bounds the round's possible saving. If pool × FUTILITY_SLACK(1.2) < payloadEstimate − limit, skip the whole round with zero summary calls and an honest quantified detail ("futile round: maximum possible saving ~P tokens is below the required reduction ~D tokens"). If the normal-regime pool falls short but the relaxed soft-zone view would suffice, relax up front instead of burning calls first (preflight fail-fast × soft-protection livelock: over-window payload with nothing foldable outside the protected zone 502s forever #330 path preserved).
  2. Mid-walk bail. As ranges are consumed/skipped, stop before summarizing any range whose remaining potential can no longer close the gap; accepted folds are kept and the per-range skip notes are carried into the verdict (bug: preflight 兜底静默跳过零诊断且与插件压缩路径不一致(同范围插件 compress 成功,preflight 报 no range could be compressed) #1372 diagnosis contract).

Soundness notes:

Behavior change disclosure (old → new)

Config surface

None added. FUTILITY_SLACK is an internal constant, not user-facing. No env/CLI/config.json changes.

Pre-flight evidence

  • npm run typecheck: clean
  • Targeted local runs (per local-testing policy): the full preflight family — all tests/preflight-*.test.ts + issue1372/issue1615/issue1841 suites — 105/105 pass, including 3 new tests (pre-walk skip with 0 calls / non-futile control / mid-walk bail)
  • Two existing assertions updated to the new contract, core pins retained: fix: preflight tries all viable ranges before declaring exhaustion (#569) #574 truthful-exhaustion now accepts the futility verdict (still pins ≥2 summary calls = moved past the bad oldest range, no forward, no blocks); fix: preflight tries all viable ranges before declaring exhaustion (#569) #574 budget-cap fixture resized (conversation(48)→(192)) so the 16-call cap remains the binding bound ahead of the new bail threshold, keeping dedicated coverage of the cap itself
  • Full suite + build: remote CI. E2E: src/preflight.ts is not in ci-e2e.yml's auto-trigger path list, so the e2e workflow is dispatched manually on this head (request pipeline per AGENTS.md)

Coordination note

Open PR #1818 also touches src/preflight.ts (defects A/D/E). This change is additive around the round/walk control flow and does not intersect A's acceptance gate or D's length-budget code paths; whichever lands second rebases as a semantic union.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_preflight-futile-round-skip (78abb43)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2378-pr.1851.48d30ae

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 结论:方向正确,gate 实现通过审查;但全量 CI 在全部 4 个平台红——根因已定位并就地修好(仅测试迁移),已推 PR 分支(ee950f93),等 CI 重跑绿即可合。

验证过程(证据先行)

结构化七问

  1. 是什么问题:PR 给 preflightCompress 加两道 fail-closed futility gate(pre-walk skip + mid-walk bail,模型压缩输出是输入的数倍 #1841);PR 本身无方向问题,红 CI 来自一处未迁移的旧断言。
  2. 什么原因导致的:场景 C 是真正 futile 的回合(image 单独超窗),gate 正确地零调用跳过整轮,旧断言 summaryCalls > 0 不再成立;契约迁移漏了该 suite。
  3. 怎么修复的:test-only 迁移(见上)。附带发现:原测试的 write-back 断言本来就是 vacuous 的——手工置入的 baseline 1,072,519 高于任何 text+overhead write-back 值(~8.6K),旧代码下 write-back 从未 raise,断言恒真;所以本 PR 没有实际 C1 覆盖损失(C1 逻辑本 diff 未动,仅在轮次折出 ≥1 range 时可达;已在文件头注释标注)。
  4. 是否有回归问题:无。逐项审过 diff 触碰路径的既有行为:
  5. 是否破坏缓存:不涉及。prefix cache/affinity/增量游标未触碰;可达轮次的 fold 集合与旧代码一致。
  6. 是否改了设计方向:不涉及。纯增量 fail-closed gate,FUTILITY_SLACK=1.2 为内部常量,无 config surface 新增(符合 Configuration Surface Discipline)。
  7. 是否引入新配置:无。

合并判定:等 ee950f93 的 CI 重跑绿即可合(push 触发的重跑稍后出现)。备注:PR 落后 master 21 commits,但 merge-base 之后 master 未改 src/preflight.ts / tests/preflight-multi-range.test.ts,无文本冲突;开放中的 #1818 也碰 src/preflight.ts(defects A/D/E),后落地者需按 semantic union 处理。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 更新:CI 已绿,PR 可合。

  • push e488235f..ee950f93 后,pull_request synchronize 事件未自动触发 CI(bot-authored PR 的已知门控),我通过 workflow_dispatch 显式触发了 ci.yml(该 trigger 本就为 release-manual fallback 声明,one-click release fallback PRs are not immediately mergeable under current branch protection (#772 push-CI mechanism never fires) #1744 同款机制)。
  • Run 36849896070 @ ee950f93:test 矩阵 4/4 全绿(ubuntu/windows × node22/24,每 job 实跑 ~4-5 min 全量套件;version-guard skipped = 非 release 分支的正常行为)。
  • E2E 证据沿用旧 head:git diff e488235f..ee950f93 仅 tests/issue857-image-baseline.test.ts(+21/-7)——src/preflight.ts 与旧 head 逐字节相同,而旧 head 上 E2E(real codex)、e2e-fake-codex、native pi/dsh/opencode、hermetic registry 全部 success,故无需重跑。

最终判定:可合。 合并动作按规则由人来执行:#1851

(前一条回复的七问结论不变,此处仅补 CI 状态。)

ework-agent added 2 commits October 6, 2026 23:09
When the sum of all foldable range masses cannot close the gap between
the payload estimate and the model window, no combination of folds can
fit the payload; walking the ranges only burns summarization calls
minutes at a time (incident 08cc0df7: ~9 calls over 5 min, net -5.5%).

Two gates, both on local estimates only (zero network overhead,
re-evaluated per request, no new config surface):

- Pre-walk: if resolvable pool * FUTILITY_SLACK < payloadEstimate - limit,
  skip the whole round with zero summary calls and an honest quantified
  detail. If the normal-regime pool falls short but the relaxed soft-zone
  view would suffice, relax up front instead of burning calls first.
- Mid-walk: as doomed ranges are consumed, stop before summarizing any
  range whose remaining potential cannot change the outcome; carry the
  per-range skip notes into the verdict (#1372 diagnosis contract).

The deficit is measured on payloadEstimate (the floorless wire estimate
the caller's forward decision uses), never on the floor-pinned
currentTokens: the usage floor covers system prompt + tool definitions
that folding cannot remove. Unresolvable nudge refs count as zero mass,
matching the walk's dead-test, so an all-dead pool still walks
call-free for its skip-note diagnosis.
… all four platforms

The #1841 pre-walk gate correctly skips scenario C's round (image floor
~1.1M alone exceeds the ~999K window; the ~4.4K foldable filler pool
cannot close the ~110K gap), so the old 'ranges were folded' assertion
no longer holds — the same contract the two #574 assertions were already
migrated to. Keep the 502/hatch-closed pins, pin the new zero-call
behavior + 'futile round' verdict wording, and assert the baseline stays
exactly untouched (it was never re-poisonable here: the armed 1,072,519
usage baseline sat above any text+overhead write-back value, so the old
write-back assertion passed trivially even before this PR).
@ranxianglei
ranxianglei force-pushed the 2026-10-01_preflight-futile-round-skip branch from ee950f9 to 78abb43 Compare October 6, 2026 15:10
@ranxianglei

Copy link
Copy Markdown
Owner Author

已 rebase 到当前 master(818d24e+),冲突已解,本地全绿。 语义合并说明:

  1. walk 循环终止条件对齐 DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 口径:模型压缩输出是输入的数倍 #1841 引入的 oi 索引循环 + futileBail 状态保留,但每轮提前终止从 PR 时代的 currentTokens < target 改为 master 的 decisionTokens < textTarget(校准后决策口径);pre-walk relax-up-front 分支里的 target = limit 相应为 textTarget = Math.max(0, limit - imageReserve)。
  2. fix: preflight tries all viable ranges before declaring exhaustion (#569) #574 budget-cap 测试改窗口构造:老构造(10K 窗,~20x overshoot)在 futility gate 之下注定先触发 futile round(这正是 模型压缩输出是输入的数倍 #1841 的目的,该排序已在 tests/issue1841-preflight-futility.test.ts pin)。为保住 budget-exhausted 路径的 dedicated pin,窗口改为 230K(~1.04x overshoot):deficit ~9K 恒低于 remaining pool × 1.2 → futility 不触发,base-16 cap(overshoot < 1.06x,DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 raise 不生效;raised 变体仍由 tests/preflight-round-budget.test.ts pin)成为 binding bound。另外 summarizeRange 存在 in-call fallback HTTP,call 计数 pin 放宽为 [16,18] 区间(文本断言不变)。
  3. issue1841 测试的 proxyOptions 补 master 新必填字段 promptCache。

本地验证:tsc 干净;npm run build 过;PR 自带 issue1841-preflight-futility 3/3、迁移后的 issue857 C 用例、preflight-multi-range 3/3、preflight-round-budget 2/2;preflight 家族回归 56/56(compress×2、#1933/#1987/#2117/#2122/#1372/#1615/#1993/#2189、codex-headroom)。

与 #1818 的关系:两个 PR 都在 preflight 区域但不相互依赖(#1818 = net-shrink gate + budget + anchor;#1851 = round 级可行性预检 + mid-walk bail)。#1841 事故里 preflight 烧 5 分钟净 −5.5% 的场景,合并后由本 PR 在零 summary call 下止损;#2110 事故里 748s 只省 13K 的场景由两者共同覆盖。建议先合 #1818 再合本 PR(或反过来都行,冲突面小)。

@ranxianglei
ranxianglei merged commit 4245277 into master Oct 6, 2026
22 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.87-master.4245277 (rolling master tag).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

模型压缩输出是输入的数倍

1 participant