You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Claude models with extended thinking, the API returns `thinking`/`redacted_thinking` blocks. When OpenCode replays these back (on next message or compaction), if they're modified during storage/retrieval, Claude rejects them:
@@ -11,93 +11,34 @@ messages.3.content.1: `thinking` or `redacted_thinking` blocks in the latest ass
11
11
12
12
Session becomes stuck — even compaction triggers the same error.
13
13
14
-
## Root Cause
15
-
`MessageV2.toModelMessages()` stores reasoning parts as `{type: "reasoning", text: part.text}` but the original API response had `{type: "thinking", thinking: "..."}`. The reconstruction is not byte-identical. Claude's constraint only applies to the LAST assistant message.
16
-
17
-
## Approach: Strip reasoning from last assistant message (user-controlled)
Description: "Automatically retry without thinking blocks when API rejects modified thinking content"
89
-
```
90
-
91
-
## Implementation Order
92
-
1. Backend strip logic (message-v2.ts)
93
-
2. Config setting (config.ts)
94
-
3. Auto-retry logic (processor.ts)
95
-
4. Error card button (message-part.tsx)
96
-
5. Settings toggle (settings-general.tsx)
97
-
98
-
## Testing
99
-
- Reproduce with Claude Opus in long conversation
100
-
- Verify error → button appears
101
-
- Click button → retries successfully
102
-
- Enable auto-mode → errors auto-recover
103
-
- Compaction still works after fix
14
+
## Root Cause (verified via PR #14393)
15
+
1.**Bug 1:**`toModelMessages()` strips `providerMetadata` (including Bedrock thinking signatures) when `differentModel` is true — which always happens during compaction due to model ID format mismatch.
16
+
2.**Bug 2:** Asymmetric compaction buffer (20K vs 32K) causes compaction to trigger too late for some models.
17
+
18
+
## Solution: Root Fix + Configurable Strategy
19
+
20
+
### Root Fix (from PR #14393)
21
+
- Always pass `providerMetadata` for reasoning parts and `callProviderMetadata` for tool parts (removed `differentModel` guard)
22
+
- Symmetric compaction buffer using `maxOutputTokens()` consistently
23
+
24
+
### Configurable Thinking Strategy
25
+
Three options available in Settings and Context tab:
26
+
-**"none" (default):** Original behavior — send thinking blocks as-is. With the root fix, signatures are now preserved correctly.
27
+
-**"strip":** Proactively remove thinking from last assistant message before sending. Prevents errors but loses thinking context.
28
+
-**"compact":** Preserve thinking but auto-compact on error. First message may fail, then auto-recovers.
0 commit comments