Skip to content

[PR] fix: preflight — refuse doomed bodies before folding when tools[]/system/other alone exceed the window - #7175

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-11-18_preflight-irreducible-gate
Open

ranxianglei wants to merge 4 commits into
masterfrom
2026-11-18_preflight-irreducible-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #7167

查重: 不重复 — related-but-distinct: #6459 (probe-for-evidence doom-bar 413 before any fold — the #2490 byte-floor gate), #7168 (egress fuse counts non-contextual upload fields into the model window), #7092/#7016 (egress fuse and doom gates price prompt mass, not the whole body). None measures the irreducible dimensions (tools[]/system/other) of the unmodified outbound body before preflightCompress runs — that is this issue's distinct mechanism.

What

The preflight trigger's text channel includes tools[] (estimateWireOverhead counts them), so a body whose tools[] alone clear the window triggers the fold — irreversibly rewriting session history and billing real summary tokens — only for the post-fold measured dooms (#1839/#3146 arms) to discover tools[] ≥ window and answer with the 413 anyway. The fold was guaranteed-doomed before it started.

Fix

Right after the trigger guard (before probeForEvidence / preflightCompress), measure the unmodified prepared body with the #554 guard meter (measuredOutbound + estimateRawBodyBreakdown). If tools + system + other — dimensions folding cannot touch — measure ≥ the doom bar (the native window when bili knows it, the headroom limit as fallback — the same bar the post-fold dooms use), fail fast with 413 / retryable:false and a message that states compaction was NOT attempted, the body was NOT forwarded, and names the remedies (trim the tool surface / lazy tool discovery, shorten the system prompt, raise the effective window when the native window is unknown).

Behavior change (intended — per the issue's request)

  • Old: a doomed body (parseable, non-growth-armed, tools+system+other ≥ doomBar) ran the full preflight fold — irreversible history rewrite + summary billing — then 413'd via the post-fold measured dooms ("context ~N tokens exceeds the model window M … preflight compression could not bring it under").
  • New: the same body 413's immediately with the irreducible-dimension message ("tools[] + system + other alone measure ~N … Compaction was NOT attempted and the body was NOT forwarded. Trim the tool surface …"). No history rewrite, no summary billing.
  • No new failure mode: the gate uses the same doom bar and the same meter as the post-fold dooms — it can only refuse a body the post-fold flow would have 413'd anyway. Bodies that previously forwarded are byte-identical on the wire. Growth-armed payloads keep the autoFold fail-open rule (the auto-fold sharp edges: a sub-floor autoFoldTargetTokens causes a fold storm, and externalSummary.* file edits do not take effect until a PUT /__bili/config #3444 floor mechanism owns that regime); unparseable bodies fall through as before.
  • The 413 message is the operator-facing HTTP error body, not model-facing text — no prompt surface moved.

Tests

tests/issue7167-preflight-irreducible-gate.test.ts — e2e through the proxy (window 20K):

  1. The gate: 250 tools (~31K measured) + 50 messages (~10K) → 413 preflight_compress_failed, retryable:false, message asserts compaction was NOT attempted; zero upstream calls, zero summary calls; then the same session with a small tool surface forwards with the ORIGINAL history intact (MARKER-0…MARKER-49 present, no fold block).
  2. Control: 20 tools (~8.5K) + 100 messages (~16K) → trigger fires, irreducible part under the bar → the fold proceeds as before (summary chain runs, folded body forwarded).

Targeted suites green: this file + preflight-fail-fast + issue5000-count-gate + issue3846-local-refusal-evidence + issue2313-probe-forward + external-summary-autofold (35 pass) + preflight-compress + issue1839-ghost-denominator + issue1800-image-arbitration-compress + preflight-window-clamp + preflight-round-budget (12 pass). npm run typecheck clean.

…tem/other alone exceed the window (#7167)

The preflight trigger's text channel includes tools[] (estimateWireOverhead counts them), so a body whose tools[] alone clear the window triggers the fold — irreversibly rewriting session history and billing real summary tokens — only for the post-fold measured dooms (#1839/#3146) to answer with the 413 anyway.

Measure the UNMODIFIED prepared body with the #554 guard meter right after the trigger guard: if tools+system+other (dimensions folding cannot touch) >= the doom bar (native window when bili knows it, headroom limit as fallback — the SAME bar the post-fold dooms use), fail fast with the 413 before probeForEvidence / preflightCompress. The gate can only refuse a body the post-fold flow would have 413'd with the same meter — no new failure mode. Growth-armed payloads keep the autoFold fail-open rule; unparseable bodies fall through as before.

Tests: tests/issue7167-preflight-irreducible-gate.test.ts (e2e through the proxy: doomed body -> 413 with zero summary calls and history intact on the next request; foldable control body still folds).
@ranxianglei ranxianglei added bug Something isn't working p2 scope/kernel labels Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-18_preflight-irreducible-gate (e836df8)

Latest build — install this exact version

npm install -g billion-context@0.0.10840-pr.7175.b83e951

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
e836df8 billion-context@0.0.10840-pr.7175.b83e951 build
8e64e12 billion-context@0.0.10837-pr.7175.8266134 build
bd3d0a2 billion-context@0.0.10830-pr.7175.215da41 build
290384d billion-context@0.0.10822-pr.7175.8785357 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: preflight — refuse doomed bodies before folding when tools[]/system/other alone exceed the window [PR] fix: preflight — refuse doomed bodies before folding when tools[]/system/other alone exceed the window Nov 18, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

查重: 不重复 — this PR is the only open PR for the pre-fold irreducible-dimension gate. Related-but-distinct open PRs touch other mechanisms: #4928 (convergence walk past the doom bar), #5006 (doom byte-floor pricing), #7123 (egress-fuse 413 wording). None gates the irreducible dimensions before the fold.

Review status: BLOCKED — the PR head is red on CI, and I've pinned the root cause.

CI test (windows-latest, node22, shard1) fails two EXISTING e2e tests this PR never touched:

  • #3686 e2e: declared pi past the FULL window folds… — tests/issue3686-pi-codex-ua-host-policy.test.ts:284: "over-window preflight must succeed on the strict relay, got 413" (expected 200)
  • e2e #488-B (Responses): preflight summary requests carry store:false… — tests/fix-488-multimodal.test.ts:175: "oversized restored session's request succeeds" (expected 200, got 413)

Root cause (confirmed): both are Responses-API tests (they post to /v1/responses). The new gate computes irreducible = tools + system + other from estimateRawBodyBreakdown (src/preflight.ts:508), which buckets the body by TOP-LEVEL key and only recognizes messages/tools/system. On the Responses wire the foldable message array lives under input (Google: contents), so it lands in the other bucket — the gate then reads an entirely-foldable 22K message body as "irreducible" and 413s it before any fold runs. The "no new failure mode" claim holds for the OpenAI-chat/Anthropic wires but is false for the Responses/Google wires.

Plan (fixing now): the meter's bucketing must be wire-aware — input/contents → messages, instructions/systemInstruction → system. This is safe: every doom verdict (post-fold #1839/#3146 arms, the egress fuse at src/server/relay.ts:1040) prices total, which a bucket re-split does not change; the gate is the only consumer that reads the bucket split for a verdict, and the measuredBreakdownClause display becomes more accurate, not less. I'll run the targeted suites, push a labeled commit to the PR branch, and follow up with the full 8-question review.

ci-check added 3 commits November 18, 2026 23:08
…7167)

The #7175 irreducible gate reads tools+system+other from
estimateRawBodyBreakdown, which bucketed the outbound body by top-level key
and only recognized 'messages'/'system'. On the Responses wire the foldable
message array lives under 'input' (Google: 'contents'), so it landed in the
'other' bucket and the gate 413'd an entirely-foldable body before any fold
ran — the #3686 / #488-B Responses e2e regressions on the PR head.

Make the bucketing wire-aware: 'input'/'contents' -> messages,
'instructions'/'systemInstruction' -> system. 'total' is the sum of the
buckets either way, so the doom verdicts that price 'total' (post-fold
#1839/#3146 arms, the egress fuse) are untouched; only the gate's bucket
split and the measuredBreakdownClause display shift.
…post-fold measured doom

The new pre-fold irreducible-dimension gate (src/server.ts) now answers a
tools-heavy body before the fold runs, so the e2e #5000 case (120 tools ×
40KB, core text clearing the byte floor) 413s with the irreducible message
instead of the post-fold 'outbound body measures ~N TEXT tokens' doom. The
behavior is the PR's intended change (no history rewrite, no summary
billing); the test's assertion and comment were stale. Update them to pin
the new verdict: code preflight_compress_failed, retryable false, the
irreducible-dimension message, 'Compaction was NOT attempted', zero
upstream calls.
…ges bucket)

The #7167 irreducible-dimension gate prices total - messages, so the foldable
message channel must be bucketed as messages for every wire shape (chat
messages[], Responses input, Google contents). Pin that with a unit test so
the gate cannot doom an over-window Responses/Google body before a fold could
run (the CI break where input/contents mass landed in other and the gate 413'd
perfectly-foldable bodies).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

The red CI reported by this wake (head 290384d, 11 failing test shards) is already fixed. The current head of the PR branch is e836df8a14, and its CI is fully green (56 check runs: 40 success, 16 skipped, 0 pending, 0 failed). No further work needed.

八问摘要

  1. 是什么问题: PR [PR] fix: preflight — refuse doomed bodies before folding when tools[]/system/other alone exceed the window #7175 的 CI 红了——11 个 test shard 全部失败在同一个测试:egress-fuse [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(tests/issue4079-egress-window-fuse.test.ts:204)的消息断言不匹配。

  2. 什么原因导致的: PR 新增的 Preflight folds message ranges before checking whether tools[] alone already exceed the window (wasted compression + guaranteed 413) #7167 不可约维度门(src/server.ts:4049-4063)在 tools[] 质量体上先于 post-fold measured tier 触发,返回更精确的消息("tools[] + system + other alone measure ~X tokens … vs the model's window …")。[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 测试的消息正则(/outbound body measures ~[\d,]+ TEXT tokens/)是旧的 measured-tier 措辞,与新门的消息不匹配。判定不变(413 / preflight_compress_failed / retryable=false / NOT forwarded / 零上游调用),只有消息措辞变了。

  3. 影响范围与严重程度: 仅 [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 测试的一行消息断言过时。非行为回归——判定不变,只有消息措辞变了。严重度:测试断言过时(p3)。

  4. 怎么修复的: 更新 [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 测试的消息断言到新门的消息(/tools\[\] \+ system \+ other alone measure ~[\d,]+ tokens/),并加 "Compaction was NOT attempted" 断言(确认 fold 没跑)。另加回归测试(tests/raw-body-walk-depth.test.ts)钉住 shape-aware breakdown(messages/input/contents → messages bucket),防止门在 Responses/Google 线上把可折叠质量误判为 other 而误 413。

  5. 是否有回归问题: 无。判定不变(413 / retryable=false / NOT forwarded / 零上游调用),只有消息措辞变了。回归测试钉住 breakdown 的 bucket 逻辑,防止 future regression。

  6. 是否破坏缓存: 不涉及。

  7. 是否改了设计方向: 不涉及。

  8. 是否引入了新的配置: 不涉及。

结论: CI 已绿,PR 可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Confirmed green. The current head of the PR branch is e836df8a14 (ahead of the reported bd3d0a2726), and its CI is fully green: 56 check runs, 40 success, 16 skipped, 0 pending, 0 failed. The 3 failing shards reported by this wake were already fixed in the earlier run. No further work needed.

This branch has not been deployed

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

Labels

bug Something isn't working p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preflight folds message ranges before checking whether tools[] alone already exceed the window (wasted compression + guaranteed 413)

1 participant