fix(tui): abort active stream before processing new message - #257
Merged
Conversation
When a user sends a message while a stream is active, the TUI now aborts the current stream first, preventing forked UX where both streams render to the same destination. Fixes #245
handleInterrupt() now returns a promise that resolves once the abort signal has propagated through dispatchProvider and cleanup is complete. handleSubmit() awaits this promise before processing new input, preventing two streams from running in parallel when the user submits a message during an active stream.
…eam fork handleInterrupt now captures and awaits the dispatchProvider promise via dispatchPromiseRef, ensuring the stream is fully dead (including cleanup in the try/catch/finally) before handleSubmit proceeds. This fixes two bugs: - Status bar stuck on 'Interrupted...' because handleSubmit moved on before dispatchProvider finished its AbortError cleanup - New message not processed because the race condition left state inconsistent Also wires up auto-continue dispatchProvider calls so interrupts work during continuation sequences.
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.
Problem
When a user sends a message while the assistant is still streaming a response, the TUI tries to render both streams to the same destination, causing a forked UX.
Fix
Abort any active stream in
handleSubmitbefore processing a new message. This ensures only one stream is active at a time.The existing
handleInterrupt()function (triggered by escape key) already handles the abort logic cleanly — we just reuse it.Changes
handleSubmitbefore dispatching tohandleCommandorhandleChatTesting