Skip to content

[Improvement] Add concurrency guard to prevent parallel advance_dag for same team #131

Description

@mvillmow

Objective

Add a per-team lock or deduplication mechanism to prevent multiple concurrent advance_dag calls for the same team from racing each other.

Motivation

When multiple tasks in the same team complete in rapid succession, the NATS listener will trigger multiple advance_dag("team-X") calls concurrently. Since advance_dag fetches tasks, finds ready ones, and claims them in a non-atomic sequence, two concurrent calls could both see the same pending task as ready and both attempt to claim it. While ProjectAgamemnon's PUT endpoint may reject the second claim, this creates unnecessary API calls and noisy error logs.

Deliverables

  • Add a dict[str, asyncio.Lock] in TaskClaimer keyed by team_id
  • Acquire the per-team lock at the start of advance_dag and release it on completion
  • Optionally, if a call arrives while the lock is held, skip it (coalesce) rather than queue, since the in-flight call will already see the latest state
  • Log when a call is coalesced/skipped for observability

Success Criteria

  • At most one advance_dag call executes per team at any given time
  • No deadlocks or lock leaks (use async with for safety)
  • Unit test demonstrating that concurrent advance_dag calls for the same team are serialized or coalesced

Priority

HIGH -- Race conditions in task claiming are the most likely source of production bugs in the current architecture


Updated per ADR-006 — ai-maestro references replaced with current architecture terminology.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions