Repository navigation
[PR] fix: egress window fuse — stop provably-doomed bodies at the last send site (#4079) - #4090
Conversation
…d site (#4079) Every send-side check was either pure bytes (5GiB budget) or lived only inside preflight's two escape hatches (#2313/#3146); a request that reached forward() without preflight judging it hit the socket with zero window comparison (#4068: a 6,165,048-token send against a 1,048,580 window; #3872: a 5.35x re-send after a wire switch). Two layers, same doom math as #2490 (core text bytes vs the densest observed tokenizer, 7.5 B/token #2122 — only bodies NO tokenizer can fit are blocked, so a dense-but-fitting payload never false-positives): - relay egress fuse in forward(): pre-send check against session.metadata.effectiveContextLimit for every non-side, non-passthrough POST; answers 413 request_too_large/egress_window_fuse (retryable:false, #2847 semantics) instead of forwarding a guaranteed 4xx. No LocalRefusalRecord — the body itself re-trips the fuse on every retry, a record would only lock the route the way #3974 suffered. - gate `none` oversize arm: an UNATTRIBUTED body whose optimistic byte floor (bytes/4) already exceeds the window refuses LOCALLY (422, oversize-refusal-unattributed) instead of riding #1117's direct send into the #4068 upstream-rejection loop. Mirrors the threw arm (#2924); unknown window or unreadable body keeps #1117 semantics, attributed traffic is untouched. Refs #4079. Local: typecheck, issue4079 suite 2/2, ACP_TEST_E2E_FAKE 8/8.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4887-pr.4090.e44d356This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4090.tgz
npm install -g packageInstall instructions are refreshed on each push. |
A declared window can be wrong SMALL — stale modelContextLimit, a registry miss, a model-catalog fallback (#3993: 475K->258K), a plugin under-reporting — and a catastrophic-only byte-floor guard keyed to an undersized window would false-block bodies the real upstream accepts. Both guards now size against max(declared, MIN_ASSUMED_WINDOW_TOKENS = 1,000,000) (src/util.ts, shared by the relay lane and the dsh gate so the floor cannot drift): - relay egress fuse: bar = max(2MB, max(declared, 1M) x 7.5 B/token); the refusal message states the floor for the operator. - dsh gate threw + none oversize arms: refuse only when bytes/4 exceeds the floored bar; log lines print declared and floored values. Trade (deliberate): bodies 'only' 2-5x a small declared window now pass the byte guards — preflight + the calibration loop own that range; only bodies no 1M-token window could hold are stopped locally. #4068's 6.16M-token body (~18MB core text) still trips the fuse. Tests: e2e positive moves to 8.68MB (> 7.5MB floored bar) and pins the floor note in the message; the under-bar case doubles as the mis-sized-window both-ways pin (1.63MB vs a 20K declared window forwards). dsh gate tests move the refusal boundary to 4,000,004 B and add the over-declared-but-under-floor negative. Refs #4079. Related: #4068, #3993.
|
(ai: zai-org/GLM-5.3) 按 owner 要求收紧了拦截线的口径(e17e8df6):两条闸的窗口一律以 100 万 token 打底( 理由:声明/配置的窗口可能被拿小(用户手滑设小 新拦截线:
代价(刻意):小窗口会话 2–5 倍超窗的 body 现在会放行冲上游吃一次 400——这个量级归 preflight + #4093 校准闭环管,字节闸只管"1M 窗口都装不下"的灾难级(#4068 的 6.16M tok ≈18MB 依旧拦住)。拒绝文案里同时打出 declared 和 floored 两个值,方便运维看出窗口声明有问题。 测试已同步:e2e 正例改 8.68MB(>7.5MB floored 线),负例 1.63MB 对 20K 声明窗口放行(错杀防护的 both-ways 钉子);dsh 门边界移到 4,000,004B,并新增"超声明窗口但低于 1M 地板→不拒"的反向断言。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.705-master.37afa81 # this exact build
npm install -g billion-context@master # always the newest merged build
|
(ai: vllm-qwen/qwen3.8-27b) 本 PR(#4098,发送侧窗口闸)是 #4090 的重复实现,按先来后到关闭。 说明:#4098 于昨晚开出时做了出站查重但未命中 #4090(标题措辞「egress window fuse」与我的检索词不匹配——按失败签名/机制匹配的教训记下了)。两者同症状、同机制、同根因:在最终发送点用同一套 doomed-probe 字节数学( #4090 胜出的三点:
无内容需要保留:我分支里的机械重构(DOOMED 常量移位、local-refusal 模块抽取)依附于闸门本身,闸门被吸收后无独立价值。关闭。 |
What this fixes
Upstream 413/400 loops where bili forwarded a body that provably cannot fit any context window:
413 {"code":3,"message":"Request size limit exceeded"}). The host then retries the SAME oversized history every turn.ContextWindowExceededError.Root-cause umbrella: #4079 (统一根因分析). This is the cheapest damage-control layer from that analysis — the closed-loop calibration fix (teach the estimator from 400s) follows separately.
The hole
Every send-side check in
forward()was either pure bytes (checkOutboundBody's 5GiB budget,relay.ts:569) or lived only inside preflight's two escape hatches (#2313 estimate-only probe / #3146 fresh-session forward-once). A request that reachedforward()without preflight judging it — nomodelin the body, trigger not firing, plugin lane, a wire-dialect reconcile that re-anchored nothing and re-sent verbatim — hit the socket with zero window comparison. No token-vs-window check exists anywhere between the prepared body and the socket.The fix (two layers, same bars)
Both layers reuse the existing doom-probe math (#2490): core-text bytes vs
max(2MB, floored-window × 7.5 B/token)— 7.5 B/token is the densest tokenizer density ever observed on a live route (#2122), so only bodies no tokenizer can fit are blocked. A dense-but-fitting payload is never false-positived (pinned both-ways in tests, #3617).The window itself is floored at 1,000,000 tokens (
MIN_ASSUMED_WINDOW_TOKENS, src/util.ts, shared by both lanes so it cannot drift): a declared window can be wrong SMALL — stalemodelContextLimit, a registry miss, a #3993-style catalog fallback (475K→258K) — and a catastrophic-only guard keyed to an undersized window would false-block bodies the real upstream accepts. Deliberate trade: bodies "only" 2–5× a small declared window now pass the byte guards (preflight + the calibration loop own that range); only bodies no 1M-token window could hold are stopped locally. #4068's 6,165,048-token body (~18MB core text) still trips the fuse.Relay egress fuse (
src/server/relay.ts, right aftercheckOutboundBody): for every non-side, non-passthrough POST with a knownsession.metadata.effectiveContextLimit, compare the final payload's core-text byte mass against the doom bars and answer413 {type:"request_too_large", code:"egress_window_fuse", retryable:false}([Evidence] pi 车道切供应商(同 modelId)后 fold 不随会话迁移:裸上下文 2.23MB(≥298K est tokens)被 preflight 10 秒拒 3 次;账面 ≤157K 与裸水位背离 10.5h #2847 semantics: hosts must not retry) instead of forwarding a guaranteed 4xx. Deliberately noLocalRefusalRecord: the doomed body itself re-trips the fuse on every retry — a record would only outlive the turn and lock the route the way The context window suddenly hit its limit and threw an error. Starting a new session didn't help either. dsh | 上下文突然满了报错 新会话也没用 dsh #3974 suffered.Gate
noneoversize arm (src/agent/dsh-native.ts): the The input (6165048 tokens) is longer than the model's context length (1048580 tokens(todo fix)). #4068 channel specifically. When the takeover gate cannot attribute a request (none— agentless lane, quota/model-switch path without an ALS boundary, The D4.1F model accessed via the WorkBuddy reverse proxy cannot be compressed. | 使用workbuddy反代的D4.1F模型无法压缩 #2975/Why did it spike to several M tokens: after dsh attribution was lost, requests bypassed bili and were sent directly, ren | 为什么会涨到几 M tokens:dsh 归因丢失后请求绕过 bili 直发,压缩与护栏全部失效 #4082), it currently lets the raw body go DIRECT (「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117) — where no bili check exists at all. Now an unattributed body whose optimistic byte floor (bytes/4) already exceeds the window refuses LOCALLY (422,oversize-refusal-unattributed, its own remedy wording — there is no broken scope to restart) instead of riding direct into the upstream-rejection loop. This mirrors the existingthrewarm ([dsh-native] takeover-gate refusal (threw state) fails open with the FULL uncompressed transcript; a >window local history dies upstream with 400 (maximum context length) #2924) with identical never-false-refuse reasoning; unknown window or unreadable/stream body keeps 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117 semantics, and attributed traffic is untouched (it goes to the proxy where preflight's own doom math decides).What this PR deliberately does NOT do
LocalRefusalRecord, analyzed in Context Window Overflow Issue Summary: Raw Requests Sent Directly to Upstream Rejected + Local Intercept Cooldown Lockin | 上下文超窗问题汇总:请求裸冲上游被拒 + 本地拦截冷却锁死会话(统一分析入口) #4079 — separate discussion).Tests
tests/issue4079-egress-window-fuse.test.ts(new): e2e both-ways — a no-model 8.68MB body (preflight skipped via!model) answers 413egress_window_fusewith the byte math and the 1M floor note in the message and zero upstream calls; bodies under the bars — including a 1.63MB one against a 20K declared window (over its own ×7.5 ratio bar, under the floored bar) — still forward: a mis-sized small window never false-blocks.tests/dsh-native.test.ts: gatenone+threwarms — refusal fires at 4,000,004B (bytes/4 = 1,000,001 > floored bar 1M),falseat exactly the bar,falsefor over-declared-but-under-floor bodies (4004B vs a 1000-token declared window),falseon unreadable body / unknown window,truefor attributed traffic, durable LOCAL-refusal line in bili.log.Local:
typecheck✅, issue4079 suite 2/2 ✅,ACP_TEST_E2E_FAKE=18/8 ✅. The dsh-native attach-flow tests cannot run in my sandbox (they time out identically on clean master — environment); relying on the CI test lane per repo discipline.Refs #4079. Related: #4068, #3872, #3918, #4082, #2924, #2490.