[PR #11572] fix: strip reasoning parts when switching to non-interleaved models #13844

Open
opened 2026-02-16 18:18:40 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11572

State: open
Merged: No


Summary

Fixes cross-model switching errors when moving from a thinking model (e.g., Claude Opus) to a non-thinking model (e.g., GPT 5.2, Claude Sonnet).

  • Strip reasoning parts from message history at the start of normalizeMessages() for models with interleaved: false
  • Prevents API errors like messages.1.content.0.thinking: each thinking block must contain thinking

Fixes #11571

What Changed

packages/opencode/src/provider/transform.ts:

  • Moved reasoning stripping logic to the beginning of normalizeMessages() so it runs before any model-specific early returns (Claude, Mistral, etc.)
  • When all content is reasoning, inserts a placeholder text to avoid empty messages

packages/opencode/test/provider/transform.test.ts:

  • Added 3 new tests for the cross-model reasoning stripping behavior
  • Updated existing tests to reflect the new behavior

How I Verified It Works

  1. Started OpenCode with Claude Opus (extended thinking enabled)
  2. Got a response with thinking blocks
  3. Switched to GPT 5.2 mid-session using Ctrl+M
  4. Sent another message
  5. No error - reasoning parts were stripped from history

Also ran the full test suite: bun test test/provider/transform.test.ts → 97 pass, 0 fail

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11572 **State:** open **Merged:** No --- ## Summary Fixes cross-model switching errors when moving from a thinking model (e.g., Claude Opus) to a non-thinking model (e.g., GPT 5.2, Claude Sonnet). - Strip `reasoning` parts from message history at the start of `normalizeMessages()` for models with `interleaved: false` - Prevents API errors like `messages.1.content.0.thinking: each thinking block must contain thinking` Fixes #11571 ## What Changed **`packages/opencode/src/provider/transform.ts`:** - Moved reasoning stripping logic to the **beginning** of `normalizeMessages()` so it runs before any model-specific early returns (Claude, Mistral, etc.) - When all content is reasoning, inserts a placeholder text to avoid empty messages **`packages/opencode/test/provider/transform.test.ts`:** - Added 3 new tests for the cross-model reasoning stripping behavior - Updated existing tests to reflect the new behavior ## How I Verified It Works 1. Started OpenCode with Claude Opus (extended thinking enabled) 2. Got a response with thinking blocks 3. Switched to GPT 5.2 mid-session using Ctrl+M 4. Sent another message 5. ✅ No error - reasoning parts were stripped from history Also ran the full test suite: `bun test test/provider/transform.test.ts` → 97 pass, 0 fail
yindo added the pull-request label 2026-02-16 18:18:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13844