Skip to content

bug: acquire_slot checks capacity and then adds the slot in two calls, so two workers can exceed an agent's cap #3318

Closed

Description

@vybe

Summary

services/slot_service.py::acquire_slot reads ZCARD and then does ZADD as two separate Redis round-trips. Two backend workers can both read count < max_parallel_tasks before either adds its slot, so an agent with cap 1 ends up running 2 tasks. The docs describe this path as an atomic counter (docs/memory/architecture/execution.md, plus a comment in services/capacity_manager.py).

Context

Inside one process nothing can run between the two calls, so only cross-worker admissions are affected. Production compose runs --workers 2. Found by the 2026-10-06 /edge-cases sweep.

Acceptance Criteria

  • Admission is atomic: a Lua script or a WATCH/MULTI transaction does the count, cap check and add in one step.
  • tests/unit/test_ec_capacity_slots_edges.py::test_r14_concurrent_acquire_across_workers_never_overshoots_cap passes with its marker removed.

Activity

  1. added
    status-readyGreenlit and ready for development (vetted; counterpart to status-incubating)
    on Oct 7, 2026
  2. vybe commented on Oct 8, 2026

    @vybe
    ContributorAuthor

    Groom 2026-10-08: duplicate of #3305 (same ZCARD-then-ZADD race in SlotService.acquire_slot), which has the fix in PR #3306.

  3. removed
    status-readyGreenlit and ready for development (vetted; counterpart to status-incubating)
    on Oct 8, 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions