Fix duplicate task execution race condition#209
Conversation
Tasks without a Perpetual dependency could execute multiple times in parallel because the `known` field is deleted when `claim()` is called, before the task function runs. This opens a window where duplicate `docket.add()` calls with the same key succeed. The fix adds a check for `state='running'` in the schedule Lua script's deduplication logic. Now a task "exists" if either the `known` field exists (scheduled/queued) OR the `state` is `running` (currently executing). Also updated the self-perpetuating test patterns to use `replace()` instead of `add()` for rescheduling, which is the correct pattern (matching how Perpetual tasks work). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @chrisguidry's task —— View job Review CompleteReview Checklist
SummaryThis PR effectively fixes a critical race condition where tasks without a Perpetual dependency could execute multiple times in parallel. The fix is minimal, well-targeted, and includes comprehensive test coverage. Strengths✅ Root Cause AnalysisThe PR correctly identifies the race condition: the ✅ Minimal and Effective FixThe solution adds a check for
This elegantly closes the race window without major architectural changes. ✅ Comprehensive Test Coverage
✅ Pattern UpdatesThe test updates in test_fundamentals.py correctly switch from Code Quality✅ Clean Implementation
✅ Documentation
Potential Concerns
|
|
📚 Documentation has been built for this PR! You can download the documentation directly here: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 48 48
Lines 7545 7567 +22
Branches 395 396 +1
=========================================
+ Hits 7545 7567 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Tasks without a Perpetual dependency could execute multiple times in parallel
because the
knownfield is deleted whenclaim()is called, before the taskfunction runs. This opens a window where duplicate
docket.add()calls withthe same key succeed.
The fix adds a check for
state='running'in the schedule Lua script'sdeduplication logic. Now a task "exists" if either the
knownfield exists(scheduled/queued) OR the
stateisrunning(currently executing).Also updated the self-perpetuating test patterns to use
replace()instead ofadd()for rescheduling, which is the correct pattern (matching how Perpetualtasks work).
🤖 Generated with Claude Code