fix: emit terminal Done when the model stream ends without a done marker#212
Merged
Merged
Conversation
Signed-off-by: Logan Nguyen <lg.131.dev@gmail.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.
Overview
Chat (and the in-place transforms like
/rewrite) could hang with the spinner stuck forever when the local model's stream ended without Ollama's terminaldone:trueline. This happens when a small model degenerates on pathological input (for example, trying to reproduce a long, mostly-zero hex address verbatim) and the runner closes the connection without sending its usual final marker.Root cause
stream_ollama_chatemitted the terminalDonechunk only when it observeddone:true. When the stream ended any other way (the connection closing mid-generation, or an empty response body), the loop returned without emitting any terminal chunk. The frontend clears its streaming state only on a terminal event, so it spun forever.How it works
The stream loop now tracks whether a terminal
Donewas already emitted and emits one when the stream ends without adone:trueline. The frontend finalizes the turn onDone, so the spinner stops and any partial content is kept. Normal completion is unchanged: thedone:truepath still emits exactly oneDone, with no duplicate on stream end.Testing
done:truestill produces exactly one terminalDone.Done.bun run test:all:coverageandbun run validate-buildboth pass; backend stays at 100% line coverage.Note: this fixes the hang only. For inputs a small model cannot reproduce verbatim (long hex strings or IDs), the rewritten text may still be truncated or imperfect; that output-quality issue is a model limitation tracked separately and is best addressed by masking verbatim zones before generation.