Home / Race condition in scheduler causes duplicate runs

Race condition in scheduler causes duplicate runs

created medium manu supervisor 2026-04-01 21:01

Next step: Evaluate this item to determine if it's worth fixing. Or approve directly if you already know what needs to be done.

Location

src/supervisor/scheduler.py:107

Description

scheduler.py has a critical race condition when multiple scheduled runs are due for the same resource. The _get_due_jobs() method (line 107) fetches all resources and checks schedules in one batch, but there's no lock preventing concurrent execution of the same resource. If two scheduler loops overlap or if the web API triggers a run while scheduler is running, the same resource can have concurrent discovery/health-check runs. The engine has per-resource locking (line 116 in engine.py), but by the time it reaches there, the Run record is already created (line 123), causing duplicate PENDING runs. The scheduler should check for existing PENDING/RUNNING runs before creating new ones.

Evaluation

Click "Evaluate with Claude Code" to have an agent analyze this item.

Actions