Skip to content

[PR] feat: host lane for unknown anthropic blocks — session notice + billing parity (#3410) - #3981

Merged
ranxianglei merged 1 commit into
2026-10-20_3939-prc-wire-fidelityfrom
2026-10-20_3410-host-lane
Oct 20, 2026
Merged

ranxianglei merged 1 commit into
2026-10-20_3939-prc-wire-fidelityfrom
2026-10-20_3410-host-lane

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

Stacked on #3961(base 指向其分支,合并顺序:#3961 先;其合并后本 PR 会自动改指 master)。

kernel 侧(#3961)把 anthropic 未知顶层 block 挂 sidecar 原样透传;本 PR 补齐它明说留给 host 车道的部分:

文件 内容
src/wire-drop-warn.ts unknownAnthropicBlocks():扫 messages[].content 顶层 block,已知六类之外报 {count, types, firstIndex}(干净返回 null)
src/server.ts + src/server/prepare-anthropic.ts 每 session 每 type-set 一次 NOTICE(warnedWireDropKeys FIFO cap,与 droppedOpenaiParts 同纪律)——document/PDF 流量走透传时运维能看见,不再静默
src/image-tokens.ts 计费对齐:未知 block 按媒体计——base64 按编码长度、URL 按 REMOTE_IMAGE_TOKENS(带 cap)、裸 unknown 按 flat 4096;已知非媒体类(text/thinking/tool_use/tool_result)不进该分支,golden anthropic stats 字节不变
tests/issue3410-unknown-anthropic-block.test.ts 报告形状、NOTICE 节奏、计费矩阵(base64/url/bare/mixed)、真实 server 车道 e2e 透传

Evidence

  • tests/issue3410-unknown-anthropic-block.test.ts 5/5
  • golden-storage-render 5/5(未 regen,walker 语义保持)· image 计费族(image-request-budget/fold-images-archive/image-restore/learned-image-cost/preflight-billing-block/image-arbitration)33/33
  • basic + cache-friendly-proxy 34/34 · typecheck 绿

与 #3961 的关系

无文件冲突(#3961 只动 kernel/;本 PR 只动 src/ 与 tests/issue3410-*)。#3961 body 中「issue completes when #3547's host lane lands」即指本 PR——两者合并后 #3410 完整闭环。

Part of #3938。

…ng parity (#3410)

The kernel side (PR #3961) rides unknown anthropic top-level blocks on
the sidecar and re-emits them verbatim; the host side it expects:

- src/wire-drop-warn.ts: unknownAnthropicBlocks() - scans parsed
  anthropic bodies for top-level block types outside the known six and
  reports {count, types, firstIndex} (null when clean).
- src/server.ts + src/server/prepare-anthropic.ts: one NOTICE per
  session per type-set (warnedWireDropKeys FIFO, same discipline as
  droppedOpenaiParts) so operators can see document/PDF traffic riding
  the passthrough instead of vanishing silently.
- src/image-tokens.ts: billing parity - unknown blocks meter like
  media: base64 payloads by encoded length, urls at REMOTE_IMAGE_TOKENS
  (capped), bare unknowns at the flat 4096 floor. Known non-media
  blocks (text/thinking/tool_use/tool_result) stay outside the branch -
  the walker's golden anthropic stats are byte-stable.
- tests/issue3410-unknown-anthropic-block.test.ts: report shape, NOTICE
  once-per-type-set cadence, billing matrix (base64/url/bare/mixed),
  e2e passthrough through the real server lane.

Stacked on #3961 (kernel passthrough); Part of #3938.
@ranxianglei ranxianglei changed the title feat: host lane for unknown anthropic blocks — session notice + billing parity (#3410) [PR] feat: host lane for unknown anthropic blocks — session notice + billing parity (#3410) Oct 20, 2026
@ranxianglei
ranxianglei merged commit 2cb6123 into 2026-10-20_3939-prc-wire-fidelity Oct 20, 2026
17 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

一个必须补的 pin(已本地复现):tests/issue3398-opaque-media-reserve.test.ts 的「top-level document」用例仍断言旧契约(document 不收费 / count 0)。本分支的计费变更会让它红——我在等价实现上本地复现:2048 !== 0(base64 8192B → Math.ceil(8192/4) = 2048,断言期望 0)。需要把该用例的 docBody 两行断言改为:

assert.equal(imageTokensInParsedBody("anthropic", docBody, "bytes"), Math.ceil(8192 / 4));
assert.equal(countImagesInParsedBody("anthropic", docBody), 1);

并把测试标题里 "(the codec drops it)" 的措辞更新为保留语义(#3961 合入后 codec 逐字透传 document,计费与转发字节对齐)。这是 Floor 协调时预告过的有意 pin 移动,其余 pin 不动。

计费门宽度的对比说明(不要求改,留档供决策):本 PR 的门是「已知四类之外全部按媒体计」(type ∉ {text, thinking, tool_use, tool_result}),而 kernel 侧 protected.ts 的新保护判定排除名单是 {image, tool_result, redacted_thinking}——即 kernel 把所有未知类型都当 media 排除折叠。本 PR 的宽门与 kernel 保护面一致(未来新出现的未知类型:保护+计费同步生效,不会 undercount);更窄的「仅 document」门则会在非 document 未知类型上出现「受保护但不计费」的缺口。结论:建议保持本 PR 的宽门,无需改动。

另外:此前 #3547(同范围、更早开的宿主侧 PR)今天被收窄重推过,其 head 已含上述 pin 修正文本,可直接摘用。owner 已将 #3981 定为 PR-C 的 host 车道,#3547 我按其关闭为 superseded(见该 PR 评论)。合并顺序不变:#3961 → 本 PR。

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