Skip to content

fix: normalize Google user-side part order for Vertex — plain text before functionResponse (#3159) - #3167

Merged
ranxianglei merged 9 commits into
masterfrom
2026-10-14_fix-3159-vertex-nudge-order
Oct 15, 2026
Merged

ranxianglei merged 9 commits into
masterfrom
2026-10-14_fix-3159-vertex-nudge-order

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Closes #3159

kernel-change: Vertex rejects user content carrying plain text after a functionResponse part (400 "Requests ending with a model turn are not supported"), and coreToGoogle's flushUser reassembled every user run as [responses..., content...] regardless of the client's own order — the ordering guarantee cannot be expressed host-side, so the fix lives in the wire rebuild. Host append boundaries add text post-rebuild, so they consume the new exported helper normalizeGoogleUserPartOrder from acp-kernel/wire rather than duplicating the predicate.

What

Vertex A/B matrix from #3159: final user parts [functionResponse] -> 200; [functionResponse, text] -> 400; [text, functionResponse] -> 200 (Gemini Developer API accepts both orders — Vertex-specific strictness). Bili produced the defective shape at four boundaries:

  1. kernel/src/wire/google.ts — coreToGoogle's flushUser rebuilt every merged user run as [...responses, ...content], so even a client sending the safe order was forwarded defective. New normalizeGoogleUserPartOrder(parts) stable-partitions unsigned, non-thought plain text before non-text parts when plain text follows a functionResponse part; applied in flushUser. Signed (thoughtSignature) / thought / non-text parts never move; nothing is dropped or rewritten; shapes without the defect come back byte-identical (the prefix-cache anchor is untouched).
  2. src/server/prepare-google.ts — appendGoogleNudge appended nudge/note text AFTER the existing parts post-rebuild (invisible to the kernel fix). It now wraps the appended parts in the same normalizer, covering all append callers: nudge, system-anchor drift notes, image notes.
  3. src/wire-body.ts — appendTrailingUserText (degenerate-retry nudge, fake-completion hint) built the same post-assembly shape; now normalized at the shared boundary.
  4. src/chain-checkpoint.ts — insertCheckpointCarrier (opt-in outbound chain stamping) likewise; now normalized at the shared boundary.

Wire-contract ledger (#1304)

WC-018 added (wire: google) with provenance (#3159 production 400 on dsh-vertex-argon 1.1.4 / DSH 0.2.0-rc.2 over billion-context 0.1.196, official Vertex endpoint, gemini-4-argon generateContent; controlled A/B matrix 2026-10-14), enforced in the validation-parity fake on every forwarded Google body, plus a unit gate and a ledger self-check probe. (Landed as WC-017 on the feature branch; master's #3072 took that id first for the codex lane, so the rule renumbers to WC-018 on rebase.)

Tests

  • kernel/tests/wire-google.test.ts: 3 new tests (stable partition + same-reference no-op, mixed-run rebuild order, safe-order byte-identical round-trip). Kernel suite 1295/1295 green.
  • tests/issue3159-vertex-nudge-order.test.ts: full-proxy e2e against the WC-018-enforcing fake covering ALL FOUR producers — a system-anchor drift note appended after a tool response, a client's own defective [functionResponse, text] order, the degenerate-retry/fake-completion trailing-text appends, and the chain-stamp carrier insertion; each relays the fake's 400 pre-fix.
  • tests/cache-friendly-plugin.test.ts: scoped allowCanonShift in assertPrefix (google lane only, two call sites) — the P1 byte-prefix pin ([test] Plugin-mode cache-friendliness invariants — same matrix as #1548's proxy-mode suite, as a permanent gate #1553/plugin mode: in-place acp_summary never stripped when the client's own compress pair rides inbound — double summary carrier on every post-fold turn #1567) now sanctions exactly one canonical move: after a fold turn, the new plain text leads the fold-pair's functionResponse, shifting the pair result right past it. Every other wire and turn stays strict byte-prefix.
  • tests/golden/storage-render/google.json regenerated through scripts/update-storage-render-goldens.ts (intentional render-contract change): 14 turn-body shas + state/metadata digests; byte counts unchanged (pure reorder); chat/anthropic/responses goldens byte-identical; regeneration deterministic.
  • Targeted host suites on the rebased head (wire-contract incl. golden + go-session, pi-subagent-registry, cache-friendly plugin+proxy, e2e-google-compress, adapter-google, preflight-google-summary, issue1204 google-plugin, chain-checkpoint-step2/step3, fake-completion, toolargs-adversarial, storage suites): 809/809 green locally; full-suite verdict = CI on this head.
  • typecheck clean.

Rebase / integration note

Rebased onto master bd2aa6e, which includes #3171 (fix(pi): tolerate undefined ctx in tool-guardrails event handlers, #3170 ①) and its test follow-ups (#3170 ② XDG lock fixture) — master's own test defects that had been red-ing this PR's shard-2/shard-3 legs via merge-ref checkout before the rebase. Also integrates two sibling-session commits fixing the remaining two post-assembly boundaries (items 3–4 above).

Behavior change (old -> new)

A mixed Google user content carrying plain text after a functionResponse part is now forwarded with the plain-text parts BEFORE the non-text parts — a one-time wire-byte reorder per affected request ([fr..., text...] -> [text..., fr...]). Pure/safe shapes are byte-identical (the normalizer is a no-op without the defect). This changes what Vertex receives for exactly the requests that currently 400; nothing else moves. One bounded prefix-cache invalidation at those turns (documented by the cfp suite amendment).

Config surface

None. No config field added, renamed, or re-semantics'd; no new env var or flag.

Out of scope: #3158 (response-side signature loss found during the same investigation) is tracked separately.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_fix-3159-vertex-nudge-order (b1611bf)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3708-pr.3167.005cd70

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

独立 review 完成。结论:方向正确、机制健全,但初版 head 有两处遗漏——已在 PR 分支上顺手补齐,当前 head 0964bbf75,最终判定等 CI 全绿(出结果我会跟进)。

结构化八问

  1. 是什么问题:Vertex 拒绝「user content 里纯文本排在 functionResponse 之后」的请求(400 "Requests ending with a model turn are not supported")。dsh-vertex-argon 上工具调用成功后的下一个请求直接失败。这是 Vertex 特有严格性,Gemini Developer API 两种顺序都收。
  2. 什么原因导致的:顺序保证无法在 host 侧表达——coreToGoogle 的 flushUser 把每个合并后的 user run 无条件重排成 [responses…, content…],客户端即使发安全顺序也会被转发成缺陷形;appendGoogleNudge 又在 rebuild 之后追加文本,是第二个生产者。
  3. 影响范围与严重程度:所有「工具响应后追加文本」的 Vertex 会话(nudge / system-anchor 漂移注记 / image note)→ hard 400,该轮失败。特定条件下完全不可用(Vertex + 结尾 functionResponse + 后续追加文本)。
  4. 怎么修复的:wire rebuild 边界加 stable-partition normalizer(纯文本移到非文本 part 之前);安全形状返回同一数组引用(byte-stable);host 侧各追加边界消费同一导出 helper,不复制谓词。
  5. 是否有回归问题:逐项审过的既有行为——安全形状字节稳定(保持,kernel round-trip 测试钉住);google storage-render golden(有意再生,见第 6 问);cfp plugin 矩阵 google lane 的 t5/t7 前缀断言(有意 relayout,allowCanonShift 钉住,f1badaa54 审阅后采用);chain-checkpoint 识别/摘要契约(识别是 any-part 位置无关,digest 在 strip carrier 之后哈希故位置无关,step2/step3 既有 pin 全部不变);degenerate-retry/fake-completion/wire-body 的其他 wire(只动 google 分支)。Windows-only 时序 flake(responses-websocket cancelledByParent 簇、wire-exit-gap-cells header 时序)与本 diff 无关(master 同时段全绿)。
  6. 是否破坏缓存:纯/安全形状逐字节不变(no-op 同引用),无影响。有意变更:当新纯文本落入已含 functionResponse 的 user run 时,该内容整体重排([texts…, frs…])——受影响请求从该点起一次性上游前缀缓存重新计费,之后恢复稳定。这些请求此前在真实 Vertex 上就是 hard 400,不存在需要保留的旧形状。已由 cfp google lane 断言 + 再生 golden 钉住。
  7. 是否改了设计方向:没有。修复留在 wire rebuild 边界,host 消费导出 helper;我补的边界也沿用同一模式。
  8. 是否引入新配置:没有。

Review 发现(独立审核产出,已顺手修掉)

  • 还漏了两个同形生产者(incomplete first pass):appendTrailingUserText(src/wire-body.ts——degenerate-turn retry nudge【默认开启】和 fake-completion hint【opt-in】共用)与 insertCheckpointCarrier(src/chain-checkpoint.ts——opt-in 出站链戳,relay.ts:260)。两者都在组好的 body 上把文本追加进最后一个 user content 的 parts 末尾——对 kernel 修复不可见,会重新造出 WC-017 缺陷形。commit 0964bbf75 修复:两处边界都消费 normalizeGoogleUserPartOrder;Vertex rejects tool responses when Bili appends trailing nudge text #3159 回归套件新增 2 个单测门(精确顺序断言 + 经 ledger validator 确认零 WC-017 违规 + 无缺陷形状的 byte-stable 对照)。
  • CI 分诊(初版 head cdfc4e99 全部 12 个 test shard 红):三个家族——① google storage-render golden 钉的是修复前的 wire 字节 → 用 sanctioned 脚本再生(只有 google.json 变;state/blockContents/stats 段不变;chat/anthropic/responses 逐字节相同);② cfp plugin 矩阵 google lane 前缀断言 → 批准 relayout(并行会话推的 f1badaa54 经审阅采用,我的重复方案弃用,避免同文件双改);③ Windows 时序 flake(路径与本 diff 无关,master 同时段绿)。
  • 已核验:normalizer 语义(幂等、signed/thought/非文本 part 永不动、不丢不改写、安全形状同引用 no-op);kernel 边界合规(kernel-change 声明、版本 0.0.123→0.0.124、lock 同步、kernel-guard 绿);WC-017 ledger 条目带 provenance 且在每个转发的 Google body 上强制;appendGoogleNudge 全部 5 个调用点(nudge×2、directive、drift note、imgNote)均被覆盖。
  • 本地定向验证:issue3159 套件 4/4、chain-checkpoint-step2+3、loop-degenerate-retry、fake-completion、wire-contract 合计 84/84;cfp + golden-storage-render + storage-engine-proofs 28/28;kernel 套件 1295/1295;typecheck 干净。全量判定 = CI on 0964bbf75。

行为变更披露(old → new)

混合 Google user content(纯文本跟在 functionResponse 后)现在以 [texts…, non-texts…] 转发——每个受影响请求一次性的 wire 字节重排;纯/安全形状逐字节不变。另含第 6 问所述的重排/缓存重计费细化。

判定:0964bbf75 CI 转绿即可合并;CI 结果出来我会回帖跟进(若 Windows flake 复现且能证明与本 diff 无关,按 flake 单独处理)。

awork added 8 commits October 14, 2026 21:12
… functionResponse (#3159)

Vertex rejects a request whose user content carries plain (unsigned,
non-thought) text AFTER a functionResponse part with 400 'Requests
ending with a model turn are not supported' (controlled A/B matrix in
#3159; Gemini Developer API accepts both orders). coreToGoogle's
flushUser reassembled every user run as [responses..., content...],
so even a client sending the safe [text, functionResponse] order was
forwarded defective. Add normalizeGoogleUserPartOrder (stable
partition; signed/thought/non-text parts never move; byte-stable no-op
when no plain text follows a functionResponse) and apply it in
flushUser. Bump acp-kernel to 0.0.124.
…ailing content (#3159)

appendGoogleNudge appended any trailing note or nudge text AFTER the
existing parts of the last user content — after a tool response that
produced the same Vertex 400 shape the kernel rebuild fixed (the note
was added post-rebuild, so the kernel fix alone could not cover it).
Wrap the appended parts in the kernel's normalizeGoogleUserPartOrder so
the new text leads; all append callers (nudge, system-anchor notes,
image notes) share this one boundary.
Add WC-017 to the wire-contract ledger (Vertex rejects plain unsigned
non-thought text after a functionResponse part in user content;
provenance: #3159 production 400 + controlled A/B matrix), enforced in
the validation-parity fake on every forwarded Google body plus a unit
gate and ledger self-check probe. New e2e regression drives both
producers through the real proxy against the enforcing fake: a
system-anchor drift note appended after a tool response, and a client's
own defective [functionResponse, text] order — both must forward with
text first or the fake relays its 400.
…lugin matrix

The google lane now forwards user contents ending on tool results with
new plain-text parts LEADING (Vertex rejects text after functionResponse,
#3159). Between a fold turn and the next, the previous body's trailing
tool units therefore shift right past an inserted run of text units from
the same content — assertPrefix gains a scoped allowCanonShift that
sanctions exactly that move (google lane, two call sites); every other
comparison stays an exact byte-prefix.
The golden scenario drives tool pairs on every even turn, so each merged
user run [fr, next-text] hits exactly the shape Vertex rejects and the
normalizer now re-lays out. Outbound body digests from turn 1 onward and
the fold-reconciliation canon snapshot (metadata.foldPositions) reflect
the new layout; state/blockContents/stats sections are unchanged. Only
google.json drifts — chat/anthropic/responses regenerate byte-identical.
…aries (#3159)

Two more producers of the WC-017 shape survived the rebuild-level fix:
appendTrailingUserText (degenerate-turn retry nudge — enabled by default,
and the opt-in fake-completion hint) merges its text into the last user
content's parts AFTER the body is assembled, and insertCheckpointCarrier
(opt-in outbound chain stamp, relay egress) appends the carrier tag the
same way. Both landed plain text after a trailing functionResponse part
— exactly what Vertex rejects — invisible to the kernel rebuild and to
appendGoogleNudge. Both boundaries now consume the exported
normalizeGoogleUserPartOrder; safe shapes stay byte-identical. Regression
gates added to the #3159 suite: exact order assertions plus a WC-017
ledger-validator check on each mutated body, and a no-defect byte-stable
control.
…3159)

Master moved the google golden's stateDigest/metadata section digests
since our base (post-base state-level changes); re-running the generator
on the rebased tree folds master's baseline in under the #3159 part-order
re-layout. Turn body shas unchanged by this step; other wires
byte-identical.
@ranxianglei
ranxianglei force-pushed the 2026-10-14_fix-3159-vertex-nudge-order branch from 9df9817 to 5fc68be Compare October 14, 2026 13:20
@ranxianglei
ranxianglei merged commit e7e7c39 into master Oct 15, 2026
26 of 27 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.436-master.e7e7c39 (rolling master tag).

npm install -g billion-context@0.0.436-master.e7e7c39  # 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

Development

Successfully merging this pull request may close these issues.

Vertex rejects tool responses when Bili appends trailing nudge text

1 participant