Repository navigation
[PR] fix(#4111): dsh unattributed gate — core-text byte math, stop billing base64 media as text - #4119
Merged
Conversation
… base64 media as text The gate's two oversize arms (the #2924 `threw` arm and the #4068 unattributed arm) priced the RAW request body at bytes/4. That floor only holds for text (real text density >= ~6.8 B/token, #2122); inline media is base64 on the wire and resolution-billed upstream (~2,000-4,000 B/token), so a ~4MB screenshot minted ~1M phantom tokens and tripped a "provably over window" LOCAL 422 the real upstream would never have made (#4111: media-heavy agentless requests went dead on arrival). The relay egress fuse already excludes media from its byte math (server/relay.ts, same caliber as preflight's doomed probe) — the agent lane now matches it. - mediaBytesOfWireBody(): protocol-agnostic walk pricing the inline-media shapes of every wire family (anthropic base64 source blocks + redacted_thinking, openai input_audio + data: URLs incl. file file_data, google inlineData). Keyed structurally, never by content: base64 pasted as TEXT is not media on any wire and stays billed as text — the genuinely-huge-text direction keeps its teeth. - bodyProvablyOverWindow(): two-stage predicate shared by both arms. Stage 1 is the old raw bytes/4 bar (cheap, unchanged verdicts for bodies that were never provisionally over). Stage 2 runs only on the would-refuse path: re-price on media-excluded core bytes; disarm when core text alone fits. No body / unreadable body / unresolvable window -> undefined (#1117 direct semantics preserved; can never false-refuse from missing data). When init is unavailable the raw floor keeps the old conservative verdict. - Log lines now carry "core est <B>B/4" plus the excluded media mass. Tests (#3617 both directions, both arms): media-heavy unattributed/threw bodies ride #1117 direct again (the #4111 field shape: 4.2MB data-URL screenshot + modest text on a 1M-floored window); genuinely over-limit TEXT at the same mass still refuses LOCALLY; pure-function rows price every wire family's media shapes, never treat pasted-text base64 as media, and check both predicate stages incl. the no-init/no-window disarm paths. Co-authored-by: worker-delegate <del_mvhpqwn0_nr3v>
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4921-pr.4119.82079c6This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4119.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…a URLs mediaBytesOfWireBody only recognized data-URL media under url/file_data keys. The responses wire carries input_image's whole data URL as a bare STRING under image_url (singular form), which stayed billed as core text — so a responses-wire screenshot body would still trip the old false refusal even after the core-text re-price. Treat image_url string values with the same data:-prefix structural check (no content guessing; pasted-text base64 under other keys is unaffected). Unit assertion added for the singular form.
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.718-master.933b5d5 # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 21, 2026
This was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(ai: zhipuai-lb/glm-5.3)
Fixes #4111
什么坏了
带大截图的 dsh 无归属请求(没走会话盖章的车道)被 bili 在本地直接 422 拒掉,上游根本没收到:守卫把整个请求体按
bytes/4当文本估 token,而 base64 图片在线上是以「分辨率计费」的(每 token 摊 2000-4000 字节)——一张 4MB 截图被算成 ~100 万 token,恰好超过 100 万的地板线,触发「必超窗口」的本地拒绝。用户看到的就是:发图就挂、去掉图就好。根因
src/agent/dsh-native.ts两条超限臂(#2924 threw 臂、#4068 无归属臂)都用原始字节数 ÷4 当乐观下界。这个下界只对纯文本成立(真实文本密度 ≥6.8 B/token);服务端 relay 的出站保险丝早就不把媒体算进字节数(同口径),agent 车道漏了。改了什么
mediaBytesOfWireBody():协议无关地走一遍请求体,把各 wire 家族的内联媒体字节算出来(anthropic base64 source 块/redacted_thinking、openai input_audio、data: URL 图片/文件、google inlineData)。按结构识别、永不按内容猜:用户当纯文本粘贴的 base64 不是媒体,照旧按文本计费——「真超限文本必须拦」的方向不松。bodyProvablyOverWindow():两阶段判定,两条臂共用。第一阶段保持原 bytes/4 快筛(本来就不超的体完全不受影响);只在「原口径会拒」时跑第二阶段——排除媒体后按 core 文本重算,core 能装下就放行走 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117 直发。拿不到 body/窗口未知时一律不拒(「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117 语义保持,绝不因缺数据误拒)。core est …B/4与被排除的媒体字节数。验证
npm run typecheck干净;全量交远端 CI。不碰 kernel/、不加配置面、不动版本号。