fix(mac-chat): actually stop [stream] lines interleaving (the part #152 squash-dropped)#153
Merged
Conversation
The per-block '[stream] blk=.. t=..s' lines went to stderr while the answer delta went to stdout; on a shared terminal they interleaved INTO the text (在计算机[stream] blk=1...). Emit the timing line ONLY on the non-interactive (scripted/bridge) path; the interactive CLI now streams ONLY the clean answer delta. Add --chat-stream-stdout so a non-tty bridge run can capture the exact clean live format for validation. Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
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.
Why this is needed (the format problem is still happening after #152)
PR #152 was squash-merged at its first commit only. That first commit added token streaming but wrote the per-block
[stream] blk=.. t=..sprogress line unconditionally to stderr. The follow-up commit that fixed the format — moving that write into anelse:branch so it only fires on the non-interactive path — never reachedmain(the squash captured the pre-fix state).So merged
mainstill has the unconditionalsys.stderr.write("[stream]…"), which fires even in interactive (to_stdout=True) mode, and on a shared terminal it interleaves into the answer (DIGEST[stream] blk=99 …,sprintf([stream] blk=102 …) — exactly the screenshot the user reported.Fix
Cherry-picks the missing commit onto current
main: the[stream]timing line now lives in theelse:(non-interactive) branch of_make_stream_cb, so the interactive CLI streams only the clean answer delta. Also brings the--chat-stream-stdoutflag so a non-tty bridge run can capture the exact clean format.Validation (Mac M4, re-run on this branch)
Stream probe on the user's exact prompt, capturing stdout: 0
[stream]occurrences; the answer streams as clean continuous markdown:gemma-4 [根据pow的机制…]> 在计算机科学中,实现 \pow(base, exp)` 函数通常有两种主要的机制:快速幂算法(Binary Exponentiation) 和 对数/指数转换法…` (blocks=62, f_theta_ran=True, 5.16 tok/s).mac_chat_format_fix_completion.txt
Testing
pytest tests/inference_engine/bridge/test_manifest.py(31 passed)[stream]interleaving, clean streamed answerpy_compilecleanTo show artifacts inline, enable in settings.