Skip to content

[FEATURE]: inject queued messages into the next LLM call instead of interrupting the current task #16102

@shdomi8599

Description

@shdomi8599

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:

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 pointpackages/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:

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions