Repository navigation
[PR] preflight: stop hard-truncating extreme overflows by default; fold fresh-session first resends in parallel - #7549
Conversation
…le hard truncation) The >=19.2x-coverage regime converts every fold into a CPU-only deterministic digest (no LLM calls) because the LLM ladder provably cannot converge within its raised budget. From the model's point of view that is a hard truncation: the conversation history is replaced by size-labelled head-fragment digests, and a session that enters this regime keeps serving digests of its own digest history (#4224/#4047 show it is a recurring, sticky outcome for oversized fresh sessions). Owner decision 2026-11-22: do not ship this behavior by default — a session should fail fast with an actionable structured 413 (client decides: drop oldest tool results / start fresh) instead of silently degrading into digest soup. The regime is preserved verbatim behind an opt-in: - env BILI_PREFLIGHT_EMERGENCY_DIGEST=1 (wins) or - file config network.emergencyDigest: true When disabled at the overshoot, the LLM fold ladder runs as before and, if it exhausts its raised budget, the request fails fast — no digest blocks are ever created. The warn log distinguishes the two paths so production #2383-class cases stay diagnosable from the log alone. Tests: the e2e regime test now sets the env explicitly (it tests the opt-in behavior), plus a new default-off e2e proving an unconvergent extreme-overflow fresh session gets fail-fast 413/502 with NO digest blocks and NO forward. The fresh-session size math is documented in the test: below the byte floor a fresh session cannot reach the regime's char-based trigger, so the 2.56MB test payload is answered by the deterministic byte-floor fail-fast under default-off — same user-visible contract (no digests, no forward), env=1 flips it to digest convergence.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11532-pr.7549.74ae7e9This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7549.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…summaries (owner decision 2026-11-22, #2383 follow-up) A session that has never been forwarded (no usage sample ever landed — lastInputTokens <= 0) resends its whole raw history verbatim, so no compression blocks can have been lost and folding is pure gain. For those fresh sessions below the 6M-char bound (~1M real tokens x 4 chars/token x 1.5 headroom), preflight now nominates K=2 disjoint ranges per round, runs their in-model summarization calls CONCURRENTLY (Promise.all — the pure call part only), and commits the candidates sequentially afterwards (kernel state mutates single-threaded, #2678 shape). The serial walk keeps one fold per round; the half-life of the 15-40s ladder halves, and a range the parallel pass cannot summarize is deliberately left out of the skipSet so the walk takes it over with its halving/transient/probe semantics. Existing sessions are untouched: a large payload there may indicate LOST folds, and the owner's rule for that case is to diagnose (warn), not to spend tokens folding — that tier lands as a separate diagnostic. Above the 6M-char bound the request fails fast instead (the default-off digest regime, prior commit) rather than burning the call budget without converging. Nomination, span selection, preview/render gates, acceptance (max cap, net-shrink monotonicity, rescue truncate) and failure shapes mirror the walk and the external batch lane byte-for-byte. Test: fresh anonymous session, 30 x 10k-char messages (~300k chars, under the doomed-probe byte floor, non-emergency), asserts peak in-flight >= 2 summarization calls, single forward, mid-history folded out of the rebuilt payload (kernel anchor + recent tail stay resident by design), and the blocks hold the upstream-written summaries.
49781ce to
9f2d74e
Compare
…est (PR #7549 review) - gate: require zero compression blocks in addition to lastInputTokens <= 0 — credit-floored existing sessions (cache-ledger settle) and adopted anonymous forks (fork-adoption) both look 'fresh' on the usage stat but carry active blocks; folding them would spend tokens on possibly-LOST fold state, which the owner's rule says to diagnose instead (review M1) - lane: #1993 halving parity across rounds — a hard 400/413 on a span now remembers the two snapped halves by ref (freshHalvedSpans) and the next round's nomination consumes them before retrying the full span; at/below the minimum-span floor the range goes to skipSet like the walk (M2) - lane: a hard upstream verdict stands as the round's failure BEFORE the sequential commits (each successful commit still clears it via commitFold's #1993 reset) — the old committed===0 guard swallowed a deterministic shape wall (#2189) behind one lucky commit (M2) - lane: first hard verdict wins (abort always wins) instead of last-writer-wins under concurrency (L2); 400 detail text now matches the walk's #2189 wording (L4); 'nomination order' comment corrected to size-desc (L3); failed-range takeover comment now states the real semantics (walk only runs in a round where the lane committed nothing) - test (M3/L1): the default-off e2e was 2.56MB — above the 2MB doomed-probe byte floor, so it answered 413 before preflight and pinned nothing about the gate. Resized to 60x32k = 1.92MB (below the floor, ~20x the window): asserts the ladder actually ran (summarization calls >= 1) and no digest artifacts — a clean A/B against the env=1 e2e at the same size. The incorrect 'fresh sessions below the byte floor cannot reach the regime' comment is replaced with the correct geometry.
ranxianglei
left a comment
There was a problem hiding this comment.
Review(agent 深度评审,1.9M tokens 上下文,独立工作树实测 9/9 测试 + typecheck):结论 = 可合并,无 blocker。 发现 3 个 medium + 5 个 low,其中 3 个 medium 已在本分支修掉(commit 917845bc),low 里注释/文案 4 处一并修掉,1 处(测试内注释几何错误)随 medium 测试重写解决。
已修(917845bc):
- M1 — 新会话 gate 不够严。
lastInputTokens <= 0会把两种「看起来是新的」存量会话误判进来:① credit-floor 结算后 usage 归 0 的长折叠会话(src/cache-ledger.ts settle 逻辑,值持久化);② adopted anonymous fork(src/fork-adoption.ts 故意不继承 stats 但继承 blocks)。它们带着 active blocks 进来,并行 lane 就恰好花在「可能丢了折叠状态」的会话上 —— 正是 owner 规则说不能盲折的那类。修复:gate 加state.blocks.length === 0,零块 = 没有任何东西可以丢。 - M2 — 失败 range 的跨轮恢复与串行 walk 不一致。旧注释说「同一轮串行 walk 接管」,实际 lane commit ≥1 时占满了该轮唯一 fold 额度,walk 根本不跑;且 lane 没有 halving 等价物,持续 400 的 span 会每轮烧全尺寸调用直到预算耗尽;另一个 hard verdict(#2189 shape wall)在「有 commit 成功」时被静默吞掉。修复:① 400/413 按 span 记住两个折半 ref(
freshHalvedSpans),下轮提名优先消费,低于最小 span 下限进 skipSet —— 对齐 walk 的 #1993 halving 语义;② lane failure 在串行 commit 之前置位,成功 commit 经 commitFold 的既有 #1993 reset 清除 —— 有成功就清、没成功就报,与 walk 的语义一致。 - M3 — default-off 测试 pin 的是别的东西。原尺寸 2.56MB 超过 2MB doomed-probe 字节底线,413 发生在 preflight 之前,master 上同样通过,gate 路径零 pin。重写到 1.92MB(底线之下、~20× 窗口之上):断言 ladder 真的跑了(≥1 次摘要调用)+ 无 digest 产物,与 env=1 的 e2e 同尺寸构成干净 A/B。顺带修正了测试里一段错误的「新会话进不了 regime」几何注释。
低优先级已顺手修:并发失败 first-writer-wins(原来 last-writer-wins,非确定性);400 detail 文案补齐 walk 的 #2189 说明句;两处注释(「oldest first」实为 size-desc;takeover 语义)改为真实行为。
评审确认过的问题点(无需改动):无 TOCTOU(summaryBudget 是硬顶,所有先查后增都在同步段);顺序 commit 在并发摘要之后是保守正确的(foldTargetKey 失配丢弃朝安全侧偏);lane 与 walk 的 span 选择 / preview / 接受阈值 / #2832 deterministic-empty 语义一致;batch lane、串行 walk、存量会话路径纯增量 gated;#7546 one-shot preflight 计数不受非 abort 失败消耗。
留档说明(PR body 已注明,非本 PR 范围):#2383 生产形态(已知 baseline 的超大首重发)在新默认下走完整 ladder、收敛不了就 502 —— 需要旧零调用 digest 收敛的部署用 BILI_PREFLIGHT_EMERGENCY_DIGEST=1 保留;存量大会话的「块丢失诊断(warn 而非折叠)」按 owner 决定是后续项。
…not zero calls With the #2383 emergency digest default-OFF (#7549), the fresh-parallel fold lane spends a few small summarization calls on the (unreducible) core text before the fail-fast. The #5000 test's calls.length===0 assertion (written for the always-on digest) now fails on those calls. Assert the actual intent instead: no call may carry the 4.8MB tools-mass body itself.
(ai: vllm-qwen/qwen3.8-27b) CI fix pushed — The red CI (test windows-latest 22 shard 5) was the Fix: updated the #5000 assertion from Note for the PR author (not blocking): the fresh-parallel fold lane makes 3 futile summarization calls for a body whose mass is in 八问(结构化审核结论)
收工判定:CI 红已修( |
(ai: vllm-qwen/qwen3.8-27b) This event is stale — it reports CI run |
(ai: vllm-qwen/qwen3.8-27b) Duplicate of the previous stale event — same CI run |
… off; opt digest-designed tests in (#2383, #2847) - default-off + payload > 19.2x the window (the ladder's own 32-call x 0.6-window coverage product, above which no combination of successful folds is guaranteed to land under the window): fail IMMEDIATELY with a deterministic structural-exhaustion verdict — zero summarization calls, zero wall clock. Burning up to 32 large-context summary calls for minutes no client outlives is exactly #2383's 300s-disconnect loop. The verdict is deterministic (a retry changes nothing), so the caller's existing contracts apply unchanged: a trusted session keeps the identity fast path (upstream usage reality outranks local doom math), every other session gets the terminal non-retryable 413 (#2847: 502 would be retried forever by status-code-driven hosts). The fresh parallel lane spends the same budget concurrently, so it does not raise the bound either — it only makes the convergent band below it faster. - default-off e2e now pins the terminal 413 with zero upstream calls (the #554 measured-body guard may answer with its own over-window wording ahead of the preflight detail — both accepted). - three tests designed around the digest regime now opt in explicitly: the knob reads env or the ON-DISK config file, never in-process startServer options — the #5631 lanes get it via their spawned proxy's BILI_CONFIG_FILE, #1987 and #4227 set the env for the test's duration. - CI note: #6069 epoch-pause e2e is red on master itself (run 45047243756 on rebase base 9ad612e; reproduced on a clean baseline checkout) — pre-existing, not a regression here.
追加:CI 回归修复 + 红项归因(commit 990bd41,已推)上一条评审后,PR 的 CI 出现 9 个红分片。逐条定位、修复、归因如下: 1. 真回归(本 PR 引入,已修):fix-identity 快速通道两条 e2e。 2. 三个"为 digest 设计"的测试改为显式 opt-in(不删不削弱): 3. 非本 PR 回归(归因,不动):
测试:受影响套件(fix-identity 5/5、preflight-emergency-fold 9/9、#5631/#1987/#4227/#2952/#5000/#4079)本地全绿; |
(ai: vllm-qwen/qwen3.8-27b) 收到。已核实当前 PR head 为 归因确认(与 owner 描述一致):
CI 完成后若仍有红项我再跟进;当前无需进一步动作。 |
…est line split) N3: lifecycle row said ≥19.2x, the code gate is strict > (src/preflight.ts:2049). N4: env assignment crammed onto the next statement's line in the #1987 test.
ranxianglei
left a comment
There was a problem hiding this comment.
Final review of HEAD (990bd41) — ready to merge, no blockers.
Reviewed the full 13-file diff against master commit-by-commit, verified the six server.ts contract rows for the structural fast-fail (trusted forward-once, deterministic 413 mapping, #2847 terminal-vs-retryable, #3918 progress, #7546 one-shot, #496 images), and re-ran all five touched test files locally (20/20) plus typecheck. The coverage-bound math checks out (19.2x = the ladder's maximum scaled budget of 32 × 0.6-window folds), and the (19.2x, ~20.2x] band failing fast instead of burning 32 calls for 8–21 minutes is the right call — that band was exactly #2383's 300s-disconnect loop.
Five minor nits found, none blocking:
- N3 (docs): lifecycle row said "≥19.2×", the code gate is strict
>— fixed in d3eb7ff. - N4 (test formatting): env assignment crammed onto the next line in the #1987 test — fixed in d3eb7ff.
- N1 (optional): the walk loop has no top-of-iteration
failurecheck, so after a 0-commit hard lane failure the walk may spend ≤1 extra bounded summary call before breaking. Verdict is correct either way; left as-is (one wasted call at worst, matches the walk's existing mid-loop style). - N2 (doc note): for fresh (no-baseline) sessions the overshoot is char-based, so the fast-fail bound trips at ~4.8× true-token overshoot for ASCII text — conservative direction (fail fast, never forward a guaranteed 400), inherited from #2383's char-regime math. Not a bug; noted for the follow-up doc.
- N5 (micro-perf):
refMaps()is recomputed per nominated range (≤2/round); negligible, left as-is.
d3eb7ff touches only docs and one test-file line split — runtime behavior is byte-identical to 990bd41, the commit the local real-model gate passed 17/17 on, so that result stands for this head.
…ency-digest-default-off # Conflicts: # tests/issue4079-egress-window-fuse.test.ts
…ge of 9236576) #7537 dropped the local estimate-based 413 refusals: a deterministic exhaustion verdict on a session with NO proven upstream wall now forwards (src/server.ts:4951) and the upstream's own size verdict is authoritative. The default-off pin keeps the property this PR owns — the structural verdict fires BEFORE the 32-call ladder (exactly one upstream call, the forward itself) — and the evidence-based 413 remains for sessions with a proven window.
4c43d6f to
4ae7e33
Compare
ranxianglei
left a comment
There was a problem hiding this comment.
Merge-conflict resolution: master 9236576 (#7548/#7537) into this branch
Heads-up on the force push: the branch previously carried an automated master-merge commit (4c43d6f) made from a stale master that predates #7548/#7537, which forked the branch against my local merge. The new head 4ae7e33 is a single clean merge of current master (9236576) plus the two re-pin test edits below — same logical content as before, nothing lost (verified by diff).
The semantic interaction (this is the whole story): #7537 changed the repo's contract for untrusted sessions — no more local size refusals; forward and let the upstream's own verdict be authoritative (only refusals backed by a proven upstream wall survive). One of this PR's pinned behaviors — "untrusted session + deterministic local exhaustion → local 413" — was killed by #7537's owner ruling. The tests were re-pinned to the post-#7537 contract:
tests/preflight-emergency-fold.test.ts(default-off e2e): the untrusted no-wall session is now forwarded per #7537, so the pin flips to: status 200, exactly one upstream call — the forward itself — and zero digest artifacts. What the test still pins for this PR is the property that mattered: the structural verdict fires before the 32-call ladder (zero wasted calls, zero ladder wallclock).tests/issue4079-egress-window-fuse.test.ts(merge conflict): took master's #7537 side (upstream 413 passthrough +x-bili-cause: upstream-size+ payload actually forwarded) and relaxedcalls.length === 1to "exactly one ≥1MB full-body call, with only small summary calls before it" — the fresh-parallel lane may spend a couple of small in-model calls before the forward, which master's stricter pin didn't anticipate.- The 413-veto arm of
fix-identity-fast-path-preflightis untouched and still green because it seeds a usage baseline — a proven upstream wall, exactly the class #7537 preserves.
What the structural fast-fail still does after the merge: zero wasted LLM calls and zero ladder wallclock for >19.2× payloads with digest off; deterministic exhaustion with a proven wall → 413 (the only remaining local refusal); trusted sessions → immediate forward-once. The CI run on 4ae7e33 is in progress; expected to be green apart from the pre-existing master #6069 reds (documented in the PR body). Local real-model gate (gate:local) is being re-run on the merged tree per the all-green-before-merge flow.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1288-master.15f06c6 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…lict, round 7) Master moved 0b68ade -> 15f06c6 (kernel 0.0.205, +preflight emergency-digest default-off #7549, +preflight 413 passthrough #7548, +sessions reattach #7512, +opencode user-fork detection #5511, +acp-status uncompressed nudge-align #7536, +preflight gate epoch exception #7558, +413 egress fuse pins #7488, +Korean README #7551, +many host/test changes). Conflicts: 3 version-only files (kernel/package.json, kernel/package-lock.json, root package-lock.json). Resolved to kernel 0.0.206 (merged kernel = superset of master's 0.0.205 + PR #6720/#6762 changes; kernel/src changed vs master => must bump above master's 0.0.205). Auto-merged clean: kernel/src/compress.ts (PR markers 13x + master changes), src/stream.ts (PR markers 3x), src/server.ts, master's new test files, docs. Local verification: typecheck ✓, build ✓, kernel 1671 pass / 0 fail, host nudge/receipt 7 pass / 0 fail, kernel-guard ✓ (SRC_CHANGED=2 BUMPED=1 0.0.205->0.0.206), version-guard ✓ (root 0.1.216 untouched), lock-sync ✓.
Why
Two behaviors for "session is far bigger than the model window" (the #2383/#7271 family), per owner decision 2026-11-22:
What changed
Commit 1 — the digest regime is OFF by default, with a structural fast-fail in its place.
BILI_PREFLIGHT_EMERGENCY_DIGEST=1ornetwork.emergencyDigest: truerestores the old behavior. With it off, a payload beyond the fold path's coverage bound (19.2x the window — the ladder's own 32-call × 0.6-window coverage product, above which no combination of successful folds is guaranteed to land under the window) fails immediately with a deterministic structural-exhaustion verdict: zero summarization calls, zero wall clock. Burning up to 32 large-context summary calls for minutes of wall clock that no client outlives is exactly #2383's 300s-disconnect loop. The verdict isdeterministicbecause a retry changes nothing, so the caller's existing contract handling applies: a trusted session keeps the identity fast path (upstream usage reality outranks local doom math — the fix-identity e2es pass unchanged), a session with a proven upstream wall (usage evidence on this origin+model) keeps the non-retryable 413 — now the only local size refusal left after #7537, which dropped every estimate-based refusal — and a session with no wall forwards, letting the upstream's own size verdict be authoritative (#7537, owner ruling 2026-11-22). For an established session a payload this size is additionally the lost-compression-blocks symptom — diagnosing, not token-burning, is the owner's rule for that case.Merged master 9236576 (which brought in #7548 / #7537 "no local estimate-based refusals"). The only conflict was the re-pinned issue4079 arm (kept #7537's forward-plus-upstream-verdict pin, shaped to tolerate this PR's small pre-forward summary calls); the default-off e2e was re-pinned from local-413 to #7537's forward semantics. The fast-fail's own value is unchanged — zero ladder calls, zero wall clock — only what the verdict leads to follows the #7537 ruling.
Commit 2 — fresh sessions fold in parallel. Only for sessions that have never been forwarded AND never landed a fold (no usage sample and zero compression blocks — nothing could have been "lost", folding is pure gain; the zero-block clause is what excludes the two look-alikes: credit-floored existing sessions whose usage stat settles to 0, and adopted anonymous forks that inherit blocks but not stats). Below the 6M-char bound (~1M real tokens x 4 chars/token x 1.5 headroom): preflight now nominates two disjoint ranges per round instead of one. The in-model summarization calls run concurrently (Promise.all over the pure call part); the commits stay sequential (kernel state mutates single-threaded — same shape as the #2678 external batch lane). A range the parallel pass cannot summarize is deliberately left out of the skip-set: the next round re-nominates it (a hard 400/413 also remembers the span's two halves, mirroring the serial walk's #1993 halving recovery), and a round where the parallel pass commits nothing falls through to the serial walk unchanged.
Beyond the coverage bound (19.2x) the structural fast-fail applies to fresh sessions too — the parallel lane spends the same 32-call budget concurrently, so it does not raise the bound; it only makes the convergent band below it faster. Fresh resends above 6M chars (≈1M real tokens) also get the fast-fail: the owner's gate says folding that much is not worth the token spend.
Existing sessions (any session with a usage sample or any compression block), the external batch lane, the serial walk, and all failure shapes are untouched.
What is explicitly NOT in this PR
Tests
tests/preflight-emergency-fold.test.ts(9/9 on rebased master,tsc --noEmitclean):TAIL_5_convention), blocks hold the upstream-written summaries.CI regression notes (all fixed in this PR):
BILI_CONFIG_FILE; in-process e2es setBILI_PREFLIGHT_EMERGENCY_DIGEST=1for the test's duration).