Skip to content

feat: inject queued messages into next API call for mid-task guidance#11813

Open
shdomi8599 wants to merge 1 commit intoRooCodeInc:mainfrom
shdomi8599:feat/mid-task-message-injection
Open

feat: inject queued messages into next API call for mid-task guidance#11813
shdomi8599 wants to merge 1 commit intoRooCodeInc:mainfrom
shdomi8599:feat/mid-task-message-injection

Conversation

@shdomi8599
Copy link

@shdomi8599 shdomi8599 commented Mar 2, 2026

Related GitHub Issue

Closes: #11802

Roo Code Task Context (Optional)

N/A

Description

TL;DR: Queued messages now get injected into the very next API call instead of waiting for the task to fully complete.

After discussing the approach with @hannesrudolph in DMs, we agreed that the simplest and most natural UX is to enhance the existing message queue rather than adding a separate steering mechanism. When users type a message while the agent is working, they expect it to be noticed at the next step — not after the entire task finishes.

Implementation (25 lines in Task.ts):

  • At the finalUserContent assembly point in recursivelyMakeClineRequests, drain the message queue
  • Append any pending messages as a [USER_MID_TASK_MESSAGE] block
  • The agent reads them immediately at the next API request and incorporates the feedback

What's NOT changed:

  • No new UI elements, buttons, or message types
  • No new dependencies
  • Existing ask blocking-point queue handling is preserved — messages queued during an API call are still handled by the existing logic at the ask blocking point

Design trade-off: This is "reactive" injection (between API calls), not "preemptive" (mid-stream abort). Preemptive injection is noted as future work. The reactive approach is zero-risk to existing behavior and covers the most common use case.

Test Procedure

Automated:

  • npx vitest run core/task/__tests__/mid-task-message-injection.spec.ts — 5 tests covering: empty queue, single message injection, multiple message ordering, queue drain completeness, and post-drain independence
  • Existing ask-queued-message-drain.spec.ts continues to pass

Manual (F5 Extension Development Host):

  1. Start a long task: "Write a Python script to find primes from 1-100 with detailed comments"
  2. While the agent is streaming, queue a message: "Actually, use JavaScript instead"
  3. Observe: the agent picks up the message at the next API call and switches to JavaScript

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

No UI changes.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The original issue proposed using an external @steer-agent/core library. After feedback from @hannesrudolph ("Why not make that the default?"), the approach was simplified to a minimal change to the existing queue behavior — no external dependencies, no new UI, just 25 lines that make the queue smarter.

Future work: Preemptive injection — abort the current stream when a queued message arrives and restart with the message injected, enabling truly real-time mid-stream course correction.

Get in Touch

Discord: shdomi_8599

Interactively review PR in Roo Code Cloud

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Real-time steering: coach the agent mid-task without stopping it

1 participant