anthropics / anthropics/anthropic-sdk-python

[Bug] API returns 400 'Invalid signature in thinking block' when replaying conversation history — no recovery path

Đang mở
#1,598 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
3.9k
Fork
853
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
11

Mô tả

## Bug Description

When using extended thinking with claude-sonnet-4.x/claude-opus-4.x in a multi-turn conversation, the API begins returning `400: Invalid `signature` in `thinking` block` after N turns. Once triggered, **every subsequent message in the session fails permanently** — there is no recovery without manually stripping thinking blocks from history.

## Reproduction

1. Enable extended thinking on claude-sonnet-4-6 or claude-opus-4
2. Run a long multi-turn conversation (20+ turns with tool use)
3. Pass full conversation history on each turn (including `type: "thinking"` blocks from prior assistant messages)
4. At some turn, the API begins rejecting with 400: `messages.X.content.Y: Invalid `signature` in `thinking` block`
5. The position (X, Y) is consistent — the same thinking block triggers it every time
6. The session cannot recover — every subsequent call with that history fails

## Error

```json
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "messages.27.content.0: Invalid `signature` in `thinking` block"
}
}
```

## Questions / Issues

1. **What invalidates a signature?** The API docs say to pass thinking blocks back unmodified. If signatures expire or become invalidated server-side, clients have no way to know without trying.
2. **No recovery path** — the error is a hard 400, not retryable. Clients must strip thinking blocks from history to continue, but the API docs don't describe this scenario or recommend this workaround.
3. **Cascading failure** — subagents or forked sessions that inherit the conversation history also fail immediately.

## Environment

- SDK: used via OpenClaw gateway (direct Anthropic REST API)
- Model: claude-sonnet-4-6
- Platform: macOS 26.4.1, Node.js 22.x

## Related

- anthropics/claude-code#21726 (session resume fails with same error)
- anthropics/claude-code#10627

## Requested

1. Document under what conditions a thinking block signature becomes invalid
2. Provide a recommended recovery path (e.g., strip thinking blocks from history on 400, retry)
3. Ideally: return a more specific error type so clients can handle it programmatically

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.