-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
Summary
Add support for asynchronous task management where the main session can dispatch subagents and continue interacting with the user while tasks execute in the background, rather than blocking until completion.
Current Behavior
When using the Task tool to dispatch subagents:
- Main session dispatches a subagent
- Main session blocks waiting for the subagent to complete
- User cannot interact with main session during execution
- After subagent returns, main session continues
This is a synchronous, blocking model.
Desired Behavior
The main session should act as a "secretary" or task coordinator:
- Main session dispatches one or more subagents
- Main session immediately returns and remains interactive
- User can continue conversing with main session
- User can dispatch additional tasks
- Main session can query task status or receive notifications when tasks complete
- Main session can retrieve results asynchronously
This is an asynchronous, non-blocking model.
Use Cases
1. Long-Running Tasks
User: "Refactor the authentication module and update all the tests"
Agent: "I've dispatched a subagent to handle that (task-123). What else can I help with?"
User: "Also, can you explain how the payment system works?"
Agent: "Sure, let me explain... [provides explanation]"
Agent: "By the way, task-123 just completed. The refactoring is done."
2. Multiple Independent Tasks
User: "Fix all the failing tests in these 5 files"
Agent: "I've dispatched 5 subagents, one per file. I'll monitor their progress."
User: "While they're running, show me the git history for the auth module"
Agent: [Shows git history while tasks run in background]
Agent: "3 of 5 tasks completed. 2 still running..."
3. Interactive Task Management
User: "Start implementing the new dashboard feature"
Agent: "Task dispatched (task-456). This will take a while."
User: "Actually, can you pause that? I need to check something first"
Agent: "Task paused. Let me know when you're ready to resume."
Technical Requirements
To support this pattern, OpenCode would need:
1. Non-blocking Task API
// Current (blocking)
const result = await Task("Do something")
// Proposed (non-blocking)
const taskId = await Task.dispatch("Do something", { async: true })
// Returns immediately with task ID2. Task Status Query
const status = await Task.status(taskId)
// Returns: "pending" | "running" | "completed" | "failed"3. Result Retrieval
const result = await Task.getResult(taskId)
// Returns result when task is completed4. Task Notifications (Optional)
// System could notify main session when tasks complete
// Or main session could poll periodically5. Task Management
await Task.cancel(taskId)
await Task.pause(taskId)
await Task.resume(taskId)
await Task.listAll() // Show all active tasksBenefits
- Better UX: User doesn't have to wait for long-running tasks
- Parallelization: Multiple tasks can run truly in parallel
- Flexibility: User can change priorities mid-execution
- Efficiency: Main session remains responsive and useful
- Scalability: Handle complex multi-task workflows more naturally
Implementation Considerations
- Task isolation: Ensure tasks don't interfere with each other
- Resource management: Limit concurrent tasks to prevent overload
- State management: Track task status, results, and errors
- Error handling: How to handle task failures asynchronously
- Context preservation: Main session needs to remember task context when results arrive
Alternative Approaches
If full async support is complex, consider intermediate solutions:
- Fire-and-forget mode: Dispatch tasks that don't return results
- Background monitoring: Main session periodically checks task status
- Manual session management: User manages multiple sessions manually (current workaround)
Related
This pattern is similar to:
- Job queues in web applications
- Background workers in task processing systems
- Async/await patterns in modern programming languages
Context: This request comes from a user workflow where they want to dispatch multiple complex tasks and continue working with the AI while those tasks execute, rather than waiting for each to complete sequentially.