Repository navigation
Fixed OpenAI proxy streaming crash on single-chunk responses - #138
Merged
oleg68 merged 1 commit intoMay 23, 2026
Merged
Conversation
Replaced manual JSON string escaping in StreamingState build* methods
with proper Jackson ObjectNode serialization. The old code missed \b, \f
and control characters U+0000–U+001F, producing invalid JSON when model
output (especially reasoning/thinking) contained these characters.
Backends that return the full response as one SSE chunk (pseudo-streaming)
triggered the bug reliably, causing Claude Code to exit immediately.
Also added:
- stream_options: {include_usage: true} in outgoing streaming requests
- Defensive buildDoneEvents() call if backend closes without [DONE]
- doneReceived / isMessageStarted flags on StreamingState
- 8 regression tests covering control-char escaping, single-chunk
scenario, stream_options, and the doneReceived flag
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
StreamingStatebuild*methods with JacksonObjectNodeserialization — the old code missed\b,\fand control characters U+0000–U+001Fstream_options: {include_usage: true}to outgoing streaming requests so token counts are reported correctlybuildDoneEvents()call if the backend closes the stream without sending[DONE]Root cause
When an OpenAI-compatible backend (e.g. gptunnel.ru / deepseek-v4-pro) returns the full response as a single SSE data chunk (pseudo-streaming), the model's reasoning output can contain control characters (
\f,\b, etc.). The manual escaping only handled\n,\r,\t,\\,\", so the resulting SSE event contained invalid JSON. Claude Code failed to parse it and exited immediately.Test plan
mvn test)