Skip to content

[PR] fix: refuse provably over-window payloads at the send path — final window gate (#4079 PR①) - #4098

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_send-side-window-gate
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-21_send-side-window-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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

What & why

#4079 统一分析 fix-plan step 1 / PR①(发送侧最后一道窗口护栏),同时落地 #3872 option B(option A「换 wire 触发强制折叠」仍留在 #3872 讨论)。

Preflight 用校准后的估算尺判窗。两条路让超窗请求逃过所有本地检查、裸冲到上游被拒:

  1. 估算尺系统性低估(密集多字节内容、换 wire 后体积跳变 —— Mid-session wire/dialect switch sends one request far beyond the declared window (upstream ContextWindowExceededError); no send-time size guard #3872 的 5.35×):preflight 判"fits",实际字节量远超任何 tokenizer 能装下的量;
  2. preflight 根本没触发(基线安静 + 客户端侧突然膨胀,G3 盲区)。

本 PR 在 forward() 发送漏斗加一道字节数学兜底:把 preflight 两个逃生分支里已有的 doomed-probe 数学(max(2MB, window×7.5) 字节,#2490/#3146)扩展到最终出站路径。

机制(为什么零误伤)

行为变更披露(旧值→新值)

项 旧 新
核心文本字节量 > max(2MB, window×7.5) 且 preflight 已放行(估算尺低估或触发缺失)的请求 转发到上游 → 不透明 400/413(或超大 body 的 ECONNRESET/413 size-limit) 本地 413 stage=send-window-guard,零上游调用,消息可读
低于该阈值的请求 / passthrough / side / 无声明窗口 转发 完全不变(测试钉住)
新增错误响应字段 — error.stage="send-window-guard"(既有 stage="forward" 5GiB cap 不变)

误伤面:ASCII 为主的载荷在 preflight 阶段就会被先拦(est=bytes/4 > 1.875×window 时门必亮),所以门的增量价值集中在多字节密集内容与触发缺失路径——正是 #3872/#3900 的形状。

结构改动(机械抽取,行为不变)

  • DOOMED_PROBE_* 常量从 server.ts 移到 preflight.ts(三处 doomed 调用点单一来源);
  • LocalRefusalRecord 三件套抽到新模块 src/local-refusal.ts(server.ts 与 relay.ts 共用,避免 relay→server 循环依赖)。

验证

Addresses #4079(hub fix-plan step 1)· Implements #3872 option B · 查重: 无(open+closed 均无发送侧窗口护栏在途 PR/issue)

…sed locally

#4079 fix-plan step 1 (PR①): extend the doomed-probe byte math (window×7.5 /
absolute 2MB, #2490/#3146) from the two preflight escape branches to the
forward() send funnel. Preflight judges on the calibrated ESTIMATE scale, so a
systematically underestimated payload (dense content, wire-switch bloat #3872)
or one that never triggered preflight (quiet baseline + sudden client-side
growth) passed every local check and arrived at upstream as a guaranteed-reject
multi-MB body (400/413). The gate prices the FINAL outbound core text in UTF-8
bytes — bytes/7.5 is a LOWER bound on token count, so exceeding the window at
the lower bound means no tokenizer can fit it: honest local 413 (stage
"send-window-guard") + LocalRefusalRecord for the scope, zero upstream calls.

- initial send only: #1195 refold resends re-run preflight (incl. its own
  doomed check) against the upstream-STATED window further down
- excluded lanes: passthrough (no declared window), side requests (#1110),
  Buffer bodies, GET/HEAD
- deliberately does NOT arm the dead-end cooldown marker: deterministic byte
  math with zero upstream cost — re-evaluating on retry is free, a cooldown
  would only add lockout latency (#4079 Q3)
- DOOMED_PROBE_* consts moved to preflight.ts (one source for all three doom
  sites); LocalRefusalRecord helpers extracted to src/local-refusal.ts
  (shared by server.ts and relay.ts)

Addresses #4079 (hub fix-plan step 1). Implements #3872 option B (send-side
final gate); #3872 option A (reconcile-triggered fold) stays open there.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_send-side-window-gate (5c60c94)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4885-pr.4098.4c3d8da

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-pr4098.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

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

关闭本 PR:与已并入 master 的 #4090 重复(同症状、同机制、同根因),按先来后到保留先到者。

本 PR 昨晚开出时做了出站查重但未命中 #4090——它的标题措辞是「egress window fuse」,与我的检索词不匹配;教训:出站查重要按失败签名/机制匹配,不能只按标题措辞。两者做的是同一件事:在最终发送点用同一套 doomed-probe 字节数学(max(2MB, window×7.5),#2122/#2490)拦下任何 tokenizer 都装不下的载荷,诚实本地拒绝 + 零上游调用。

#4090 胜出的三点:

  1. 1M 窗口打底(MIN_ASSUMED_WINDOW_TOKENS)——灾难闸不信可能被拿小的声明窗口(D 组坏分母放大效应);本 PR 信声明窗口,偏小声明下会错杀真实上游装得下的请求;
  2. 第二层 dsh 门 none-arm——把 The input (6165048 tokens) is longer than the model's context length (1048580 tokens(todo fix)). #4068 的 DIRECT 通道也管住了;
  3. 不记 LocalRefusalRecord 的取舍更干净——doomed 体每次重试自触发熔断,记录只会跨 turn 锁路由(与 [PR] remove the #726 dead-end cooldown; expire #3846 local-refusal records after 10m (#4079) #4105 给记录加 TTL 的方向一致)。

本分支的机械重构(DOOMED 常量移入 preflight.ts、local-refusal 模块抽取)依附于闸门本身,闸门被吸收后无独立价值,不拆出单独立项。关闭。

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