Skip to content

Commit 81a8c02

Browse files
fix: preserve non-empty reasoning_content during coalescing
When coalescing consecutive assistant messages, an empty reasoning_content fallback ("") would overwrite a non-empty thinking text from a previous message. Now we only overwrite when the incoming value is non-empty or the existing value is already empty/undefined.
1 parent ae739c9 commit 81a8c02

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/services/api/openaiShim.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,15 +751,19 @@ function convertMessages(
751751
}
752752

753753
// Preserve reasoning_content when coalescing assistant messages.
754-
// Prefer the incoming message's reasoning_content if present, otherwise
755-
// keep the existing one. Both cannot be preserved simultaneously since
756-
// the field is singular per message.
754+
// Never overwrite a non-empty reasoning_content with an empty one,
755+
// since empty values are fallback placeholders while non-empty ones
756+
// carry actual thinking text that providers require.
757757
if (
758758
msg.role === 'assistant' &&
759759
msg.reasoning_content !== undefined &&
760760
lastAfterPossibleInjection.role === 'assistant'
761761
) {
762-
lastAfterPossibleInjection.reasoning_content = msg.reasoning_content
762+
const existing = lastAfterPossibleInjection.reasoning_content
763+
const incoming = msg.reasoning_content
764+
if (typeof existing !== 'string' || existing.length === 0 || incoming.length > 0) {
765+
lastAfterPossibleInjection.reasoning_content = incoming
766+
}
763767
}
764768
} else {
765769
coalesced.push(msg)

0 commit comments

Comments
 (0)