Skip to content

fix(tui): abort active stream before processing new message - #257

Merged
avoidwork merged 3 commits into
mainfrom
fix/245-stream-fork
Jun 15, 2026
Merged

fix(tui): abort active stream before processing new message#257
avoidwork merged 3 commits into
mainfrom
fix/245-stream-fork

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

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 handleSubmit before 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

  • src/tui/app.js: Added abort check at the top of handleSubmit before dispatching to handleCommand or handleChat

Testing

  • All 1132 existing tests pass
  • Manual testing: send a message while streaming → current stream aborts, new stream begins cleanly

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.
@avoidwork
avoidwork merged commit c314000 into main Jun 15, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/245-stream-fork branch June 15, 2026 03:21
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