feat: add per-team concurrency guard to TaskClaimer.advance_dag#294
Merged
Conversation
Add TaskClaimer class in src/keystone/task_claimer.py with a per-team asyncio.Lock and coalesce/skip mechanism to prevent concurrent advance_dag calls for the same team from racing each other. - Two-layer guard: _advancing set for O(1) coalesce check + per-team asyncio.Lock for mutual exclusion over the full fetch->find->claim cycle - Concurrent calls for the same team are skipped (not queued) with a log message, since the in-flight call already sees the latest state - async with + finally ensure lock and set are always released on exceptions - 7 unit tests covering basic claiming, coalescing, parallelism across teams, error recovery, and sequential reuse Closes #131 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Security Scan Results
Recommendations
Workflow: Security Scanning |
CI Summary
|
mvillmow
enabled auto-merge (rebase)
April 23, 2026 14:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TaskClaimerclass atsrc/keystone/task_claimer.pywith a two-layer per-team concurrency guard_advancing: set[str]provides an O(1) coalesce/skip check: concurrent calls for the same team return[]immediately with a log message instead of queuing_team_locks: dict[str, asyncio.Lock]provides mutual exclusion over the full fetch→find→claim cycleasync with+finallyguarantee the lock and_advancingentry are always released, even whenget_tasksorclaim_taskraisesTest plan
test_advance_dag_claims_ready_tasks— basic happy path, all tasks claimedtest_advance_dag_empty_team_returns_empty— no tasks, no claim attemptstest_advance_dag_partial_claim_failures— failed claims excluded from resulttest_concurrent_advance_dag_coalesced— second same-team call skipped while first is in-flight;get_taskscalled exactly oncetest_concurrent_advance_dag_different_teams_parallel— different teams proceed independentlytest_advance_dag_lock_released_on_error— exception inget_tasksdoes not deadlock subsequent callstest_sequential_calls_same_team_both_execute— sequential (non-concurrent) same-team calls both execute normallyAll 7 tests pass:
python3 -m pytest tests/test_task_claimer.py -vCloses #131
🤖 Generated with Claude Code