Skip to content

[PR] DSH gate: Out-of-window requests guaranteed to be rejected upstream are no longer sent as raw direct calls (calibrated e | dsh 闸门:必然被上游拒绝的超窗请求不再裸发直连(校准估算 + 每次直连留痕) - #5875

Merged
ranxianglei merged 1 commit into
masterfrom
2026-11-07_dsh-gate-direct-send-guard
Nov 7, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是什么问题(一句话)

经网关进来的 ds-harness-remote 大历史请求,在归属识别失败(none/threw)时会不压缩直接裸发上游;而本地那道「超窗就拒」的熔断用 bytes/4 乐观估算,系统性低估真实计费(实测 ≈×1.14),于是「其实必然被上游拒掉」的超大请求反而穿过熔断去裸发——上游要么 400/413、要么把 max_tokens 挤到 1(真实现场:927K prompt 只剩 1 token 回复;1.3M prompt 后整会话报废)。而且裸发只在第一次留一行日志,之后整条泄漏环路静默。#5613 的三层安全网(owner 2026-11-07 裁决:①②③ 一个 PR,④砖机自救另议)。

改动三件事

  1. 校准估算档(src/util.ts + src/agent/native-intercept.ts 共享谓词)
  2. 两臂都落本地拒绝(src/agent/dsh-native.ts 闸门)
  3. 每次裸发 DIRECT 必留痕

没改的东西

验证

refs #5613

@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Nov 7, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

自审结论(按惯例直接发评审):

正确性:双档计价是严格嵌套关系——floor 档的每个拒绝都在新判定里保留(provablyOver 只是文案分层),新拒区间完全落在「旧 floor 判直通、但 ×1.14 校准估算已过窗」的带内,这正是 ledger 实测必然 4xx 的那段;fail-open 只保留给数据缺失(无尺寸/无窗口/不可解码→全字节按 core 保守计),方向上永远偏安全侧。两臂(threw/unattributed)共用同一谓词,不存在单臂漏改。native-ws-intercept.ts:412 的 === false 同步比较契约未破(仅 no-init 路径返回裸 false)。

留痕面:节奏为 首次/状态变化/每第 10 次,256 键 Map 上限与溢出清表行为未动(内存有界);#3651「none 不上面板」契约未动,新增信息只进 durable 日志。web-diagnostics-enrichment 的字面前缀钉仍通过。

风险与取舍:1.14 为当前标定值,计费比若下移则拒绝面偏严——代价是本地 422(可诊断、可重试压缩),换取不再出现上游炸会话,owner 已认可。Content-Length 声明值被恶意/错误地填小会削弱流式体熔断,但该路径原本就是全盲(跳过计价),净效果仍为正。

实现期发现并已修的小问题:① 测试文件 regex 内 streamed/unreadable 的 / 曾漏转义致 tsc 语法错——已修;② 留痕测试初版对第 20 次计数误算行数(count%10==0 同发 10/20 两行)——断言改为精确 3+1 行并逐行钉算式;③ 本机跑套件必须剥离 BILI_PROVIDER_REWRITES/BILI_MITM_HOSTS/BILLION_CONTEXT_PROXY/HTTPS_PROXY 并隔离 XDG_CONFIG_HOME(机器级生产 env + 全局 config 会制造 apply() 就绪看门狗的成片假红,#3103 描述的场景之外的又一污染源),CI 不受影响。

本地证据:tsc 干净;定向电池 165/165 绿(75+160 去重后合计见 PR 描述)。等 CI。

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-07_dsh-gate-direct-send-guard (e920fb0)

Latest build — install this exact version

npm install -g billion-context@0.0.8530-pr.5875.0532a63

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
e920fb0 billion-context@0.0.8530-pr.5875.0532a63 build
50a87c4 billion-context@0.0.8506-pr.5875.6051943 build
c8b9586 billion-context@0.0.8486-pr.5875.eb334fc build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title dsh 闸门:必然被上游拒绝的超窗请求不再裸发直连(校准估算 + 每次直连留痕) [PR] DSH gate: Out-of-window requests guaranteed to be rejected upstream are no longer sent as raw direct calls (calibrated e | dsh 闸门:必然被上游拒绝的超窗请求不再裸发直连(校准估算 + 每次直连留痕) Nov 7, 2026
@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/wiring labels Nov 7, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复——开放 issue/PR 中无同主题条目,本 PR 即 #5613(owner 裁定 ①②③ 一个 PR)的交付物。
标签: bug, dsh, scope/wiring, p1(缺陷修复;dsh 车道请求管道;底层缺陷会炸毁整个会话 = 数据丢失类 → p1)。

我独立重审了 PR head c8b9586(逐行读 diff、本地定向验证),并查清了 CI 上唯一的红项。结论:PR 自身代码干净、无回归;红项是继承自 master 的既有失败,与本 PR 无关。已按 CI 协调政策处置(见下)。

独立审核结果

正确性(与自审结论一致,独立复核)

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

  1. 超窗拒绝门槛下移:旧 = 仅当乐观 bytes/4 floor 本身过窗才本地 422;新 = floor×1.14 校准估算过窗即拒。对 1M 窗口,floor 估算落在约 [877K, 1M] tok 的体从「裸发上游赌一把」变为「本地 422」。原因:ledger 实测该宿主族计费比系统性高于 floor ~14%,旧门槛下这段带的直连是必然的上游 4xx([Bug][dsh] Model requests silently bypass the compression proxy (fail-open gate) — 927K-token prompt sent raw, 1-token reply, session bricked with 400 #5613 现场:1.3M prompt 过全部旧检查后整会话报废)。owner 已在 [Bug][dsh] Model requests silently bypass the compression proxy (fail-open gate) — 927K-token prompt sent raw, 1-token reply, session bricked with 400 #5613 认可此方向(大历史本地 fail-closed)。
  2. 声明 Content-Length 的流式体现在参与计价:旧 = 流式体直接跳过尺寸判定(全盲 fail-open);新 = 有声明长度就按声明值计价(全字节按 core 保守计)。已知取舍:恶意/错误填小的 Content-Length 会削弱该路径熔断,但该路径原本全盲,净效果为正(自审已列)。
  3. 小体量合法直通语义(sidecar 短调用等)逐字节保留,Model request is connecting directly (uncompressed) | 模型请求正在直连(不压缩) #3651「none 不上面板」契约未动。

本地定向验证(全量回归交给 CI)

  • 改名残留扫描:0 处;12 个 lane 套件无一引用被改面(DIRECT 行格式断言仅 dsh-native.test.ts 与 web-diagnostics-enrichment.test.ts,后者不在红色车道内)。
  • dsh-plugin-lane 的 12 个套件本地隔离环境跑(剥离机器级 BILI_/代理 env + 独立 XDG_):11 绿 1 红——红的 fork-nudge-trigger 我在当前 master(5af5f9fed3)上原样复现同样 2 个失败,确认为继承性失败(详见下)。

CI 红项定位与处置

结构化八问

  1. 是什么问题:dsh 归属车道(none/threw)上的超窗历史请求,要么按偏低 ~14% 的乐观估算判「不超窗」裸发上游、被 4xx 后整会话报废,要么即便超窗也没有持续留痕(首行之后全静默)。
  2. 什么原因导致的:估算系统性低于真实计费(ledger 实测 ×1.14),而旧闸门只在连下限都过窗时才拦——两者之间必然存在一段「上游必拒但本地放行」的带;叠加 DIRECT 发送只记一次日志,泄漏环路不可见。
  3. 影响范围与严重程度:所有经 dsh 插件车道、归属降级(threw/none)、历史体量落在校准带内的会话;严重度为会话报废级(数据丢失类,p1),触发条件明确(归属降级 + 大体量 or 连续泄漏循环)。
  4. 怎么修复的:共享谓词双档计价(校准档先触发、裸 floor 仅作「必然超窗」文案分层),两臂本地 422 且 durable 日志带完整算式;每次 DIRECT 发送带体积留痕,按首次/状态变化/每第 10 次限界节奏;声明 Content-Length 的流式体纳入计价;fail-open 收窄到纯数据缺失。
  5. 是否有回归问题:逐项过过——小体直通语义(「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117)、媒体排除(DSH's unattributed over-limit gate prices base64 images as text (bytes/4) — media-heavy requests are falsely rejected wi | dsh 无归属超限门把 base64 图片当文本计价(bytes/4)——媒体重的请求被假拒 422,上游本会正常接受 #4111)、小窗口声明保护(Context Window Overflow Issue Summary: Raw Requests Sent Directly to Upstream Rejected + Local Intercept Cooldown Lockin | 上下文超窗问题汇总:请求裸冲上游被拒 + 本地拦截冷却锁死会话(统一分析入口) #4079)、不可解码保守判决(opencode V2 fallback direct-send path: For oversized bodies >~536MB, string decoding within the over-window rejection lo | opencode V2 降级直发路径:>~536MB 的超大 body 在超窗拒绝逻辑里解码字符串抛 RangeError,逃出路由处理器 #4912)、面板契约(Model request is connecting directly (uncompressed) | 模型请求正在直连(不压缩) #3651)、256 键上限、=== false 契约,全部保持;有意变更仅上述 3 条(已披露)。本地 11/12 lane 套件绿,唯一红项在 master 上原样复现 = 继承,非本 PR 引入。
  6. 是否破坏缓存:不涉及——拒绝发生在出站前的本地 422,不产生缓存写入;留痕节奏与缓存/重试/游标机制零交互。
  7. 是否改了设计方向:架构不变(仍是 takeover gate 本地熔断 + 宿主重试压缩),仅把大历史的姿态从「骑向上游赌」收紧为「本地 fail-closed」(owner 已裁定的方向),外加可观测性。
  8. 是否引入了新的配置:无——CALIBRATED_TEXT_TOKEN_RATIO = 1.14 是内部常量,不是 config/env 旋钮(若日后要可调,另走配置面提案)。

收工判定

代码层面本 PR 可合(独立审核无回归,行为变更均已披露且获 owner 预先认可);CI 唯一红项为继承性(master 今日 phantom-pressure guard 使两个零基线 nudge 场景断言过期),已按政策 merge ci-fixes(新 head 50a87c46b2)并在 #4599 留痕,待哨兵在 ci-fixes 处置后该车道转绿——建议 owner 验收代码时不必阻塞于该继承红。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

补充更正(CI 全貌):首条回复时 12 个 test shard 尚在跑,现全部落定,更正快照——

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

上一条 shard 列表表述有误,精确更正——新 head 50a87c46b2 失败的 8 个 test shard 为:windows(24,1)、windows(24,2)、windows(22,1)、windows(22,2)、ubuntu(24,1)、ubuntu(24,3)、ubuntu(22,1)、ubuntu(22,3);被 ci-fixes 修绿的是 windows(24,3)、windows(22,3)、ubuntu(24,2)、ubuntu(22,2)。

…ses large histories locally; log every direct send with its size

Owner ruling 2026-11-07 (items 1-3 as one PR; item 4 deferred):

(1) Calibrated estimate tier. The shared over-window predicate now
    prices bodies at bytes/4 x CALIBRATED_TEXT_TOKEN_RATIO (1.14, the
    measured billing bias from #5613's session ledger) on top of the
    optimistic floor. The old bar is strictly nested: anything the floor
    already refused is still refused (provablyOver); anything only the
    calibrated estimate crosses is refused too, since direct-sending it
    was a coin flip weighted toward a guaranteed upstream 4xx. Missing
    data (no size / no window / undecodable stays all-core) keeps
    fail-open by construction.
(2) Large-history fail-close lands on BOTH gate arms: the thrown-
    attribution settle path (#2924/#3581/#5609 lineage) and the unattributed
    arm (#4068). Local refusal = 422 with the token math in the durable
    line; small lanes keep #1117 direct semantics byte-for-byte.
(3) Every bare DIRECT send now carries its body size (or an explicit
    'size unknown - the fuse could not run' note) and logs on a bounded
    cadence (first occurrence / state change / every 10th), so a leaking
    agentless lane can no longer stay silent after line one. Streamed
    bodies with a declared Content-Length are now priced from it instead
    of being skipped, so the fuse also arms for large streaming sends.
@ranxianglei
ranxianglei force-pushed the 2026-11-07_dsh-gate-direct-send-guard branch from 50a87c4 to e920fb0 Compare November 7, 2026 14:22
@ranxianglei
ranxianglei merged commit 1d509b9 into master Nov 7, 2026
33 checks passed
Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 7, 2026
…efs ledger, ranxianglei#5199 throttle429Scope, ranxianglei#5875 dsh gate safety net

Adopts a fourteen-commit batch. Three genuine overlaps, all auto-merged
without manual resolution:

- `src/loop/core.ts` — master adds the `ranxianglei#5613` direct-send size guard in
  `dsh-native.ts`/`native-intercept.ts`; the lane's `isDraftDump` gate is on a
  different hunk. Both sides verified present after the merge.
- `src/server/relay.ts` — master touches `forward()` bookkeeping; the lane's
  non-streaming `pipePluginJson` guard survives at `src/server/relay.ts:2062`.
- `src/storage/mysql.ts` — master's incremental refs ledger lands in
  `store.ts`/`ingest.ts`; the lane's `export const MYSQL_SCHEMA_VERSION = 11;`
  at `src/storage/mysql.ts:77` is untouched.

Everything else in the batch (process.yaml throttle scope knob, WAL/checkpoint
observability, `ccr_entries`/`blocks` incremental legs) lands with zero lane
contact.

Verified on the merged tree (CI preload chain, BILI_STORAGE_UNIFIED=legacy,
kernel rebuilt to 0.0.185):

tests/issue5175-drift-name-leak.test.ts 58/0, tests/tag-echo.test.ts 79/0,
tests/issue2190-degen-close.test.ts 32/0, tests/golden-storage-render.test.ts 5/0,
tests/storage-engine-proofs.test.ts 12/0, tests/wire-contract.test.ts 23/0,
tests/issue4666-migration-dedup.test.ts 2/0,
tests/native-compact-terminal.test.ts 1/0,
tests/issue5199-throttle429-scope.test.ts 6/0,
tests/issue5744-incremental-refs.test.ts 2/0,
tests/issue5744-ingest-diff.test.ts 5/0,
tests/issue4739-storage-read-snapshot.test.ts 4/0,
tests/dsh-native.test.ts 75/0.

`tsc --noEmit` clean; the four repo gates exit 0; `gen-config-docs generate` is
a no-op on the four generated artifacts.
ranxianglei pushed a commit that referenced this pull request Nov 12, 2026
…l lines

Reconciled onto #5875 (owner ruling 2026-11-07): the every-10th cadence
and the trailing size note stay verbatim; this change adds only the
resolved context window to the size note so a single refusal line is
self-describing (body scale + the window it was judged against), no
provider-log correlation needed. An unresolvable window degrades to
"window unknown" — never a fabricated number.

Closes #5613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR dsh p1 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant