anthropics / anthropics/anthropic-sdk-python

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

未關閉
#1,598 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
3.9k
分支
853
平均合併
1 天 18 小時
30 天內合併 PR
11

描述

## 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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。