Skip to content

fix: apply the chat stream filter to disaggregated router output - #212

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-198-router-stream-filter
Jun 11, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-198-router-stream-filter

Conversation

@inureyes

Copy link
Copy Markdown
Member

Closes #198

Problem

The disaggregated router (src/server/router_front.rs) forwarded the decode node's raw detokenized text directly into the SSE delta.content. For reasoning models or tool-calling prompts, model-specific structural markers (<think>, <|channel>, tool-call delimiters, stray turn tokens) leaked to the client, and thinking content was never routed to reasoning_content. This is why tests/disaggregated_router_e2e.rs only covered enable_thinking=false.

Implementation

  • The router's chat handler now instantiates the same StreamFilter the single-node chat route uses, including the primed-open-thinking start state when the rendered prompt ends inside an open thinking block (is_prompt_primed_open_thinking, now pub(crate)).
  • Every text piece, including the prefill node's first token (which can be the first reasoning token), passes through the filter in both the streaming and non-streaming paths. Filtered content goes to delta.content, thinking content to delta.reasoning_content (new chat_chunk_reasoning helper). The filter is flushed after the handoff completes so buffered partial-delimiter text is not lost.
  • The non-streaming response includes message.reasoning_content when the filter routed any thinking text.
  • Tool-call parsing (accumulate-then-parse into tool_calls) is deferred and documented in the module docs: the router emits content and reasoning_content only; tool-call delimiter markers are suppressed by the filter.

Verification (M1 Ultra, qwen3-0.6b-4bit, real 3-process E2E)

  • New disaggregated_router_filters_thinking_output: runs a thinking-enabled request against a single-node hybrid reference first, then through the 3-process router (prefill + decode + router). The router's reasoning_content and content are byte-identical to the single-node chat route's split (96 reasoning chars on the test prompt), and no <think> markers appear in either field.
  • Existing disaggregated_router_streams_correct_output (thinking disabled) still pins the byte-exact "2 + 2 = 4." output, confirming the filter is transparent for plain content.
  • Cold clippy (-D warnings, both feature sets), cargo fmt.

@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:architecture Architecture and code structure changes labels Jun 11, 2026
@inureyes
inureyes merged commit 13002eb into main Jun 11, 2026
4 checks passed
@inureyes
inureyes deleted the fix/issue-198-router-stream-filter branch June 11, 2026 00:32
@inureyes inureyes added this to the 0.2 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…lup#212)

* fix: apply the chat stream filter to disaggregated router output

* refactor: import FilterOutput alongside StreamFilter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture Architecture and code structure changes priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disaggregated router: apply the chat stream filter to output

1 participant