-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Problem
Queued messages currently interrupt the running task. This causes several related issues:
- Messages lost after session interrupt ([FEATURE]: Graceful handling of queued messages after session interrupt #5333)
- Queued messages break todolist execution (Queued message interrupts todolist execution #5135)
- Users want delayed/non-interrupting queue ([FEATURE]: Delayed queue feature #5408)
The root cause: when a session is busy, SessionPrompt.assertNotBusy() throws BusyError. Queued messages either interrupt the task or wait until the session is fully idle. There's no mechanism to inject them as mid-task guidance.
Proposed solution
Drain queued messages at the start of each loop() iteration in prompt.ts and inject them as context before the next LLM.stream() call:
Current flow:
loop() → LLM.stream() → streaming → tool execution
→ user queues message → ❌ BusyError or task interrupts
Proposed flow:
loop() → [★ drain queue here] → LLM.stream() → streaming → tool execution
→ user queues message → next iteration picks it up → ✅ agent adjusts
Injection point — packages/opencode/src/session/prompt.ts, inside the loop() function's while(true), before LLM.stream() is called via SessionProcessor:
while (true) {
// ... existing message history loading ...
// ★ Inject queued messages here
if (queue.hasMessages()) {
const queued = queue.drainAll()
const injection = `\n[USER_MID_TASK_MESSAGE]\n${queued.map(m => m.text).join("\n")}\n[/USER_MID_TASK_MESSAGE]`
// append as user message content before LLM call
}
// ... existing SessionProcessor.create() + process() ...
}This approach:
- Zero overhead when no messages are queued
- Doesn't interrupt the running task
- Preserves existing Esc interrupt behavior
- Addresses [FEATURE]: Graceful handling of queued messages after session interrupt #5333, Queued message interrupts todolist execution #5135, [FEATURE]: Delayed queue feature #5408
Prior art
I've implemented this same pattern in Roo Code PR #11813 — 25 lines in their equivalent Task.ts, all tests passing. I can open a PR if there's interest.
Additional context
- Related issues: [FEATURE]: Graceful handling of queued messages after session interrupt #5333, Queued message interrupts todolist execution #5135, [FEATURE]: Delayed queue feature #5408
- Key files reviewed:
prompt.ts(loop),processor.ts(stream),session/index.ts(BusyError)