fix(wasm): remove prefill sleep — restores token streaming#33
Merged
Conversation
The emscripten_sleep(0) added to quant.h's prefill loop (PR #30) broke ASYNCIFY for the entire quant_generate call. The call stack during tq_forward() is too deep (matmul → SIMD kernels) for ASYNCIFY to unwind/rewind — it silently fails and the generation callback's sleep stops working too. Fix: remove prefill sleep entirely. The prefill blocks the browser for a few seconds (unavoidable without a step-by-step API), but "Thinking..." is shown before via requestAnimationFrame. Token streaming during generation works again. Also: pthreads removed (PR #32) to avoid pthreads+ASYNCIFY conflict, build.sh now uses single-thread SIMD + ASYNCIFY only. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Root cause
PR #30 added
emscripten_sleep(0)inside quant.h's prefill loop to prevent UI hang. But the call stack at that point is too deep (quant_generate → prefill → tq_forward → matmul → SIMD) for ASYNCIFY to unwind. This silently broke ASYNCIFY for the ENTIRE generate call — including the token callback's sleep, killing streaming.Fix
Remove the prefill sleep. Accept the prefill blocking (few seconds) with "Thinking..." shown via requestAnimationFrame. Token streaming during generation works again.
Behavior after fix
🤖 Generated with Claude Code