Repository navigation
fix(protocol): preserve whitespace in streamed reasoning deltas - #152
Merged
jasonxu114514 merged 1 commit intoOct 29, 2026
Merged
jasonxu114514 merged 1 commit into
jasonxu114514 merged 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an upstream Chat Completions stream is converted to Anthropic Messages or Responses, leading/trailing whitespace in each reasoning delta is removed. For example,
"We"followed by" need"becomes"Weneed". Whitespace-only deltas (including newlines) are discarded, or incorrectly replaced by the alternate reasoning field when both fields are present.parseChatEventselectsreasoning_content/reasoningthroughjsonutil.FirstString, which callsstrings.TrimSpace. Stream fragments are content, not configuration values; their whitespace must survive conversion. Native-protocol forwarding does not use this conversion path, which explains why the same upstream can look correct in Chat clients.Change
Select the first nonempty original string, keeping
reasoning_contentprecedence and falling back toreasoningonly when the former is empty or absent. Preserve whitespace-only fragments. Keep the sharedFirstStringhelper unchanged for its other callers.Validation
TranscodeStreamSSE input/output boundary for both reasoning field names and both target protocols.57b906b23fbecf3eed12297883a9e3bbf44e1493and pass with the fix.go test ./...go build ./...git diff --checkNo configuration changes or production deployment are included. Already stored text with missing whitespace cannot be reconstructed by this fix.