#22119: feat(tui): queue user messages while a run is active
size: M
Cluster:
TUI and Tool Execution Fixes
## Summary
- queue user submissions in TUI when a run is already active instead of firing overlapping sends
- flush queued messages automatically when the active run settles (final, aborted, or error)
- keep queued messages visible in chat immediately and send them in FIFO order
## Implementation notes
- added an in-memory queue in `createCommandHandlers`
- added `flushQueuedMessage()` and wired it to event handling via `onRunSettled` callback
- avoids duplicate user chat-log entries when queued messages are later sent
## Tests
- `corepack pnpm vitest run src/tui/tui-command-handlers.test.ts src/tui/tui-event-handlers.test.ts src/tui/tui.submit-handler.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR implements message queuing in the TUI to prevent overlapping runs. When a user submits messages while a run is active, they're queued in FIFO order and automatically flushed when the run settles. The implementation adds a `queuedMessages` array in `tui-command-handlers.ts`, refactors the send logic into `sendMessageNow` and `sendMessage`, and wires `flushQueuedMessage` to an `onRunSettled` callback in the event handlers.
**Key changes:**
- Added in-memory queue that prevents duplicate sends when a run is active
- Queue automatically flushes on run completion (final, aborted, or error states)
- Queued messages appear immediately in chat with status indicators
- Comprehensive test coverage for the queuing behavior
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with very low risk
- The implementation is clean with proper test coverage. The queue logic is straightforward FIFO with clear state management. Only minor edge case around recursive flushing prevents a perfect score, but it's unlikely to cause issues in practice.
- No files require special attention
<sub>Last reviewed commit: 1143652</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9220: Fix: TUI drops API responses silently when runID already finalized
by vishaltandale00 · 2026-02-05
75.5%
#22627: control-ui: agent runner queue view
by vctorabrdge · 2026-02-21
74.9%
#6690: UX: clearer /queue and /subagents output
by kamb5686 · 2026-02-01
74.3%
#16501: feat(telegram): add inbound subagent queue with prefork progress
by cometjc · 2026-02-14
73.1%
#19033: feat(ui): treat 'btw' as addendum while chat is busy
by KnottyDyes · 2026-02-17
72.5%
#7760: fix(agents): resolve message ordering conflict during tool execution
by aryan877 · 2026-02-03
72.1%
#21932: fix(tui): eliminate stale model indicator lag in TUI
by graysurf · 2026-02-20
72.1%
#13548: feat(control-ui): Add quote reply and send message to session features
by Annaxiebot · 2026-02-10
71.9%
#7522: fix(webchat): auto-scroll when message queue changes
by alsoknownasfoo · 2026-02-02
71.4%
#8083: fix(tui): update model status immediately after /model command
by rohanjangala · 2026-02-03
71.4%