#18926: fix(agents): preserve thinking signatures for direct Anthropic API
channel: mattermost
agents
size: S
Cluster:
Tool Call ID Sanitization
## Summary
- Set `preserveSignatures: true` for direct Anthropic API connections (not just Antigravity Claude), preventing `Invalid signature in thinking block` rejections during compaction and announce relay.
## Root Cause
`resolveTranscriptPolicy` only set `preserveSignatures` for `isAntigravityClaudeModel`, causing thinking block signatures to be stripped when using Claude models directly via the Anthropic API. On follow-up API calls (compaction, session cleanup, announce relay), the stripped signatures triggered `Invalid signature in thinking block` errors.
## Changes
- `src/agents/transcript-policy.ts`: Change `preserveSignatures: isAntigravityClaudeModel` → `preserveSignatures: isAntigravityClaudeModel || isAnthropic`
- `src/agents/transcript-policy.test.ts`: Add 3 tests covering direct Anthropic, Antigravity Claude, and non-Anthropic models
## Test plan
- [x] `pnpm vitest run src/agents/transcript-policy.test.ts` — 7 tests pass
- [ ] Verify extended thinking sessions on direct Anthropic API complete compaction without signature errors
Fix #18653
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Extends thinking block signature preservation to direct Anthropic API connections (not just Antigravity Claude), preventing `Invalid signature in thinking block` errors during transcript compaction and session cleanup operations.
- Changes `preserveSignatures` logic from only `isAntigravityClaudeModel` to also include `isAnthropic` (direct Anthropic API via `anthropic-messages` API or `anthropic` provider)
- Adds comprehensive test coverage for the three scenarios: direct Anthropic API, Antigravity Claude, and non-Anthropic models
- Includes unrelated but valid test fix for Mattermost websocket race condition (registering listeners before emitting events)
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is a simple, well-tested boolean logic extension that correctly addresses the root cause. The change is minimal (one line), logically sound, and comes with comprehensive test coverage. The Mattermost test fix is also a valid race condition resolution.
- No files require special attention
<sub>Last reviewed commit: 84f6b21</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15379: fix(antigravity): strip unsigned thinking blocks in agent loop via ...
by jg-noncelogic · 2026-02-13
83.1%
#16100: fix: convert unsigned thinking blocks to text to prevent signature ...
by claw-sylphx · 2026-02-14
81.8%
#2806: [AI-Assisted] Fix: Repair tool_use/tool_result pairing for Claude o...
by Arthur742Ramos · 2026-01-27
79.6%
#13831: fix(agents): include Anthropic in tool call ID sanitization
by lailoo · 2026-02-11
79.3%
#17914: Resolve merge conflicts in PR #13361
by SovranAMR · 2026-02-16
79.1%
#20945: fix: strip thinking blocks with field-name signatures from OpenAI-c...
by austenstone · 2026-02-19
78.1%
#13361: fix(google-antigravity): add Opus 4.6 support and fix thinking.sign...
by SovranAMR · 2026-02-10
77.8%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
77.4%
#22270: fix: add auto-recovery for thinking block immutability errors
by MunemHashmi · 2026-02-20
77.3%
#6685: fix: suppress thinking leak for Synthetic reasoning models
by AkiLetschne · 2026-02-01
77.3%