ductor icon indicating copy to clipboard operation
ductor copied to clipboard

feat: Task priority levels for background tasks (interactive vs batch)

Open alexeymorozua opened this issue 8 months ago • 1 comments

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.

alexeymorozua avatar Mar 18 '26 12:03 alexeymorozua

Shipped in v0.16.0.

create_task.py now accepts --priority {interactive|batch}. Interactive tasks bypass the max_parallel cap and are excluded from the running-task count; batch queues normally (default). Kept the implementation minimal on purpose — no preemption, no anti-starvation, no full priority queue. That felt like the right trade-off for what 80% of users need without over-engineering.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto