Skip to content

[PR] fix(#4111): dsh unattributed gate — core-text byte math, stop billing base64 media as text - #4119

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-21_dsh-media-byte-gate
Oct 21, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-21_dsh-media-byte-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(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 车道漏了。

改了什么

验证

不碰 kernel/、不加配置面、不动版本号。

… 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>
@ranxianglei ranxianglei changed the title fix(#4111): dsh unattributed gate — core-text byte math, stop billing base64 media as text [PR] fix(#4111): dsh unattributed gate — core-text byte math, stop billing base64 media as text Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-21_dsh-media-byte-gate (d6a314b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4921-pr.4119.82079c6

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-pr4119.tgz
npm install -g package

Install 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.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.718-master.933b5d5 (rolling master tag).

npm install -g billion-context@0.0.718-master.933b5d5  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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

Labels

None yet

Projects

None yet

1 participant