From 2ddd24ec1f5cbda3a9c7eff9ebc1a2dba3dd090f Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 8 Aug 2026 13:42:06 +0530 Subject: [PATCH] fix: use is_job_runnable/effective_job_state in remaining pause-check sites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two claim-failure diagnostic paths (cronjob_tools.py:629,921) still used the old inline 'not enabled or state==paused' check. After get_job() normalizes via effective_job_state, a half-paused record has state='scheduled' and enabled=True, so the inline check returned False — mislabeling the job as 'already being fired' instead of 'paused/disabled'. Also hoists effective_job_state/is_job_runnable to the top-level import in cronjob_tools.py (was function-local) and updates console_engine.py's _format_job to use effective_job_state instead of the old inline state-or-enabled derivation — a fourth display path the original PR missed. Follow-up to PR #81287. --- hermes_cli/console_engine.py | 4 +++- tools/cronjob_tools.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hermes_cli/console_engine.py b/hermes_cli/console_engine.py index dd1922af0a..18f9f3e0d4 100644 --- a/hermes_cli/console_engine.py +++ b/hermes_cli/console_engine.py @@ -148,9 +148,11 @@ def _format_sessions(sessions: Sequence[dict]) -> str: def _format_job(job: dict, action: str) -> str: + from cron.jobs import effective_job_state + job_id = job.get("id") or job.get("job_id") or "?" name = job.get("name") or "(unnamed)" - state = job.get("state") or ("scheduled" if job.get("enabled", True) else "paused") + state = effective_job_state(job) return f"{action} job: {name} ({job_id}) [{state}]" diff --git a/tools/cronjob_tools.py b/tools/cronjob_tools.py index 659eb8bec1..de5ba5441b 100644 --- a/tools/cronjob_tools.py +++ b/tools/cronjob_tools.py @@ -40,7 +40,9 @@ sys.path.insert(0, str(Path(__file__).parent.parent)) from cron.jobs import ( AmbiguousJobReference, claim_job_for_fire, + effective_job_state, get_job, + is_job_runnable, list_jobs, mark_job_run, parse_schedule, @@ -552,8 +554,6 @@ def _validate_cron_script_path(script: Optional[str]) -> Optional[str]: def _format_job(job: Dict[str, Any]) -> Dict[str, Any]: - from cron.jobs import effective_job_state - prompt = str(job.get("prompt") or "") skills = _canonical_skills(job.get("skill"), job.get("skills")) job_id = str(job.get("id") or "unknown") @@ -626,7 +626,7 @@ def _execute_job_now( refreshed = get_job(job_id) if refreshed is None: reason = "Job no longer exists; nothing to run." - elif not refreshed.get("enabled", True) or refreshed.get("state") == "paused": + elif not is_job_runnable(refreshed): reason = "Job is paused/disabled; resume it before running." else: reason = "Job is already being fired by the scheduler; not run again." @@ -918,7 +918,7 @@ def _try_dispatch_background_run( refreshed = get_job(job_id) if refreshed is None: reason = "Job no longer exists; nothing to run." - elif not refreshed.get("enabled", True) or refreshed.get("state") == "paused": + elif not is_job_runnable(refreshed): reason = "Job is paused/disabled; resume it before running." else: reason = "Job is already being fired by the scheduler; not run again."