Repository navigation
[PR] kernel: wire byte fidelity — anthropic unknown-block passthrough + openai/google stability pins (#3410) - #3961
Conversation
9803bb8 to
e04faee
Compare
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4754-pr.3961.5859e31This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3961.tgz
npm install -g packageInstall instructions are refreshed on each push. |
e04faee to
cfc3b96
Compare
anthropicToCore's block switch had no default case: unknown top-level block types (in the wild today: document/PDF) fell out silently and their payload vanished on every rebuild with no warning. Unknown blocks now ride rawAnthropicBlock exactly like image/redacted_thinking — coreToAnthropic re-emits them byte-exact (cache_control included) and never renders the label text; protected.ts classifies them as media AND unrecoverable so a fold can never destroy a payload the host archives nowhere. Absorbs the kernel-side hunks of PR #3547 (adapted to master's #3642 canonical identity); #3547 keeps its host-side notice/billing surface. kernel-change: wire保真(#3938 / #3939⑥, 吸收#3547)
…ion (#3938 / #3939⑥) The openai leading-opaque reorder and the google part-order normalization are the "convention-stable" rows of #3938's root-cause table: they rewrite bytes on every request by convention rather than by state. This commit makes that stability an EXPLICIT contract and pins it: - coreToOpenai JSDoc: emission is a pure function of the core array; the canonical user-run shape is fixed (lone plain text -> string, else parts in CORE order, text first then rawOpenaiContentParts); the leading-opaque PREPEND exists so [opaque,text,opaque] emits [text,opq1,opq2] deterministically. - coreToGoogle JSDoc: for alternating-role histories emission is pure in the core array; the canonical orders ARE the merge rules (model reasoning->text->tool-call, user functionResponse-then-content); same-role merging is required normalization and its output order is canonical. - issue3939-wire-byte-stability.test.ts: golden rebuild shapes per line plus cross-request prefix byte-identity (same shape re-sent on consecutive requests must produce identical request bytes) and id determinism on both lines. Same-role google merging is pinned as behavior, not chased as a bug (reachable only with client-invalid non-alternating input). No runtime change: comments + tests only. The goldens fail if a future edit turns either normalization into a shape-dependent or order-dependent rewrite.
cfc3b96 to
477f3d7
Compare
(ai: vllm-qwen/qwen3.8-27b) 冲突已解除:PR 分支 rebase 到当前 master( 八问
另提醒一条既有协调事项(非本次引入):#3547 收窄为 host-only 且排在本 PR 之后合入;它落地时 tests/issue3398-opaque-media-reserve.test.ts:87-106 的 document 计费断言需要同步更新(本 PR 单独在时该测试保持绿),目前无人认领该更新,已在 PR 描述中 flag。 判定:冲突解决完毕,等 CI 转绿即可按正常流程进入人工 review/merge。 |
(ai: vllm-qwen/qwen3.8-27b) 收到冲突转发,核查后无需再次 rebase——当前 PR 在 GitHub 上并不处于 dirty 状态。 八问
当前 CI 实况(head |
Host-side half of #3410: price document/other unknown top-level blocks in the billing reserve (probe + cost/count walkers) and warn once per shape that they ride verbatim but stay out of folding. The kernel-side codec fix (sidecar passthrough) ships separately in #3961 — merge #3961 first so priced bytes == forwarded bytes. Pin updated: #3398 document case now expects opaque-media pricing.
(ai: vllm-qwen/qwen3.8-27b) Review(独立重审了新 head ① 原 issue 方向:#3939⑥ 要的是「anthropic 未知顶层 block 透传 + 丢弃告警对齐 openai 线」。本 PR 在 codec 源头( ② 回归审查(逐项过既有行为):
③ 代码审查:default case 的 label 派生( ④ 测试有效性:有牙——round-trip 是真实序列化比对(含 cache_control 位置);byte-stability 套件(214 行)用 ⑤ diff 整洁度:10 文件 +441/−14,全部与本 PR 目的相关;kernel 版本 0.0.145→0.0.146 符合 CI 强制的版本纪律;无跑题文件、无空白噪音。 风险披露(不阻塞):① 合并顺序——本 PR 先于 #3547 合时,document 转发但未计价(#3547 正文已带 pin 备注,少收方向,风险低);若 #3547 先合则 NOTICE 文案会声称 "preserves verbatim" 而 codec 仍在丢(honest-output 违约窗口)——所以顺序必须是 #3961 → #3547。② 新 sidecar 消息让 nudge/token-count/reconcile 多看到一个 ~2 token 的小文本行(payload 本体不计),量级可忽略,且与 image sidecar 现状一致,无新失败类。 八问:
CI: |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.681-master.768a60c # this exact build
npm install -g billion-context@master # always the newest merged build
|
…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.
…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.
kernel-change: wire byte fidelity (#3938 / #3939⑥, absorbs #3547 kernel hunks)
Part of #3938 · implements #3939 item ⑥ · kernel-side fix for #3410 (issue completes when #3547's host lane lands)
What changed
Rebased onto current master (post-#3941 stubs, post-#3944 invariant judge, post-MySQL-backend landings, post-#3969 config-docs regen); per-commit lockfiles synced for the
lock-synclane.Commit 1 —
42147ecanthropic unknown top-level block passthrough (#3410)kernel/src/wire/anthropic.ts: newdefaultcase in the per-block switch. Unknown block types (document/PDF, future types) now ride the existingrawAnthropicBlocksidecar exactly likeimage/redacted_thinkingand are re-emitted VERBATIM bycoreToAnthropic(block-internalcache_controlincluded). Previously they were silently dropped at parse — repro on master:[text, document]rebuilds as[text], the payload is gone from every later request and from any fold touching that message.kernel/src/protected.ts: absorbed verbatim from [PR] fix: preserve unknown anthropic top-level blocks verbatim in the anthropic wire codec #3547 — an unknown anthropic sidecar block now counts as media AND unrecoverable (the payload exists only in the sidecar; bili archives images only, so folding it = permanent loss). Parity preserved: base64/url image, redacted_thinking and plain text keep their exact old verdicts (pinned).kernel/tests/issue3410-wire-passthrough.test.ts: round-trip byte-exactness incl. cache_control, order preservation both directions, multiple unknown types, assistant-side blocks, predicate matrix, id determinism, parse∘rebuild fixed point.kernel/tests/issue3939-wire-unknown-parts-pins.test.ts("anthropic silently drops…") rewritten to pin the NEW contract (document survives round trip byte-exact), as that file's own header planned ("update the anthropic pins IN THE SAME PR"). Its google/responses pins are untouched and still green.package-lock.json+kernel/package-lock.jsonregenerated to match the bump (lock-synclane). Version 0.0.137 → 0.0.138.Commit 2 —
cfc3b96openai/google byte-stability contract + pinsThe "convention-stable" rows of #3938's root-cause table (openai leading-opaque reorder, google fixed part-order normalization) become an EXPLICIT contract:
coreToOpenaiJSDoc: emission is a pure function of the core array; the canonical user-run shape is fixed (lone plain text → string, else parts in CORE order, text first then rawOpenaiContentParts); the leading-opaque PREPEND makes[opaque,text,opaque]emit[text,opq1,opq2]deterministically.coreToGoogleJSDoc: for alternating-role histories emission is pure in the core array; the canonical orders ARE the merge rules (model reasoning→text→tool-call, user functionResponse-then-content); same-role merging is required normalization and its output order is canonical.kernel/tests/issue3939-wire-byte-stability.test.ts: golden rebuild shapes per line plus cross-request prefix byte-identity (same shape re-sent on consecutive requests ⇒ identical request bytes) and id determinism on both lines. Same-role google merging is pinned as behavior, not chased as a bug (reachable only with client-invalid non-alternating input).Behavior change disclosure
No other behavior changes: hidden-content sets, truncation, ref allocation, summary texts are untouched — those are items ①–⑤, delivered by #3956. Golden pins
tests/golden/wire-contract/kernel.jsonunchanged. Semantics-unchanged commitment per #3939 holds: what gets changed is identical, only the wire now keeps what it was always supposed to keep.Config surface
None. No new env vars, config fields or CLI flags.
Coordination
deriveCanonicalMessageIdidentity scheme (The intermediate message (core) is not protocol-agnostic: switching protocols/models causes identity churn; cross-protoc | 中间消息(core)没有做到协议无关:切协议/切模型制造身份 churn,补齐跨协议映射 #3642). [PR] fix: preserve unknown anthropic top-level blocks verbatim in the anthropic wire codec #3547 narrows to host-only (src/image-tokens.tsdocument billing,warnUnknownAnthropicBlocksnotice, e2e test). Suggested merge order: this PR first (or concurrently), then [PR] fix: preserve unknown anthropic top-level blocks verbatim in the anthropic wire codec #3547 rebased onto the result.tests/issue3398-opaque-media-reserve.test.ts:87-106asserts the anthropic top-level document prices at 0/0 ("the codec drops it"). This PR alone keeps it green — the billing walkers walk the RAW wire body and are untouched here — but once [PR] fix: preserve unknown anthropic top-level blocks verbatim in the anthropic wire codec #3547's document-billing hunk lands, those assertions must be updated (expected: costMath.ceil(8192/4), count 1). The file predates [PR] fix: preserve unknown anthropic top-level blocks verbatim in the anthropic wire codec #3547's base, so nobody currently owns that update; flagged here.kernel/package.json/lockfile version line (bump from their head).Verification
cfc3b96: all lanes pass — docs-sync, lock-sync, kernel-guard, version-guard, ubuntu/windows × node22/24 test shards, e2e suites (codex/dsh/pi/opencode/registry/image-billing), PR build artifact.lock-synccommands clean locally.