Cron reschedule cancels currently executing jobs
Bug
When cron_jobs.json is modified while a cron job is executing, the file-watcher triggers _reschedule_all() which cancels all scheduled tasks — including the currently running one.
Reproduction
- Have a cron job running (e.g.
play-earnings-reportat 20:00) - Add or modify another cron job in
cron_jobs.json(e.g. create a new one-time reminder) - The file-watcher detects the change and calls
_reschedule_all() _reschedule_all()cancels all tasks inself._tasks, including the executing one- The running job is terminated mid-execution
Expected behavior
Currently executing jobs should not be cancelled when rescheduling. Only pending (not-yet-started) jobs should be cancelled and rescheduled.
Root cause
In ductor_bot/cron/observer.py, _reschedule_all() iterates over self._tasks and cancels every task unconditionally:
for task in self._tasks.values():
task.cancel()
self._tasks.clear()
There is no distinction between a task that is waiting for its scheduled time vs. one that is currently executing _execute_job().
Suggested fix
Track currently executing job IDs in a set (e.g. self._executing). In _reschedule_all(), skip tasks whose job ID is in _executing. In _run_at(), add the job ID to _executing before calling _execute_job() and remove it after.
Logs
2026-03-12 20:18:26 INFO Detected cron_jobs.json change, rescheduling
2026-03-12 20:18:26 INFO CronObserver: cancelled 7 pending tasks
The play-earnings-report job that started at 20:00 was killed at 20:18 when a new cron was added.
Fixed in v0.15.0. I added an _executing set to track running jobs. _reschedule_all() now skips executing jobs, and _run_at() checks job.enabled before rescheduling. Also added a pre-execution enabled check as double safety.