Skip to content

fix(server): preserve UTF-8 across stream boundaries - #580

Open
Amidwestnoob wants to merge 2 commits into
Luce-Org:mainfrom
Amidwestnoob:fix/utf8-stream-boundary
Open

fix(server): preserve UTF-8 across stream boundaries#580
Amidwestnoob wants to merge 2 commits into
Luce-Org:mainfrom
Amidwestnoob:fix/utf8-stream-boundary

Conversation

@Amidwestnoob

@Amidwestnoob Amidwestnoob commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve valid UTF-8 code points when token output splits a multibyte sequence across stream chunks.
  • Reject malformed and impossible UTF-8 prefixes without retaining unbounded state.
  • Discard a pending incomplete suffix when a stop sequence matches.
  • Flush a genuinely truncated final code point as one replacement character.
  • Use one finish-reason policy for streaming responses, non-streaming responses, and completion logs.
  • Preserve semantic reasons such as tool_calls; report capped output as length / max_tokens.

Problem

The emitter sanitized each token fragment independently. A valid multibyte code point split across fragments could therefore become replacement characters. Finish-reason derivation also differed between API responses and the final server log.

Validation

  • Release dflash_server build passed.
  • Server unit suite: 344/344 passed.
  • Feature gate: 126 assertions, 0 failures.
  • CUDA communicator, Qwen3.5 tensor split, and two-GPU NCCL all-reduce tests passed.
  • Live streaming and non-streaming output preserved café — π ∈ ∅ ⊆ and ∀∃∈∅⊆⊇∩≠→ in layer and tensor modes.
  • Live capped output returned and logged length.
  • Live tool output preserved tool_calls.
  • A one-hour mixed runtime test remained healthy with no transport, CUDA, NCCL, fatal, or replacement-character failures.
  • Production was restored unchanged after validation.

Patch SHA-256:

1c7b29b1fee3db63e52b696bc7e8812110f396feb1fd2b09ffa614a69a0470db

Scope

This patch changes stream assembly and finish-reason reporting only. It does not change tensor-parallel math, speculative decoding, model loading, draft compatibility, or production configuration.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread server/src/server/http_server.cpp Outdated
@Amidwestnoob
Amidwestnoob force-pushed the fix/utf8-stream-boundary branch from d74db44 to e6ae9ba Compare August 5, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant