← Back to PRs

#22119: feat(tui): queue user messages while a run is active

by joshuajerin open 2026-02-20 18:46 View on GitHub →
size: M
## 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