Repository navigation
Description
Summary
When the model output (content, reasoning_content, or a tool call's function.arguments) contains the literal string "[DONE]", the SSE stream is cut at that exact point yet finish_reason still reports "stop". Clients receive silently truncated text and/or invalid tool-call JSON.
This is distinct from #785 (large-argument silent drop with NO terminator). Here the stream dies because a "[DONE]" appears mid-payload - i.e. the gateway appears to substring-match "[DONE]" against the raw stream bytes instead of matching the full terminator line "data: [DONE]".
Expected Behavior
A streaming response should deliver the complete generated output regardless of what characters it contains. A "[DONE]" sequence inside content or tool-call arguments must be passed through verbatim.
The stream should be terminated only by a full SSE terminator line "data: [DONE]" emitted by the server itself, followed by finish_reason "stop" / "tool_calls".
Actual Behavior
-
Plain text: a request asking the model to output exactly "data: [DONE]" returns content = "data" - the "[DONE]" and everything after is dropped.
-
Tool call: asking the model to call write_file with content containing:
if line == 'data: [DONE]':
the returned arguments is invalid JSON; the "[DONE]" segment is swallowed (observed as: if line == 'data break). -
Boundary behaviour (all inside tool-call arguments):
- "[DONE]" with surrounding text -> truncated at the "["
- "[DONE" (no closing bracket) -> complete
- "DONE]" (no opening bracket) -> complete
- "[END]" -> complete
- "AAA[DONE]BBB" -> truncated to "AAA"
-
In practice this makes the model unusable for any task that involves SSE / streaming code: every attempt to write the marker corrupts the tool arguments, the agent retries, writes it again, and is cut again - producing repeated empty turns (finish_reason=stop, output_tokens=0).
Steps to reproduce the issue
- POST to https://api.commandcode.ai/provider/v1/chat/completions with model "deepseek/deepseek-v4.1-flash", stream: true, and messages: [{"role":"user","content":"Output exactly this line and nothing else: data: [DONE]"}]
- Observe the SSE stream stops right at the "[DONE]" and content is just "data".
- Repeat with stream: false -> the full line is returned correctly.
- Repeat against another OpenAI-compatible provider -> the full line is returned correctly.
- Repeat with "[END]" instead of "[DONE]" -> the line is returned correctly.
Command Code Version
Provider API via ZCode 3.18.2 (no local cmd CLI - reported against the hosted API)
Operating System
Windows
Terminal/IDE
ZCode 3.18.2 desktop
Shell
bash (Git Bash, win32)
Session file (optional)
No response
Fix prompt (optional)
No response
Additional context
Controls that isolate the fault to the streaming gateway:
- Same prompt with stream:false -> complete output (OK)
- Same prompt via another OpenAI-compatible provider -> complete output (OK)
- Replace the marker with "[END]" -> complete output (OK)
- Cut lands exactly at the "[" character, which points to a substring match on the raw byte stream rather than a line-based terminator check.
Client used: ZCode 3.18.2, requests are standard OpenAI-compatible chat.completions with stream:true and tool definitions. Reproducible with stdlib Python only (urllib + json).
Suggested fix: treat only a full line equal to "data: [DONE]" as the stream terminator; do not substring-scan the SSE payload for the marker.
Activity
hjyescut commentedon Nov 18, 2026
Additional data: the bug is localized to the
/chat/completionsstreaming pathI ran the same tool-call payload (a
write_filecall whosecontentcontainsif line == 'data: [DONE]':) against both endpoints, 10 requests each, modeldeepseek/deepseek-v4.1-flash,stream: true:/provider/v1/chat/completions/provider/v1/responsesPlain-text probe (
Output exactly this line: data: [DONE]), 6 requests each:/chat/completions"data:")/responses"data: [DONE]"every timeSo the Responses path handles the same payload correctly. That strongly suggests the defect is in the Chat Completions SSE writer specifically, not in the model output or in a shared post-processing step.
FYI on endpoint compatibility (from
/provider/v1/models), in case others hit this:deepseek/deepseek-v4.1-flash->["/chat/completions", "/responses"]stealth/glyph-cluster:free->["/chat/completions", "/responses"]thinkingmachines/inkling-2-small:free->["/chat/completions"]onlyAnd
/messages(Anthropic shape) correctly rejects non-Anthropic models with 400Model "..." is not supported on this endpoint, which is good - that one is behaving as documented.Suggested scope of the fix: line-based terminator matching in the chat.completions stream writer.
hjyescut commentedon Nov 18, 2026
Full comparison matrix (same prompts, same model, both endpoints)
deepseek/deepseek-v4.1-flash,stream: true, prepared prompt/response pairs. PASS = expected marker survives intact./chat/completions/responsesdata: [DONE]Failure signatures on
/chat/completionsfor S1 and S2 are consistentlycontent = ""withfinish_reason = "stop": the entire visible answer is lost because the model's text mentions the marker. In S4 the arguments end mid-string, e.g.{"content": "import json\n\ndef read_sse(resp):\n...with the closing brace missing.On
/responsesevery one of the 22 requests completed withresponse.completedand byte-identical marker text.Practical consequence: switching a client from Chat Completions to the Responses endpoint avoids the defect entirely, so this is a viable workaround for affected users in addition to being a strong signal that the fault is in the Chat Completions stream writer.