Skip to content

Concurrency Queue

Caps concurrent agent operations. Additional requests queue with priority-aware ordering + starvation prevention.

graph TB A[Agent request] --> B{Slot available?<br/>running < maxConcurrent} B -->|yes| C[Acquire slot<br/>Status: RUNNING] B -->|no| D[Queue with priority<br/>Status: WAITING] D --> E[Sorted: USER > SCHEDULED > BACKGROUND] E --> F{Slot freed?} F -->|yes| G[Drain highest priority] F -->|no| H[Wait with timeout + cancellation] G --> C C --> I[Op completes → release → drain next]
LevelValueUse case
USER2Direct user actions (chat, commands)
SCHEDULED1Automated tasks (standup, health check)
BACKGROUND0Background indexing, embedding generation

Higher priority dequeued first. Within same priority: FIFO.

Background timer runs every 15 s. Any item waiting > 60 s gets bumped up one priority level. BACKGROUND eventually promotes to SCHEDULED, SCHEDULED to USER — no indefinite starvation.

maxQueueDepth = maxConcurrent × 10

At maxConcurrentStreams = 3, queue holds up to 30 waiting items. Beyond → immediate reject.

  • AbortSignal — pass an AbortSignal for cooperative cancellation.
  • Timeout — set timeoutMs deadline; item rejected if it hasn’t acquired a slot by then.
CommandEffect
Show Agent Queue StatusRunning + waiting items, per-item cancel
Cancel All Queued Agent RequestsCancels all waiting items; running ops NOT interrupted

Emits onDidChange with { running, waiting, maxConcurrent }. Displays:

  • Agent: 2/3 — 2 slots in use out of 3
  • Agent: 3/3 (2 queued) — full, 2 waiting
SettingDefaultRangePurpose
codebuddy.agent.maxConcurrentStreams31–10Max concurrent agent streams

Live-reloads on change. Raising the limit drains queued items into newly available slots.