Repository navigation
[PR] fix: keep tool_result-first google part order for Claude targets (#5392) - #5397
ranxianglei wants to merge 3 commits into
Conversation
…argets (#5392) Claude-family backends routed through Google's v1internal / Cloud Code Assist wire translate role:user parts into Anthropic content blocks IN ORDER and require every tool_result(functionResponse) to LEAD the user message that follows an assistant tool_use turn — the opposite of the WC-018 text-first rule (#3159). Thread an optional target-model through normalizeGoogleUserPartOrder and coreToGoogle; when it matches /claude/i the input order is returned untouched so the natural responses-first shape survives. Default (no model) behavior is byte-identical.
#5392) Forward the request model (googleModel ?? v1Model on the proxy path incl. countTokens, modelVersion in the loop adapter) through each boundary that reorders google user parts: prepareGoogle, appendGoogleNudge, appendTrailingUserText (degenerate-retry nudge + fake-completion hint), and the outbound chain-checkpoint carrier — so Claude-through-Google targets keep tool_result-first order end-to-end instead of 400ing upstream. The validation-parity fake skips WC-018 for /claude/i targets and the WC-018 ledger entry documents the carve-out. Adds tests/issue5392-claude-google-part-order.test.ts pinning both directions (Claude keeps tool_result-first; non-Claude stays text-first).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7638-pr.5397.17f5f5eThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5397.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ies for google
Review of this PR found a completeness gap on secondary paths. prepareGoogle
returns Prepared with the model nested under google:{system,model}, and the
google lane early-returns before handle.ts assigns top-level Prepared.model, so
prepared.model is undefined for google requests. The three outbound boundary
sites added here that read prepared.model (outbound chain-checkpoint stamp,
degenerate-terminal continuation nudge, fake-completion hint) therefore silently
fell back to the WC-018 text-first reorder for Claude-through-Google targets,
re-introducing the exact 400 #5392 fixes on those retry/stamp turns.
Fall back to prepared.google?.model (the same canonical source the loop adapter
already uses via pickAdapter) at those sites. Inert for every non-google lane
(prepared.model is defined there); activates only where prepared.model is unset.
Verified: typecheck clean; issue5392/issue3159/wire-contract targeted suites green.
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 这是修 #5392 的 PR(#5397),落实 owner 在 #5393 拍板的方案 A;检索 open+closed 无同主题竞争条目。WC-018/#3159 是「被本 PR 打例外」的那套 Gemini text-first 归一,属机制来源而非重复项。 标签: 独立审核结论方向对、kernel 改动干净、主路径修好且有双向测试钉;但我独立审 diff 时发现并就地修掉了一个真实的完整性缺口(见下「
|
| 经 Google wire 的目标 | 旧 | 新 |
|---|---|---|
| 非 Claude(Gemini/Vertex) | text-first(WC-018) | 不变 |
Claude(/claude/i) |
text-first → 上游 400 | responses-first(tool_result 领先) |
只动了原本就坏的 Claude-through-Google 路径,恢复其可用性,无其它漂移。
CI 状态(读镜像缓存)
PR head 222a265:mergeable_state=blocked,test / static-gates / e2e / dsh / codex 等 lane 全部显示 skipped,仅 mysql-contract success——目前没有全量绿判据,看着像这次 run 没真正执行测试矩阵(可能被 path-filter 或调度跳过)。需要一次干净重跑才能作为合并依据。我已 push 31763b6,请让 CI 在新 head 上真跑一遍再合。
收工判定
方向与实现成立,kernel 改动合规、主路径修好且有双向测试钉;我额外堵上了 relay 三条次级边界的同源缺口(commit 31763b6)。代码层面可合,前提:①CI 在全量 lane 上真跑绿(现显示 skipped,需重跑确认);②(建议)补一条 claude-google 重试/stamp 边界的行为钉。kernel 变更按 Kernel Boundary 走人工 review,不 auto-merge。
…gle targets (for ranxianglei#5397, closes ranxianglei#5392) kernel-change: make normalizeGoogleUserPartOrder/coreToGoogle model-aware so Claude-through-Google targets keep tool_result-first part order. The host side cannot solve this: the offending reorder happens INSIDE the kernel codec (coreToGoogle's flushUser), and the stable text-first partition is non-invertible, so no host-only workaround exists. Owner approval via decision request ranxianglei#5393 (option A). Kernel version 0.0.188 -> 0.0.189 (master was already at 0.0.188 past this PR's 0.0.175->0.0.176 base bump).
kernel-change: make
normalizeGoogleUserPartOrder/coreToGooglemodel-aware so Claude-through-Google targets keep tool_result-first part order. The host side cannot solve this: the offending reorder happens INSIDE the kernel codec (coreToGoogle's flushUser), and the stable text-first partition is non-invertible (an interleaved[fr,text,fr,text]collapses to[text,text,fr,fr]), so no host-only workaround exists. Owner approval via decision request #5393 (option A).Summary
Claude-family models routed through Google's v1internal / Cloud Code Assist wire (e.g. Antigravity, pi-antigravity) behind bili returned HTTP 400 on any user turn carrying BOTH a tool response and injected text (ACP tags / nudge / system-drift note):
Reproduced on 0.1.209 and 0.1.210.
Root cause
WC-018 (#3159) makes bili stable-partition plain text before
functionResponseparts in the Google codec (normalizeGoogleUserPartOrder, called fromcoreToGoogle). That text-first order is what Gemini/Vertex require. But Google's v1internal backend translatesrole:"user"parts into Anthropic content blocks in order, and Anthropic requires alltool_resultblocks to lead the user message that follows an assistanttool_useturn — the opposite order. The unconditional reorder emitted exactly the bytes Anthropic rejects.Fix
Make the reorder model-aware. An optional target-model is threaded through every google-wire part-order boundary; when it matches
/claude/ithe natural responses-first (tool_result-first) order is kept, otherwise the existing text-first WC-018 behavior is byte-identical.kernel/src/wire/google.ts—normalizeGoogleUserPartOrder(parts, {model?})returns the input untouched for a Claude target;coreToGoogle(messages, {model?})threads it. Kernel version 0.0.175 → 0.0.176.googleModel ?? v1Modelon the proxy path incl. countTokens,modelVersionin the loop adapter):prepareGoogle,appendGoogleNudge,appendTrailingUserText(degenerate-retry nudge + fake-completion hint), and the outbound chain-checkpoint carrier./claude/itargets; the WC-018 ledger entry documents the carve-out (ledger only grows).Behavior change (old → new)
/claude/i)Only the previously-broken Claude-through-Google path changes; every other path is byte-identical. This restores availability (a hard 400) for that lane with no other behavioral drift. No new config/env/CLI surface.
Tests
kernel/tests/wire-google.test.ts— two new pins:normalizeGoogleUserPartOrderreturns the input unchanged (same reference) for Claude models while still reordering without a model;coreToGoogleemits functionResponse-first under a Claude model vs text-first by default.tests/issue5392-claude-google-part-order.test.ts(new) — real-proxy integration: a Claude-named target forwards the trailing user content withfunctionResponsefirst and zero fake violations; the same turn on a non-Claude target still normalizes text-first (guards against the carve-out overreaching / regressing Vertex rejects tool responses when Bili appends trailing nudge text #3159).tests/issue3159-vertex-nudge-order.test.tsandtests/wire-contract.test.tsremain green (no WC-018 regression).Verified locally on the rebased head (origin/master
7578e8184): typecheck clean, build clean, 46/46 targeted tests pass. Full-suite verdict = remote CI.Closes #5392. Implements approved option A from decision request #5393.