Skip to content

[PR] fix: forward complete Google frames once + preserve stream-error cause (root-cause #6634) - #6637

Closed
ranxianglei wants to merge 0 commit into
masterfrom
2026-11-14_google-adapter-root-cause
Closed

ranxianglei wants to merge 0 commit into
masterfrom
2026-11-14_google-adapter-root-cause

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #6621
Fixes #6629

What this is

One root-cause PR for the google-adapter batch (aggregation #6634). It combines the two already-validated contributor fixes into a single delivery, cherry-picked with original authorship preserved (-x, original SHAs in each commit message):

This supersedes the two per-issue PRs #6623 and #6631; please close those in favor of this one.

Bug 1 — duplicated frames + dropped output-only frames (#6621)

The Google loop adapter attached the complete raw frame to every text/thought event it extracted from that frame. A single [text A, signed thought, text B] frame therefore sent all three parts three times to the client. Because signed thought bytes must stay byte-exact (#1960), the duplicated signed thoughts desynchronize text from signature. Output-only frames (inlineData, executableCode, codeExecutionResult) fell through the text/call/signature dispatch and were dropped entirely.

Fix: the forwarding decision is made once per complete frame, after all prose edits. Non-text parts and signed-thought bytes keep their original order; the frame is attached to a single carrier event. Structured text/reasoning events still feed internal accounting but carry an explicit rawHandled flag so continuation rounds do not synthesize a second copy of the buffered content.

Bug 2 — stream errors lose their cause (#6629)

A top-level Google error envelope ({"error":{...}}) carries no candidates, so the adapter classified it as ordinary metadata marked firstRoundOnly. On round 1 that misclassified the error as client framing (blocking the loop's existing zero-output retry); after a proxy-tool continuation the firstRoundOnly flag suppressed it, so the client lost the provider's code/status/message and received only a generic no completion event error.

Fix: a non-null top-level error is recognized before candidate/metadata classification and yielded through the loop's existing kind: "error" path, retaining the numeric code, status and message. Already-received text/usage are flushed; parsing of the failed response stops.

Validation

Base e1f31ad9d5 (0.1.213), Node v22.

  • 16 new cases (frame forwarding) + 9 new cases (stream errors) pass; both reproduce failures on unchanged master.
  • 73 related Google/SSE/signed-thinking tests pass (adapter, standalone signatures, e2e Google compression, part order, degenerate retry, retry error body, wire rebuild stability, SSE framing).
  • Typecheck, full build, unused-export gate and test-import-graph gate all pass.
  • Full regression is the remote CI verdict on the pushed head.

No kernel, config surface, persistence format, version or plugin-path changes.

@ranxianglei ranxianglei changed the title fix: forward complete Google frames once + preserve stream-error cause (root-cause #6634) [PR] fix: forward complete Google frames once + preserve stream-error cause (root-cause #6634) Nov 14, 2026
@ranxianglei ranxianglei added bug Something isn't working gemini p1 scope/wiring labels Nov 14, 2026
@ranxianglei
ranxianglei force-pushed the 2026-11-14_google-adapter-root-cause branch from 3b2835a to 2b47e90 Compare November 14, 2026 01:38
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复. This is a root-cause aggregation PR (marker rcagg:google-adapter, owner-sanctioned flow) that consolidates two already-validated contributor fixes (#6623 + #6631) into one delivery. It is not a duplicate of any third open PR — it explicitly supersedes #6623 and #6631. No parallel PR fixing the same thread was found.

Review verdict: code correct, tests have teeth — mergeable once CI is green

I reviewed the full 4-file diff (src/loop/adapter-google.ts, src/loop/core.ts, +2 new test files) against the two source issues. Both fixes address the root cause, not the symptom.

Bug 1 (duplicated frames + dropped output-only frames, #6621): The forwarding decision is now made once per complete frame, after all prose edits, and the frame is attached to a single carrier event. Non-text parts and signed-thought bytes keep their original order; structured text/reasoning events feed internal accounting but carry an explicit rawHandled flag so continuation rounds don't synthesize a second copy. I traced the old code: it attached the whole raw frame to every text/thought event, so a [text, signed thought, text] frame was sent 3× — duplicating signed thoughts, which desyncs text from signature (#1960) and bricks the session on the in-turn re-request. The fix removes the producer of the duplication at the source. Output-only frames (inlineData/executableCode/codeExecutionResult) now flow through nonCallPartsOf (renamed from prosePartsOf, which dropped them) and are forwarded verbatim.

Bug 2 (stream errors lose their cause, #6629): A non-null top-level error envelope is now recognized before candidate/metadata classification and yielded through the loop's existing kind: "error" path, retaining numeric code/status/message. I traced the old code: the error envelope (no candidates) hit the !candidate branch and was misclassified as firstRoundOnly metadata — round 1 blocked the loop's zero-output retry (forwardedFraming), round ≥2 (post proxy-tool continuation) suppressed the error entirely, so the client lost the provider's code/status/message and got only a generic no completion event. The fix restores the cause and re-opens the zero-side-effect retry.

Latent bug also fixed (not in the PR description, flagged): stored call chunks now drop finishReason at buffer time, so a finish-frame-with-real-call delivers ONE finishReason (the stub) instead of TWO (kept frame + stub). The old wire sent finishReason twice. Pinned by a dedicated test.

Behavior changes (old → new), all intended fixes — flagged per policy:

  1. finish-frame-with-real-call: TWO finishReason frames → ONE (latent double-finishReason bug fixed).
  2. Call-frame text/reasoning: not recorded in the reply ledger in round 1 → now recorded (ledger accounting fix, correct direction).
  3. Output-only frames: silently dropped → now forwarded verbatim (data no longer lost).
  4. Error envelopes: misclassified as firstRoundOnly meta (cause lost) → now yield kind: "error" with provider code/status/message (cause preserved, zero-side-effect retry re-opened).

Regression checks I walked: the !candidate/usageMetadata path is unchanged; the blockReason (safety) path is unchanged; the firstRoundOnly meta for genuinely empty frames is unchanged; the byte-fidelity control (unedited single-part frame keeps exact wire bytes → prefix cache not disturbed) is pinned by a test; the proxy-only/real-call settle replay paths use the renamed nonCallPartsOf correctly. One minor pre-existing edge (non-blocking): an output-only frame forwarded raw while tagFilter holds a tail from a prior text frame can reorder the held tail after the media frame — this is the pre-existing filter re-layout class, and the old code dropped the frame entirely (worse). No fail-fast→swallow, no threshold/timing drift beyond the flagged items.

Tests: both new files have teeth — exact wire-frame assertions (framesOf/partsOf on forwarded bytes), negative gates (absent/null error → no error event; unedited frame → exact rawBuf), loop-level retry tests (zero-side-effect retry fires on first-frame error; persistent error exhausts one retry and retains the provider cause), and a full e2e through the real proxy (two-round flow, signed replay byte-exact in the re-request body, both compression modes considered per §6(4)). I did not re-run the full suite locally (that is the remote CI's job, §7.2); the verdict below is gated on CI.

CI state (verified live)

The run for the previous head (2b47e906f2) was fully cancelled (41/41) — part of the external whole-run cancellation event during the current master red storm (documented in #4599 floors 1345/1349). Master is currently RED (inherited: dsh/opencode/pi lanes + Windows EBUSY flake + notice-registry). Per the mandatory CI-coordination policy, I merged origin/ci-fixes (cd8bc8a184) into the PR branch — clean, no conflicts, non-content-changing — and pushed (new head 170cd59793). CI will re-run on the new head; the final green/red verdict is the remote CI on that head.

For the owner

八问

  1. 是什么问题:Google 循环适配器两个缺陷——(1) 完整原始帧被附加到每个抽取的 text/thought 事件,多 part 帧重复发送(签名 thought 重复使 text 与 signature 失步,[acp-loop] In-turn compress re-request edits the latest assistant message → Anthropic 400 "thinking blocks … cannot be modified" (session stays broken) #1960,轮内重发即坏会话),纯输出帧(inlineData/executableCode/codeExecutionResult)整个丢弃;(2) 顶层错误信封(无 candidates)被误分类为 firstRoundOnly 元数据,客户端丢失 provider 的 code/status/message。
  2. 什么原因导致的:(1) 转发决策按事件(每个 part)而非按帧做一次,且分发只处理 text/call/signature,不透明输出 part 落空;(2) 错误信封命中 !candidate 分支被当 firstRoundOnly meta,未在 candidate/metadata 分类前被识别为错误。
  3. 影响范围与严重程度:所有 Google/Gemini proxy 会话,只要产生多 part 帧(text+签名 thought)或纯输出帧,或遇到 provider 错误(quota/safety/5xx)。签名 thought 重复 = 会话破坏性缺陷(轮内重发即坏,之后经客户端 echo 持续坏);纯输出帧静默丢失;错误原因丢失。p1(会话破坏 + wire 完整性)。
  4. 怎么修复的:(1) 每帧所有 prose 编辑完成后转发决策只做一次,帧挂单一载体事件,rawHandled 标志让续轮不合成第二份;(2) 非空顶层 error 在分类前识别,走既有 kind: "error" 路径保留 code/status/message,已收 text/usage 先 flush,解析停止。
  5. 是否有回归问题:逐项审过。有意变更(均修复,已披露):real-call 终帧 2 个 finishReason→1 个;call 帧 text/reasoning 第 1 轮入 reply ledger;纯输出帧丢弃→转发;错误信封→kind:"error"。非回归核对:!candidate/usageMetadata、blockReason(safety)、真空帧 firstRoundOnly meta 均不变;字节保真控制(未编辑单 part 帧精确 wire 字节)有测试钉死;settle 重放路径正确使用改名后的 nonCallPartsOf。一处既有小边缘(非阻塞):tagFilter 持尾时纯输出帧 raw 转发可能重排——属既有 filter 重排类,旧代码整帧丢弃(更糟)。无 fail-fast 变吞错、无阈值/时序漂移。
  6. 是否破坏缓存:不涉及。未编辑单 part 帧保持精确 wire 字节(rawBuf),前缀缓存不受扰;编辑帧本就重序列化(此前亦然);无 cache-key/dedup-key 变更。
  7. 是否改了设计方向:没有。留在适配器既有架构内(每帧一次转发、循环既有 kind:"error" 路径、既有 settle/重放机制);无新 wire 协议;rawHandled 是 ParsedStreamEvent 附加字段。
  8. 是否引入了新的配置:没有。无新 env/config key/默认值。

结论:代码与测试均达标,可合入;唯一闸门是新 head 170cd59793 上重触发的 CI 转绿(已 merge ci-fixes 清继承红)。请 owner 关闭被取代的 #6623/#6631。

@ranxianglei
ranxianglei force-pushed the 2026-11-14_google-adapter-root-cause branch from 170cd59 to 4b77eab Compare November 18, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant