Skip to content

stream: hold back only a marker-prefix suffix (removes the ~135 ms/delta SSE lag) - #67

Merged
AzeezIsh merged 3 commits into
mainfrom
fix/stream-sanitizer-holdback
Sep 26, 2026
Merged

AzeezIsh merged 3 commits into
mainfrom
fix/stream-sanitizer-holdback

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With a leak-marker tool parser active (qwen3_coder, i.e. every Qwen3.8 recipe), sanitize_content_chunk held back a flat tag_max - 1 bytes (~18) from every content delta so that a marker split across chunks could fuse. Plain prose was therefore delayed by several tokens on every delta:

  • client deltas trail generation by ~135 ms and arrive byte-sliced mid-word ('text consis' / 'ts of a r');
  • the first content delta waits for later tokens, inflating client TTFT by ~195 ms over the scheduler's own TTFT= line (GB10, qwen4_exp, measured 2026-08-30).

At short context that lag was larger than the entire remaining TTFT gap to vLLM.

Fix

A marker can only be completed by future bytes if the buffer ends in a proper prefix of it. In this branch no complete marker is in the buffer (the searches above would have matched it), so every byte before the earliest such suffix is final. marker_prefix_hold_start holds exactly that suffix. The emitted bytes are identical; they are just emitted sooner. End-of-stream flush still receives any genuine partial marker (flush_content_sanitizer only scrubs complete markers and a trailing partial one). The reasoning stream shares the same function.

Tests

  • New holdback_tests: prose passes through in the same delta; a partial <tool_ is held and resolved; chunk invariance: 7 texts (markers, partial closes, bare <, unicode) × 200 random chunkings each produce the same total output as feeding the text whole.
  • Two split-tag tests asserted the old flat hold on the non-tag abc before <param; they now assert abc emits and <param is held. Their leak assertions are unchanged.
  • cargo test -p spark-server --bin spark: 2368 passed, 0 failed (reiner, GB10, a28c4684).

Live A/B (GB10 job 241, 2026-09-25): the lag is gone

nvidia/Qwen3.8-Flash-Next-NVFP4, --tool-call-parser qwen3_coder, 3 prompts x 5 reps per arm, run as A, F, A, F. lag is the client's time to the first content delta minus the scheduler's own TTFT= for the same request.

arm binary lag median
A main66 5b07b953 0.206 s
F this PR a28c4684 0.002 s
A2 main66 0.205 s
F2 this PR 0.002 s

The inter-delta gap is unchanged (median ~52 ms, one decode step). Deltas are token-aligned again instead of byte-sliced. The only change from a28c4684 to the head is the clippy fix.

Merge gate

This PR merges as part of the GB10 merge train (main + #78 + #67 + #68). That combined tree is gated by the ST-995 accuracy leg (bfcl-subset --pull-request-gate on the Flash-Next recipe) and the 2.5 h agentic perf leg. Results will be posted here before the merge.

AzeezIsh and others added 3 commits September 25, 2026 02:49
…x-1 bytes

With a leak-marker parser active (qwen3_coder: the Qwen3.8 recipes), the
streaming content sanitizer held the last `tag_max - 1` bytes (~18) of
EVERY delta so a marker straddling two chunks could fuse. Plain prose was
therefore delayed by several tokens on every delta, deltas were sliced
mid-word ('text consis' / 'ts of a r'), and the first content delta waited
on later tokens — the ~135 ms/delta, ~195 ms client-TTFT lag measured
against the scheduler's own TTFT= line on GB10.

A marker can only be completed by future bytes if the buffer ENDS in a
proper prefix of it. No complete marker is present in this branch (the
searches above would have matched), so every byte before the earliest
such suffix is final. `marker_prefix_hold_start` holds exactly that
suffix; the emitted bytes are identical, only earlier. End-of-stream
flush still receives any genuine partial marker.

Tests: prose passes through in the same delta; a partial `<tool_` is held
and resolved; and chunk invariance — 7 texts x 200 random chunkings each
must produce the same total output as feeding the text whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ontract

Their first assertion encoded the old flat hold (the non-tag 'abc' before
'<param' was withheld too). The leak properties they exist for are
unchanged and still asserted: '<param' is held, fuses with 'eter=x>',
the body is suppressed, and the total output is 'abctail'.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Live A/B on GB10 (job 241, 2026-09-25) — the lag is gone

nvidia/Qwen3.8-Flash-Next-NVFP4, --tool-call-parser qwen3_coder, 3 prompts x 5 reps per arm, arms A, F, A, F. lag = client time to first content delta − the scheduler's own TTFT= for the same request.

arm binary lag median first deltas (example)
A main66 5b07b953 0.206 s "A ", "hea", "t pu", "mp operate"
F this PR a28c4684 0.002 s "A", " heat", " pump", " operates"
A2 main66 0.205 s
F2 this PR 0.002 s

Inter-delta gap unchanged (median ~52 ms, the decode step). Deltas are token-aligned again instead of byte-sliced. Every client-visible TTFT on a leak-marker parser drops by ~0.2 s — at short context that is more than the whole remaining gap to vLLM on this model. a28c4684 → head differs only by the clippy fix.

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Merged as part of the GB10 merge train (main 1ab38536b). The train was #78, #67, #68, #82, #83, then #89 and #90.

Gates on the combined tree:

  • ST-995 (job 280): PASS, 84.72 / 84.68 against bars of 82.72 / 81.65.
  • Agentic perf leg (job 298): VALID. 1007 of 1007 turns, 0 failed, 0 missing, 89 min.
  • Support matrix (job 346): green. Nemotron-3.5-Lightning NVFP4, Qwen3.6-35B-A3B NVFP4 and Qwen3.6-35B-A3B FP8 each boot with 0 unresolved lookups on main66 + fixes and on the train tree. Greedy probes are identical between the two trees (mean |Δlogprob| 0.0000), and 10k TTFT is equal or slightly faster.

Tree check: main has the same tree as the job-346 build (f8a04db1f): git diff is empty. main also differs from the tree the gates ran on (53f4a3d3a) only by the marker [expected_absent] declarations (f261446bd), which are TOML and tests only.

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