JIA-ss
ad90bb4645
fix(api): 修复 thinking 块被意外修改导致的 400 错误
问题描述:
使用扩展思考功能时,偶现以下错误:
"thinking or redacted_thinking blocks in the latest assistant message cannot be modified"
根因分析:
当代理服务修改请求体中的某些字段时(如 metadata.user_id、model),
使用 map[string]any 解析整个 JSON 后重新序列化,导致:
1. 字段顺序改变(Go map 序列化按字母排序)
2. 数字格式变化(如 1.0 → 1)
3. Unicode 转义变化
Claude API 对 thinking 块进行字节级验证,任何变化都会触发错误。
修复内容:
1. identity_service.go - RewriteUserID/RewriteUserIDWithMasking
使用 json.RawMessage 保留其他字段的原始字节
2. gateway_service.go - replaceModelInBody
使用 json.RawMessage 保留其他字段的原始字节
3. gateway_service.go - normalizeClaudeOAuthRequestBody
保留 messages 的原始字节,跳过包含 thinking 块的消息修改
4. gateway_service.go - isThinkingBlockSignatureError
添加 "cannot be modified" 错误检测,触发自动重试
5. antigravity_gateway_service.go - isSignatureRelatedError
添加 "cannot be modified" 错误检测
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 16:15:37 +08:00
..
2026-01-31 03:58:01 +08:00
2026-02-03 13:38:44 +08:00
2026-02-03 15:02:15 +08:00
2026-01-01 01:43:20 +08:00
2026-01-18 16:10:54 +08:00
2026-01-30 13:21:25 +08:00
2026-02-03 15:02:15 +08:00
2026-02-03 13:38:44 +08:00
2026-02-03 16:15:37 +08:00
2026-01-31 03:58:01 +08:00
2026-01-26 10:21:41 +08:00
2026-01-16 17:05:49 +08:00