Skip to content

fix: preserve standalone thoughtSignature parts in the Google loop adapter (#3158) - #3162

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-14_fix-3158-google-standalone-signature
Oct 15, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-14_fix-3158-google-standalone-signature

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3158

Problem

Gemini streams sign reasoning blocks with thoughtSignature. The signature can ride its OWN part with no text at all (a late association for an earlier block, or the whole block's signature when the text arrived unsigned). The Google loop adapter modeled only text/thought/functionCall parts, so a signature-only part fell through every branch and vanished from the client's wire; the loop's proxy-tool rebuild had no record of it either, so re-requests lost the association as well.

Verified on master before the fix with the issue's exact four-frame repro: signature occurrences in forwarded bytes = 0.

Fix

src/loop/adapter-google.ts

  • New per-chunk gate: when a chunk carries no functionCall parts and nothing else was modeled from it, its standalone signature parts are forwarded verbatim — the whole raw frame when it carries no nonempty-text part and no finish reason, otherwise a wrapper carrying exactly those parts. The wrapper can never smuggle filter-held text bytes, and an early finishReason is stripped so the synthetic completion stays the sole terminal frame.
  • prosePartsOf (the drop-path resynthesis after a proxy-only call chunk) now keeps nonempty-signature parts alongside prose, so a signature sibling of a dropped call chunk still reaches the client.
  • Both settle branches emit one standalone_signature event per such part so the loop records them in stream order.

src/loop/core.ts

  • New shared event/round-part kind standalone_signature, recorded into roundParts.
  • The proxy-tool rebuild pushes an assistant core (acp_loop_r{round}_asst_sig[_N]) with googleThoughtSignature + rawGoogleParts:[{thoughtSignature}] at the part's stream position. rawGoogleParts is required: contentParts returns the raw verbatim only when the raw's texts equal the core's text, and an empty-text core without raw would serialize to zero parts — content vanishes.

The kernel already round-trips this shape verbatim (inbound sig-only part → empty-text core + rawGoogleParts; outbound returns raw verbatim), so no kernel change.

Behavior change (disclosed)

A truncated Google round whose only output was a forwarded standalone-signature chunk previously qualified for the blind zero-side-effect refetch (#413 gate shape (a)). The forwarded chunk now sets forwardedFraming, which bars that refetch on google (only openai/anthropic keep the framing exception). Such a turn now ends with the truncation surfaced through the completion instead of a silent re-fetch — correct, because the signature bytes were already client-visible and a re-fetch would duplicate them. Rare corner: requires truncation immediately after a late signature-only frame.

Out of scope (unchanged): other opaque non-text parts (inlineData/fileData/videoMetadata) are still not modeled by the streaming path — that family belongs to #2609/#2614. FunctionCall-attached signatures were never affected (separate handling path).

Tests

New tests/issue3158-google-standalone-signature.test.ts (10 cases): the issue's exact four-frame repro in SSE and JSON-array transport forms, empty-text-with-signature, mixed text+signature (no duplication), terminal-chunk shapes (no early finish leak), real-call sibling (verbatim replay), proxy-call sibling (drop-path resynthesis), loop-level re-request carrying the signature back (both the per-chunk and the settle path), and the retry-gate change pinned. Existing tests/adapter-google.test.ts and tests/issue1455-truncation-ping.test.ts green locally; full suite on CI.

No config-surface change. No kernel change. No version bump.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_fix-3158-google-standalone-signature (0b9c4db)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3609-pr.3162.3b46741

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

Install instructions are refreshed on each push.

…ol rebuild (#3158)

Review follow-up: a standalone thoughtSignature part sharing a frame with
successfully forwarded text was client-visible through the whole-frame raw
forward but never emitted as a standalone_signature event (the per-chunk
block gated on !emitted), so a later proxy-tool rebuild dropped it from the
re-request — the same lost-association class this PR fixes, narrower trigger.
Decouple recording from forwarding; add test #3158 l pinning it.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

独立审核完成(不复述 PR 描述,以下结论均基于自己对 diff、周边代码与 kernel 源码的重新核查)。审核中发现一处完整性缺口,已按「小问题直接修」直接在 PR 分支补掉(commit 0b9c4db94,见第 5 问)。新 head 的 CI 正在跑,最终判定见文末。

1. 是什么问题:Gemini 的推理签名 thoughtSignature 可以骑在一个没有任何文本的独立 part 上(晚到的关联,或整块文本到达时未带签名)。Google loop adapter 只建模了 text/thought/functionCall 三类 part,签名-only part 从客户端 wire 丢失,loop 的 proxy-tool rebuild 也没有它的记录——重放请求时关联同样丢失。我按 issue 的四帧 repro 思路核过:修复前该帧在转发字节里签名出现次数为 0。

2. 什么原因导致的:adapter 的 part 建模缺口(源头层),不是下游过滤问题。kernel 侧我独立验证了 PR 的关键论断:入站(kernel/src/wire/google.ts step 3,sig-only part 通过 isContentPart → 空文本 core + rawGoogleParts)和出站(contentParts:raw 非空且 rawTexts join 等于 core text 时原样返回 raw;没有 rawGoogleParts 则序列化为零 part)——所以 rebuild core 必须带 rawGoogleParts,kernel 确实无需改动。

3. 影响范围与严重程度:触发条件 = Google lane + 流中出现签名-only part + 会话走 proxy-tool rebuild(即发生过 proxy-only 调用轮次)。后果是 wire 保真度问题(签名关联静默丢失),不是硬故障;特定条件下有问题,属数据完整性级。FunctionCall 附着签名不受影响(独立路径),PR 说明准确。

4. 怎么修复的:在源头(adapter)把 standalone 签名 part 纳入建模:per-chunk 逐字转发(无其他内容时整帧原样,否则只装这些 part 的 wrapper,早到 finishReason 剥离)+ settle 两分支各发 standalone_signature 事件 + rebuild 在流位置插入空文本 core(googleThoughtSignature + rawGoogleParts)。是疏不是堵,方向正确。

5. 是否有回归问题(逐项审过的既有行为):

  • 混合帧(text+sig,无调用):整帧 raw 转发后 per-chunk 块因 emitted=true 跳过 → 不重复;
  • 真实调用重写路径:filterRealCallChunk(adapter-google.ts:103-129)保留全部非 call part,改写副本中的 sig part 随 wrapper 转发,无双发;
  • per-chunk 与 settle 对同一 chunk 互斥(callIndexes>0 走 settle),无重复事件;
  • 终端帧:wrapper 剥离早到 finishReason,合成 completion 保持唯一终止帧;空帧兜底、JSON-array 传输形态均被测试钉住;
  • KDD#10 thinking 字节纪律:签名字节全程 byte-exact 转发/重放,未触碰任何变换路径;
  • 发现并修复的缺口:standalone sig 与成功转发的文本同帧时(emitted=true),客户端可见但原先不发事件 → proxy-tool rebuild 丢它,与本 fix 同类(更窄触发面)。已在 src/loop/adapter-google.ts 解耦「记录」与「转发」:事件只要 callIndexes.length===0 && sigParts>0 就发,meta 转发仍留在 !emitted 分支(flushFilter 绝不能跨帧跑)。新增测试 #3158 l(混合帧 + acp_status proxy 调用 → 重放请求体携带签名、客户端恰好一次)。改前红(定向复现失败)、改后绿,commit 0b9c4db94 已推到 PR 分支并单独标注。

6. 是否破坏缓存:不涉及。去重键、增量游标、prefix-cache 策略均未触碰;rebuild 新增的 core 只在该会话实际出现过 sig part 时才出现。

7. 是否改了设计方向:没有。kernel 零改动(已独立验证其 round-trip 能力),仅扩展 loop 的事件/round-part 词汇表一种类型。

8. 是否引入了新的配置:没有(config surface 零变更,PR 声明属实)。

披露的行为变更(重试门)我独立核实为真且正确:core.ts:832-844 的盲重取门要求 !forwardedVisible && (!forwardedFraming || openai/anthropic);meta chunk 经 fwd() 置 forwardedFraming。故 google 上转发过 sig chunk 的截断轮不再盲重取,改为让截断从 completion 暴露——旧值:盲重取(#413 shape (a))/ 新值:拦截+暴露,原因成立(签名字节已客户端可见,重取会重复)。罕见角落(截断紧跟晚到 sig-only 帧),PR 披露充分。openai/anthropic 的 framing 例外保持不变。

测试有效性:断言有牙——字节计数(count(fwd,SIG)===1)、无早 finishReason 泄漏、fetch-mock 的 loop 级 e2e 断言重放请求体携带签名(per-chunk 与 settle 两条路径各一)、重试门钉死(calls=0、MAX_TOKENS 暴露)。本地定向跑(issue3158 + adapter-google + issue1455-truncation-ping)30/30 绿,typecheck/build 干净;全量以 CI 为准。

CI 状态:旧 head 上 38 项检查恰有 1 项红:test (windows-latest, 24, 2)(其余全绿,含 static-gates/e2e 各 lane/kernel-guard);而 master 最新一次完整 CI 全绿(含全部 Windows 分片)→ 疑似已知 flake 家族(#3152「Windows CI 偶发假红」、#3112 测试锁)。新 head 0b9c4db94 的 CI 正在跑,该分片结果出来我会补一条跟进。

热文件观察:在途 #3154(round 级熔断 → core.ts)、#3107(degenerate-turn 诊断 → adapter-google)、#2805(google lane ACP strip)、#2783(dsh novelty gate 双 lane)与本 PR 语义相邻,当前与 master 无文本冲突;若其中任一先合并,需 rebase 后再看。

判定:方向正确、根因在源头修、回归审计通过(含我自己补掉的同族缺口)、披露诚实。待新 head CI 全绿即可合并(合并留给人)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

跟进 CI 结果:新 head 0b9c4db94 的 41 项检查全部通过(含 static-gates、kernel-guard、各 e2e lane 与全部测试分片)。其中旧 head 上唯一红的 test (windows-latest, 24, 2) 在新 head 通过——结合 master 最新完整 CI 全绿,判定旧 head 那次红为环境性偶发(已知 flake 家族,#3152/#3112),与本 PR 变更无关。

最终判定:CI 全绿,可合并。 审核结论维持上一条回复:根因在源头修复、回归审计通过(含我补掉的同帧 sig 完整性缺口)、披露的重试门行为变更核实为真且正确、无 kernel/配置面改动。合并留给人。

@ranxianglei
ranxianglei merged commit 805f12b into master Oct 15, 2026
41 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.434-master.805f12b (rolling master tag).

npm install -g billion-context@0.0.434-master.805f12b  # 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.

Google loop adapter drops standalone thoughtSignature SSE parts

1 participant