Skip to content

Unify ExecutionQueue and SlotService (mutual blindness) #98

Closed

Description

@vybe

Problem

Two independent concurrency control systems exist that are completely unaware of each other:

System A: Execution Queue (for /api/chat)

  • File: services/execution_queue.py
  • Serial execution (1 at a time per agent)
  • Redis keys: agent:running:{name}, agent:queue:{name}
  • Max 3 queued requests
  • 600s TTL

System B: Slot Service (for /api/task, scheduler, public, paid)

  • File: services/slot_service.py
  • Parallel execution (1-10 concurrent per agent)
  • Redis keys: agent:slots:{name}, agent:slot:{name}:{exec_id}
  • 1800s TTL

Impact

  • A /chat execution occupies the queue but NOT a slot → capacity meter doesn't show it
  • A /task execution occupies a slot but NOT the queue → queue doesn't know about it
  • An agent could have 1 chat + 10 tasks running simultaneously (11 total) while capacity shows 10/10
  • No single system gives a true picture of agent load

Required Changes

Option A (Recommended): SlotService becomes the single source of truth

  1. /api/chat acquires a slot in addition to using the queue
  2. Capacity meter shows ALL execution types
  3. Queue continues to enforce serial chat, but slot tracks the resource usage
  4. Total capacity = max_parallel_tasks (shared between chat and tasks)

Option B: Merge into one system

  1. Replace both with a unified ExecutionManager
  2. Supports both serial (chat) and parallel (task) modes per agent
  3. Single Redis key namespace
  4. Single capacity counter

Files to Change

  • src/backend/services/execution_queue.py — Integrate with SlotService
  • src/backend/services/slot_service.py — Accept queue-based executions
  • src/backend/routers/chat.py — Acquire slot alongside queue
  • src/frontend/src/components/CapacityMeter.vue — May need to show queue vs task breakdown

Activity

  1. added
    priority-p1
    on Mar 11, 2026
  2. vybe commented on Mar 21, 2026

    @vybe
    ContributorAuthor

    Implementation Complete

    Approach: Option A — SlotService becomes the single source of truth.

    Changes

    src/backend/routers/chat.py:

    • chat_with_agent(): Acquires a capacity slot via SlotService when the chat execution starts, releases it in the finally block alongside the queue completion
    • terminate_agent_execution(): Releases the capacity slot when terminating a chat execution

    src/backend/services/agent_service/queue.py:

    • force_release_agent_logic(): Now also clears all capacity slots when force-releasing an agent

    How it works

    • The ExecutionQueue still enforces serial chat (one at a time per agent)
    • The SlotService slot makes the chat resource usage visible to the capacity meter
    • Total capacity = max_parallel_tasks (shared between chat and tasks)
    • A chat execution now counts as 1 slot, so an agent with max_parallel_tasks=3 running a chat can still accept 2 parallel tasks
    • Slot is acquired non-blocking (failure to acquire doesn't prevent chat — the queue already controls serialization)

    What this fixes

    • ✅ Capacity meter now shows ALL execution types (chat, task, schedule, public, paid)
    • ✅ A /chat execution occupies both the queue AND a slot
    • ✅ Force-release clears both queue state and capacity slots
    • ✅ Execution termination releases both queue and slot
  3. vybe commented on Mar 21, 2026

    @vybe
    ContributorAuthor

    Fixed in 4c8de95 — chat executions now acquire capacity slots, making SlotService the single source of truth for agent load.

  4. added
    complexity-medium
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions