Repository navigation
fix(server): stop truncated UTF-8 from hanging streamed responses - #820
Merged
Merged
Conversation
A generation cut off by the length limit or a cancel can stop partway through a multi-byte character. finalize() sent those bytes, json::dump() threw on the invalid UTF-8, and the error went out as a plain response after the stream had started, so the stream was never terminated and the client waited until its own timeout. This is what made qwen3-tk:4b time out after 600 s in the model sweep. - Streaming (OpenAI chat/completions, Ollama chat/generate): drop an incomplete trailing UTF-8 sequence at finalize. - OpenAI streaming handlers: errors after the first chunk now go out as an error event plus [DONE], ending the stream; finalize failures are logged. - Non-streaming chat (OpenAI and Ollama): trim the incomplete tail from the generated text before building the JSON response, instead of failing the request. incomplete_utf8_tail moves from the Whisper transcript header to wstream_buf.hpp so both share it. Model sweep: - Raise the default max_completion_tokens from 512 to 1024; thinking models were spending the whole budget on reasoning. - Give qwen3.8-mtp:27b a 1200 s request timeout via a per-model override table, since it decodes at ~1.7 tok/s. Co-Authored-By: Claude <[email protected]>
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
Model Sweep run 39454907120 failed on
sweep-windows-hrx (llm):qwen3-tk:4bround 2 timed out after 600 s, although the model decodes at ~20 tok/s.The server log shows the reply ending in
### \xF0\x9F\x94, 3 of the 4 bytes of an emoji, at the 512-token cap. Then:finalize()sent the leftover bytes, including the incomplete character.json::dump()threw on the invalid UTF-8 (nlohmann's default strict mode).ostream.finalize()was outside anytry. The outercatchsent a plain error response, but the stream had already started, so the closing chunk was never sent and the socket stayed open.This happens whenever a reply is cut off by the token limit or a cancel partway through a multi-byte character. That is why the sweep fails seemingly at random.
Changes
Server
/v1/chat/completions,/v1/completions,/api/chat,/api/generate): drop an incomplete trailing UTF-8 sequence infinalize().done_reasonand counts./v1/completionsno longer ends the stream beforefinish_reason.[DONE], which ends the stream. A failure while finishing the stream is also logged./v1/chat/completions,/api/chat): trim the incomplete tail from the generated text instead of failing the request with a 500.incomplete_utf8_tailmoves fromwhisper/transcript_format.hpptowstream_buf.hppso both share it.Model sweep
max_completion_tokensgoes from 512 to 1024. Thinking models such asqwen3:1.7bandqwen3:8bwere spending the whole budget on reasoning.qwen3.8-mtp:27bgets a 1200 s request timeout through a newREQUEST_TIMEOUT_OVERRIDEStable. It decodes at ~1.7 tok/s, so a full 1024-token reply takes about 600 s plus model load.Testing
flmtarget builds on Windows (MSVC, Release).--request-timeoutabove the override still wins;🤖 Generated with Claude Code