Confirmed the collection error pre-exists on the clean tree (mlx is Apple-Silicon-only; that file runs in the Apple CI job). I manually traced the two Bug A invariants that file pins against my new finalize() — the parser-based fallback still fires first and the shared recovery is gated on not self.tool_calls_detected, so no double emission — and additionally covered both scenarios in the new unit tests, which do run here.
Done. Summary of the fix:
Problem
Non-streaming chat (routes/chat.py → _parse_tool_calls_with_parser) always falls back to the shared parse_tool_calls() recovery in api/tool_calling.py — which parses XML tool-call formats (<function=name>{...}</function>, <tool_call><function=...><parameter=...>, <toolcall>, [Calling tool: ...], <|python_tag|>) — both when no tool parser is configured and when a configured parser finds nothing. Streaming had no equivalent:
StreamingPostProcessor.finalize() was gated on self.tool_parser existing, so with no configured parser it returned [] unconditionally.
- Even worse, the standard and channel-routed paths never accumulated the raw stream text (only the reasoning path fed
accumulated_text), so there was nothing to recover from at end of stream.
- A parser exception during finalize would propagate and abort the SSE stream (non-streaming catches it and falls back).
Fix (vllm_mlx/service/postprocessor.py)
raw_accumulated_text — new accumulator filled in process_chunk() for every delta on every path (standard, channel-routed, reasoning), mirroring the raw output.text the non-stream parser sees. This is why reasoning mode and channel routing don't alter recovery.
- Shared recovery in
finalize() — when nothing was detected by the streaming parser or the parser-based fallback, run the exact same parse_tool_calls(raw_text, self.request) the non-stream route uses, and emit one tool_call StreamEvent with finish_reason="tool_calls" (the chat route already formats finalize tool_call events into an SSE chunk with finish_reason="tool_calls"). Runs regardless of tools_requested/request tool selection — same as non-streaming. Gated on not tool_calls_detected so there's never a duplicate emission.
- Robustness — both the parser-based fallback and the shared recovery are wrapped in try/except (log + continue), and recovery keeps the cheap
< / { / [Calling structural-marker pre-check, so plain text or malformed markup neither creates calls nor aborts the stream.
Tests
Added TestStreamingXmlToolCallRecoveryParity (12 tests) to tests/test_postprocessor.py covering: split-across-chunks recovery, exact parity with parse_tool_calls, multiple calls with ordered indices, Nemotron format, reasoning mode, request-tools present/absent/mismatched, channel-routed streams, plain text → no calls, malformed markup → no calls/no raise, configured-parser-miss fallback, parser-exception tolerance, and no double emission. All 86 postprocessor tests pass; the 912-test related suite (tool parsers, reasoning parsers, anthropic adapter, streaming filters, CI no-MLX list) passes with no regressions; ruff check/format clean. The only failing tests in the environment (test_structured_output.py, test_mcp_security.py, mlx-importing modules) fail identically on the clean tree — they require Apple-Silicon MLX.