#16100: fix: convert unsigned thinking blocks to text to prevent signature error
stale
size: M
Cluster:
OpenAI Model Fixes and Updates
## Summary
Fixes #15681
When using Claude thinking models via the `google-antigravity` provider, accumulated thinking blocks in session history cause API failures with `thinking.signature: Field required`. This happens because:
1. **`transform-messages.ts`**: When `isSameModel` is true, thinking blocks without `thinkingSignature` are kept as `type: "thinking"` instead of being converted to plain text.
2. **`google-shared.ts` `convertMessages()`**: Sends `thought: true` without `thoughtSignature` to the Google Cloud Code Assist API. The Antigravity proxy does not map the missing `thoughtSignature` to Anthropic's required `signature` field, causing rejection.
## Changes
Patches `@mariozechner/pi-ai@0.52.10` (via `pnpm patch`):
### `transform-messages.js`
- Remove the fallback that keeps unsigned thinking blocks as `type: "thinking"` when `isSameModel` is true
- Unsigned thinking blocks are now always converted to `type: "text"`, regardless of model match
- Signed thinking blocks (with `thinkingSignature`) are still preserved for replay
### `google-shared.js` `convertMessages()`
- When `isSameProviderAndModel` is true but `resolveThoughtSignature()` returns no valid signature, convert the thinking block to plain text instead of sending `thought: true` without `thoughtSignature`
- This prevents the Antigravity proxy from forwarding unsigned thinking blocks to Anthropic
### Tests
- `transform-messages.unsigned-thinking.test.ts` — 4 tests covering unsigned/signed/empty thinking block handling
- `google-shared.unsigned-thinking-blocks.test.ts` — 6 tests covering `convertMessages` behavior for unsigned, signed, invalid-signature, empty, multi-turn, and cross-provider scenarios
All 10 new tests pass. All 31 existing provider tests still pass.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes API failures when using Claude thinking models via the `google-antigravity` provider (#15681). The root cause was that unsigned thinking blocks (without `thinkingSignature`) were being sent to the Anthropic API via the Antigravity proxy, which requires the `signature` field on all thinking blocks.
The fix is applied as a `pnpm patch` to `@mariozechner/pi-ai@0.52.10`, modifying two files:
- **`transform-messages.js`**: Removes the `if (isSameModel) return block;` fallback that preserved unsigned thinking blocks as `type: "thinking"`. Signed blocks (with `thinkingSignature`) are still preserved via the earlier guard at line 32. Unsigned blocks now always convert to `type: "text"`.
- **`google-shared.js`**: Adds an explicit check — when `resolveThoughtSignature()` returns no valid signature, the thinking block is converted to plain text instead of being sent with `thought: true` but without `thoughtSignature`.
- 10 new tests cover unsigned, signed, invalid-signature, empty, multi-turn, and cross-provider scenarios across both patched functions
- The lockfile includes minor `axios`/`follow-redirects` deduplication changes as a side effect of running `pnpm install`
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — the patch correctly addresses a targeted API compatibility bug with defensive changes and thorough test coverage.
- Score of 4 reflects: (1) the patch logic is correct — signed blocks are still preserved by existing guards while unsigned blocks are safely converted to text, (2) 10 new tests cover the key scenarios comprehensively, (3) the change is narrowly scoped to a specific bug fix with no functional regression risk to other providers. Deducted 1 point because patching a dependency introduces maintenance overhead — this fix should ideally be upstreamed.
- The `patches/@mariozechner__pi-ai@0.52.10.patch` file should be tracked as a maintenance item — this patch will need to be verified or removed when `@mariozechner/pi-ai` is upgraded.
<sub>Last reviewed commit: c2bd83c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#13361: fix(google-antigravity): add Opus 4.6 support and fix thinking.sign...
by SovranAMR · 2026-02-10
83.7%
#18926: fix(agents): preserve thinking signatures for direct Anthropic API
by BinHPdev · 2026-02-17
81.8%
#15379: fix(antigravity): strip unsigned thinking blocks in agent loop via ...
by jg-noncelogic · 2026-02-13
81.8%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
80.8%
#17914: Resolve merge conflicts in PR #13361
by SovranAMR · 2026-02-16
80.2%
#6685: fix: suppress thinking leak for Synthetic reasoning models
by AkiLetschne · 2026-02-01
78.7%
#20945: fix: strip thinking blocks with field-name signatures from OpenAI-c...
by austenstone · 2026-02-19
78.5%
#20050: fix: Telegram polling regression and thinking blocks corruption (AI...
by Vaibhavee89 · 2026-02-18
77.4%
#20620: feat: add anthropic/claude-opus-4-6 to XHIGH_MODEL_REFS
by chungjchris · 2026-02-19
76.8%
#10097: fix: add empty thinking blocks to tool call messages when thinking is…
by cyxer000 · 2026-02-06
76.8%