Skip to content

[PR] fix: preserve signed Google text on replies and tool replay - #6845

Closed
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-15_google-signed-text
Closed

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-15_google-signed-text

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

Fixes #6842.

Gemini can attach a thoughtSignature to an ordinary text part without setting thought: true (Google's thought-signature documentation). The existing thought-only guards leave two gaps:

  • Proxy and plugin response filters can rewrite signed ordinary text, changing the payload associated with the signature.
  • After a proxy-owned tool call, the loop joins text into plain strings and drops the original text-part signatures and boundaries before the next upstream request.

This is separate from standalone signature parts (#3162), signature promotion from removed proxy function calls (#6103), and complete-frame forwarding (#6623).

Changes

  • Preserve nonempty signed text verbatim in the Google streaming adapter and the proxy/plugin JSON and streaming response paths.
  • Carry each signed text part through loop accumulation so tool continuations replay the original part, signature, and boundary.
  • Keep unsigned prose filtering and existing thought, standalone-signature, opaque-output, and real-tool handling unchanged.

The implementation stays in existing modules and adds no configuration or dependency changes.

Validation

Tested against master 2e3cfc9 (0.1.215), also the parent of this commit. Head: 6134736.

Baseline reproduction: the seven new regressions fail on unchanged master, while the sixteen existing complete-frame tests pass. The failures cover ordinary signed text in SSE/JSON-array parsing, actual HTTP responses in proxy/plugin modes and SSE/JSON formats, and signatures lost from the second upstream request after an acp_status call.

Candidate: 142 focused tests pass across google-complete-frame, plugin-passthrough-progress-frame-google, issue1960-thinking-verbatim, adapter-google, issue3158-google-standalone-signature, anthropic-thinking-replay, anthropic-round2-thinking-hold, loop-core, loop-adapters, and e2e-google-compress.

The HTTP regressions inspect both client-visible signed parts and the actual continuation body received by a local upstream server. Adjacent signed text parts, unsigned neighbors, whitespace, Unicode, ACP-like text, plugin/proxy modes, and JSON/SSE responses are covered. The wider controls include Anthropic signed replay and the existing hermetic Google compression scenarios.

Also passed:

  • node node_modules/typescript/bin/tsc --noEmit --project tsconfig.json
  • npm run build
  • node scripts/check-test-import-graph.mjs
  • git diff --check

The repository's live Codex four-phase E2E has not been run. E2E_CHECK=1 confirms the built distribution and installed Codex CLI, but its upstream probe reports http://127.0.0.1:8199/v1/models unreachable. The local HTTP tests above are hermetic tests, and the real-client/live-upstream gate remains outstanding.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:按现状批准。方向对、三层一致、带测试,可以合并。

方向正确性:签名正文(带 thoughtSignature 的普通文本 part)逐字节校验,剥一个字节就 400 断会话——和 #1960(thought part)、#3158(独立签名 part)同一死伤等级。三层(压缩循环 adapter-google / 非流式 stream-google / 客户端流 plugin.ts pipe+stripGoogleChunk)都按"带签名即原样放行"处理,行为一致;core.ts 的 RoundPart 拆分条件(任一侧带 rawGooglePart 即不合并)保证了签名边界不被跨 part 拼接糊掉。

两个残留边角,记录在案、不阻塞:

  1. 签名 chunk 里若含 ACP 标签/标记,会原样漏给客户端。这是被迫接受的代价:签名覆盖原始字节,"又剥又保签名"不存在。与 #1960 既有裁决("cosmetic leaks inside a thought pane are accepted")一致,此处同理。
  2. 签名迟到:现有代码已证明 Google 会发"只有签名、没有文本"的独立 part(#3158),即签名与文本可分 chunk 到达。若签名 part 的文本跨 chunk、前面的 chunk 含 ACP 垃圾(已被剥)、签名在后续 chunk 才到,客户端回传的是剥过的文本+签名 → 该 turn 回放 400。此边角在代理层无法修复(前面的字节已经发给客户端),根治需"整 part 缓冲到边界再放行",属流式语义的设计改动,另行跟进、不阻塞本 PR。触发需"签名迟到 ∧ 前面 chunk 恰好含 ACP 垃圾"同时成立,最坏后果是一次显式 400(可见、可恢复),非静默损坏。

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #7101 (batch-2) — this PR's content (and its review-patch fix where applicable) is now merged via #7101. Closing to avoid a duplicate merge. 本 PR 的内容(含评审补丁,如适用)已通过 #7101 合并,关闭以免重复合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google signed ordinary text is rewritten and loses signatures in tool continuations

2 participants