Repository navigation
[PR] fix(agent): price the client-local doom gate by prompt mass, not raw body bytes (#7106) - #7119
ZzXxYy1234 wants to merge 5 commits into
Conversation
|
上游 #7092 刚推到 这对本 PR 有一个可预期的收敛点:本 PR 里的 本 PR 先按现状评审即可(独立、基于 master、不依赖 #7092);#7092 落地后我来 rebase 并做这次去重,如果 review 希望当场就复用,我也可以等它合并再改。 |
…body bytes (ranxianglei#7106) The DSH client gate (bodyOverWindowDetail) estimated tokens from the whole outbound body (bytes/4, x1.14) with no notion of which bytes are prompt. On official DeepSeek lanes the body also carries dsh_session_log - a transport-only session-log contribution of up to 8 MiB - so a prompt well inside the declared window (e.g. 736K < 1,048,576) was refused locally with doom-gate-pricing-mismatch. When the body parses, the gate now prices only the protocol's prompt keys (anthropic messages/tools/system, openai messages/tools, google contents/systemInstruction/tools, responses input/instructions/tools) with the same CJK-aware counter the server uses, and keeps the ranxianglei#4111 two-tier math: calibrated tier = floor x 1.14, bare floor = provably-over tier. Inline media stays excluded (as it has since ranxianglei#4111); transport-only fields are dropped from the floor. Unparseable bodies keep the whole-body byte estimate, with the early bound raised from bytes/4 to bytes/3 so CJK-dense bodies are not missed. Refusal wording now says prompt mass is what counts. Tests: tests/issue7106-client-doom-gate-prompt-mass.test.ts (6 cases: transport-field-does-not-doom, genuinely-over prompt still dooms, CJK-aware pricing, google/openai shape sniffing, byte fallback, image exclusion). Regression: 179/180 across the gate suites; the one failure (ranxianglei#3578) is a pre-existing Windows temp-dir EPERM cleanup flake, reproduced on clean master.
66afea8 to
266b286
Compare
|
确认这个 bug,已修(PR #7119 head 更新为 修法// shape-priced prompt 已是 token 数,直接与窗口比;只有字节兜底保留 1.14
const estTokens = promptMass === undefined
? Math.ceil(floorTokens * CALIBRATED_TEXT_TOKEN_RATIO)
: floorTokens;
补的测试(红先绿后)
同时更新了 #4111 里把「prompt-priced 也乘 1.14」写死的那条断言( 验证
谢谢这条 review——它正好落在「注释写了 as-is、代码乘了 1.14」的反差上,是我改动时没自检出来的。 |
…e in the architecture map (ranxianglei#7106)
… gate - drop the dead imageTokens field from WirePromptMass (computed but never consumed; the text walk already excludes image keys, ranxianglei#4111) - remove the accidental UTF-8 BOM that landed on native-intercept.ts line 1 - fix the stale CJK test comment (400K/1.2MB -> 1.1M/3.3MB) and its mojibake - rename the image test to match what it asserts (image bytes excluded, not "added back") - restore the trailing newline and drop a doubled blank line in the test file
|
CI 目前唯一的红是 这不是本 PR 引入的,master 自己就红在同一处:
我没有这个仓库的 rerun 权限( 如果你们希望, |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重结论不重复。#7119 修的是客户端本地 doom gate( 审核结论(八问)
我的顺手修(已 push 到 PR 分支,commit
|
|
感谢完整的八问审核和顺手修——97c7c30 我本地也同步验证过:unused-exports 绿、architecture-docs 绿(326 文件全覆盖)、tsc --noEmit 干净、issue7106 + native-intercept 101 条全过,与你的验证一致。BOM 和 imageTokens 死字段确实都是我的问题,谢了。 关于 CI:同意你的判定——server-process-listeners 是继承性、确定性失败(master 同处红,rerun 不变),不进本 PR 范围;等 ci-fixes 修完重跑即可。 关于 #7092 合入后的去重,我确认两点约定:
等 #7092 落地我就上门做这个 follow-up。 |
(ai: vllm-qwen/qwen3.8-27b) 确认,三点都对齐了。我把两个分支的代码都对照过了,去重比预想的还干净: 键表对照(你的第 2 点):本 PR 的 一个机械点(影响去重怎么写):#7092 的 显式测试(你的第 1 点):一个建议——要钉死「走字节估计、不是整包 token 估计」,测试 body 最好CJK 密集并断言精确 CI:同意—— 现状:从 review 角度本 PR 可合入(方向对、无回归、测试充分、97c7c30 双方本地验证一致);唯一红是继承性 Windows 失败。#7092 去重作 follow-up 跟踪——你上门时 PR 正文记得同时引用 #7119 与 #7092。 合并决定留给 @ranxianglei。 |
…3186e54) The PR branch's only CI red (test windows-latest 22,5 -> tests/server-process-listeners.test.ts) is an inherited master-level failure, not introduced by this PR: test 4 assumed POSIX signal semantics, and on win32 process.kill(self, SIGINT) terminates the child without running the handler (deterministic, file-level failure, zero TAP output). The owner fixed it on master in 3186e54 (invoke the installed handler directly on win32). This merge brings that fix into the PR branch so the inherited red clears on the next CI run. Master has not touched any of this PR's five files since the merge base, so the merge is clean and the PR's own diff is unchanged. Verified on the merged head: tsc --noEmit clean; targeted gate suites (issue7106 + native-intercept + dsh-native + issue4894 + server-process-listeners) 186/186 pass; unused-exports and architecture-docs gates green.
(bot) (ai: vllm-qwen/qwen3.8-27b) CI 自动修复车道 attempt 1/6 — 本轮结论:继承红已解,新 head 先核对了 live 状态:PR head 仍是 七问:
现状:新 head |
|
State note (no action needed, just keeping the two PRs' relationship explicit): The client-local doom gate work in this branch now also lives in #7092 as:
The file set is identical to this branch (prompt-mass.ts, native-intercept.ts, issue7106-client-doom-gate-prompt-mass.test.ts), and #7092's CI is green as well. So: if #7092 lands first, this PR can simply be closed; if you prefer merging this one first, the three commits above are the only ones #7092 would need to drop. I'm not closing it unilaterally — leaving the choice to you. |
(bot) (ai: vllm-qwen/qwen3.8-27b) State note verified against live sources this run — with one correction to the commit count: Verified live (2026-11-19 ~01:30Z):
Correction — it's 4 commits, not 3. #7092's tip commit One freshness note: master moved since yesterday's merge ( Decision left to @ranxianglei (I can't close PRs or pick merge order):
Both PRs are green right now; the choice is purely merge-order bookkeeping. |
问题(#7106)
DSH 客户端本地 doom gate(
bodyOverWindowDetail)按整个出站 body 的字节数估 token(bytes/4 × 1.14),不区分哪些字节是 prompt。官方 DeepSeek 通道的 body 还带dsh_session_log(传输用会话日志增量,上限 8 MiB),实测一次被拒的 body:旧口径
ceil(9947234/4×1.14) ≈ 2.8M> 窗口 1,048,576 → 本地直接拒绝;而真实 prompt ≈ 736K,远在窗口之内(服务端 PR #7092 已按 prompt mass 计价,客户端这条残面未覆盖)。改法(方案 A:客户端也按 prompt mass 计价)
src/agent/prompt-mass.ts:按 body 形状识别协议(contents→google、input→responses、system→anthropic、其余→openai),只取该协议的 prompt 键(anthropic messages/tools/system;openai messages/tools;google contents/systemInstruction/tools;responses input/instructions/tools)拼成浅对象,用服务端同一套 CJK-aware 计数器estimateRawBodyTokens计价;传输字段自然被排除。bodyOverWindowDetail:floorTokens = promptTokens;不能解析时保留旧的ceil(coreBytes/4);bytes/4提到bytes/3(CJK 密集 body 的字节上界,bytes/4 只对 ASCII 成立);promptTokens/protocol,被拒文案改为「prompt mass 计价 + 已排除传输字段」。测试
新增
tests/issue7106-client-doom-gate-prompt-mass.test.ts(6 条):7 MiBdsh_session_log+ 736K prompt → 不再 doom;4.5M 字符 messages → 仍 doom 且provablyOver;1.1M CJK 字符 → doom(CJK 计数);google/openai 形状识别;非 JSON 走字节兜底;含 2 MiB base64 图片 → 不 doom。回归:
node --import ./tests/preload-test-env.mjs --import tsx --test tests/issue7106-... tests/issue4894-direct-window-guard.test.ts tests/native-intercept.test.ts tests/dsh-native.test.ts→ 179/180;唯一失败 #3578 是本机 Windows 临时目录清理的 EPERM(干净 master 上同样失败,与本改动无关)。npx tsc --noEmit干净。原 #7118(基于 #7092 分支的
otherPrompt方案)已被 #7092 的 ccfee8a 用「修分桶」取代并关闭,本 PR 改为基于 master、只做客户端一条。