Skip to content

feat(prompt): queue prompts while the agent is busy - #194

Open
hcsum wants to merge 1 commit into
grinev:mainfrom
hcsum:feat/queue-prompts-while-busy
Open

feat(prompt): queue prompts while the agent is busy#194
hcsum wants to merge 1 commit into
grinev:mainfrom
hcsum:feat/queue-prompts-while-busy

Conversation

@hcsum

@hcsum hcsum commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Description of changes

A prompt sent while a run is in flight is currently rejected. This queues it instead and dispatches it when the session goes idle, one at a time, like the OpenCode TUI.

  • Per-session FIFO queue, cap 10.
  • Plain text/media sent while busy is queued. Reply-keyboard buttons and pending interactions (permissions, questions) stay blocked as today.
  • Each queued prompt gets a reply bubble with an inline Cancel button; the bubble is edited in place to running / cancelled / failed.
  • /unqueue removes the newest queued prompt, for when the bubble has scrolled out of reach.
  • A queued prompt is never replayed into a different session.
  • The queue is dropped when (with a message stating "cleared n queued messages"):
    • /abort,
    • /detach,
    • a session.error,
    • a session mismatch reset,
    • at dispatch time if the session is no longer the active one.
  • Individual prompts are also dropped when the queue is full (rejected up front) or after 5 consecutive busy re-parks.
  • Also drained from busy-state reconciliation, so a run whose session.idle was missed doesn't strand the queue.
  • New i18n strings for all 7 locales.

On the visibility concern in #119 — a queued message scrolls away fast in a busy session. This PR does not solve that; it only adds the per-message bubble and /unqueue and leaves the pinned message alone. If queue state should live in the pinned message or elsewhere, that's a separate call and I'd rather have the queue mechanics reviewed first.

Closes issue (optional)

How it was tested

Manual: queue several prompts mid-run and let them execute; cancel via the inline button; /unqueue; /abort with items queued; /detach with items queued. Note that switching sessions while a run is in flight isn't possible in the current UI, so that path is covered by unit tests only.

Unit tests cover the queue lifecycle (ack, ordering, cap, cancel, /unqueue, failed dispatch, session change) plus the guard, abort, detach and reconciliation paths: tests/bot/handlers/prompt-queue.test.ts and additions to the interaction-guard, abort, detach, busy-reconciliation and command-router suites.

pic6

Checklist

  • PR title follows Conventional Commits: <type>(<scope>)?: <description>
  • This PR contains one logically complete change
  • Branch is rebased on the latest main
  • I ran npm run lint, npm run build, and npm test
  • Not OS-sensitive — the change is entirely in bot-layer message handling.

Draft — #119 hasn't been confirmed by a maintainer yet, so this is here to review the shape against.

Instead of rejecting a prompt sent while a run is in flight, park it in a
per-session queue and dispatch it (one at a time) when the session goes
idle, mirroring the OpenCode TUI. Queued prompts get an inline cancel
button; the guard lets plain prompts through as queueable while blocking
reply-keyboard buttons and pending interactions.

Reliability fixes:
- Drain the queue from busy-state reconciliation, so a run whose
  session.idle event was missed no longer strands queued prompts forever
  (injected via setQueueFlusherForReconciliation to keep the app layer
  free of a bot-layer import).
- Clear the queue explicitly on /abort local release instead of relying
  on a session.error event that may never arrive when abort is confirmed
  via status polling.
- On a failed async prompt start, flip the queued item's ack to failed
  and advance the rest of the queue, which no idle event would drain.

UX:
- Add /unqueue to drop the most recent queued prompt from the bottom of
  the chat, where a scrolled-away inline cancel button is out of reach.
- On batch clears, post a single summary instead of editing each
  (already scrolled-away) queued bubble in place.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@hcsum
hcsum force-pushed the feat/queue-prompts-while-busy branch from 4690df8 to 828a812 Compare July 27, 2026 15:21
@hcsum
hcsum marked this pull request as ready for review July 29, 2026 03:33
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.

[Feature]:Queuing for delivery

1 participant