Repository navigation
fix(nah_chat): chat completion stream event loss, reasoning_content, error surfacing - #28
Merged
Merged
Conversation
…error surfacing - chat_completion_stream now buffers SSE via responses::SseBuffer; events split across network chunks were silently dropped (empirically up to 22/36 deltas lost with 511-byte chunks on a real DeepSeek stream). After the fix: 0 loss at every chunk size from 3B to 4KB. - ChatMessage.reasoning_content now (de)serializes as reasoning_content (was reasoningContent) so non-stream chat_completion no longer drops chain-of-thought from DeepSeek/Qwen-style providers. - chat_completion (non-stream) now checks HTTP status and surfaces the server error body instead of a misleading 'missing choices field' error. - Regression tests: chunk-split reassembly, reasoning_content round-trip.
linmx0130
force-pushed
the
fix/chat-completion
branch
from
August 2, 2026 04:28
cdb376f to
35c2c85
Compare
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.
Fixes for the chat completion API found by live-testing against DeepSeek V4 Flash. Stacked on #27 (based on
feat/responses-apito reuse its buffered SSE parser); the diff will shrink to just these fixes once #27 merges.Problems found & fixed
P0 — stream event loss (up to 61% of deltas)
chat_completion_streamsplit each rawres.chunk()on\n\nwith no buffering — any SSE event crossing a network-chunk boundary was silently dropped. Replaying a real captured DeepSeek stream through the old parser at typical chunk sizes lost 22/36 deltas (511B) and 2/36 (4KB). This corrupts streaming text and tool-call argument deltas.Fixed by reusing
responses::SseBuffer(buffered, CRLF-safe). After the fix: 0 loss at every chunk size from 3B to 4KB on the same real stream. Regression test:test_chat_stream_chunk_split_reassembly.P1 — non-stream drops
reasoning_contentChatMessage.reasoning_contentwas serde-renamed toreasoningContent(camelCase) while DeepSeek/Qwen sendreasoning_content— chain-of-thought silently vanished from non-stream responses (stream mode already used the snake_case name and worked). Renamed toreasoning_content; verified live (non-stream now returns the reasoning text). Tests:test_deserialize_reasoning_content_snake_case,test_serialize_reasoning_content_snake_case.P1 — misleading error on 4xx/5xx (non-stream)
chat_completionhad no HTTP status check, so a 400 (e.g. unknown model) surfaced as "Invalid response format: missing choices field" instead of the server's message. Now mirrors the stream path and returns the server error body. Verified live: invalid model → real 400 body with the supported-model list.Live verification (deepseek-v4-flash)