-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Problem
All background tasks currently have equal priority. When a user sends a message while batch tasks are running (e.g. a long music generation batch or a heavy analysis task), the interactive response competes with background work for the same resources.
This is particularly noticeable with long-running agent tasks (5+ hours) where the user's direct messages should always be processed first.
Proposed Solution
Add a --priority flag to task creation with MLFQ-inspired levels (reference: AgentRM paper, arxiv 2603.13110):
# Interactive (highest priority — user-facing)
create_task.py --priority interactive --name "..." "..."
# Background (default — normal async work)
create_task.py --priority background --name "..." "..."
# Batch (lowest priority — long-running bulk work)
create_task.py --priority batch --name "sonic-batch" "..."Priority Levels
| Level | Use case | Preemptable? |
|---|---|---|
interactive (0) |
Direct user request, needs fast response | No |
background (1) |
Standard async task | Yes, by interactive |
batch (2) |
Long-running bulk work (music gen, large analysis) | Yes, by higher levels |
Anti-starvation
Lower-priority tasks that have been waiting too long should be promoted to prevent indefinite starvation — similar to Linux CFS nice values.
Impact
- User messages always feel responsive even under heavy background load
- Explicit intent declaration at task creation (no guessing)
- Safer long-running batch work without blocking interactive use
Note: Current LockPool handles per-session locking well; this is complementary — about scheduling order, not mutual exclusion.