← Back to PRs

#18926: fix(agents): preserve thinking signatures for direct Anthropic API

by BinHPdev open 2026-02-17 05:54 View on GitHub →
channel: mattermost agents size: S
## 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