From c5ab76052892552202612b50259fb962d4a819cc Mon Sep 17 00:00:00 2001 From: coffee Date: Fri, 10 Apr 2026 11:36:02 +0800 Subject: [PATCH] fix(cron): missing field init, unnecessary save, and shutdown cleanup 1. Add missing `last_delivery_error` field initialization in `create_job()`. `mark_job_run()` sets this field on line 596 but it was never initialized, causing inconsistent job schemas between new and executed jobs. 2. Replace unnecessary `save_jobs()` call with a warning log when `mark_job_run()` is called with a non-existent job_id. Previously the function would silently write unchanged data to disk. 3. Add `cancel_futures=True` to the `finally` block in cron scheduler's thread pool shutdown. The `except` path already passes this flag but the normal exit path did not, leaving futures running after inactivity timeout detection. --- cron/jobs.py | 5 +++-- cron/scheduler.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cron/jobs.py b/cron/jobs.py index 4096d1fd8..c405d1a6d 100644 --- a/cron/jobs.py +++ b/cron/jobs.py @@ -452,6 +452,7 @@ def create_job( "last_run_at": None, "last_status": None, "last_error": None, + "last_delivery_error": None, # Delivery configuration "deliver": deliver, "origin": origin, # Tracks where job was created for "origin" delivery @@ -620,8 +621,8 @@ def mark_job_run(job_id: str, success: bool, error: Optional[str] = None, save_jobs(jobs) return - - save_jobs(jobs) + + logger.warning("mark_job_run: job_id %s not found, skipping save", job_id) def advance_next_run(job_id: str) -> bool: diff --git a/cron/scheduler.py b/cron/scheduler.py index 23de3ffcc..cdd6877f9 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -769,7 +769,7 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: _cron_pool.shutdown(wait=False, cancel_futures=True) raise finally: - _cron_pool.shutdown(wait=False) + _cron_pool.shutdown(wait=False, cancel_futures=True) if _inactivity_timeout: # Build diagnostic summary from the agent's activity tracker.